DrishtiSharma commited on
Commit
60453ba
·
verified ·
1 Parent(s): b66466a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -135,15 +135,22 @@ def initialize_vector_store(documents, persist_dir):
135
  """
136
  Initialize the vector store with the provided documents.
137
  """
138
- embeddings = HuggingFaceEmbeddings()
139
- vectordb = Chroma.from_documents(
140
- documents=documents,
141
- embedding_function=embeddings.embed_query, # Use .embed_query explicitly
142
- persist_directory=persist_dir
143
- )
144
- vectordb.persist() # Persist the vector store to disk
145
- return vectordb
 
 
 
 
146
 
 
 
 
147
 
148
  def create_retriever(vectordb):
149
  """
 
135
  """
136
  Initialize the vector store with the provided documents.
137
  """
138
+ try:
139
+ # Initialize HuggingFace embeddings
140
+ embeddings = HuggingFaceEmbeddings()
141
+
142
+ # Create a Chroma vector store with the embeddings
143
+ vectordb = Chroma.from_documents(
144
+ documents=documents,
145
+ embedding=embeddings, # Pass embeddings directly
146
+ persist_directory=persist_dir
147
+ )
148
+ vectordb.persist() # Persist the vector store to disk
149
+ return vectordb
150
 
151
+ except Exception as e:
152
+ st.error(f"Failed to initialize the vector store: {e}")
153
+ st.stop()
154
 
155
  def create_retriever(vectordb):
156
  """