run-llama/llama_index · error · NotImplementedError

Delete not implemented for tree index.

Error message

Delete not implemented for tree index.

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/indices/tree/base.py:167

        )
        return index_builder.build_from_nodes(nodes, build_tree=self.build_tree)

    def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None:
        """Insert a document."""
        # TODO: allow to customize insert prompt
        inserter = TreeIndexInserter(
            self.index_struct,
            llm=self._llm,
            num_children=self.num_children,
            insert_prompt=self.insert_prompt,
            summary_prompt=self.summary_template,
            docstore=self._docstore,
        )
        inserter.insert(nodes)

    def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None:
        """Delete a node."""
        raise NotImplementedError("Delete not implemented for tree index.")

    @property
    def ref_doc_info(self) -> Dict[str, RefDocInfo]:
        """Retrieve a dict mapping of ingested documents and their nodes+metadata."""
        node_doc_ids = list(self.index_struct.all_nodes.values())
        nodes = self.docstore.get_nodes(node_doc_ids)

        all_ref_doc_info = {}
        for node in nodes:
            ref_node = node.source_node
            if not ref_node:
                continue

            ref_doc_info = self.docstore.get_ref_doc_info(ref_node.node_id)
            if not ref_doc_info:
                continue

            all_ref_doc_info[ref_node.node_id] = ref_doc_info

View on GitHub (pinned to afd0fef371)

Solutions

  1. Rebuild the TreeIndex from the remaining documents instead of deleting — the operation is simply unsupported.
  2. Route deletions to a different index type (VectorStoreIndex supports delete_ref_doc) if incremental deletion is a hard requirement.
  3. Catch NotImplementedError in generic pipelines and fall back to full rebuild for tree indexes.

Example fix

# before
index.delete_ref_doc(stale_doc_id)  # NotImplementedError on TreeIndex

# after
keep = [d for d in docs if d.doc_id != stale_doc_id]
index = TreeIndex.from_documents(keep)  # full rebuild
Defensive patterns

Strategy: try-catch

Validate before calling

from llama_index.core.indices.tree.base import TreeIndex

def supports_delete(index) -> bool:
    return not isinstance(index, TreeIndex)

Type guard

from llama_index.core.indices.tree.base import TreeIndex

def is_tree_index(index) -> bool:
    return isinstance(index, TreeIndex)

Try / catch

try:
    index.delete_ref_doc(doc_id)
except NotImplementedError:
    # tree index: full rebuild instead of delete
    index = TreeIndex.from_documents(remaining_docs)

Prevention

When it happens

Trigger: 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.

Common situations: Reusing a VectorStoreIndex-style incremental update pipeline against a tree index; document-management features (remove stale docs) ported to tree indexes.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/44418dd4049e0c21. Report an issue: GitHub.