fix(python): average MRR reciprocal ranks over all rankings#3599
Merged
Conversation
wjones127
self-requested a review
July 1, 2026 22:15
wjones127
approved these changes
Jul 1, 2026
wjones127
left a comment
Contributor
There was a problem hiding this comment.
Excellent fix. I appreciate the clear PR description and the unit test. 🙌
Contributor
Author
|
Always a pleasure! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
MRRReranker.rerank_multivectoraverages each document's reciprocal ranks over the wrong denominator. It divides by the number of rankings the document happens to appear in, instead of the total number of rankings being fused.mrr_score_map[doc]only accumulates a reciprocal rank for the systems in which the document was returned, sonp.meannever accounts for the systems that missed it.Why it's wrong
Mean Reciprocal Rank fusion treats a system that didn't return a document as a reciprocal rank of
0and averages across all systems. That's the exact mechanism by which it rewards cross-system consensus. Dividing by the appearance count removes that, so a document liked by a single ranking can beat one ranked highly by every ranking.Concretely, fusing 3 vector rankings:
mean([1.0]) = 1.0001.0 / 3 = 0.333mean([1, 1, .5]) = 0.8332.5 / 3 = 0.833The current code ranks A above B - a document two of three rankings ignored outranks one all three ranked at or near the top.
This also makes
rerank_multivectorinconsistent withrerank_hybridin the same file, which already treats a missing system as0(vector_rr = 0.0/fts_rr = 0.0), and with the class docstring ("average of reciprocal ranks across different search results").Fix
Divide the summed reciprocal ranks by the total number of rankings:
Tests
Adds
test_mrr_multivector_rewards_consensus, which asserts the exact MRR scores and that the consensus document ranks first. It fails onmainand passes with this change. Existing reranker tests are unaffected.