Skip to content

feat: add opt-in reference range expansion to AnswerBuilder#11623

Merged
julian-risch merged 4 commits into
deepset-ai:mainfrom
vedjaw:feat/answer-builder-reference-ranges
Jun 16, 2026
Merged

feat: add opt-in reference range expansion to AnswerBuilder#11623
julian-risch merged 4 commits into
deepset-ai:mainfrom
vedjaw:feat/answer-builder-reference-ranges

Conversation

@vedjaw

@vedjaw vedjaw commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

AnswerBuilder only 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_ranges parameter to AnswerBuilder.__init__ and run() (default False for 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
  • invalid ranges like [3-1] are ignored
  • the default reference_pattern is automatically broadened to capture range syntax

How did you test it?

Added unit tests:

  • test_run_expands_reference_ranges_when_enabled
  • test_run_expands_comma_separated_reference_ranges
  • test_run_ignores_invalid_reference_ranges
  • test_run_does_not_expand_reference_ranges_by_default
pytest test/components/builders/test_answer_builder.py

All 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

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

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 vedjaw requested a review from a team as a code owner June 14, 2026 11:31
@vedjaw vedjaw requested review from julian-risch and removed request for a team June 14, 2026 11:31
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@vedjaw is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Jun 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Jun 14, 2026
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>
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Jun 16, 2026 8:54am

Request Review

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

@julian-risch

Copy link
Copy Markdown
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>
@julian-risch julian-risch enabled auto-merge (squash) June 16, 2026 08:13
… 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>
@julian-risch julian-risch merged commit b48d3e7 into deepset-ai:main Jun 16, 2026
23 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/builders
  answer_builder.py 269, 277, 290, 302
Project Total  

This report was generated by python-coverage-comment-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support reference ranges in AnswerBuilder (e.g. [6-10])

3 participants