fix(reranker): detect pre-normalized scores and use rank-based normalization#1512
Open
xuli500177 wants to merge 2 commits into
Open
fix(reranker): detect pre-normalized scores and use rank-based normalization#1512xuli500177 wants to merge 2 commits into
xuli500177 wants to merge 2 commits into
Conversation
…ization External API rerankers (SiliconFlow, Cohere, etc.) return pre-normalized relevance_score in [0, 1] with very small absolute values. Applying sigmoid to these compresses everything to ~0.5, destroying the ranking signal and making recency the sole sorting factor. This fix detects the score range: - If all scores are in [0, 1]: use rank-based normalization with tie handling (equal scores get equal ranks) - Otherwise (logits): use sigmoid as before This preserves the correct behavior for local models (logits) while fixing ranking quality for external API rerankers.
nicoloboschi
reviewed
May 7, 2026
Collaborator
nicoloboschi
left a comment
There was a problem hiding this comment.
lgtm, can you add unit tests on this function
- Rank-based normalization for [0,1] scores - Tied scores receive identical normalized values - Sigmoid normalization for logit scores - Empty candidates returns [] without calling predict() - Fix typo: "sole排序 factor" -> "sole sorting factor"
Author
|
Unit tests added for
Also fixed a typo in the comment: "sole排序 factor" → "sole sorting factor". Tests use AsyncMock, no external API calls. |
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.
Problem
External API rerankers (SiliconFlow, Cohere, etc.) return pre-normalized
relevance_scorein[0, 1]with very small absolute values. The current code applies sigmoid to all scores, assuming they are logits. This compresses everything to~0.5, destroying the ranking signal and making recency the sole sorting factor.Example with SiliconFlow BAAI/bge-reranker-v2-m3
With sigmoid, all scores are
~0.5and recency becomes the only ranking signal. With rank-based normalization, the CE signal correctly dominates.Fix
Detect the score range in
CrossEncoderReranker.rerank():[0, 1]: Use rank-based normalization with tie handling (equal scores get equal ranks). This preserves relative ordering without depending on absolute score magnitudes.cross-encoder/ms-marco-MiniLM-L-6-v2).Testing
Verified with real SiliconFlow API scores:
Unit tests added in
tests/test_reranker_score_normalization.py.Related