fix: treat [0] document references as out of range in AnswerBuilder#12061
Merged
sjrl merged 2 commits intoJul 20, 2026
Conversation
References are 1-based, so a [0] citation yields index -1, which Python resolves to the last document instead of triggering the IndexError guard. The unrelated last document was returned marked referenced=True with source_index=0. Use an explicit bounds check so [0] (and expanded ranges starting at 0) warn and attach nothing, like any other out-of-range reference.
|
@vidigoat 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.
Related Issues
Proposed Changes:
AnswerBuilderdocuments references as 1-based, so extracted indices are decremented by 1. When an LLM cites[0](LLMs frequently 0-index), the extracted index becomes-1. The out-of-range guard relies ondocuments[idx]raisingIndexError, but Python resolvesdocuments[-1]to the last document — so the guard never fires and an unrelated document is silently attached to the answer, markedreferenced=Truewith a bogussource_index=0:Expanded reference ranges starting at 0 (
[0-1],expand_reference_ranges=True) hit the same hole viarange(start - 1, end).Fix: replace the
try/except IndexErrorwith an explicit bounds check (0 <= idx < len(documents)), keeping the exact same warning message and skip behaviour for all out-of-range references.How did you test it?
main(wrong doc attached) and with the fix (warning + no doc) for both[0]and[0-1].[0]and[0-1]-range cases), which fail onmainand pass with the fix.test/components/builders/test_answer_builder.py: 32 passed.Notes for the reviewer
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.