fix: sort unscored retriever results last - #13090
Open
linhongyu510 wants to merge 1 commit into
Open
linhongyu510 wants to merge 1 commit into
linhongyu510 wants to merge 1 commit into
Conversation
linhongyu510
requested review from
bogdankostic
and removed request for
a team
October 2, 2026 16:54
Contributor
|
@linhongyu510 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
This branch has not been deployed
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 this PR does
Fixes #13089.
MultiQueryEmbeddingRetriever,MultiQueryTextRetriever, andTextEmbeddingRetrieveruseddoc.score or 0.0when sorting results. That placesscore=Nonealongside zero and therefore above valid negative retrieval scores.This PR follows Haystack's existing convention in
_deduplicate_documents,DocumentJoiner, andAnswerJoiner: a missing score sorts as negative infinity, while every numeric score—including0.0and negative values—keeps its real ordering.The change covers both sync and async execution paths for all three retriever wrappers. It does not modify the underlying retrievers or their scoring.
Why this matters
Negative retrieval scores are supported. In particular, unscaled
BM25Okapimay return them. Before this fix, combining or wrapping such results could promote an unscored document above a genuinely scored match:Tests
Added paired sync/async regression tests for:
MultiQueryEmbeddingRetrieverMultiQueryTextRetrieverTextEmbeddingRetrieverEach test mixes positive, zero, negative, and missing scores.
Verification performed:
UV_EXCLUDE_NEWER=false hatch run test:unit <six affected test files>git diff --checkUV_EXCLUDE_NEWER=falsewas only needed locally because the repository's 24-hour supply-chain cutoff filtered the already-published build dependency while resolving against the current system date; no dependency or project configuration was changed.Scope
Nonemoves after all numeric scores.AI assistance
Developed with AI-assisted tooling. I reviewed and understood the final changes and independently ran the reproducer, counterfactual regression test, unit tests, lint, and type checks.