fix(vdb): correct malformed metadata-filter SQL in relyt and analyticdb - #39554
Open
AlexMultiAgent wants to merge 1 commit into
Open
fix(vdb): correct malformed metadata-filter SQL in relyt and analyticdb#39554AlexMultiAgent wants to merge 1 commit into
AlexMultiAgent wants to merge 1 commit into
Conversation
The Relyt vector provider built its metadata filter predicate using
`{key!r}` for the key interpolation. With key='document_id' that renders
`metadata->>''document_id''` — doubled single quotes that make every
metadata-filtered search fail with a SQL syntax error. Drop the !r so the
key is interpolated as a plain identifier; values remain repr()-quoted.
The AnalyticDB search_by_vector path concatenated `WHERE 1=1` and
`AND metadata_->>'document_id' IN (...)` with no separator, producing
`WHERE 1=1AND ...`. PostgreSQL-based backends (including AnalyticDB) reject
`1AND` as a malformed numeric literal from PG15 onward, breaking filtered
vector search. Add a trailing space so the predicate is well-formed.
Tests:
- relyt: assert filter SQL has `metadata->>'document_id'` (not doubled quotes)
- analyticdb: assert SQL has `WHERE 1=1 AND ...` (not `1=1AND ...`)
Refs langgenius#39507, langgenius#39487
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.
Summary
api/providers/vdb/vdb-relyt/src/dify_vdb_relyt/relyt_vector.py: drop the{key!r}→{key}in the metadata-filter predicate so the key renders asdocument_id, not'document_id'.api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py:WHERE 1=1→WHERE 1=1(trailing space) before the concatenatedAND metadata_->>'document_id' IN (...).api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py: regression test asserting the emitted SQL containsmetadata->>'document_id' in (...)and not''document_id''.api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py: regression test asserting the emitted SQL containsWHERE 1=1 ANDand not1=1AND.Refs #39507, #39487.
Test Plan
uv run --project api pytest api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py -q