From 0f9033dfd7a436808f2ac8fb6b556fc72067b19f Mon Sep 17 00:00:00 2001 From: Varun Chawla Date: Sat, 7 Feb 2026 17:19:08 -0800 Subject: [PATCH] Fix FilterTypedDict to accept field-based filters Fixes #461 The FilterTypedDict was incorrectly typed to only accept operator-only filters like {"$eq": "value"}, but Pinecone's actual filter syntax requires field names: {"field": {"$eq": "value"}}. This caused type checkers to show false positives when using the correct filter format with IndexAsyncio.query() and Index.query(). Changes: - Added FieldFilter type to support {"field": {operator}} syntax - Added OperatorFilter type alias for clarity - Included FieldFilter in SimpleFilter union - Updated FilterTypedDict to accept both formats The fix maintains backward compatibility while allowing the proper nested filter syntax that Pinecone actually requires. --- pinecone/db_data/types/query_filter.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pinecone/db_data/types/query_filter.py b/pinecone/db_data/types/query_filter.py index ebeaae716..925f91609 100644 --- a/pinecone/db_data/types/query_filter.py +++ b/pinecone/db_data/types/query_filter.py @@ -17,6 +17,22 @@ NinFilter = dict[Literal["$nin"], list[FieldValue]] ExistsFilter = dict[Literal["$exists"], bool] +# Operator-only filters (e.g., {"$eq": "value"}) +OperatorFilter = ( + EqFilter + | NeFilter + | GtFilter + | GteFilter + | LtFilter + | LteFilter + | InFilter + | NinFilter + | ExistsFilter +) + +# Field-level filters that can use operators or exact match (e.g., {"field": {"$eq": "value"}}) +FieldFilter = dict[str, OperatorFilter | FieldValue] + SimpleFilter = ( ExactMatchFilter | EqFilter @@ -28,6 +44,7 @@ | InFilter | NinFilter | ExistsFilter + | FieldFilter ) AndFilter = dict[Literal["$and"], list[SimpleFilter]] OrFilter = dict[Literal["$or"], list[SimpleFilter]]