Skip to content

Commit

Permalink
Fix semantic_search_usearch() for single query (#2572)
Browse files Browse the repository at this point in the history
This patch fixes a bug where the semantic_search_usearch() method would
fail with `TypeError: 'numpy.float32' object is not iterable` where only
a single query is used.
  • Loading branch information
karmi authored Apr 4, 2024
1 parent 0253363 commit 3f4067f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sentence_transformers/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ def semantic_search_usearch(
scores = matches.distances
indices = matches.keys

if scores.ndim < 2:
scores = np.atleast_2d(scores)
if indices.ndim < 2:
indices = np.atleast_2d(indices)

# If rescoring is enabled, we need to rescore the results using the rescore_embeddings
if rescore_embeddings is not None:
top_k_embeddings = np.array([corpus_index.get(query_indices) for query_indices in indices])
Expand Down

0 comments on commit 3f4067f

Please sign in to comment.