Skip to content

fix(pg): align SearchByEmbedding SQL placeholders with scope args#623

Merged
viettranx merged 1 commit intonextlevelbuilder:mainfrom
wwenrr:fix/601-skill-embedding-param-index
Apr 1, 2026
Merged

fix(pg): align SearchByEmbedding SQL placeholders with scope args#623
viettranx merged 1 commit intonextlevelbuilder:mainfrom
wwenrr:fix/601-skill-embedding-param-index

Conversation

@wwenrr
Copy link
Copy Markdown
Contributor

@wwenrr wwenrr commented Apr 1, 2026

Summary

Fix placeholder index alignment in PGSkillStore.SearchByEmbedding when scope args are present/absent.

Problem

Issue #601 reports:
SQLSTATE 42P18: could not determine data type of parameter $2

SearchByEmbedding built a dynamic query with hardcoded placeholder offsets (starting scope at $3) while argument composition was dynamic. This could produce placeholder/index mismatch depending on scope shape.

Changes

  • internal/store/pg/skills_embedding.go
    • start scope placeholders at $2 (after $1 vector)
    • use nextParam returned by scopeClause() for ORDER BY ... <=> $n
    • use n+1 for LIMIT
    • centralize tenant/system condition formatting in helper:
      • buildSkillEmbeddingTenantCond(scope string)
  • internal/store/pg/skills_embedding_test.go
    • add tests for tenant condition builder:
      • empty scope
      • tenant-only scope
      • tenant + project scope

Closes #601

@viettranx viettranx merged commit d334a20 into nextlevelbuilder:main Apr 1, 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: SQLSTATE 42P18 in PGSkillStore.SearchByEmbedding due to parameter indexing misalignment

2 participants