You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AutoMergingRetriever counts a leaf document retrieved more than once as several matched children #13505
AutoMergingRetriever counts every copy of a matched leaf document when it decides whether to return the parent. If the same leaf is in documents more than once, for example because the results of two retrievers were concatenated before reaching it, each copy counts as another matched child. The parent can then be returned even though fewer distinct children than threshold matched.
When the parent isn't returned, the duplicate leaf is returned once per copy.
Error message
None. The output is wrong silently.
Expected behavior
Each leaf document is counted once, so the merge decision depends on how many distinct children of the parent were matched. A leaf retrieved twice is returned once, the copy with the highest score.
Additional context
run and run_async group the input documents by __parent_id and compute len(child_docs) / len(parent.meta["__children_ids"]) without deduplicating child_docs. Other components that merge results (DocumentJoiner, MultiRetriever, the multi-query retrievers) already deduplicate by document ID with _deduplicate_documents. I have a PR ready that applies the same deduplication before merging.
To Reproduce
On current main (8e38c6331):
fromhaystackimportDocumentfromhaystack.components.retrieversimportAutoMergingRetrieverfromhaystack.document_stores.in_memoryimportInMemoryDocumentStorestore=InMemoryDocumentStore()
parent=Document(id="p", content="abc", meta={"__children_ids": ["a", "b", "c"], "__level": 0, "__block_size": 3})
leaves= [
Document(id=i, content=i, meta={"__parent_id": "p", "__level": 1, "__block_size": 1}) foriin ("a", "b", "c")
]
store.write_documents([parent, *leaves])
retriever=AutoMergingRetriever(store, threshold=0.5)
print([d.idfordinretriever.run([leaves[0]])["documents"]])
# >> ['a'] 1 of 3 children matched, below the thresholdprint([d.idfordinretriever.run([leaves[0], leaves[0]])["documents"]])
# >> ['p'] the same single child, passed twice, returns the parentprint([d.idfordinAutoMergingRetriever(store, threshold=0.9).run([leaves[0], leaves[0]])["documents"]])
# >> ['a', 'a']
Hi, I'd be interested in contributing to this issue! I'd like to help reproduce the bug, implement deduplication by document ID, and add regression tests to ensure the highest-scoring document is retained.
I noticed you mentioned having a PR ready. Is this issue still available for contributions, or would there be an opportunity to help with testing or the fix?
Activity
senthurapandi2000 commentedon Oct 31, 2026
Hi, I'd be interested in contributing to this issue! I'd like to help reproduce the bug, implement deduplication by document ID, and add regression tests to ensure the highest-scoring document is retained.
I noticed you mentioned having a PR ready. Is this issue still available for contributions, or would there be an opportunity to help with testing or the fix?
Thanks!