Semantic-search-cache / src /vector_store.py
YENUGU SUJITH REDDY
Initial commit with Git LFS models
45fe8b6
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