deepset-ai/haystack · error · ValueError
Parent document with id {parent_id} does not have any childr
Error message
Parent document with id {parent_id} does not have any children. What it means
A parent document found in the store must declare its '__children_ids' meta so the retriever can merge siblings upward. If the parent exists but has no '__children_ids' (empty or missing), this ValueError is raised.
Source
Thrown at haystack/components/retrievers/auto_merging_retriever.py:135
Recursively groups documents by their parents and merges them if they meet the threshold,
continuing up the hierarchy until no more merges are possible.
:param documents: List of leaf documents that were matched by a retriever
:returns:
List of documents (could be a mix of different hierarchy levels)
"""
AutoMergingRetriever._check_valid_documents(documents)
def _get_parent_doc(parent_id: str) -> Document:
parent_docs = self.document_store.filter_documents({"field": "id", "operator": "==", "value": parent_id})
if len(parent_docs) != 1:
raise ValueError(f"Expected 1 parent document with id {parent_id}, found {len(parent_docs)}")
parent_doc = parent_docs[0]
if not parent_doc.meta.get("__children_ids"):
raise ValueError(f"Parent document with id {parent_id} does not have any children.")
return parent_doc
def _try_merge_level(docs_to_merge: list[Document], docs_to_return: list[Document]) -> list[Document]:
parent_doc_id_to_child_docs: dict[str, list[Document]] = defaultdict(list) # to group documents by parent
for doc in docs_to_merge:
if doc.meta.get("__parent_id"): # only docs that have parents
parent_doc_id_to_child_docs[doc.meta["__parent_id"]].append(doc)
else:
docs_to_return.append(doc) # keep docs that have no parents
# Process each parent group
merged_docs = []
for parent_doc_id, child_docs in parent_doc_id_to_child_docs.items():
parent_doc = _get_parent_doc(parent_doc_id)
# Calculate merge scoreView on GitHub (pinned to e318778c9b)
Solutions
- Write the full hierarchy (parent + children with '__children_ids') to the store
- Add '__children_ids' to the parent's meta and update the store
- Re-index with HierarchicalDocumentSplitter
Example fix
// before
parent = Document(content="...")
store.write_documents([parent])
// after
parent = Document(content="...", meta={"__children_ids": [c.id for c in children]})
store.write_documents([parent]) Defensive patterns
Strategy: validation
Validate before calling
for pid in {d.meta.get("__parent_id") for d in leaves}:
parents = store.filter_documents({"field": "id", "operator": "==", "value": pid})
if parents and not parents[0].meta.get("__children_ids"):
raise ValueError(f"Parent {pid} has no __children_ids") Try / catch
try:
result = retriever.run(documents=leaves)
except ValueError as e:
logger.warning("Parent without children meta: %s — returning leaf documents", e)
result = {"documents": leaves} Prevention
- Write parents with '__children_ids' populated
- Re-index with the standard hierarchical pipeline if meta is missing
- Avoid manual Document construction for hierarchy
When it happens
Trigger: Merging where the fetched parent document lacks meta['__children_ids'] — e.g. parent stored outside the hierarchical pipeline or meta overwritten.
Common situations: Parents written by a custom writer that skips splitter meta; documents re-serialized and losing dunder meta keys.
Related errors
- Expected 1 parent document with id {parent_id}, found {len(p
- The matched leaf documents do not have the required meta fie
- The matched leaf documents do not have the required meta fie
- The matched leaf documents do not have the required meta fie
- document_store must be an instance of InMemoryDocumentStore
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/eeb4f82ea9eaa017.
Report an issue: GitHub.