{"record":{"id":"c9e407c51c5857da","repo":"run-llama/llama_index","slug":"invalid-number-of-children","errorCode":null,"errorMessage":"Invalid number of children.","messagePattern":"Invalid number of children\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/common_tree/base.py","lineNumber":43,"sourceCode":"    GPT tree index builder.\n\n    Helper class to build the tree-structured index,\n    or to synthesize an answer.\n\n    \"\"\"\n\n    def __init__(\n        self,\n        num_children: int,\n        summary_prompt: BasePromptTemplate,\n        llm: Optional[LLM] = None,\n        docstore: Optional[BaseDocumentStore] = None,\n        show_progress: bool = False,\n        use_async: bool = False,\n    ) -> None:\n        \"\"\"Initialize with params.\"\"\"\n        if num_children < 2:\n            raise ValueError(\"Invalid number of children.\")\n        self.num_children = num_children\n        self.summary_prompt = summary_prompt\n        self._llm = llm or Settings.llm\n        self._prompt_helper = Settings._prompt_helper or PromptHelper.from_llm_metadata(\n            self._llm.metadata,\n        )\n        self._callback_manager = Settings.callback_manager\n        self._use_async = use_async\n        self._show_progress = show_progress\n        self._docstore = docstore or get_default_docstore()\n\n    @property\n    def docstore(self) -> BaseDocumentStore:\n        \"\"\"Return docstore.\"\"\"\n        return self._docstore\n\n    def build_from_nodes(\n        self,","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/common_tree/base.py#L25-L61","documentation":"Tree-index builders (BaseTreeBuilder, used by TreeIndex) partition leaf nodes into parent summaries; num_children < 2 makes hierarchical folding impossible (each parent needs at least two children to reduce). The constructor rejects num_children less than 2 with ValueError.","triggerScenarios":"Constructing TreeIndex with num_children=1 or 0 (e.g. TreeIndex.from_documents(docs, num_children=1)); passing num_children=0 hoping to disable summarization; computing num_children dynamically and hitting an edge case.","commonSituations":"Tuning tree fan-out for small documents; CLI/config-driven setups where 0 or 1 slips in as a default; misunderstanding num_children=0 as 'no summarization layer'.","solutions":["Set num_children to at least 2 (typical values are 8–20 depending on token limits).","If you don't want a hierarchical summary structure, use VectorStoreIndex instead of TreeIndex.","Validate config values at load time with a minimum bound check."],"exampleFix":"# before\nindex = TreeIndex.from_documents(docs, num_children=1)  # ValueError\n\n# after\nindex = TreeIndex.from_documents(docs, num_children=10)","handlingStrategy":"validation","validationCode":"if not isinstance(num_children, int) or num_children < 2:\n    raise ValueError(\"num_children must be an integer >= 2\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound-check all tree-index hyperparameters at config load time.","Use VectorStoreIndex when you don't want hierarchical summarization."],"tags":["tree-index","validation","constructor"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}