feat: add opt-in reference range expansion to AnswerBuilder#11623
Merged
julian-risch merged 4 commits intoJun 16, 2026
Conversation
Add expand_reference_ranges to AnswerBuilder so citations like [6-10] and [1-3,7-9] can be expanded into referenced document indices. The feature is disabled by default to preserve existing behavior. Fixes deepset-ai#11002 Signed-off-by: vedjaw <vedant.jawandhia@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
|
@vedjaw is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
An out-of-range citation like [1-999999999] in the Generator output would materialize a huge index set and emit one out-of-range warning per index. Clamp the expanded range end to the number of input documents to bound it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
julian-risch
approved these changes
Jun 16, 2026
julian-risch
left a comment
Member
There was a problem hiding this comment.
Thank you for opening this PR @vedjaw . Looks good to me! The PR is ready to be merged now and I changed only three small things:
- _extract_reference_idxs now clamps the expanded range end to num_documents, so an out-of-range citation like [1-999999999] no longer results in a large set
- added a test for the above
- Ran Pre-commit hooks, which re-formatted some of the changes you made. You can find more info on our pre-commit hooks here: https://github.com/deepset-ai/haystack/blob/main/CONTRIBUTING.md#clone-the-git-repository
Member
|
Congratulations on your first contribution to Haystack @vedjaw ! 🎉 |
…ions AnswerBuilder.run gained an expand_reference_ranges input, which adds an auto-mapped input socket to the RAG SuperComponent fixture. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… BDD tests The new opt-in expand_reference_ranges run parameter on AnswerBuilder is now recorded in the pipeline component_calls, so the expected component call dictionaries in the run feature tests must include it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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:
AnswerBuilderonly parsed individual document references like[1]and[3]. Citations such as[6-10]or[1-3,7-9]were not expanded.This adds an opt-in
expand_reference_rangesparameter toAnswerBuilder.__init__andrun()(defaultFalsefor backwards compatibility, per maintainer feedback on the previously closed PR).When enabled:
[6-10]expands to documents 6, 7, 8, 9, and 10[1-3,7-9]expands to documents 1, 2, 3, 7, 8, and 9[3-1]are ignoredreference_patternis automatically broadened to capture range syntaxHow did you test it?
Added unit tests:
test_run_expands_reference_ranges_when_enabledtest_run_expands_comma_separated_reference_rangestest_run_ignores_invalid_reference_rangestest_run_does_not_expand_reference_ranges_by_defaultAll 29 tests pass locally.
Notes for the reviewer
Previous PR #11214 was closed after review feedback requesting opt-in behavior. This implementation follows the suggested design in #11002, including default-off behavior and automatic broadening of the default reference pattern when range expansion is enabled.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.