Repository navigation
perf(server): embed a recall or remember outside the store lock (#1518) - #1585
Merged
Merged
Conversation
The embedder slot lock is released before an embed call, and the router embeds the query or content of POST /recall and /remember before taking the store lock so the call under the lock hits the embedding cache. With a 50 ms mock embedder, 8 clients go from 19 to 141 ops/s.
…1518) The warm-up handle carries the privacy filter: content is validated and masked like a write, a strict-mode refusal or invalid content embeds nothing, and a blank query is skipped. Adds the Modal result for the ONNX backend.
| /// A warm-up handle once the embedder is built and caches its results. | ||
| /// It never initialises the embedder, so it is cheap to ask for. | ||
| pub fn embedding_warmer(&self) -> Option<EmbeddingWarmer> { | ||
| let handle = self.embedder.lock().ok()?.clone()?; |
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
The handle was stored once; it now follows the store (embedder and privacy config) on each request while the store lock is held.
This was referenced Oct 29, 2026
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
Arc), so a slow backend no longer blocks other embeds.queryofPOST /recalland thecontentofPOST /rememberBEFORE it takes the store lock, through a newEmbeddingWarmerhandle. The call under the lock then finds the vector in the embedding cache. It starts once the first request has built the embedder and only applies when the embedder caches results (the default cache); otherwise nothing changes.read_bodyconsumes, with the same size limit and errors.Why
#1518: one lock around the whole request put the embedding (a network round trip for
openai/ollama) inside the critical section, so throughput stayed flat however many clients there were.Testing
cargo fmt,cargo clippy --workspace --all-targets --locked -- -D warnings,cargo test --workspace --locked,cargo run -p docgen(no diff).route: concurrent requests overlap their embedding (fails when the warm-up is disabled: 964 ms vs ~400 ms), read-your-writes, a poisoned store lock does not fail later requests, a secret is masked before the warm-up, strict mode sends nothing.perf-aa75441, Modal 2 vCPU,perf-2652f0e-embed-outside-lock-*.json):uteke bench(in-process, does not touch the server path): insert/s 13.5 to 10.4 at 100 rows and 52.9 to 49.8 at 1000, recall avg 12.1 to 14.6 and 15.6 to 15.1 ms; run-to-run noise at this size (the 100-row insert is dominated by model warm-up), not re-run.