Skip to content

AutoMergingRetriever treats __level=0 / __block_size=0 as missing metadata #12634

Closed

Description

@coder058

Description

AutoMergingRetriever._check_valid_documents validates __level and __block_size with truthiness checks:

if not all(doc.meta.get("__level") for doc in matched_leaf_documents):
    raise ValueError("...")

HierarchicalDocumentSplitter intentionally sets __level=0 and __block_size=0 on the root document. When a document carries those values (field present, value zero), validation raises ValueError: The matched leaf documents do not have the required meta field '__level' even though the field exists.

Reproduction

from haystack import Document
from haystack.components.retrievers.auto_merging_retriever import AutoMergingRetriever
from haystack.document_stores.in_memory import InMemoryDocumentStore

store = InMemoryDocumentStore()
parent = Document(
    content="parent",
    id="parent1",
    meta={"__level": 0, "__block_size": 0, "__children_ids": ["leaf1", "leaf2"]},
)
store.write_documents([parent])
leaf = Document(
    content="leaf",
    id="leaf1",
    meta={"__parent_id": "parent1", "__level": 0, "__block_size": 0},
)
AutoMergingRetriever(store).run([leaf])
# ValueError: The matched leaf documents do not have the required meta field '__level'

Expected

Documents with __level / __block_size present should pass validation even when the value is 0.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions