Update app.py
Browse files
app.py
CHANGED
@@ -448,6 +448,33 @@ class OptimizedRAGLoader:
|
|
448 |
for i, chunk in enumerate(chunks)
|
449 |
]
|
450 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
def create_index(self, documents=None):
|
452 |
if documents is None:
|
453 |
documents = self.load_and_split_texts()
|
|
|
448 |
for i, chunk in enumerate(chunks)
|
449 |
]
|
450 |
|
451 |
+
def load_index(self) -> bool:
|
452 |
+
"""
|
453 |
+
Charge l'index FAISS et les documents associés s'ils existent
|
454 |
+
|
455 |
+
Returns:
|
456 |
+
bool: True si l'index a été chargé, False sinon
|
457 |
+
"""
|
458 |
+
if not self._index_exists():
|
459 |
+
print("Aucun index trouvé.")
|
460 |
+
return False
|
461 |
+
|
462 |
+
print("Chargement de l'index existant...")
|
463 |
+
try:
|
464 |
+
# Charger l'index FAISS
|
465 |
+
self.index = faiss.read_index(str(self.index_path))
|
466 |
+
|
467 |
+
# Charger les documents associés
|
468 |
+
with open(self.documents_path, 'rb') as f:
|
469 |
+
self.indexed_documents = pickle.load(f)
|
470 |
+
|
471 |
+
print(f"Index chargé avec {self.index.ntotal} vecteurs")
|
472 |
+
return True
|
473 |
+
|
474 |
+
except Exception as e:
|
475 |
+
print(f"Erreur lors du chargement de l'index: {e}")
|
476 |
+
return False
|
477 |
+
|
478 |
def create_index(self, documents=None):
|
479 |
if documents is None:
|
480 |
documents = self.load_and_split_texts()
|