|
5 | 5 | from uuid import UUID, uuid4
|
6 | 6 |
|
7 | 7 | import s3fs
|
| 8 | +from fastapi import HTTPException |
8 | 9 | from llama_index.core import (ServiceContext, Settings, SimpleDirectoryReader,
|
9 | 10 | StorageContext, SummaryIndex, TreeIndex,
|
10 | 11 | VectorStoreIndex, load_index_from_storage)
|
|
15 | 16 | from llama_index.vector_stores.pinecone import PineconeVectorStore
|
16 | 17 | from llama_index.vector_stores.weaviate import WeaviateVectorStore
|
17 | 18 | from llama_index.vector_stores.zep import ZepVectorStore
|
| 19 | +from pinecone import Pinecone, ServerlessSpec |
18 | 20 |
|
19 | 21 | from config import Config
|
20 | 22 | from services.aws_s3 import AWSS3Service
|
@@ -93,20 +95,28 @@ def get_vector_store(self, is_retriever: bool = False):
|
93 | 95 | embedding_dimensions=1536,
|
94 | 96 | )
|
95 | 97 | elif self.vector_store == VectorStoreProvider.PINECONE.value:
|
96 |
| - import pinecone |
97 |
| - |
98 | 98 | # Pinecone only supports alphanumeric characters. Max length 40
|
99 | 99 | index_name = UUID(self.datasource_id).hex
|
100 | 100 |
|
101 |
| - pinecone.init( |
| 101 | + # pinecone.init( |
| 102 | + # api_key=self.settings.pinecone_api_key, |
| 103 | + # environment=self.settings.pinecone_environment, |
| 104 | + # ) |
| 105 | + |
| 106 | + pc = Pinecone( |
102 | 107 | api_key=self.settings.pinecone_api_key,
|
103 | 108 | environment=self.settings.pinecone_environment,
|
104 | 109 | )
|
105 | 110 |
|
106 | 111 | if not is_retriever:
|
107 |
| - pinecone.create_index(index_name, dimension=1536, metric="cosine") |
108 |
| - |
109 |
| - pinecone_index = pinecone.Index(index_name) |
| 112 | + pc.create_index( |
| 113 | + index_name, |
| 114 | + dimension=1536, |
| 115 | + metric="cosine", |
| 116 | + spec=ServerlessSpec(cloud="aws", region="us-west-2"), |
| 117 | + ) |
| 118 | + |
| 119 | + pinecone_index = pc.Index(index_name) |
110 | 120 |
|
111 | 121 | vector_store = PineconeVectorStore(
|
112 | 122 | pinecone_index=pinecone_index,
|
|
0 commit comments