Spaces:
Sleeping
Sleeping
Update vector_store.py
Browse files- 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 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def search_similar_cvs(query_vector, index, k=3):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 []
|