Repository navigation
refactor(core): document upsert/update as embed-then-commit - #1350
Merged
Merged
Conversation
Embed all chunks first (no index lock, no transaction), write the document and its chunks in one SQLite transaction (upsert_document_with_chunks / update_document_with_chunks), then mirror into the vector index through index_sync. A failure while embedding now leaves the previous document, chunks and index untouched; recall is no longer blocked for the whole embedding time. doc_delete uses the shared removal policy. Refs #1341 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This was referenced Oct 7, 2026
ajianaz
added a commit
that referenced
this pull request
Oct 7, 2026
…#1361) #1350 made document upsert/update embed-then-commit, but embed_document_chunks still held the embedder mutex across the whole chunk loop. recall/remember embed their query through the same mutex, so a long document made every other embed wait for all of its chunks. Take the lock per chunk instead. Co-authored-by: Aji Anaz <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.
What
Item B of the architecture review (#1341, tracked in #1345; builds on #1347/#1348).
doc_upsert_with_parentanddoc_updateembed all chunks first — no index lock, no open transaction — then write the document row and every chunk in one SQLite transaction (Store::upsert_document_with_chunks,Store::update_document_with_chunks;upsert_documentis split into a begin/commit wrapper and a transaction body), then mirror the result into the vector index throughindex_sync(remove_unsavedoldchunk:keys,insert_unsavednew ones, onepersist).doc_deleteremoves chunk vectors with the sharedremove_idspolicy and no longer swallows the save error (let _ = index.save()).embed_document_chunks/sync_document_chunks_to_indexhelpers replace three copies of the chunk loop.Why
Previously the document row was committed first, then each chunk was embedded while holding the embedder mutex and the index write lock, and chunks were inserted one by one outside a transaction. An embed failure at chunk 50 of 200 left the new document row with 49 chunks (old chunks already deleted) and blocked recall for the whole embedding time; chunk index inserts were warn-and-continue.
Behaviour changes (intended)
doc_upsertwithout an embedder committed the row and then errored.Testing
cargo fmt --check,cargo clippy --workspace --all-targetsclean;cargo test --workspacegreen (core 602); vecq-only core build green (600).Found on the way (not fixed here)
Changing a document's title fails with "database corruption" (FTS5 external-content update trigger) — filed as #1349. The new tests keep the title constant so they isolate embed failure.
Refs #1341
🤖 Generated with Claude Code