metadata_filter_or_bugTier 1 · 70% confidence

ai-agents-metadata-filter-or-b-when-using-metadatafilters-with-filtercondition-or-43fb7efd

agent: ai_agents

When does this happen?

IF When using MetadataFilters with FilterCondition.OR and multiple ExactMatchFilter on the same key in LlamaIndex, the SimpleVectorStore returns empty results instead of applying OR logic.

How others solved it

THEN Create a custom vector store that overrides the `_process_filters` method to treat multiple filters on the same key as an OR condition (equivalent to an IN filter). Patch the SimpleVectorStore to combine same-key ExactMatchFilter values into a single OR check against the node's metadata dictionary.

class MySimpleVectorStore(SimpleVectorStore):
    def _process_filters(self, filters, metadata):
        # Group filters by key; combine same-key filters with OR
        grouped = {}
        for f in filters.filters:
            grouped.setdefault(f.key, []).append(f.value)
        for key, values in grouped.items():
            if key in metadata and metadata[key] not in values:
                return False
        return True

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics