Spaces:
Sleeping
Sleeping
File size: 443 Bytes
45fe8b6 | 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 | import faiss
import numpy as np
import os
def build_faiss_index(embeddings):
dimension = embeddings.shape[1]
index = faiss.IndexFlatL2(dimension)
index.add(np.array(embeddings))
return index
def save_index(index, path="models/faiss_index"):
faiss.write_index(index, path)
def load_index(path="models/faiss_index"):
if os.path.exists(path):
return faiss.read_index(path)
else:
return None |