You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix BM25 term frequency for colliding token IDs - #942
Two distinct BM25 terms can hash to the same sparse index. When their frequencies differ, the last distinct term to be processed overwrites the weight at that index, so reordering the same document changes its embedding.
Count occurrences per hashed index before applying BM25 saturation. The regression test uses two real colliding tokens in both orders and checks the expected weight, a non-colliding document, and binary query weights. It runs without downloading a model.
Local validation: 9 focused tests passed, along with the Ruff lint and format hooks. The full multi-model test suite is left to CI.
All Submissions:
Have you followed the guidelines in our Contributing document?
Have you checked to ensure there aren't other open Pull Requests for the same update/change?
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
No actionable comments were generated in the recent review.
Walkthrough
Bm25._term_frequency now combines occurrence counts for stems that share a hashed token ID before applying BM25 saturation. A regression test checks document weights for colliding and distinct tokens, verifies that token order does not affect collision weights, and confirms that query embeddings retain unit weights.
This fixes order-dependent BM25 weights when different terms hash to the same sparse index. The change is small and has regression coverage, so no merge-blocking risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the actual change: BM25 term frequency is now computed per hashed token ID so colliding IDs no longer overwrite each other. It matches the raw summary and the PR objectives, and it is …
Description check
The description explains the problem (distinct BM25 terms hashing to the same sparse index overwrite each other, making embeddings order-dependent), the fix (count occurrences per hashed index before …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the actual change: BM25 term frequency is now computed per hashed token ID so colliding IDs no longer overwrite each other. It matches the raw summary and the PR objectives, and it is specific enough for a reviewer scanning history.
Full details: Description check
Explanation
The description explains the problem (distinct BM25 terms hashing to the same sparse index overwrite each other, making embeddings order-dependent), the fix (count occurrences per hashed index before BM25 saturation), the regression test, and local validation. It is related to the changeset and fully on-topic.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: e2467bdc-2d01-4170-b24c-43845a425803
Commits
Reviewing files that changed from the base of the PR and between ac9ab5c and db90a43.
Files selected for processing: 2
fastembed/sparse/bm25.py
tests/test_sparse_embeddings.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two distinct BM25 terms can hash to the same sparse index. When their frequencies differ, the last distinct term to be processed overwrites the weight at that index, so reordering the same document changes its embedding.
Count occurrences per hashed index before applying BM25 saturation. The regression test uses two real colliding tokens in both orders and checks the expected weight, a non-colliding document, and binary query weights. It runs without downloading a model.
Local validation: 9 focused tests passed, along with the Ruff lint and format hooks. The full multi-model test suite is left to CI.
All Submissions: