Skip to content

fix(vdb): correct malformed metadata-filter SQL in relyt and analyticdb - #39554

Open
AlexMultiAgent wants to merge 1 commit into
langgenius:mainfrom
AlexMultiAgent:fix-vdb-metadata-filter-sql-v2
Open

fix(vdb): correct malformed metadata-filter SQL in relyt and analyticdb#39554
AlexMultiAgent wants to merge 1 commit into
langgenius:mainfrom
AlexMultiAgent:fix-vdb-metadata-filter-sql-v2

Conversation

@AlexMultiAgent

@AlexMultiAgent AlexMultiAgent commented Jul 25, 2026

Copy link
Copy Markdown

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 as document_id, not 'document_id'.
  • api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py: WHERE 1=1WHERE 1=1 (trailing space) before the concatenated AND metadata_->>'document_id' IN (...).
  • api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py: regression test asserting the emitted SQL contains metadata->>'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 contains WHERE 1=1 AND and not 1=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

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
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant