Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,15 +37,29 @@ def doc_preprocessing():
|
|
37 |
def embedding_db():
|
38 |
# we use the openAI embedding model
|
39 |
embeddings = OpenAIEmbeddings()
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
)
|
|
|
44 |
docs_split = doc_preprocessing()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
doc_db = Pinecone.from_documents(
|
46 |
-
docs_split,
|
47 |
-
embeddings,
|
48 |
-
index_name='langchain-demo-indexes'
|
|
|
49 |
)
|
50 |
return doc_db
|
51 |
|
|
|
37 |
def embedding_db():
|
38 |
# we use the openAI embedding model
|
39 |
embeddings = OpenAIEmbeddings()
|
40 |
+
|
41 |
+
# Initialize Pinecone
|
42 |
+
pc = Pinecone(
|
43 |
+
api_key=PINECONE_API_KEY,
|
44 |
+
environment=PINECONE_ENV
|
45 |
)
|
46 |
+
|
47 |
docs_split = doc_preprocessing()
|
48 |
+
|
49 |
+
# Check if index exists, create if needed
|
50 |
+
if 'langchain-demo-indexes' not in pc.list_indexes().names():
|
51 |
+
pc.create_index(
|
52 |
+
name='langchain-demo-indexes',
|
53 |
+
dimension=1536, # Adjust dimension if needed
|
54 |
+
metric='euclidean',
|
55 |
+
spec=ServerlessSpec(cloud='aws', region='us-west-2')
|
56 |
+
)
|
57 |
+
|
58 |
doc_db = Pinecone.from_documents(
|
59 |
+
docs_split,
|
60 |
+
embeddings,
|
61 |
+
index_name='langchain-demo-indexes',
|
62 |
+
client=pc # Pass the Pinecone object
|
63 |
)
|
64 |
return doc_db
|
65 |
|