Update retriever.py
Browse files- retriever.py +10 -3
retriever.py
CHANGED
|
@@ -23,12 +23,19 @@ def indexes_loaded() -> bool:
|
|
| 23 |
|
| 24 |
def load_indexes():
|
| 25 |
global _faiss_index, _bm25_index, _chunks, _sources, _model, _reranker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
_faiss_index = faiss.read_index(FAISS_INDEX_PATH)
|
| 27 |
with open(BM25_PATH, "rb") as f: _bm25_index = pickle.load(f)
|
| 28 |
with open(CHUNKS_PATH, "rb") as f: _chunks = pickle.load(f)
|
| 29 |
with open(SOURCES_PATH, "rb") as f: _sources = pickle.load(f)
|
| 30 |
-
_model
|
| 31 |
-
_reranker = CrossEncoder(RERANKER_MODEL)
|
| 32 |
print(f"Indexes loaded: {_faiss_index.ntotal} vectors, {len(_chunks)} chunks")
|
| 33 |
|
| 34 |
|
|
@@ -87,4 +94,4 @@ def hybrid_retrieve(query: str, top_k: int = 5) -> list:
|
|
| 87 |
"ce_score": round(float(score), 4), # ← reranker confidence
|
| 88 |
}
|
| 89 |
for i, score in ranked
|
| 90 |
-
]
|
|
|
|
| 23 |
|
| 24 |
def load_indexes():
|
| 25 |
global _faiss_index, _bm25_index, _chunks, _sources, _model, _reranker
|
| 26 |
+
|
| 27 |
+
# ← ADD THIS GUARD
|
| 28 |
+
import os
|
| 29 |
+
if not os.path.exists(FAISS_INDEX_PATH):
|
| 30 |
+
print("WARNING: No FAISS index found at startup. Upload documents to initialize.")
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
_faiss_index = faiss.read_index(FAISS_INDEX_PATH)
|
| 34 |
with open(BM25_PATH, "rb") as f: _bm25_index = pickle.load(f)
|
| 35 |
with open(CHUNKS_PATH, "rb") as f: _chunks = pickle.load(f)
|
| 36 |
with open(SOURCES_PATH, "rb") as f: _sources = pickle.load(f)
|
| 37 |
+
_model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 38 |
+
_reranker = CrossEncoder(RERANKER_MODEL)
|
| 39 |
print(f"Indexes loaded: {_faiss_index.ntotal} vectors, {len(_chunks)} chunks")
|
| 40 |
|
| 41 |
|
|
|
|
| 94 |
"ce_score": round(float(score), 4), # ← reranker confidence
|
| 95 |
}
|
| 96 |
for i, score in ranked
|
| 97 |
+
]
|