Spaces:
Runtime error
Runtime error
Fix FAISS search() API compatibility for newer versions
Browse filesfaiss >= 1.9 requires pre-allocated output arrays passed explicitly as
positional args: index.search(x, k, distances, labels).
The old two-return-value form broke on the HF Space runtime.
Generated with [Devin](https://cli.devin.ai/docs)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- retrieval.py +5 -1
retrieval.py
CHANGED
|
@@ -57,7 +57,11 @@ def retrieve(query: str,
|
|
| 57 |
query_embedding = model.encode([query], normalize_embeddings=True)
|
| 58 |
query_embedding = np.array(query_embedding, dtype='float32')
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
results = []
|
| 63 |
for score, idx in zip(scores[0], indices[0]):
|
|
|
|
| 57 |
query_embedding = model.encode([query], normalize_embeddings=True)
|
| 58 |
query_embedding = np.array(query_embedding, dtype='float32')
|
| 59 |
|
| 60 |
+
# Pre-allocate output arrays for FAISS compatibility across API versions
|
| 61 |
+
distances = np.empty((1, top_k), dtype='float32')
|
| 62 |
+
labels = np.empty((1, top_k), dtype='int64')
|
| 63 |
+
index.search(query_embedding, top_k, distances, labels)
|
| 64 |
+
scores, indices = distances, labels
|
| 65 |
|
| 66 |
results = []
|
| 67 |
for score, idx in zip(scores[0], indices[0]):
|