Repository navigation
perf(core): release the embedder lock between document chunks - #1361
Merged
Merged
Conversation
#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: Claude Sonnet 5.5 <[email protected]>
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
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
embed_document_chunksnow takes the embedder mutex per call (once formax_seq_len, then once per chunk) instead of holding it across the whole chunk loop.Why
#1323 asked for atomic document upsert and for recall not to be blocked while embedding. #1350 (
6d0b778, embed-then-commit) already delivered the atomic part: all chunks are embedded with no transaction or index lock, then the document and chunks are written in one SQLite transaction, with testsupsert_failing_mid_document_keeps_previous_version_and_indexandupdate_failing_mid_document_keeps_previous_content_and_chunks. It referenced #1341, so #1323 stayed open.What remained:
recall/rememberembed their query through the same embedder mutex (embed_text), so one long document still made them wait for every chunk. Locking per chunk lets other embeds interleave between chunks.Not covered here:
uteke-servewraps the wholeUtekein oneMutex<Uteke>per request, so over HTTP a document upsert still serializes with other requests. That needs a server-level change and is out of scope for this PR.Closes #1323
Testing
cargo test -p uteke-core --lib: all pass, including the existing mid-document failure tests (atomicity unchanged).cargo clippy -p uteke-core --all-targets -- -D warningsandcargo fmt --all -- --checkclean.std::sync::Mutexis unfair, so an interleave assertion would be timing-dependent.🤖 Generated with Claude Code