Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,9 +53,18 @@ document_store = {}
|
|
53 |
def initialize_faiss():
|
54 |
if os.path.exists(faiss_index_file):
|
55 |
try:
|
56 |
-
print(f"FAISS index file {faiss_index_file} exists, attempting to load it.")
|
57 |
index = faiss.read_index(faiss_index_file)
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
except Exception as e:
|
60 |
print(f"Error loading FAISS index: {e}, reinitializing a new index.")
|
61 |
index = faiss.IndexIDMap(faiss.IndexFlatL2(384))
|
|
|
53 |
def initialize_faiss():
|
54 |
if os.path.exists(faiss_index_file):
|
55 |
try:
|
56 |
+
print(f"FAISS index file {faiss_index_file} exists, attempting to load it.")
|
57 |
index = faiss.read_index(faiss_index_file)
|
58 |
+
if index.ntotal > 0:
|
59 |
+
print(f"FAISS index loaded with {index.ntotal} vectors.")
|
60 |
+
# If the index has non-zero entries, reset it
|
61 |
+
index.reset() # Resetting the index if non-zero entries
|
62 |
+
print("Index reset. Reinitializing index.")
|
63 |
+
index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Reinitialize the index
|
64 |
+
else:
|
65 |
+
print("Loaded index has zero vectors, reinitializing index.")
|
66 |
+
index = faiss.IndexIDMap(faiss.IndexFlatL2(384)) # Initialize with flat L2 distance
|
67 |
+
|
68 |
except Exception as e:
|
69 |
print(f"Error loading FAISS index: {e}, reinitializing a new index.")
|
70 |
index = faiss.IndexIDMap(faiss.IndexFlatL2(384))
|