Skip to content

fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding#456

Merged
tobi merged 1 commit into
tobi:mainfrom
antonio-mello-ai:fix/insert-embedding-vec0-replace
Mar 28, 2026
Merged

fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding#456
tobi merged 1 commit into
tobi:mainfrom
antonio-mello-ai:fix/insert-embedding-vec0-replace

Conversation

@antonio-mello-ai
Copy link
Copy Markdown
Contributor

@antonio-mello-ai antonio-mello-ai commented Mar 24, 2026

Summary

Fixes #445insertEmbedding uses INSERT OR REPLACE for the vectors_vec table, but sqlite-vec's vec0 virtual tables silently ignore the OR REPLACE clause. A crash mid-embed leaves orphan rows in vectors_vec without corresponding content_vectors entries, causing UNIQUE constraint failed errors on re-embed.

Changes

  • Insert content_vectors first so getHashesForEmbedding (which checks only content_vectors) won't re-select the hash if a crash occurs between the two inserts.
  • Use DELETE + INSERT for vectors_vec instead of INSERT OR REPLACE, since vec0 doesn't honor the conflict clause.

Test plan

  • All 706 existing tests pass (vitest, Node.js + macOS).
  • The fix is a minimal reorder + statement change in a single function — no new APIs or schema changes.

Built with Claude Code.

@antonio-mello-ai antonio-mello-ai changed the title fix: respect XDG_CACHE_HOME for model cache directory fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding Mar 24, 2026
@antonio-mello-ai antonio-mello-ai force-pushed the fix/insert-embedding-vec0-replace branch from a1a202b to 6f0202c Compare March 24, 2026 14:09
sqlite-vec's vec0 virtual tables silently ignore the OR REPLACE conflict
clause. When a crash interrupts embedding mid-way, chunks that were
inserted into vectors_vec but not content_vectors get re-selected by
getHashesForEmbedding, causing a UNIQUE constraint error on re-embed.

Two changes:
1. Insert content_vectors first so getHashesForEmbedding won't re-select
   the hash if a crash occurs between the two inserts.
2. Use DELETE + INSERT for vectors_vec instead of INSERT OR REPLACE.

Fixes tobi#445

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@antonio-mello-ai antonio-mello-ai force-pushed the fix/insert-embedding-vec0-replace branch from 6f0202c to 902e146 Compare March 24, 2026 14:11
zeattacker pushed a commit to zeattacker/qmd that referenced this pull request Mar 26, 2026
Merges dev-upstream-fixes (cherry-picked PRs tobi#462, tobi#463, tobi#455, tobi#418,
tobi#456, tobi#442, tobi#453) into dev. Resolved mcp/server.ts bind conflict —
keep 0.0.0.0 for Docker container accessibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tobi tobi merged commit 6a45150 into tobi:main Mar 28, 2026
jaylfc added a commit to jaylfc/qmd that referenced this pull request Apr 5, 2026
…g-vec0-replace

fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding
jaylfc added a commit to jaylfc/qmd that referenced this pull request Apr 5, 2026
…g-vec0-replace

fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding
tanarchytan referenced this pull request in tanarchytan/lotl Apr 8, 2026
…c0-replace

fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding
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.

UNIQUE constraint error in insertEmbedding: vec0 ignores OR REPLACE

2 participants