{"record":{"id":"94037b67e328331c","repo":"run-llama/llama_index","slug":"cannot-filter-stores-that-were-persisted-without-m","errorCode":null,"errorMessage":"Cannot filter stores that were persisted without metadata. Please rebuild the store with metadata to enable filtering.","messagePattern":"Cannot filter stores that were persisted without metadata\\. Please rebuild the store with metadata to enable filtering\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/vector_stores/simple.py","lineNumber":256,"sourceCode":"                self.data.metadata_dict.pop(node_id, None)\n\n    def clear(self) -> None:\n        \"\"\"Clear the store.\"\"\"\n        self.data = SimpleVectorStoreData()\n\n    def query(\n        self,\n        query: VectorStoreQuery,\n        **kwargs: Any,\n    ) -> VectorStoreQueryResult:\n        \"\"\"Get nodes for response.\"\"\"\n        # Prevent metadata filtering on stores that were persisted without metadata.\n        if (\n            query.filters is not None\n            and self.data.embedding_dict\n            and not self.data.metadata_dict\n        ):\n            raise ValueError(\n                \"Cannot filter stores that were persisted without metadata. \"\n                \"Please rebuild the store with metadata to enable filtering.\"\n            )\n        # Prefilter nodes based on the query filter and node ID restrictions.\n        query_filter_fn = build_metadata_filter_fn(\n            lambda node_id: self.data.metadata_dict[node_id], query.filters\n        )\n\n        if query.node_ids is not None:\n            available_ids = set(query.node_ids)\n\n            def node_filter_fn(node_id: str) -> bool:\n                return node_id in available_ids\n\n        else:\n\n            def node_filter_fn(node_id: str) -> bool:\n                return True","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/vector_stores/simple.py#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Rebuild the index with the current LlamaIndex version so SimpleVectorStoreData.metadata_dict is populated on add().","Delete the old persist file(s) and re-run ingestion before enabling filters.","If filtering is optional, drop the filters parameter for legacy stores or detect `not store.data.metadata_dict` and query unfiltered.","Verify after rebuild that the persisted JSON contains a non-empty metadata_dict before shipping filter-dependent code."],"exampleFix":"# before\nstore = SimpleVectorStore.from_persist_path(\"old_store.json\")\nresults = store.query(query_with_filters)  # ValueError\n\n# after\n# rebuild once with current version, then:\nstore = SimpleVectorStore.from_persist_path(\"rebuilt_store.json\")\nresults = store.query(query_with_filters)","handlingStrategy":"validation","validationCode":"def store_supports_filters(store) -> bool:\n    data = getattr(store, \"data\", None)\n    if data is None:\n        return True\n    return not data.embedding_dict or bool(data.metadata_dict)\n\nif filters is not None and not store_supports_filters(store):\n    filters = None  # or raise your own migration error","typeGuard":null,"tryCatchPattern":"try:\n    result = store.query(query)\nexcept ValueError as e:\n    if \"persisted without metadata\" in str(e):\n        raise RuntimeError(\"legacy index: rebuild with current version to filter\") from e\n    raise","preventionTips":["Rebuild and re-persist indexes after major LlamaIndex upgrades.","Smoke-test filter queries against persisted stores in CI.","Treat an empty metadata_dict as 'no filter support' in multi-version deployments."],"tags":["vector-store","metadata-filters","persistence","version-migration","python"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}