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

performance: Optimize ColBERT index free search with torch.topk #219

Merged
merged 2 commits into from
Aug 7, 2024
Merged
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
5 changes: 2 additions & 3 deletions ragatouille/models/colbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@ def _index_free_search(
for query in embedded_queries:
results_for_query = []
scores = self._colbert_score(query, embedded_docs, doc_mask)
sorted_scores = sorted(enumerate(scores), key=lambda x: x[1], reverse=True)
high_score_idxes = [index for index, _ in sorted_scores[:k]]
for rank, doc_idx in enumerate(high_score_idxes):
sorted_scores = torch.topk(scores, k)
for rank, doc_idx in enumerate(sorted_scores.indices.tolist()):
result = {
"content": documents[doc_idx],
"score": float(scores[doc_idx]),
Expand Down
Loading