{"record":{"id":"eeb4f82ea9eaa017","repo":"deepset-ai/haystack","slug":"parent-document-with-id-parent-id-does-not-have","errorCode":null,"errorMessage":"Parent document with id {parent_id} does not have any children.","messagePattern":"Parent document with id (.+?) does not have any children\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/retrievers/auto_merging_retriever.py","lineNumber":135,"sourceCode":"\n        Recursively groups documents by their parents and merges them if they meet the threshold,\n        continuing up the hierarchy until no more merges are possible.\n\n        :param documents: List of leaf documents that were matched by a retriever\n        :returns:\n            List of documents (could be a mix of different hierarchy levels)\n        \"\"\"\n\n        AutoMergingRetriever._check_valid_documents(documents)\n\n        def _get_parent_doc(parent_id: str) -> Document:\n            parent_docs = self.document_store.filter_documents({\"field\": \"id\", \"operator\": \"==\", \"value\": parent_id})\n            if len(parent_docs) != 1:\n                raise ValueError(f\"Expected 1 parent document with id {parent_id}, found {len(parent_docs)}\")\n\n            parent_doc = parent_docs[0]\n            if not parent_doc.meta.get(\"__children_ids\"):\n                raise ValueError(f\"Parent document with id {parent_id} does not have any children.\")\n\n            return parent_doc\n\n        def _try_merge_level(docs_to_merge: list[Document], docs_to_return: list[Document]) -> list[Document]:\n            parent_doc_id_to_child_docs: dict[str, list[Document]] = defaultdict(list)  # to group documents by parent\n\n            for doc in docs_to_merge:\n                if doc.meta.get(\"__parent_id\"):  # only docs that have parents\n                    parent_doc_id_to_child_docs[doc.meta[\"__parent_id\"]].append(doc)\n                else:\n                    docs_to_return.append(doc)  # keep docs that have no parents\n\n            # Process each parent group\n            merged_docs = []\n            for parent_doc_id, child_docs in parent_doc_id_to_child_docs.items():\n                parent_doc = _get_parent_doc(parent_doc_id)\n\n                # Calculate merge score","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/retrievers/auto_merging_retriever.py#L117-L153","documentation":"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.","triggerScenarios":"Merging where the fetched parent document lacks meta['__children_ids'] — e.g. parent stored outside the hierarchical pipeline or meta overwritten.","commonSituations":"Parents written by a custom writer that skips splitter meta; documents re-serialized and losing dunder meta keys.","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"],"exampleFix":"// before\nparent = Document(content=\"...\")\nstore.write_documents([parent])\n// after\nparent = Document(content=\"...\", meta={\"__children_ids\": [c.id for c in children]})\nstore.write_documents([parent])","handlingStrategy":"validation","validationCode":"for pid in {d.meta.get(\"__parent_id\") for d in leaves}:\n    parents = store.filter_documents({\"field\": \"id\", \"operator\": \"==\", \"value\": pid})\n    if parents and not parents[0].meta.get(\"__children_ids\"):\n        raise ValueError(f\"Parent {pid} has no __children_ids\")","typeGuard":null,"tryCatchPattern":"try:\n    result = retriever.run(documents=leaves)\nexcept ValueError as e:\n    logger.warning(\"Parent without children meta: %s — returning leaf documents\", e)\n    result = {\"documents\": leaves}","preventionTips":["Write parents with '__children_ids' populated","Re-index with the standard hierarchical pipeline if meta is missing","Avoid manual Document construction for hierarchy"],"tags":["retriever","document-store","meta-field","data-integrity"],"backgroundTag":"parent-document-not-found","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}