Spaces:
Sleeping
Sleeping
| # build_index.py | |
| import os | |
| import json | |
| import pickle | |
| import faiss | |
| import numpy as np | |
| from embeddings import get_embedding | |
| DOCS_FILE = "data/documents.json" | |
| with open(DOCS_FILE, "r") as f: | |
| docs = json.load(f) | |
| # Compute embeddings | |
| embs = [get_embedding(d["section"]) for d in docs] | |
| # Create FAISS index | |
| dim = len(embs[0]) | |
| index = faiss.IndexFlatL2(dim) | |
| index.add(np.array(embs).astype("float32")) | |
| # Save outputs for the Space runtime | |
| faiss.write_index(index, "data/index.faiss") | |
| with open("data/docs.pkl", "wb") as f: | |
| pickle.dump(docs, f) | |
| print("✅ Index and docs saved to data/") | |