Spaces:
Sleeping
Sleeping
| # vector_store.py | |
| import faiss | |
| import numpy as np | |
| def create_faiss_index(vectors): | |
| try: | |
| dim = vectors[0].shape[0] | |
| index = faiss.IndexFlatL2(dim) | |
| index.add(np.array(vectors).astype("float32")) | |
| return index | |
| except Exception as e: | |
| print(f"β Error creating FAISS index: {e}") | |
| return None | |
| def search_similar_cvs(query_vector, index, k=3): | |
| try: | |
| query_vector = np.array([query_vector]).astype("float32") | |
| distances, indices = index.search(query_vector, k) | |
| return indices[0].tolist() | |
| except Exception as e: | |
| print(f"β Error searching index: {e}") | |
| return [] | |