Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from langchain.chains import create_history_aware_retriever
|
|
9 |
from langchain.memory import ChatMessageHistory
|
10 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
11 |
from langchain_pinecone import PineconeVectorStore
|
|
|
|
|
12 |
from langchain.schema import Document
|
13 |
from dotenv import load_dotenv
|
14 |
from prompt import system_prompt, retriever_prompt
|
@@ -199,7 +201,25 @@ PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY')
|
|
199 |
os.environ['PINECONE_API_KEY'] = PINECONE_API_KEY
|
200 |
|
201 |
index_name = 'humblebeeai'
|
|
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
docsearch = PineconeVectorStore.from_documents(
|
204 |
documents=text_chunks,
|
205 |
index_name=index_name,
|
|
|
9 |
from langchain.memory import ChatMessageHistory
|
10 |
from langchain_core.runnables.history import RunnableWithMessageHistory
|
11 |
from langchain_pinecone import PineconeVectorStore
|
12 |
+
from pinecone.grpc import PineconeGRPC as Pinecone
|
13 |
+
from pinecone import ServerlessSpec
|
14 |
from langchain.schema import Document
|
15 |
from dotenv import load_dotenv
|
16 |
from prompt import system_prompt, retriever_prompt
|
|
|
201 |
os.environ['PINECONE_API_KEY'] = PINECONE_API_KEY
|
202 |
|
203 |
index_name = 'humblebeeai'
|
204 |
+
pc = Pinecone(api_key=PINECONE_API_KEY)
|
205 |
|
206 |
+
existing_indexes = [index['name'] for index in pc.list_indexes()]
|
207 |
+
if index_name in existing_indexes:
|
208 |
+
print(f"🟢 Index '{index_name}' already exists. Skipping creation.")
|
209 |
+
else:
|
210 |
+
print(f"🔴 Index '{index_name}' not found. Creating it now...")
|
211 |
+
|
212 |
+
pc.create_index(
|
213 |
+
name=index_name,
|
214 |
+
dimension=384, # Adjust the dimension based on your embeddings
|
215 |
+
metric="cosine",
|
216 |
+
spec=ServerlessSpec(
|
217 |
+
cloud="aws",
|
218 |
+
region="us-east-1"
|
219 |
+
)
|
220 |
+
)
|
221 |
+
|
222 |
+
print(f"✅ Index '{index_name}' created successfully.")
|
223 |
docsearch = PineconeVectorStore.from_documents(
|
224 |
documents=text_chunks,
|
225 |
index_name=index_name,
|