run-llama/llama_index · error · NotImplementedError

Delete is not supported for KG index yet.

Error message

Delete is not supported for KG index yet.

What it means

KnowledgeGraphIndex supports inserting triplets (upsert_triplet, add_node, optional embeddings) but node deletion was never implemented: _delete_node() is a NotImplementedError stub ('yet'). Any base-class delete flow (delete_ref_doc, delete_nodes) that reaches this hook aborts.

Source

Thrown at llama-index-core/llama_index/core/indices/knowledge_graph/base.py:321

        Args:
            keywords (List[str]): Keywords to index the node.
            node (Node): Node to be indexed.
            include_embeddings (bool): Option to add embeddings for triplets. Defaults to False

        """
        subj, _, obj = triplet
        self.upsert_triplet(triplet)
        self.add_node([subj, obj], node)
        triplet_str = str(triplet)
        if include_embeddings:
            set_embedding = self._embed_model.get_text_embedding(triplet_str)
            self._index_struct.add_to_embedding_dict(str(triplet), set_embedding)
            self._storage_context.index_store.add_index_struct(self._index_struct)

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

    @property
    def ref_doc_info(self) -> Dict[str, RefDocInfo]:
        """Retrieve a dict mapping of ingested documents and their nodes+metadata."""
        node_doc_ids_sets = list(self._index_struct.table.values())
        node_doc_ids = list(set().union(*node_doc_ids_sets))
        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

View on GitHub (pinned to afd0fef371)

Solutions

  1. Do not route delete calls to KnowledgeGraphIndex — instead remove triplets directly via the graph store: kg_index._graph_store.delete(triplet), or upsert a corrected triplet.
  2. If full remove/replace semantics are needed, rebuild the KnowledgeGraphIndex from the current document set (delete persisted storage and re-ingest).
  3. Wrap delete flows in try/except NotImplementedError and fall back to rebuild, and track this as a llama-index feature gap for KG indices.

Example fix

# before
kg_index.delete_ref_doc(doc_id)  # NotImplementedError

# after
# remove specific triplets via the graph store, then rebuild if needed
for triplet in stale_triplets:
    kg_index._graph_store.delete(triplet)
Defensive patterns

Strategy: try-catch

Validate before calling

from llama_index.core.indices.knowledge_graph import KnowledgeGraphIndex

# no capability flag exists; plan for rebuild instead of delete
assert not isinstance(index, KnowledgeGraphIndex) or delete_supported_by_subclass(index)

Type guard

from llama_index.core.indices.knowledge_graph import KnowledgeGraphIndex

def kg_supports_delete(index: object) -> bool:
    return not type(index) is KnowledgeGraphIndex  # subclasses may override

Try / catch

try:
    kg_index.delete_ref_doc(doc_id)
except NotImplementedError:
    # deletion unsupported: remove triplets via graph store or rebuild index
    for t in stale_triplets_for(doc_id):
        kg_index._graph_store.delete(t)

Prevention

When it happens

Trigger: Calling kg_index.delete_ref_doc(doc_id) or kg_index.delete_nodes(node_ids) on a KnowledgeGraphIndex; refresh workflows that reconcile by deleting stale documents; document-management code generic over index types.

Common situations: Syncing a KG index with a changing document set and attempting to remove outdated docs; migrating delete logic from a VectorStoreIndex (which supports deletion) to a KG index; stale-URL cleanup jobs.

Related errors


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