Repository navigation
fix(postgres): use value type instead of float() to detect numeric metadata filters - #1
Open
kumarpriyanshu09 wants to merge 3 commits into
Open
kumarpriyanshu09 wants to merge 3 commits into
kumarpriyanshu09 wants to merge 3 commits into
Conversation
…ama#15962) Co-authored-by: Techboy bebop <kumarpriyanshu09@users.noreply.github.com>
…lters (run-llama#15962) Co-authored-by: Techboy bebop <kumarpriyanshu09@users.noreply.github.com>
Co-authored-by: Techboy bebop <kumarpriyanshu09@users.noreply.github.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
PGVectorStore._build_filter_clausedecided whether a comparison filter was numeric by callingfloat(filter_.value). Python'sfloat()accepts strings that Postgres'::floatcast rejects (for example"2024_123", which Python reads as2024123.0). So a plain string filter such asMetadataFilter(key="file_name", value="2024_123")emitted(metadata_->>'file_name')::float = 2024123.0, and the query failed withDataError: invalid input syntax for type double precision. Strings like"nan"or"inf"also produced invalid SQL.The check now uses the value's Python type, which
MetadataFilterpreserves throughStrictInt/StrictFloat/StrictStr:int/floatvalues (excludingbool) keep the existing::floatcomparison. The emitted SQL is unchanged.strvalues are always compared as text. Pass anint/floatfor numeric comparisons.Only the
EQ/NE/GT/GTE/LT/LTEfallback branch changes. IN/NIN/ANY/ALL/CONTAINS/TEXT_MATCH/IS_EMPTY are untouched. This follows the same idea as the idle draft run-llama#22367 (thanks @pctablet505).Fixes run-llama#15962
New Package?
Version Bump?
llama-index-vector-stores-postgres0.9.0 → 0.9.1)Type of Change
How Has This Been Tested?
DB-free unit tests in
tests/test_vector_stores_postgres.pycall_build_filter_clauseon a store created withPGVectorStore.__new__:"2024_123","123","0.5","1e5","nan","inf") × all six comparison operators produce text comparisons with no::float.int/floatvalues keep the exact::floatSQL.boolis never cast.uv run -- pytestin the package: 125 passed, 90 skipped (DB tests skip without Postgres).Suggested Checklist:
uv run make format; uv run make lintto appease the lint gods