{"record":{"id":"44418dd4049e0c21","repo":"run-llama/llama_index","slug":"delete-not-implemented-for-tree-index","errorCode":null,"errorMessage":"Delete not implemented for tree index.","messagePattern":"Delete not implemented for tree index\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/tree/base.py","lineNumber":167,"sourceCode":"        )\n        return index_builder.build_from_nodes(nodes, build_tree=self.build_tree)\n\n    def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None:\n        \"\"\"Insert a document.\"\"\"\n        # TODO: allow to customize insert prompt\n        inserter = TreeIndexInserter(\n            self.index_struct,\n            llm=self._llm,\n            num_children=self.num_children,\n            insert_prompt=self.insert_prompt,\n            summary_prompt=self.summary_template,\n            docstore=self._docstore,\n        )\n        inserter.insert(nodes)\n\n    def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None:\n        \"\"\"Delete a node.\"\"\"\n        raise NotImplementedError(\"Delete not implemented for tree index.\")\n\n    @property\n    def ref_doc_info(self) -> Dict[str, RefDocInfo]:\n        \"\"\"Retrieve a dict mapping of ingested documents and their nodes+metadata.\"\"\"\n        node_doc_ids = list(self.index_struct.all_nodes.values())\n        nodes = self.docstore.get_nodes(node_doc_ids)\n\n        all_ref_doc_info = {}\n        for node in nodes:\n            ref_node = node.source_node\n            if not ref_node:\n                continue\n\n            ref_doc_info = self.docstore.get_ref_doc_info(ref_node.node_id)\n            if not ref_doc_info:\n                continue\n\n            all_ref_doc_info[ref_node.node_id] = ref_doc_info","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/tree/base.py#L149-L185","documentation":"TreeIndex._delete_node raises NotImplementedError('Delete not implemented for tree index.') whenever the base-index deletion machinery tries to remove a node. Tree indexes interleave leaf and summary nodes in a graph where each parent summarizes specific children, so removing one node invalidates the summaries up the chain and no incremental delete was implemented. This is a permanent capability gap, not a transient state.","triggerScenarios":"Calling index.delete_ref_doc(doc_id) or index.delete_nodes([...]) on a TreeIndex; running a generic refresh/re-ingestion pipeline that calls delete for updated documents; index.refresh(...)-style flows that internally call _delete_node.","commonSituations":"Reusing a VectorStoreIndex-style incremental update pipeline against a tree index; document-management features (remove stale docs) ported to tree indexes.","solutions":["Rebuild the TreeIndex from the remaining documents instead of deleting — the operation is simply unsupported.","Route deletions to a different index type (VectorStoreIndex supports delete_ref_doc) if incremental deletion is a hard requirement.","Catch NotImplementedError in generic pipelines and fall back to full rebuild for tree indexes."],"exampleFix":"# before\nindex.delete_ref_doc(stale_doc_id)  # NotImplementedError on TreeIndex\n\n# after\nkeep = [d for d in docs if d.doc_id != stale_doc_id]\nindex = TreeIndex.from_documents(keep)  # full rebuild","handlingStrategy":"try-catch","validationCode":"from llama_index.core.indices.tree.base import TreeIndex\n\ndef supports_delete(index) -> bool:\n    return not isinstance(index, TreeIndex)","typeGuard":"from llama_index.core.indices.tree.base import TreeIndex\n\ndef is_tree_index(index) -> bool:\n    return isinstance(index, TreeIndex)","tryCatchPattern":"try:\n    index.delete_ref_doc(doc_id)\nexcept NotImplementedError:\n    # tree index: full rebuild instead of delete\n    index = TreeIndex.from_documents(remaining_docs)","preventionTips":["Never wire incremental delete/refresh pipelines into TreeIndex — it is unsupported by design.","Keep a source-document list so a full rebuild is always possible.","Choose VectorStoreIndex when per-document deletion is a requirement."],"tags":["tree-index","delete","not-implemented","llama-index"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}