Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -436,29 +436,12 @@ def load_main_data_source():
|
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
Refresh or initialize the FAISS index with updated documents.
|
| 443 |
-
"""
|
| 444 |
-
try:
|
| 445 |
-
if documents is None or not isinstance(documents, list):
|
| 446 |
-
st.error("No valid documents provided to refresh the FAISS index.")
|
| 447 |
-
return
|
| 448 |
-
|
| 449 |
embeddings = OpenAIEmbeddings()
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
if "faiss_db" not in st.session_state:
|
| 453 |
-
st.session_state["faiss_db"] = FAISS.from_documents(documents, embeddings)
|
| 454 |
-
st.success("FAISS database initialized.")
|
| 455 |
-
else:
|
| 456 |
-
# Add/Update specific documents in the index
|
| 457 |
-
st.session_state["faiss_db"].add_documents(documents, embeddings)
|
| 458 |
-
st.success("Documents added to FAISS database.")
|
| 459 |
-
except Exception as e:
|
| 460 |
-
st.error(f"Error refreshing FAISS index: {e}")
|
| 461 |
-
|
| 462 |
|
| 463 |
|
| 464 |
def update_message_counter():
|
|
|
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
+
def refresh_faiss_index():
|
| 440 |
+
combined_sources = load_main_data_source()
|
| 441 |
+
if combined_sources:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
embeddings = OpenAIEmbeddings()
|
| 443 |
+
db_faiss = FAISS.from_documents(combined_sources, embeddings)
|
| 444 |
+
st.session_state["faiss_db"] = db_faiss
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
|
| 446 |
|
| 447 |
def update_message_counter():
|