run-llama/llama_index · error · NotImplementedError
Cannot delete from an empty index.
Error message
Cannot delete from an empty index.
What it means
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.
Source
Thrown at llama-index-core/llama_index/core/indices/empty/base.py:86
Args:
documents (List[BaseDocument]): A list of documents.
Returns:
IndexList: The created summary index.
"""
del nodes # Unused
return EmptyIndexStruct()
def _insert(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None:
"""Insert a document."""
del nodes # Unused
raise NotImplementedError("Cannot insert into an empty index.")
def _delete_node(self, node_id: str, **delete_kwargs: Any) -> None:
"""Delete a node."""
raise NotImplementedError("Cannot delete from an empty index.")
@property
def ref_doc_info(self) -> Dict[str, RefDocInfo]:
"""Retrieve a dict mapping of ingested documents and their nodes+metadata."""
raise NotImplementedError("ref_doc_info not supported for an empty index.")
# legacy
GPTEmptyIndex = EmptyIndex
View on GitHub (pinned to afd0fef371)
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.
Example fix
// before
empty_index.delete_ref_doc(doc_id) # NotImplementedError
// after
from llama_index.core.indices.empty import EmptyIndex
if not isinstance(index, EmptyIndex):
index.delete_ref_doc(doc_id) Defensive patterns
Strategy: type-guard
Validate before calling
from llama_index.core.indices.empty import EmptyIndex
if not isinstance(index, EmptyIndex):
index.delete_ref_doc(doc_id) Type guard
from llama_index.core.indices.empty import EmptyIndex
def supports_delete(index: object) -> bool:
return not isinstance(index, EmptyIndex) Try / catch
try:
index.delete_nodes(node_ids)
except NotImplementedError as e:
if "empty index" in str(e):
pass # nothing to delete in an empty index
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot insert into an empty index.
- ref_doc_info not supported for an empty index.
- Delete is not supported for KG index yet.
- _delete_node not implemented for BaseManagedIndex.
- Delete not implemented for tree index.
AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15).
Data as JSON: /api/errors/90eb13c392bf268a.
Report an issue: GitHub.