run-llama/llama_index · error · ValueError

Cannot filter stores that were persisted without metadata. P

Error message

Cannot filter stores that were persisted without metadata. Please rebuild the store with metadata to enable filtering.

What it means

SimpleVectorStore supports metadata filtering only if node metadata was recorded in its `metadata_dict` when nodes were added. Stores persisted by older LlamaIndex versions (or built without metadata) have an empty metadata_dict, so applying `filters` to a query would silently match nothing or crash on key lookup — the store raises this ValueError up front instead. It is a data-shape guard, not a logic error in the query.

Source

Thrown at llama-index-core/llama_index/core/vector_stores/simple.py:256

                self.data.metadata_dict.pop(node_id, None)

    def clear(self) -> None:
        """Clear the store."""
        self.data = SimpleVectorStoreData()

    def query(
        self,
        query: VectorStoreQuery,
        **kwargs: Any,
    ) -> VectorStoreQueryResult:
        """Get nodes for response."""
        # Prevent metadata filtering on stores that were persisted without metadata.
        if (
            query.filters is not None
            and self.data.embedding_dict
            and not self.data.metadata_dict
        ):
            raise ValueError(
                "Cannot filter stores that were persisted without metadata. "
                "Please rebuild the store with metadata to enable filtering."
            )
        # Prefilter nodes based on the query filter and node ID restrictions.
        query_filter_fn = build_metadata_filter_fn(
            lambda node_id: self.data.metadata_dict[node_id], query.filters
        )

        if query.node_ids is not None:
            available_ids = set(query.node_ids)

            def node_filter_fn(node_id: str) -> bool:
                return node_id in available_ids

        else:

            def node_filter_fn(node_id: str) -> bool:
                return True

View on GitHub (pinned to afd0fef371)

Solutions

  1. Rebuild the index with the current LlamaIndex version so SimpleVectorStoreData.metadata_dict is populated on add().
  2. Delete the old persist file(s) and re-run ingestion before enabling filters.
  3. If filtering is optional, drop the filters parameter for legacy stores or detect `not store.data.metadata_dict` and query unfiltered.
  4. Verify after rebuild that the persisted JSON contains a non-empty metadata_dict before shipping filter-dependent code.

Example fix

# before
store = SimpleVectorStore.from_persist_path("old_store.json")
results = store.query(query_with_filters)  # ValueError

# after
# rebuild once with current version, then:
store = SimpleVectorStore.from_persist_path("rebuilt_store.json")
results = store.query(query_with_filters)
Defensive patterns

Strategy: validation

Validate before calling

def store_supports_filters(store) -> bool:
    data = getattr(store, "data", None)
    if data is None:
        return True
    return not data.embedding_dict or bool(data.metadata_dict)

if filters is not None and not store_supports_filters(store):
    filters = None  # or raise your own migration error

Try / catch

try:
    result = store.query(query)
except ValueError as e:
    if "persisted without metadata" in str(e):
        raise RuntimeError("legacy index: rebuild with current version to filter") from e
    raise

Prevention

When it happens

Trigger: Loading a persisted SimpleVectorStore JSON from an older LlamaIndex version and calling `query()`/`as_query_engine(filters=...)` or `MetadataFilters(...)` in retriever kwargs; any flow where `query.filters is not None`, the embedding dict is non-empty, but `metadata_dict` is empty.

Common situations: Upgrading LlamaIndex and reusing old `default__vector_store.json` persist files; indexes built via `VectorStoreIndex.from_documents` under versions that did not populate SimpleVectorStoreData.metadata_dict; setting `stores_text=False`-style configs; applying retriever filters for the first time against a legacy index.

Related errors


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