Skip to content

Fix reranked scores not matching reranked document order in HFCrossEncoderReranker - #694

Merged
vishal-bala merged 2 commits into
redis:mainfrom
adityaanikam:fix-cross-encoder-score-alignment-693
Aug 20, 2026
Merged

Fix reranked scores not matching reranked document order in HFCrossEncoderReranker#694
vishal-bala merged 2 commits into
redis:mainfrom
adityaanikam:fix-cross-encoder-score-alignment-693

Conversation

@adityaanikam

@adityaanikam adityaanikam commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #693.

HFCrossEncoderReranker.rank() sorted docs_with_scores by score to build reranked_docs, but then took scores from the original unsorted scores list instead of from the same sorted sequence. So reranked_docs[i] and scores[i] didn't correspond to the same document once the reranking actually changed the order. arank() delegates to rank(), so this fixes both.

Added a regression test that asserts the returned scores are sorted descending, matching the returned docs. Confirmed it fails with the old code (scores come back in the original order, not sorted) and passes with the fix, using a real cross-encoder model against the exact reproduction from the issue.


Note

Low Risk
Small, localized bugfix in reranker output pairing with a regression test; no auth, data, or API contract changes beyond correcting score alignment.

Overview
Fixes misaligned scores in HFCrossEncoderReranker.rank() when reranking changes document order (#693).

After sorting (doc, score) pairs by score, the method now builds both reranked_docs and the returned scores from that same sorted slice. Previously it sliced the sorted docs but still returned scores from the original prediction order, so index i in docs and scores could refer to different hits.

Adds an integration regression test that checks returned scores are in descending order when return_score is true (the failure mode from the old code).

Reviewed by Cursor Bugbot for commit 919bddc. Bugbot is set up for automated code reviews on this repo. Configure here.

@vishal-bala
vishal-bala self-requested a review August 17, 2026 09:19

@vishal-bala vishal-bala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Just one very minor optimization and I think we're good to go

Comment thread redisvl/utils/rerank/hf_cross_encoder.py Outdated
@vishal-bala vishal-bala added the auto:patch Increment the patch version when merged label Aug 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit ff4f898. Configure here.

Comment thread redisvl/utils/rerank/hf_cross_encoder.py
@vishal-bala

Copy link
Copy Markdown
Collaborator

Hi, this looks good! You just need to rebase onto origin/main to pull in some CD/CD-related fixes we made recently.

@adityaanikam
adityaanikam force-pushed the fix-cross-encoder-score-alignment-693 branch from ff4f898 to 919bddc Compare August 19, 2026 18:24
@adityaanikam

Copy link
Copy Markdown
Contributor Author

Hi, this looks good! You just need to rebase onto origin/main to pull in some CD/CD-related fixes we made recently.

done

@vishal-bala
vishal-bala merged commit 0f64097 into redis:main Aug 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HFCrossEncoderReranker returns scores in original input order after reranking

2 participants