{"record":{"id":"90eb13c392bf268a","repo":"run-llama/llama_index","slug":"cannot-delete-from-an-empty-index","errorCode":null,"errorMessage":"Cannot delete from an empty index.","messagePattern":"Cannot delete from an empty index\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/empty/base.py","lineNumber":86,"sourceCode":"\n        Args:\n            documents (List[BaseDocument]): A list of documents.\n\n        Returns:\n            IndexList: The created summary index.\n\n        \"\"\"\n        del nodes  # Unused\n        return EmptyIndexStruct()\n\n    def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None:\n        \"\"\"Insert a document.\"\"\"\n        del nodes  # Unused\n        raise NotImplementedError(\"Cannot insert into an empty index.\")\n\n    def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None:\n        \"\"\"Delete a node.\"\"\"\n        raise NotImplementedError(\"Cannot delete from an empty 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        raise NotImplementedError(\"ref_doc_info not supported for an empty index.\")\n\n\n# legacy\nGPTEmptyIndex = EmptyIndex\n","sourceCodeStart":68,"sourceCodeEnd":96,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/empty/base.py#L68-L96","documentation":"EmptyIndex stores nothing, so node deletion is meaningless and _delete_node() is a hard NotImplementedError stub. It fires whenever the base BaseIndex delete machinery (delete_ref_doc / delete_nodes with ref_doc_id or node ids) dispatches to this method.","triggerScenarios":"Calling empty_index.delete_ref_doc(doc_id) or empty_index.delete_nodes(node_ids) on an EmptyIndex; generic document-lifecycle code (refresh/delete stale docs) run against an EmptyIndex selected by config.","commonSituations":"Document-sync jobs that delete removed docs from 'the current index'; mirroring an external data source where the index may legitimately be empty; multi-tenant setups where some tenants have no data and get an EmptyIndex.","solutions":["Skip delete calls for EmptyIndex: check isinstance(index, EmptyIndex) before invoking delete_ref_doc/delete_nodes.","Branch on whether the index actually holds data (e.g. index.ref_doc_info is unsupported too, so track emptiness yourself) and route deletes only to data-bearing index types.","If deletions are required, use SummaryIndex or VectorStoreIndex, which implement _delete_node."],"exampleFix":"// before\nempty_index.delete_ref_doc(doc_id)  # NotImplementedError\n\n// after\nfrom llama_index.core.indices.empty import EmptyIndex\nif not isinstance(index, EmptyIndex):\n    index.delete_ref_doc(doc_id)","handlingStrategy":"type-guard","validationCode":"from llama_index.core.indices.empty import EmptyIndex\n\nif not isinstance(index, EmptyIndex):\n    index.delete_ref_doc(doc_id)","typeGuard":"from llama_index.core.indices.empty import EmptyIndex\n\ndef supports_delete(index: object) -> bool:\n    return not isinstance(index, EmptyIndex)","tryCatchPattern":"try:\n    index.delete_nodes(node_ids)\nexcept NotImplementedError as e:\n    if \"empty index\" in str(e):\n        pass  # nothing to delete in an empty index\n    else:\n        raise","preventionTips":["In document-sync jobs, skip tenants/indexes that are known-empty instead of calling delete unconditionally.","Track which index instances are EmptyIndex at construction time.","Prefer rebuilding an EmptyIndex from scratch over any mutation attempt."],"tags":["llama-index","empty-index","not-implemented","delete"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}