[Bug] Fix FilterTypedDict to accept field-based filters #609
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.
Summary
Fixes #461
This PR corrects the typing for the
filterparameter inIndexAsyncio.query()andIndex.query()methods.Problem
The
FilterTypedDicttype was incorrectly defined to only accept operator-only filters like:{"$eq": "value"} # Only this was allowed by type checkerHowever, Pinecone's actual filter API requires field names in the filter structure:
{"field": {"$eq": "value"}} # This is the correct syntax but caused type errorsThis discrepancy caused IDEs and type checkers (like Pylance, mypy) to show false positive errors when using the correct filter format, making the developer experience frustrating with "red squiggly lines" despite the code working correctly at runtime.
Solution
Updated
FilterTypedDictto support both formats:FieldFiltertype:dict[str, OperatorFilter | FieldValue]to support{"field": {"$eq": "value"}}OperatorFiltertype alias for clarityFieldFilterin theSimpleFilterunionThe fix maintains full backward compatibility while allowing the proper nested filter syntax.
Examples
After this fix, all these filter formats are correctly typed:
Test Plan
Documentation
The fix aligns with Pinecone's official filter documentation and the examples shown in the method docstrings, which already demonstrate the field-based syntax.
Note
Low Risk
Type-only change broadening accepted filter shapes; no runtime logic changes, but could mask some invalid filter structures for type checkers.
Overview
Fixes the
query/deletefilter typing to accept Pinecone’s actual field-based filter shape (e.g.,{"field": {"$eq": "value"}}) rather than only operator-only dictionaries.Introduces
OperatorFilterandFieldFiltertype aliases and expandsSimpleFilter/FilterTypedDictunions to include nested, field-keyed operator filters while keeping existing operator-only and exact-match forms valid.Written by Cursor Bugbot for commit 0f9033d. This will update automatically on new commits. Configure here.