Skip to content

fix(core): default MetadataFilters condition to AND when None#22155

Open
aditya-786 wants to merge 1 commit into
run-llama:mainfrom
aditya-786:fix/metadata-filters-none-condition
Open

fix(core): default MetadataFilters condition to AND when None#22155
aditya-786 wants to merge 1 commit into
run-llama:mainfrom
aditya-786:fix/metadata-filters-none-condition

Conversation

@aditya-786

Copy link
Copy Markdown

Description

build_metadata_filter_fn — the in-core metadata filter used by SimpleVectorStore.query and delete_nodes — raised ValueError: Invalid filter condition: None when a MetadataFilters had condition=None, even though the field is typed Optional[FilterCondition] (with FilterCondition.AND as the default), so None is a valid value.

The integration vector stores all normalize a missing condition to AND — e.g. condition or "and" / condition or FilterCondition.AND in Chroma, Pinecone, Weaviate, Databricks, Firestore, and OceanBase. So MetadataFilters(filters=[...], condition=None) filters correctly on those stores but crashes on the in-core SimpleVectorStore.

This defaults None to FilterCondition.AND so the in-core store behaves consistently with the rest of the ecosystem. (The now-unused cast import is also dropped.)

Fixes # (no separate issue — this mirrors the convention already used across the integration vector stores)

New Package?

  • Yes
  • No

Version Bump?

  • No (the llama-index-core package is exempt per this template)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • I added new unit tests to cover this change

Added test_none_condition_defaults_to_and to tests/vector_stores/test_metadata_filters_logic.py, asserting that condition=None filters identically to FilterCondition.AND. It fails before this change (ValueError: Invalid filter condition: None) and passes after. The full tests/vector_stores/ suite (43 tests) passes locally.

Suggested Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • I ran ruff check and ruff format (lint + format clean)

build_metadata_filter_fn raised "Invalid filter condition: None" when a
MetadataFilters had condition=None, even though the field is typed
Optional[FilterCondition] and None is a valid value. The integration vector
stores (Chroma, Pinecone, Weaviate, Databricks, Firestore, OceanBase) all
treat a missing condition as AND, so the same filters worked there but
crashed on the in-core SimpleVectorStore. Default None to FilterCondition.AND
to match the rest of the ecosystem.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant