run-llama/llama_index · error · NotImplementedError

clear not implemented

Error message

clear not implemented

What it means

`BaseVectorStore.clear()` is another base-class stub intended to wipe all nodes from a store; the base implementation unconditionally raises NotImplementedError. Stores that cannot (or do not yet) implement full wipes — including SimpleVectorStore — leave it unoverridden. The async `aclear()` delegates to it and fails the same way.

Source

Thrown at llama-index-core/llama_index/core/vector_stores/types.py:415

        node_ids: Optional[List[str]] = None,
        filters: Optional[MetadataFilters] = None,
        **delete_kwargs: Any,
    ) -> None:
        """Delete nodes from vector store."""
        raise NotImplementedError("delete_nodes not implemented")

    async def adelete_nodes(
        self,
        node_ids: Optional[List[str]] = None,
        filters: Optional[MetadataFilters] = None,
        **delete_kwargs: Any,
    ) -> None:
        """Asynchronously delete nodes from vector store."""
        self.delete_nodes(node_ids, filters)

    def clear(self) -> None:
        """Clear all nodes from configured vector store."""
        raise NotImplementedError("clear not implemented")

    async def aclear(self) -> None:
        """Asynchronously clear all nodes from configured vector store."""
        self.clear()

    @abstractmethod
    def query(self, query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult:
        """Query vector store."""

    async def aquery(
        self, query: VectorStoreQuery, **kwargs: Any
    ) -> VectorStoreQueryResult:
        """
        Asynchronously query vector store.
        NOTE: this is not implemented for all vector stores. If not implemented,
        it will just call query synchronously.
        """
        return self.query(query, **kwargs)

View on GitHub (pinned to afd0fef371)

Solutions

  1. Detect support first: `type(store).clear is not BaseVectorStore.clear`.
  2. For SimpleVectorStore, replace state directly: `store.data = SimpleVectorStoreData()` or rebuild the store object.
  3. Use `store.delete(ref_doc_id)` per document, or delete and recreate the underlying persistence/collection for stores without clear().
  4. In test fixtures, construct a fresh store per test instead of clearing.

Example fix

# before
store.clear()  # NotImplementedError

# after
from llama_index.core.vector_stores import BaseVectorStore
if type(store).clear is not BaseVectorStore.clear:
    store.clear()
elif isinstance(store, SimpleVectorStore):
    store.data = SimpleVectorStoreData()  # fresh in-memory state
Defensive patterns

Strategy: fallback

Validate before calling

from llama_index.core.vector_stores import BaseVectorStore

def supports_clear(store) -> bool:
    return type(store).clear is not BaseVectorStore.clear

Try / catch

try:
    store.clear()
except NotImplementedError:
    store.data = SimpleVectorStoreData()  # or recreate the store/collection

Prevention

When it happens

Trigger: Calling `store.clear()` or `await store.aclear()` in test teardown or reset flows on a store integration that did not override clear(); e.g. resetting a SimpleVectorStore-backed index between test cases.

Common situations: pytest fixtures that clear state between tests; CLI 'reset index' commands; multi-tenant flows that wipe per-tenant collections; backend swaps where the previous store supported clear().

Related errors


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