Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotfix] Quantization patch; fix semantic_search_faiss/semantic_search_usearch rescoring #2558

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def search(query, top_k: int = 10, rescore_multiplier: int = 4):

# 6. Sort the scores and return the top_k
start_time = time.time()
indices = scores.argsort()[:top_k]
indices = (-scores).argsort()[:top_k]
top_k_indices = binary_ids[indices]
top_k_scores = scores[indices]
sort_time = time.time() - start_time
Expand Down
4 changes: 2 additions & 2 deletions sentence_transformers/quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def semantic_search_faiss(
rescored_scores = np.einsum("ij,ikj->ik", rescore_embeddings, top_k_embeddings)
rescored_indices = np.argsort(-rescored_scores)[:, :top_k]
indices = indices[np.arange(len(query_embeddings))[:, None], rescored_indices]
scores = rescored_scores[:, :top_k]
scores = rescored_scores[np.arange(len(query_embeddings))[:, None], rescored_indices]

delta_t = time.time() - start_t

Expand Down Expand Up @@ -293,7 +293,7 @@ def semantic_search_usearch(
rescored_scores = np.einsum("ij,ikj->ik", rescore_embeddings, top_k_embeddings)
rescored_indices = np.argsort(-rescored_scores)[:, :top_k]
indices = indices[np.arange(len(query_embeddings))[:, None], rescored_indices]
scores = rescored_scores[:, :top_k]
scores = rescored_scores[np.arange(len(query_embeddings))[:, None], rescored_indices]

delta_t = time.time() - start_t

Expand Down
Loading