Skip to content

perf(core): release the embedder lock between document chunks - #1361

Merged
ajianaz merged 1 commit into
developfrom
fix/doc-upsert-atomic
Oct 7, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/doc-upsert-atomic

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

What

embed_document_chunks now takes the embedder mutex per call (once for max_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 tests upsert_failing_mid_document_keeps_previous_version_and_index and update_failing_mid_document_keeps_previous_content_and_chunks. It referenced #1341, so #1323 stayed open.

What remained: recall/remember embed 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-serve wraps the whole Uteke in one Mutex<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 warnings and cargo fmt --all -- --check clean.
  • No new test for the lock interleaving: std::sync::Mutex is unfair, so an interleave assertion would be timing-dependent.

🤖 Generated with Claude Code

#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]>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit 05ce8b2 into develop Oct 7, 2026
15 checks passed
@ajianaz
ajianaz deleted the fix/doc-upsert-atomic branch October 7, 2026 14:26
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.

fix: make document upsert atomic and embed outside the index lock

1 participant