YALCINKAYA commited on
Commit
5ded1b4
·
verified ·
1 Parent(s): 7dbd1c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -54,17 +54,22 @@ document_store = {}
54
  def initialize_faiss():
55
  if os.path.exists(faiss_index_file):
56
  try:
 
57
  index = faiss.read_index(faiss_index_file)
58
  if index.ntotal > 0:
59
  print(f"FAISS index loaded with {index.ntotal} vectors.")
 
60
  index.reset() # Resetting the index if non-zero entries
 
61
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Reinitialize the index
62
  else:
 
63
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize with flat L2 distance
64
  except Exception as e:
65
  print(f"Error loading FAISS index: {e}, reinitializing.")
66
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize if reading fails
67
  else:
 
68
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize if file doesn't exist
69
 
70
  # Check if GPU is available and move index to GPU if possible
 
54
  def initialize_faiss():
55
  if os.path.exists(faiss_index_file):
56
  try:
57
+ print(f"Attempting to load FAISS index from {faiss_index_file}.")
58
  index = faiss.read_index(faiss_index_file)
59
  if index.ntotal > 0:
60
  print(f"FAISS index loaded with {index.ntotal} vectors.")
61
+ # If the index has non-zero entries, reset it
62
  index.reset() # Resetting the index if non-zero entries
63
+ print("Index reset. Reinitializing index.")
64
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Reinitialize the index
65
  else:
66
+ print("Loaded index has zero vectors, reinitializing index.")
67
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize with flat L2 distance
68
  except Exception as e:
69
  print(f"Error loading FAISS index: {e}, reinitializing.")
70
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize if reading fails
71
  else:
72
+ print(f"FAISS index file {faiss_index_file} does not exist, initializing a new index.")
73
  index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize if file doesn't exist
74
 
75
  # Check if GPU is available and move index to GPU if possible