perf(llm): reuse embedding context across batch inputs#45
Open
saagpatel wants to merge 1 commit into
Open
Conversation
This was referenced Jul 11, 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.
Refs #44 and #34.
What changed
1e-6from the fresh-context path.Why
Startup tried several Hugging Face tokenizer candidates before falling back to metadata already present in the GGUF. Indexing also paid llama.cpp context creation and graph-planning costs once per chunk.
This is sequential context reuse, not packed multi-sequence batching. Packed batching was deliberately excluded because it did not preserve the existing vector-parity gate.
Impact
The sampled 32-document real-model run completed in 256 ms with one reused context versus 357 ms with fresh contexts, while remaining bitwise identical (
max_abs_diff=0). Absolute timing is machine-dependent; parity is the hard gate.Validation
cargo fmt --checkcargo clippy -- -D warningscargo test --lib llm::tests— 43 passedcargo build --release --example embed_batch_parityembed_batch_parity <copied-lab-models>— 0/32 vectors beyond1e-6