Skip to content

fix: deduplicate AutoMergingRetriever documents - #13511

Merged
davidsbatista merged 4 commits into
deepset-ai:mainfrom
senthurapandi2000:fix/auto-merging-retriever-dedup
Nov 5, 2026
Merged

davidsbatista merged 4 commits into
deepset-ai:mainfrom
senthurapandi2000:fix/auto-merging-retriever-dedup

Conversation

@senthurapandi2000

Copy link
Copy Markdown
Contributor

Related Issues

Fixes #13505

Proposed Changes

This PR fixes an issue in AutoMergingRetriever where duplicate leaf documents are counted multiple times when evaluating parent merge thresholds, potentially causing incorrect parent document retrieval.

Changes made:

  • Deduplicate input documents by ID before evaluating merge thresholds.
  • Reuse the existing _deduplicate_documents utility to retain the highest-scoring document when duplicates are encountered.
  • Apply the fix consistently to both run() and run_async().
  • Add three regression tests covering duplicate leaf documents, highest-score retention, and below-threshold behavior.
  • Add a release note describing the bug fix.

How did you test it?

Unit tests:

hatch run test:unit test/components/retrievers/test_auto_merging_retriever.py -q

Result: 23 passed.

Formatting and linting:

hatch run fmt-check haystack/components/retrievers/auto_merging_retriever.py test/components/retrievers/test_auto_merging_retriever.py

Result: All checks passed.

Type checking:

hatch run test:types haystack/components/retrievers/auto_merging_retriever.py test/components/retrievers/test_auto_merging_retriever.py

Result: No issues found in 2 source files.

The original issue was successfully reproduced before applying the fix, and the new regression tests pass afterward.

Notes for the Reviewer

The implementation reuses Haystack's existing _deduplicate_documents helper to keep the change minimal and consistent with other components.

The change preserves existing retrieval behavior for unique documents while preventing duplicate inputs from incorrectly affecting merge decisions.

I noticed the original issue reporter mentioned having a PR prepared. Happy to coordinate if there is overlapping work.

AI assistance disclosure: ChatGPT assisted with the implementation approach and regression-test drafting. I applied the changes, ran the tests and quality checks locally, and reviewed the Git diff.

Checklist

  • Added regression tests covering the reported issue.
  • Used the conventional fix: commit type.
  • Added a release note.
  • Ran unit tests successfully.
  • Passed formatting and linting checks.
  • Passed type checking.
  • Checked the Git diff for whitespace errors.
  • Run the complete pre-commit hooks.
  • Confirm the contribution guidelines and code of conduct have been reviewed.

@senthurapandi2000
senthurapandi2000 requested a review from a team as a code owner October 31, 2026 19:16
@senthurapandi2000
senthurapandi2000 requested review from davidsbatista and removed request for a team October 31, 2026 19:16
@vercel

vercel Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

@senthurapandi2000 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 Oct 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
haystack-docs Ready Ready Preview Nov 5, 2026 1:32pm UTC

Request Review

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/retrievers
  auto_merging_retriever.py
Project Total  

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

@davidsbatista davidsbatista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@davidsbatista
davidsbatista merged commit 75e7c15 into deepset-ai:main Nov 5, 2026
24 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2afee104 Deployed Nov 5, 2026 by vercel[bot]
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.

AutoMergingRetriever counts a leaf document retrieved more than once as several matched children

3 participants