Fix semantic search SQL: SQLAlchemy text() fails to bind :query_vec with ::vector cast #160
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#160
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Lineage
plan-pal-e-docs→ Phase 5a (Activate Semantic Search)Repo
forgejo_admin/pal-e-docsUser Story
As a pal-e-docs user
I want semantic and hybrid search to return results
So that agents and humans can find contextually relevant notes across the knowledge base
Context
Semantic search endpoints return 500 Internal Server Error. The embedding worker is running and has backfilled 186+ blocks, but the search SQL fails at query time.
SQLAlchemy's
text()parameter parser fails to recognize:query_vecwhen followed by PostgreSQL's::vectortypecast operator. The parameter never gets bound — the error showsparameters: {'limit': 10}withquery_vecmissing entirely. SQLAlchemy converts:limitto psycopg2 format%(limit)sbut leaves:query_vec::vectorunconverted because::confuses the parser.Fix: replace
:query_vec::vectorwithCAST(:query_vec AS vector)— standard SQL cast syntax that SQLAlchemy handles cleanly.File Targets
Files the agent should modify:
src/pal_e_docs/routes/notes.py— replace 4 occurrences of:query_vec::vectorwithCAST(:query_vec AS vector)Files the agent should NOT touch:
src/pal_e_docs/embedding_worker.py— uses raw psycopg2 (not SQLAlchemy text()), no issue theresrc/pal_e_docs/services/search.py— pure Python RRF logic, no SQLAcceptance Criteria
GET /notes/search?q=postgres&mode=semanticreturns results (not 500)GET /notes/search?q=postgres&mode=hybridreturns resultsGET /notes/semantic-search?q=postgresreturns resultsGET /notes/search?q=postgres) still worksTest Expectations
pytest tests/ -vConstraints
:query_vec::vector→CAST(:query_vec AS vector)in 4 placesChecklist
Related
plan-pal-e-docs— Phase 5a: Activate Semantic Searchtodo-fix-mcp-pypi-publish— related Phase 7 TODO