fix(core): default MetadataFilters condition to AND when None#22155
Open
aditya-786 wants to merge 1 commit into
Open
fix(core): default MetadataFilters condition to AND when None#22155aditya-786 wants to merge 1 commit into
aditya-786 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
build_metadata_filter_fn— the in-core metadata filter used bySimpleVectorStore.queryanddelete_nodes— raisedValueError: Invalid filter condition: Nonewhen aMetadataFiltershadcondition=None, even though the field is typedOptional[FilterCondition](withFilterCondition.ANDas the default), soNoneis a valid value.The integration vector stores all normalize a missing condition to AND — e.g.
condition or "and"/condition or FilterCondition.ANDin Chroma, Pinecone, Weaviate, Databricks, Firestore, and OceanBase. SoMetadataFilters(filters=[...], condition=None)filters correctly on those stores but crashes on the in-coreSimpleVectorStore.This defaults
NonetoFilterCondition.ANDso the in-core store behaves consistently with the rest of the ecosystem. (The now-unusedcastimport is also dropped.)Fixes # (no separate issue — this mirrors the convention already used across the integration vector stores)
New Package?
Version Bump?
llama-index-corepackage is exempt per this template)Type of Change
How Has This Been Tested?
Added
test_none_condition_defaults_to_andtotests/vector_stores/test_metadata_filters_logic.py, asserting thatcondition=Nonefilters identically toFilterCondition.AND. It fails before this change (ValueError: Invalid filter condition: None) and passes after. The fulltests/vector_stores/suite (43 tests) passes locally.Suggested Checklist:
ruff checkandruff format(lint + format clean)