File size: 658 Bytes
ba68800
1b0b844
ba68800
 
 
 
1b0b844
 
 
 
 
 
 
 
ba68800
 
1b0b844
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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 []