Repository navigation
fix(pgvector): use type check for numeric filter values - #22367
Open
pctablet505 wants to merge 2 commits into
Open
pctablet505 wants to merge 2 commits into
pctablet505 wants to merge 2 commits into
Conversation
Avoid casting string metadata values to float by checking the Python type of the filter value instead of calling float(). This prevents PostgreSQL DataError for strings like '2024_123' that Python float() accepts but PostgreSQL ::float does not. Fixes run-llama#15962
pctablet505
force-pushed
the
fix-15962-pgvector-numeric-filter
branch
from
August 21, 2026 15:17
d6c13d9 to
948b271
Compare
This was referenced Sep 29, 2026
pctablet505
marked this pull request as ready for review
October 21, 2026 16:34
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.
Fixes #15962
Replaces the
float(value)try/cast inPGVectorStore._build_filter_clausewith an explicitisinstance(filter_.value, (int, float))check (excludingbool, which subclassesint). This keeps string metadata such as"2024_123"in text comparisons and avoids a PostgreSQLDataErrorfrom the::floatcast, while still using numeric comparison for actual int/float filter values.MetadataFilter.valueis a PydanticStrictInt/StrictFloat/StrictStr, so the Python type is exact and reliable to check.Adds unit tests for underscore-separated strings, plain numeric strings, int, and float filter values. The tests call
_build_filter_clausedirectly with a store built via__new__(no DB connection needed), asserting the generated SQL uses::floatonly for real numeric types.AI assistance disclosure: this change was drafted with AI assistance. I reviewed the fix and tests line by line, confirmed the root cause (Python's
float()accepts underscore separators like"2024_123"but PostgreSQL's::floatcast rejects them), verified thatMetadataFilter.value's Pydantic Strict typing makes theisinstancecheck reliable, and confirmed the tests exercise the real code path (the onlyselfreference in the tested branch is the pure_to_postgres_operator).