wt002 commited on
Commit
b687404
·
verified ·
1 Parent(s): 880ec62

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +11 -8
agent.py CHANGED
@@ -430,21 +430,24 @@ embedding_model = HuggingFaceEmbeddings(
430
  # Create FAISS index and save it
431
  # -----------------------------
432
  try:
433
- vector_store = FAISS.load_local(
434
- "/home/wendy/my_hf_agent_course_projects/faiss_index",
435
- embedding_model,
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
- loaded_store = FAISS.load_local("/home/wendy/my_hf_agent_course_projects/faiss_index/index.faiss", embedding_model, allow_dangerous_deserialization=True)
 
 
 
 
 
 
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
  # -----------------------------