Shreyas094 commited on
Commit
2e0823c
·
verified ·
1 Parent(s): f01b00a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -133,11 +133,17 @@ def delete_files(files_to_delete):
133
  embed = get_embeddings()
134
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
135
 
136
- # Remove documents from the database
137
- database.delete(lambda doc: doc.metadata["source"] in deleted_files)
 
 
 
 
 
 
138
 
139
  # Save the updated database
140
- database.save_local("faiss_database")
141
 
142
  # Update the document selector
143
  updated_selector = gr.CheckboxGroup(
 
133
  embed = get_embeddings()
134
  database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
135
 
136
+ # Create a new list of documents, excluding the deleted ones
137
+ new_docs = []
138
+ for i, doc_id in enumerate(database.index_to_docstore_id.values()):
139
+ if database.docstore._dict[doc_id].metadata["source"] not in deleted_files:
140
+ new_docs.append(database.docstore._dict[doc_id])
141
+
142
+ # Create a new FAISS index with the remaining documents
143
+ new_db = FAISS.from_documents(new_docs, embed)
144
 
145
  # Save the updated database
146
+ new_db.save_local("faiss_database")
147
 
148
  # Update the document selector
149
  updated_selector = gr.CheckboxGroup(