Spaces:
Running
on
Zero
Running
on
Zero
Update main.py
Browse files
main.py
CHANGED
@@ -28,12 +28,12 @@ data.reset_index(inplace=True)
|
|
28 |
# Create a FAISS index for fast similarity search
|
29 |
index = faiss.IndexFlatL2(len(data["embedding"][0]))
|
30 |
index.metric_type = faiss.METRIC_INNER_PRODUCT
|
31 |
-
index.add(numpy.stack(data["embedding"].to_list(), axis=0))
|
32 |
|
33 |
|
34 |
# Define the search function
|
35 |
def search(query: str, k: int):
|
36 |
-
query = numpy.expand_dims(model.encode(query), axis=0)
|
37 |
D, I = index.search(query, k)
|
38 |
top_five = data.loc[I[0]]
|
39 |
search_results = ""
|
|
|
28 |
# Create a FAISS index for fast similarity search
|
29 |
index = faiss.IndexFlatL2(len(data["embedding"][0]))
|
30 |
index.metric_type = faiss.METRIC_INNER_PRODUCT
|
31 |
+
index.add(numpy.stack(faiss.normalize_L2(data["embedding"].to_list()), axis=0))
|
32 |
|
33 |
|
34 |
# Define the search function
|
35 |
def search(query: str, k: int):
|
36 |
+
query = numpy.expand_dims(faiss.normalize_L2(model.encode(query)), axis=0)
|
37 |
D, I = index.search(query, k)
|
38 |
top_five = data.loc[I[0]]
|
39 |
search_results = ""
|