Fix semantic search SQL: CAST instead of :: for SQLAlchemy text() #161
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
forgejo_admin/pal-e-api!161
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "160-fix-semantic-search-sql-sqlalchemy-text"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
SQLAlchemy's
text()fails to bind:query_vecwhen followed by::vector(PostgreSQL typecast syntax). The parameter is never recognized, causing semantic search to fail at runtime. This replaces all 4 occurrences withCAST(:query_vec AS vector), which SQLAlchemy parses correctly.Changes
src/pal_e_docs/routes/notes.py— replaced:query_vec::vectorwithCAST(:query_vec AS vector)in 4 locations:_semantic_search_notes()SELECT clause (line 312)_semantic_search_notes()ORDER BY clause (line 317)semantic_search()SELECT clause (line 594)semantic_search()ORDER BY clause (line 599)Test Plan
pytest tests/ -v)Review Checklist
Related
PR #161 Review
BLOCKERS
None.
NITS
None.
SOP COMPLIANCE
160-fix-semantic-search-sql-sqlalchemy-text)Closes forgejo_admin/pal-e-docs#160CODE REVIEW
Correctness: All 4 occurrences of
:query_vec::vectorreplaced withCAST(:query_vec AS vector). Both functions are covered:_semantic_search_notes()_semantic_search_notes()semantic_search()semantic_search()SQL semantics preserved:
CAST(x AS vector)is equivalent tox::vectorin PostgreSQL. The::shorthand is just syntactic sugar forCAST(). The fix is correct because SQLAlchemy'stext()parser treats:query_vecas a bind parameter name and cannot disambiguate the::that immediately follows.CAST()eliminates the parsing ambiguity entirely.No residual issues: Grep confirms zero remaining
::vectorpatterns in the file.VERDICT: APPROVED