Skip to content

fix(postgres): treat underscore-containing strings as text in metadata filters - #23431

Closed
aniketkrs wants to merge 1 commit into
run-llama:mainfrom
aniketkrs:fix/pgvector-underscore-filter
Closed

aniketkrs wants to merge 1 commit into
run-llama:mainfrom
aniketkrs:fix/pgvector-underscore-filter

Conversation

@aniketkrs

Copy link
Copy Markdown

Impact

Filtering a PGVectorStore on string metadata that merely looks numeric to Python, e.g. file_name="2024_123", crashes the query with DataError: invalid input syntax for type double precision instead of matching the document. Any metadata with underscores between digits (dates, IDs, filenames) makes metadata filtering unusable. This fixes #15962.

Cause

build_filter_clause probes float(value) to decide between the ::float and text SQL branches. Python's float() accepts underscores (float("2024_123") is 2024123.0), so the probe succeeds and emits (metadata->>'file_name')::float = 2024123.0, which Postgres rejects because the stored string is not a valid float literal. The except ValueError text fallback never fires.

Fix

Route string values containing _ to the existing text-comparison branch. Behavior is unchanged for every other input: genuine numeric strings ("3.14", "1e5") and real ints/floats still take the ::float path, and non-numeric strings still take the text path.

Fixes #15962.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 04:07
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Closing as a duplicate: #22367 was opened earlier for the same issue (#15962).
We keep the oldest open PR per issue to avoid splitting review effort.

If this PR differs meaningfully, please comment and a maintainer can reopen it and add the not-duplicate label.

@github-actions github-actions Bot closed this Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PGVectorStore incorrectly handles string metadata that resembles numbers

2 participants