{"record":{"id":"c9c1c5e20c2fa4e9","repo":"run-llama/llama_index","slug":"delete-is-not-supported-for-kg-index-yet","errorCode":null,"errorMessage":"Delete is not supported for KG index yet.","messagePattern":"Delete is not supported for KG index yet\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/knowledge_graph/base.py","lineNumber":321,"sourceCode":"\n        Args:\n            keywords (List[str]): Keywords to index the node.\n            node (Node): Node to be indexed.\n            include_embeddings (bool): Option to add embeddings for triplets. Defaults to False\n\n        \"\"\"\n        subj, _, obj = triplet\n        self.upsert_triplet(triplet)\n        self.add_node([subj, obj], node)\n        triplet_str = str(triplet)\n        if include_embeddings:\n            set_embedding = self._embed_model.get_text_embedding(triplet_str)\n            self._index_struct.add_to_embedding_dict(str(triplet), set_embedding)\n            self._storage_context.index_store.add_index_struct(self._index_struct)\n\n    def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None:\n        \"\"\"Delete a node.\"\"\"\n        raise NotImplementedError(\"Delete is not supported for KG index yet.\")\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_sets = list(self._index_struct.table.values())\n        node_doc_ids = list(set().union(*node_doc_ids_sets))\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","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/knowledge_graph/base.py#L303-L339","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","If full remove/replace semantics are needed, rebuild the KnowledgeGraphIndex from the current document set (delete persisted storage and re-ingest).","Wrap delete flows in try/except NotImplementedError and fall back to rebuild, and track this as a llama-index feature gap for KG indices."],"exampleFix":"# before\nkg_index.delete_ref_doc(doc_id)  # NotImplementedError\n\n# after\n# remove specific triplets via the graph store, then rebuild if needed\nfor triplet in stale_triplets:\n    kg_index._graph_store.delete(triplet)","handlingStrategy":"try-catch","validationCode":"from llama_index.core.indices.knowledge_graph import KnowledgeGraphIndex\n\n# no capability flag exists; plan for rebuild instead of delete\nassert not isinstance(index, KnowledgeGraphIndex) or delete_supported_by_subclass(index)","typeGuard":"from llama_index.core.indices.knowledge_graph import KnowledgeGraphIndex\n\ndef kg_supports_delete(index: object) -> bool:\n    return not type(index) is KnowledgeGraphIndex  # subclasses may override","tryCatchPattern":"try:\n    kg_index.delete_ref_doc(doc_id)\nexcept NotImplementedError:\n    # deletion unsupported: remove triplets via graph store or rebuild index\n    for t in stale_triplets_for(doc_id):\n        kg_index._graph_store.delete(t)","preventionTips":["Design KG pipelines as rebuild-on-change, not incremental delete.","Track triplets per source document yourself so targeted graph-store deletes are possible.","Watch llama-index releases — KG deletion is an open feature gap."],"tags":["llama-index","knowledge-graph","not-implemented","delete"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}