fix: AnswerBuilder returned referenced documents in scrambled order#11953
Open
Otis0408 wants to merge 1 commit into
Open
fix: AnswerBuilder returned referenced documents in scrambled order#11953Otis0408 wants to merge 1 commit into
Otis0408 wants to merge 1 commit into
Conversation
The referenced document indices were kept in a set and iterated directly, so the returned documents came out in the set's hash-table order rather than ascending source-index order (e.g. citations [3] [10] [50] yielded documents ordered 10, 3, 50). This order was deterministic but did not match the source order. Iterate the indices sorted so documents follow ascending source index.
|
@Otis0408 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 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's the problem
AnswerBuilderwithreturn_only_referenced_documents=Truecollects the referenced document indices into asetand iterates it directly to buildAnswer.documents. Because CPython sets store items in internal hash-table order, the referenced documents were emitted in that hash-table order rather than ascending source-index order.For small non-contiguous int indices this order is deterministic across runs (int hashing is identity), but it does not match the intuitive source order a user expects. For example, citations
[3] [10] [50]yielded documents ordered10, 3, 50.Anyone rendering citations, feeding the referenced documents to a downstream component, or asserting on their order hits this: the documents look shuffled relative to how they were cited.
The fix
Iterate the collected indices via
sorted(doc_idxs)so the referenced documents come out in ascending source-index order.Before / after (public component API)
Notes
Wording-only, behavior-preserving fix plus one regression test. No public API change.