Description
Summary
Reduce first-build semantic-search indexing time on CPU without assuming a particular batching algorithm or silently degrading retrieval quality. The current q8 embedding pipeline batches documents by count, but real code chunks vary widely in token length, so padding and dynamic quantization make both performance and output dependent on batch composition.
Current Behavior
Embedder.embedDocuments() processes sequential fixed-count batches. The upstream default is 32 documents, using Xenova/all-MiniLM-L6-v2 with dtype: "q8" and device: "cpu".
On a measured 14,576-chunk local corpus:
- Actual truncated input: 2.89 million tokens
- Fixed-32 padded input: 7.34 million tokens
- Estimated padding waste: 60.7%
A stratified 1,024-document CPU/q8 benchmark on an Intel i7-9750H produced:
| Fixed batch size | Time | Throughput | Final RSS |
|---|---|---|---|
| 1 | 15.9s | 64.3 docs/s | 310 MiB |
| 2 | 27.3s | 37.6 docs/s | 376 MiB |
| 4 | 35.5s | 28.9 docs/s | 533 MiB |
| 8 | 44.9s | 22.8 docs/s | 777 MiB |
| 16 | 52.8s | 19.4 docs/s | 1,211 MiB |
| 32 | 55.7s | 18.4 docs/s | 2,089 MiB |
| 64 | 54.4s | 18.8 docs/s | 4,006 MiB |
| 128 | 49.8s | 20.6 docs/s | 7,620 MiB |
Concurrent single-document calls at concurrency 1, 2, 8, and 32 remained within approximately 63-66 docs/s, suggesting that extra JavaScript concurrency does not improve this CPU workload. Progress reporting can be coalesced independently from the inference batch size.
Batch composition also changes q8 vectors. Repeating the same fixed-32 schedule was deterministic, but alternate schedules produced mean cosine near 0.993 versus fixed-32, minimum cosine near 0.98, and 17-19/20 overlap for one vector-only top-20 query. This establishes schedule-dependent output, not which schedule has better retrieval quality.
Proposed Behavior
Evaluate the CPU embedding policies against the same end-to-end workloads, then implement the smallest policy that improves indexing time and memory without degrading final search retrieval. Candidate policies include single-document inference with coalesced progress, length-aware fixed-count batches, and padded-token-budget batches; none is prescribed before integration and retrieval testing.
Acceptance Criteria
- Add a reproducible benchmark that includes tokenizer work, ONNX inference, production progress callbacks, and
Embedder/IndexManagerintegration. - Compare the current fixed-32 baseline with at least single-document inference and one length-aware policy on representative mixed-length corpora.
- Record runtime, progress cadence, and memory methodology; do not infer transient peak RSS from post-batch samples alone.
- Preserve the positional chunk-to-vector contract through
IndexManager.embedChunks()for any policy that reorders work. - Add integration coverage proving vectors are stored under the correct chunk IDs.
- Build a small, reviewable retrieval benchmark from mechanically grounded identifier, path, and natural-language queries; exclude disputed labels after independent review.
- Compare final search results using retrieval metrics such as Recall@5 and first-relevant rank, not vector cosine alone.
- Coalesce progress updates independently from inference calls if the selected policy uses small batches.
- Rebuild or version existing embeddings if the selected policy changes q8 document vectors.
- Keep GPU acceleration, model replacement, dtype changes, ranking redesign, and incremental persistence out of scope.
Technical Notes
Relevant files:
packages/semantic-search/src/embedder.tspackages/semantic-search/src/index-manager.tspackages/semantic-search/src/search.tspackages/semantic-search/test/index-manager.test.tspackages/semantic-search/test/search-engine.test.ts
Exact token-length preprocessing took 13.4 seconds for the measured 14,576-document corpus and must be included when evaluating token-aware policies. Prototype scheduling tests covered empty input, oversized singletons, budget and count limits, stable ties, exactly-once scheduling, and output-order restoration, but production integration remains untested.
The original semantic-search design discussion is available at #108.
Suggested Labels
bug, P1
Activity
Acters commentedon Jul 28, 2026
Issue Assessment
Summary
The issue has a demonstrated CPU/q8 performance problem: fixed-count batches mix widely different sequence lengths, amplify padding, increase memory, and change dynamically quantized document vectors based on batch composition. The requested outcome is to select a smaller, evidence-backed CPU policy without assuming that vector cosine alone proves retrieval quality.
Current State
Embedderdefaults to fixed batches of 32 usingXenova/all-MiniLM-L6-v2, q8, and CPU.IndexManager.embedChunks()pairs chunks and vectors positionally.Confirmed Evidence
On the reported host and corpus, fixed single-document inference materially outperformed fixed sizes 2-128 while using less observed memory. JavaScript concurrency from 1 to 32 simultaneous single-document calls did not materially improve throughput. This makes single-document inference with independently coalesced progress the leading candidate, but not a retrieval-quality conclusion.
The q8 model is deterministic for a repeated schedule but produces different vectors under different batch compositions. A one-query top-k comparison is evidence of changed inputs, not evidence that either schedule is more relevant.
Gaps and Ambiguities
Recommended Scope
The issue currently combines benchmark infrastructure, retrieval evaluation, production scheduling, progress behavior, cache invalidation, and integration correctness. That is larger than a normal focused implementation PR.
Use two focused stages:
Normal CI should test benchmark parsing/metrics and positional contracts with mocks. The real-model benchmark should run only by explicit command or environment opt-in.
Risks
Estimate
Automated assessment by mach6
Acters commentedon Jul 28, 2026
Tested Batching Alternatives: Evidence and Trade-offs
No policy is selected by this comment. These measurements document the alternatives tested before planning an implementation.
Environment and limitations
Xenova/all-MiniLM-L6-v2IndexManager, database, RPC/MCP progress, and final hybrid retrieval still require an opt-in integration benchmarkFixed-size comparison
A lightweight harness over the same stratified 1,024-document sample produced:
Observed RSS is not a guaranteed transient high-water mark.
Scheduling-policy comparison
The same instrumented 1,024-document workload was used for all policies below:
Per-batch instrumentation penalizes policies with many small batches. Separate lightweight and stratified runs confirmed the large fixed-32 versus fixed-1/token-aware difference, but exact sub-second rankings between the faster policies are not established.
Dynamic padded-token budget sensitivity
Sorted dynamic batches were tested across several budgets:
No tested value was uniquely optimal. Budgets from 512 through 8,192 had similar CPU throughput, while memory increased with the budget.
Exact versus approximate length costs
Single-document concurrency
Single-document calls were tested at JavaScript concurrency 1, 2, 8, and 32. Repeated runs remained approximately 63-66 documents/second, with identical output checksums. Extra JavaScript concurrency did not materially improve this CPU workload, likely because ONNX already uses CPU threads internally or schedules the calls over the same resources.
Inference batch size and reporting frequency are independent. Single-document inference can collect or report progress every 32 completions without creating a 32-document model batch.
Retrieval and q8 batch dependence
The q8 model was exactly deterministic when the same fixed-32 schedule was repeated. Changing peers or scheduling changed document vectors:
This proves batch-composition dependence, not which policy retrieves better results. Fixed-1 is attractive because documents and queries are both embedded independently, but retrieval quality must be evaluated through the complete hybrid search pipeline before calling it superior.
Prototype implementation costs
Prototype scheduler sizes, excluding integration and tests:
Twelve pure scheduler tests passed for exactly-once scheduling, stable ties, budget/count bounds, empty input, oversized singletons, and output restoration. They do not replace real
Embedder/IndexManagerintegration tests.Current conclusion
Fixed single-document inference is the leading CPU/q8 candidate because it is currently the fastest, simplest, lowest-memory option and removes peer-dependent batching. It is not yet the selected production solution. Required remaining gates are:
Acters commentedon Jul 28, 2026
Local fixed1 end-to-end indexing result
A fresh production-path semantic search was run after installing the local CPU/q8
batchSize: 1patch and removing the incomplete prior index.Compared with the fixed32 projection of approximately 792 seconds derived from the 1,024-document benchmark, this is:
The 66.1% wall-time reduction is close to the measured 60.6% fixed32 padding waste and is consistent with padding being a dominant cost. It does not establish a direct numerical correlation: the fixed32 value is projected from a smaller benchmark, while this fixed1 wall time also includes scanning, chunking, model setup, database writes, progress callbacks, and final ranking.
Fixed1 will remain the reporter's local default while upstream retrieval-quality and reproducibility work continues. This local decision is not evidence by itself to change the upstream default.
m-aebrer commentedon Jul 29, 2026
interesting! Definitely going to dig into this later, thanks Acters!
Acters commentedon Jul 31, 2026
I had found lightonai/next-plaid https://huggingface.co/blog/lightonai/colgrep-lateon-code
I had made an extension that uses it and directly taps into CUDA for semantic search. It is very accurate and takes about ~60 seconds vs the 268.8 second from dreb's default semantic search system.
This would be my go-to semantic search engine to replace dreb's current system. Mostly because the embedding model dreb uses is not as optimal for parsing code. the lateon code edge is also smaller compared to all-MiniLM-L6-v2 and boasts a higher accuracy metric on HF MTEB.
Acters commentedon Aug 5, 2026
Got around to completing the dreb extension that replaces search with the colgrep system if you are curious. https://github.com/Acters/dreb-extensions/tree/main/extensions/colgrep
didn't make it a PR because it is a massive change to dreb's current semantic search system. though it is more accurate for searching in code bases. it is possible if you want to move away from the current semantic search, this is what is available. Unfortunately the way it works requires someone to build it themselves. so current dreb semantic search is more or less compatible with any system.
oh and btw this issue report is mainly a single code line change of just setting batch size to 1. not really PR worthy either haha
m-aebrer commentedon Aug 5, 2026
Awesome, can't wait to try it out! When I get a chance, I'll test it, make the batch size 1 change probably, and also add your extension to a new readme section for recommended community extensions