Spaces:
Sleeping
Sleeping
Create vector_store.py
Browse files- vector_store.py +14 -0
vector_store.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|