ababio commited on
Commit
cd986d0
1 Parent(s): 16fef80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -6,23 +6,25 @@ from openai import OpenAI
6
  from llama_index.node_parser import SemanticSplitterNodeParser
7
  from llama_index.embeddings import OpenAIEmbedding
8
  from llama_index.ingestion import IngestionPipeline
9
- from pinecone.grpc import PineconeGRPC
10
- from llama_index.vector_stores import PineconeVectorStore
11
- from llama_index import VectorStoreIndex
12
- from llama_index.retrievers import VectorIndexRetriever
13
- from llama_index.query_engine import RetrieverQueryEngine
14
 
15
  # Set OpenAI API key from Streamlit secrets
 
16
  openai_api_key = os.getenv("OPENAI_API_KEY")
17
- pinecone_api_key = os.getenv("PINECONE_API_KEY")
18
 
19
  # Initialize OpenAI client
20
  client = OpenAI(api_key=openai_api_key)
21
 
22
  # Initialize Pinecone connection
23
- pc = PineconeGRPC(api_key=pinecone_api_key)
24
  index_name = "annualreport"
25
- pinecone_index = pc.Index(index_name)
 
 
 
 
 
 
26
  vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
27
 
28
  # Initialize vector index and retriever
 
6
  from llama_index.node_parser import SemanticSplitterNodeParser
7
  from llama_index.embeddings import OpenAIEmbedding
8
  from llama_index.ingestion import IngestionPipeline
9
+ from pinecone import PineconeClient, Index, create_index
 
 
 
 
10
 
11
  # Set OpenAI API key from Streamlit secrets
12
+ pinecone_api_key = os.getenv("PINECONE_API_KEY")
13
  openai_api_key = os.getenv("OPENAI_API_KEY")
 
14
 
15
  # Initialize OpenAI client
16
  client = OpenAI(api_key=openai_api_key)
17
 
18
  # Initialize Pinecone connection
19
+ pinecone_client = PineconeClient(api_key=pinecone_api_key)
20
  index_name = "annualreport"
21
+
22
+ # Check if the index exists, if not, create it
23
+ if index_name not in pinecone_client.list_indexes():
24
+ create_index(name=index_name, dimension=1536) # Dimension should match your embedding model
25
+
26
+ # Initialize Pinecone index
27
+ pinecone_index = Index(index_name)
28
  vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
29
 
30
  # Initialize vector index and retriever