Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -99,6 +99,9 @@ def save_documents(documents):
|
|
99 |
uploaded_documents = load_documents()
|
100 |
|
101 |
# Modify the update_vectors function
|
|
|
|
|
|
|
102 |
def update_vectors(files, parser):
|
103 |
global uploaded_documents
|
104 |
logging.info(f"Entering update_vectors with {len(files)} files and parser: {parser}")
|
@@ -139,14 +142,14 @@ def update_vectors(files, parser):
|
|
139 |
if os.path.exists("faiss_database"):
|
140 |
logging.info("Updating existing FAISS database")
|
141 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
142 |
-
initial_size =
|
143 |
database.add_documents(all_data)
|
144 |
-
final_size =
|
145 |
logging.info(f"FAISS database updated. Initial size: {initial_size}, Final size: {final_size}")
|
146 |
else:
|
147 |
logging.info("Creating new FAISS database")
|
148 |
database = FAISS.from_documents(all_data, embed)
|
149 |
-
logging.info(f"New FAISS database created with {
|
150 |
|
151 |
database.save_local("faiss_database")
|
152 |
logging.info("FAISS database saved")
|
|
|
99 |
uploaded_documents = load_documents()
|
100 |
|
101 |
# Modify the update_vectors function
|
102 |
+
from langchain.vectorstores import FAISS
|
103 |
+
import faiss
|
104 |
+
|
105 |
def update_vectors(files, parser):
|
106 |
global uploaded_documents
|
107 |
logging.info(f"Entering update_vectors with {len(files)} files and parser: {parser}")
|
|
|
142 |
if os.path.exists("faiss_database"):
|
143 |
logging.info("Updating existing FAISS database")
|
144 |
database = FAISS.load_local("faiss_database", embed, allow_dangerous_deserialization=True)
|
145 |
+
initial_size = database.index.ntotal
|
146 |
database.add_documents(all_data)
|
147 |
+
final_size = database.index.ntotal
|
148 |
logging.info(f"FAISS database updated. Initial size: {initial_size}, Final size: {final_size}")
|
149 |
else:
|
150 |
logging.info("Creating new FAISS database")
|
151 |
database = FAISS.from_documents(all_data, embed)
|
152 |
+
logging.info(f"New FAISS database created with {database.index.ntotal} vectors")
|
153 |
|
154 |
database.save_local("faiss_database")
|
155 |
logging.info("FAISS database saved")
|