Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,14 @@ def load_document_store():
|
|
121 |
print(f"Loaded {len(document_store)} documents into document_store.")
|
122 |
else:
|
123 |
print("Error: knowledgebase.txt not found!")
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
def load_document_store_once(file_path):
|
127 |
"""Loads knowledgebase.txt into a dictionary where FAISS IDs map to text and embeddings"""
|
|
|
121 |
print(f"Loaded {len(document_store)} documents into document_store.")
|
122 |
else:
|
123 |
print("Error: knowledgebase.txt not found!")
|
124 |
+
|
125 |
+
# Generate embeddings for all documents
|
126 |
+
embeddings = bertmodel.encode(all_texts)
|
127 |
+
embeddings = embeddings.astype("float32")
|
128 |
+
|
129 |
+
# Add embeddings to FAISS index
|
130 |
+
index.add_with_ids(embeddings, np.array(list(document_store.keys()), dtype=np.int64))
|
131 |
+
print(f"Added {len(all_texts)} document embeddings to FAISS index.")
|
132 |
|
133 |
def load_document_store_once(file_path):
|
134 |
"""Loads knowledgebase.txt into a dictionary where FAISS IDs map to text and embeddings"""
|