saherPervaiz commited on
Commit
1b0b844
·
verified ·
1 Parent(s): 8d505f4

Update vector_store.py

Browse files
Files changed (1) hide show
  1. vector_store.py +16 -7
vector_store.py CHANGED
@@ -1,14 +1,23 @@
1
  # vector_store.py
 
2
  import faiss
3
  import numpy as np
4
 
5
  def create_faiss_index(vectors):
6
- dim = vectors[0].shape[0]
7
- index = faiss.IndexFlatL2(dim)
8
- index.add(np.array(vectors))
9
- return index
 
 
 
 
10
 
11
  def search_similar_cvs(query_vector, index, k=3):
12
- query_vector = np.array([query_vector])
13
- distances, indices = index.search(query_vector, k)
14
- return indices[0].tolist()
 
 
 
 
 
1
  # vector_store.py
2
+
3
  import faiss
4
  import numpy as np
5
 
6
  def create_faiss_index(vectors):
7
+ try:
8
+ dim = vectors[0].shape[0]
9
+ index = faiss.IndexFlatL2(dim)
10
+ index.add(np.array(vectors).astype("float32"))
11
+ return index
12
+ except Exception as e:
13
+ print(f"❌ Error creating FAISS index: {e}")
14
+ return None
15
 
16
  def search_similar_cvs(query_vector, index, k=3):
17
+ try:
18
+ query_vector = np.array([query_vector]).astype("float32")
19
+ distances, indices = index.search(query_vector, k)
20
+ return indices[0].tolist()
21
+ except Exception as e:
22
+ print(f"❌ Error searching index: {e}")
23
+ return []