fix(embed): handle vec0 OR REPLACE limitation in insertEmbedding#456
Merged
tobi merged 1 commit intoMar 28, 2026
Merged
Conversation
a1a202b to
6f0202c
Compare
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>
6f0202c to
902e146
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #445 —
insertEmbeddingusesINSERT OR REPLACEfor thevectors_vectable, but sqlite-vec'svec0virtual tables silently ignore theOR REPLACEclause. A crash mid-embed leaves orphan rows invectors_vecwithout correspondingcontent_vectorsentries, causingUNIQUE constraint failederrors on re-embed.Changes
content_vectorsfirst sogetHashesForEmbedding(which checks onlycontent_vectors) won't re-select the hash if a crash occurs between the two inserts.DELETE+INSERTforvectors_vecinstead ofINSERT OR REPLACE, since vec0 doesn't honor the conflict clause.Test plan
Built with Claude Code.