Repository navigation
fix: prevent order-dependent BM25 collision weights - #772
RAMZI0TO99 wants to merge 1 commit into
Conversation
|
Thanks for reviewing and merging the other fixes. I rechecked this draft against Which collision policy would you prefer for this PR: summing independently calculated lexical-token weights (the current draft), or aggregating occurrence counts by token ID before applying the BM25 formula? For the example in the description, those give 3.582999598132007 and 1.9936283185840709, respectively. I'll keep this as a draft pending that decision and coordination with core BM25 behavior. Existing token IDs stay unchanged; affected stored document vectors would need recomputation to use the corrected weights consistently. No retrieval-quality improvement or Rust-runtime agreement has been established by these local checks. |
Different BM25 token strings can share an absolute hash ID.
kitchensandprostaglandinshave signed hashes 358434922 and -358434922, respectively. With k=1.2, b=0.75 and avg_len=256, the same bagkitchens kitchens prostaglandinsproduces weight 1.6786885245901642 or 1.904311073541843 depending on order, because later entries overwrite earlier weights.This draft proposes summing separately calculated lexical-token weights at their shared ID, yielding 3.582999598132007 for either ordering. Related: #369. Maintainer input is requested on the collision policy: aggregating counts before the nonlinear BM25 formula is a different approach and yields 1.9936283185840709 for this example. The tests establish approximate order independence and ordinary noncolliding behavior without selecting between those policies.
Existing IDs and hashing are unchanged. This does not eliminate hash aliases; affected stored document vectors need recomputation for consistent corrected weights. No bitwise invariance, Rust-runtime agreement, or retrieval-quality improvement is claimed. The query-index overflow fix is separate and is not included here.
Validation on Windows 11, Python 3.13.5, NumPy 2.3.5, FastEmbed 0.8.1:
python -m pytest -q tests/test_bm25_hash_collisions.py.The full model/OS/Python CI matrix was not run locally.
Split from #766 following the maintainer's request for one PR per problem. This branch is based directly on current main and contains only this problem's production change and regression module.