Spaces:
Sleeping
Sleeping
File size: 567 Bytes
709c859 29204d1 46670de f129d48 3298e37 f129d48 46670de 29204d1 3298e37 46670de 3298e37 46670de f129d48 46670de f129d48 42d0898 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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]]
|