Spaces:
Running
Running
daniel.diaz
commited on
Commit
·
c8801fd
1
Parent(s):
6342765
Update app.py
Browse files
app.py
CHANGED
@@ -23,20 +23,17 @@ def embed_query(text):
|
|
23 |
# Semantic search using FAISS (for older FAISS versions)
|
24 |
|
25 |
# Semantic search with fallback handling
|
|
|
|
|
26 |
def search(query, k=3):
|
27 |
query_vec = embed_query(query).astype(np.float32)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
distances = np.empty((1, k), dtype=np.float32)
|
36 |
-
labels = np.empty((1, k), dtype=np.int64)
|
37 |
-
index.search(query_vec, k, distances, labels)
|
38 |
-
except Exception as e:
|
39 |
-
raise RuntimeError(f"FAISS search failed: {e}")
|
40 |
|
41 |
return [chunks[i] for i in labels[0]]
|
42 |
|
|
|
23 |
# Semantic search using FAISS (for older FAISS versions)
|
24 |
|
25 |
# Semantic search with fallback handling
|
26 |
+
|
27 |
+
# Semantic search using FAISS - strictly for older API with preallocated arrays
|
28 |
def search(query, k=3):
|
29 |
query_vec = embed_query(query).astype(np.float32)
|
30 |
|
31 |
+
# Preallocate arrays (required for FAISS IndexFlatL2 in older versions)
|
32 |
+
distances = np.empty((1, k), dtype=np.float32)
|
33 |
+
labels = np.empty((1, k), dtype=np.int64)
|
34 |
+
|
35 |
+
# Call FAISS with all required arguments
|
36 |
+
index.search(query_vec, k, distances, labels)
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
return [chunks[i] for i in labels[0]]
|
39 |
|