File size: 594 Bytes
e490ab5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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/")