Spaces:
Sleeping
Sleeping
| import os | |
| import pickle | |
| import faiss | |
| from config import FAISS_INDEX_PATH, DOCS_PATH, TOP_K | |
| def load_index(): | |
| if not os.path.exists(FAISS_INDEX_PATH): | |
| raise RuntimeError("❌ FAISS index not found. Click 'Build Index' first.") | |
| index = faiss.read_index(FAISS_INDEX_PATH) | |
| with open(DOCS_PATH, "rb") as f: | |
| documents = pickle.load(f) | |
| return index, documents | |
| def retrieve(query_embedding): | |
| index, documents = load_index() | |
| distances, indices = index.search(query_embedding, TOP_K) | |
| return [documents[i] for i in indices[0]] | |