Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -430,21 +430,24 @@ embedding_model = HuggingFaceEmbeddings(
|
|
430 |
# Create FAISS index and save it
|
431 |
# -----------------------------
|
432 |
try:
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
allow_dangerous_deserialization=True
|
437 |
-
)
|
438 |
except Exception as e:
|
439 |
print(f"Error loading index: {str(e)}")
|
440 |
-
# Fallback to rebuilding index
|
441 |
vector_store = FAISS.from_documents(docs, embedding_model)
|
442 |
|
443 |
-
|
444 |
# -----------------------------
|
445 |
# Load FAISS index properly
|
446 |
# -----------------------------
|
447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
|
449 |
|
450 |
# -----------------------------
|
|
|
430 |
# Create FAISS index and save it
|
431 |
# -----------------------------
|
432 |
try:
|
433 |
+
# Make sure to pass the directory, not the file path
|
434 |
+
index_dir = "/home/wendy/my_hf_agent_course_projects/faiss_index"
|
435 |
+
vector_store = FAISS.load_local(index_dir, embedding_model, allow_dangerous_deserialization=True)
|
|
|
|
|
436 |
except Exception as e:
|
437 |
print(f"Error loading index: {str(e)}")
|
438 |
+
# Fallback to rebuilding the index if loading fails
|
439 |
vector_store = FAISS.from_documents(docs, embedding_model)
|
440 |
|
|
|
441 |
# -----------------------------
|
442 |
# Load FAISS index properly
|
443 |
# -----------------------------
|
444 |
+
# Ensure the directory path is correct and points to the index file directly
|
445 |
+
index_path = "/home/wendy/my_hf_agent_course_projects/faiss_index/index.faiss"
|
446 |
+
try:
|
447 |
+
loaded_store = FAISS.load_local(index_path, embedding_model, allow_dangerous_deserialization=True)
|
448 |
+
print("FAISS index loaded successfully")
|
449 |
+
except Exception as e:
|
450 |
+
print(f"Error loading FAISS index: {str(e)}")
|
451 |
|
452 |
|
453 |
# -----------------------------
|