faxenoff commited on
Commit
be601a9
·
verified ·
1 Parent(s): ee119ed

docs: simplified model card — purpose, trade-offs vs alternatives, usage profiles, files

Browse files
Files changed (1) hide show
  1. README.md +145 -682
README.md CHANGED
@@ -22,547 +22,116 @@ base_model:
22
 
23
  # code-daemon-embed-v1
24
 
25
- A **46.8M-parameter, 4-layer code-embedding model** that maps short code units — function
26
- and method bodies, signatures, docstrings, symbol names — and short natural-language queries
27
- into a shared **768-dim** space. INT8, 128-token window, **1.9k-5.5k texts/s in ordinary use on a
28
- laptop RTX 5060, 10.7k sustained on a large corpus**.
29
-
30
- It is built for one job: **embedding a whole repository fast enough to re-index it on every
31
- commit**, so that a coding agent can run semantic search on every question it is asked. Every
32
- trade-off below follows from that — the depth, the 22.7k vocabulary, the 128-token cap, the
33
- INT8 weights, the four length-bucketed engines.
34
-
35
- ```python
36
- # the whole API surface — pooled AND L2-normalized inside the graph
37
- vec = session.run(None, {"input_ids": ids, "attention_mask": mask})[0] # [B, 768], ready
38
- ```
39
-
40
- Queries and documents are embedded **the same way** — no `query:` / `passage:` prefix.
41
-
42
- > **Pick this model for throughput, not for accuracy — and for English.** Against every public
43
- > 768-dimension encoder tested it is **4× to 6× faster** and **18 to 28 nDCG behind** on our own
44
- > held-out queries. Its vocabulary was pruned to code and English, so **Russian queries score
45
- > 0 of 34** where English ones score 9. What it gives is INT8 compiled engines, a pre-pooled graph,
46
- > a hard 128-token cost ceiling and **8k-14k texts/s** in a full index, as the dense half of a
47
- > hybrid retriever. Numbers and method:
48
- > [Against 768-dimension encoders](#against-768-dimension-encoders--read-this-before-choosing-the-model).
49
-
50
- ---
51
-
52
- ## 1. What it is for, and why not a standard embedder
53
-
54
- ### The target workload
55
-
56
- 1. A repository is indexed: every function, method, type and doc chunk becomes one short text
57
- and one vector. A 700k-entity C++ codebase embeds in **~81 seconds** on one consumer GPU.
58
- 2. Someone asks something short and keyword-shaped — *"git watcher head change reindex"*,
59
- *"acquire database lock for project hash"*, *"where does the daemon start"*.
60
- 3. The vector channel runs next to a lexical (BM25-style) channel and the two are fused.
61
-
62
- Point 3 matters: this model was trained to be **the dense half of a hybrid retriever**, not
63
- to win alone. Its training queries follow the shape an agent actually issues — short keyword bags,
64
- behaviour descriptions, identifier fragments — rather than docstring paraphrases.
65
-
66
- ### Design choices vs a typical general-purpose text embedder
67
-
68
- Against the e5 / bge / gte class:
69
-
70
- | aspect | typical | this model |
71
- |---|---|---|
72
- | Parameters | 110M – 7B | **46.8M** |
73
- | Vocabulary | 30k – 250k | **22.7k**, code-pruned |
74
- | Max sequence | 512 – 8192 | **128**, hard cap |
75
- | Query format | instruction prefix | **none**, symmetric |
76
- | Pooling | you implement it | **in the graph** |
77
- | Weights | FP32 / FP16 | **INT8**, QAT |
78
- | Top-rank precision | separate reranker pass | **distilled into the vectors** |
79
-
80
- ### Ranking distilled from a cross-encoder
81
-
82
- A bi-encoder compresses each document into a vector *before* it sees the query, so it cannot
83
- do the pairwise comparison a cross-encoder reranker does. This model closes part of that gap
84
- at **training** time instead of inference time: `Qwen/Qwen3-Reranker-4B` scored every
85
- (query, candidate) pair over mined hard negatives, and the student was trained with a
86
- **listwise-KL** objective to reproduce the teacher's *ranking distribution* — not merely
87
- "positive above negative", but how much each near-miss should trail.
88
-
89
- Practical consequence: **you probably do not need a runtime reranker on top of it.** In the
90
- production system it was built for, switching one on measured net-negative — the distillation
91
- had already captured the useful part, at zero inference cost.
92
-
93
- ### Strong / weak
94
-
95
- **Strong**
96
- - Repository search with short NL, keyword and identifier queries.
97
- - Natural language → code at short lengths.
98
- - The dense channel of a hybrid retriever.
99
- - Throughput-bound work: bulk re-index, index-on-save, re-embed per commit.
100
-
101
- **Weak / out of scope**
102
- - **Long documents.** Hard 128-token cap. Not a long-context retriever (see the window
103
- recipe in §4.6 if you must handle longer text).
104
- - Benchmark-style long problem statements, multi-turn dialogue, code↔code translation.
105
- - General English prose (medical / financial / news) — the pruned vocabulary trades that
106
- away deliberately.
107
- - **Non-English queries.** The prune kept 942 Cyrillic pieces of XLM-R's 31 671; Russian queries
108
- about code score **0 of 34** on a set where the same queries in English score 9. The
109
- `multilingual-e5-base` backbone this started from handles them; this model does not.
110
-
111
- ---
112
-
113
- ## 2. Architecture — what was kept, cut and added
114
-
115
- ### Specification
116
-
117
- | Property | Value |
118
- |---|---|
119
- | Encoder layers | **4** |
120
- | Hidden size | 768 |
121
- | Attention heads | 12 |
122
- | FFN | 3072, GELU |
123
- | LayerNorm eps | 1e-5 |
124
- | Vocabulary | **22,739** |
125
- | Position embeddings | 514 |
126
- | Max sequence | **128** |
127
- | Parameters | **46.80M** |
128
-
129
- - **Base** — `intfloat/multilingual-e5-base` (XLM-RoBERTa encoder, 12L, 278M).
130
- - **Vocabulary** — SentencePiece **unigram** pieces with byte fallback; positions are learned and
131
- absolute. Special ids **pad=0, unk=1, bos=2, eos=3** (raw-SentencePiece indexing).
132
- - **Parameter split** — 17.46M embedding table + 4 × ~7.3M encoder + positions.
133
- - **Output** — **768-dim, mask-mean-pooled AND L2-normalized inside the graph.** Use it as it comes.
134
- - **Weights** — **INT8** from quantization-aware training; the Q/DQ nodes carry the trained scales.
135
- - **ONNX** — opset 19; inputs `input_ids`, `attention_mask`, both **int64** `[batch, seq]`.
136
-
137
- ### Removed from the base model
138
-
139
- - **8 of 12 encoder layers** — strided-truncated 12 → 8 → 6 → **4**, healed after each cut.
140
- - **227k of 250k vocabulary pieces**: 250,002 → 22,739, and the embedding table with them
141
- (192M → 17.5M parameters — the single largest saving in the model).
142
- - **The E5 instruction prefixes.** No `query:` / `passage:` asymmetry; both sides are encoded
143
- identically.
144
- - **The pooler head, the MLM head, token-type inputs.** The graph has exactly two inputs.
145
- - **FP32 weights** — replaced by INT8 with trained scales.
146
-
147
- ### Added
148
-
149
- - **Mask-aware mean pooling and L2 normalization fused into the ONNX graph.** The model
150
- returns unit-norm `[B, 768]`, not `[B, seq, 768]` — there is no pooling code to get wrong,
151
- no `last_hidden_state` copy, and no way to accidentally compare unnormalized vectors.
152
- - **Q/DQ nodes with QAT-trained scales**, so a TensorRT/OpenVINO build is INT8 end-to-end
153
- without a calibration pass.
154
- - **Ranking knowledge from a 4B cross-encoder** (the rank-distillation above).
155
- - **Four length-bucketed engine builds** with a dynamic sequence dimension (§3, §4.4).
156
-
157
- ### How it was made, in brief
158
-
159
- The e5 backbone was truncated in depth, its vocabulary pruned and re-indexed to the
160
- raw-SentencePiece id convention, then trained by **distillation** — dense representation
161
- distillation against the embedding teacher, plus **listwise-KL ranking distillation** against the
162
- cross-encoder teacher, which is where the rank knowledge in section 1 comes from. The INT8 weights
163
- come from **quantization-aware training**, not from a calibration pass, and the export carries the
164
- scales learned during it.
165
-
166
- ### ⚠ If you build your own engines from this ONNX
167
-
168
- **Do not run PTQ/calibration over the shipped INT8 graph.** It overwrites the trained scales with
169
- fitted ones and measurably degrades the model. `model_int8qdt.onnx` *is* the artifact — feed it to
170
- your builder as-is (sections 4.4 and 4.5 show the TensorRT and OpenVINO invocations). This is the
171
- failure mode that produces an engine which builds cleanly, loads cleanly and quietly retrieves
172
- worse.
173
-
174
- ---
175
-
176
- ## 3. Performance
177
-
178
- Measured on **one RTX 5060 Laptop GPU (sm_120, 8 GB)**, TensorRT INT8, pinned TDP,
179
- `clocks.sm` 2,647 MHz median at 114 W.
180
-
181
- ### End-to-end, inside the production indexer
182
-
183
- The whole path: build the serve text → tokenize on host threads → IPC to the worker →
184
- GPU forward → pool → collect.
185
-
186
- | corpus | vectors | wall | pipeline texts/s | GPU-only texts/s |
187
- |---|--:|--:|--:|--:|
188
- | **mysql-server** (sustained, 54 batches) | 868,795 | 80.96 s | **10,731** | 11,712 |
189
-
190
- ⚠ **That is a best case, and a two-device one.** Re-measured 2026-09-11 on the same corpus:
191
- 10 686 texts/s pipeline, but only **5 680 texts/s** of model forward — the daemon adds the Intel
192
- iGPU (OpenVINO) alongside the RTX 5060 once a batch exceeds ~820 000 texts, and mysql-server does.
193
- A full index of a smaller repository runs on one device, and the rate then depends on the
194
- language: **13.8k texts/s for C/C++, 10.6k for TypeScript, 8.0k for Java, 7.9k for C#** (see
195
- [In a real index, by programming language](#in-a-real-index-by-programming-language)).
196
-
197
- Small **incremental** runs are slower again — **1 900 - 5 500 texts/s** for deltas of a few
198
- hundred to fifteen thousand vectors — because tokenisation and IPC are paid per batch and there
199
- are few batches to amortise them over. Size a deployment for your workload, not from the
200
- headline.
201
-
202
- `pipeline texts/s` = vectors ÷ wall clock, everything included. `GPU-only` = vectors ÷ summed
203
- inference time; it is higher because host work overlaps with the GPU.
204
-
205
- ### Solo engine profiles — cost per sequence length
206
-
207
- Four engines, one per length bucket, each with a **dynamic sequence dimension** so a batch
208
- can be dispatched at its own longest text instead of the bucket ceiling. One engine alone,
209
- dispatch only, 200 iterations. These are the engines built straight from `model_int8qdt.onnx`,
210
- with attention in fp32 — what every architecture ships except the sm_120 **m / l / xl**
211
- engines, which are faster (see [Attention precision differs by bucket on
212
- sm_120](#attention-precision-differs-by-bucket-on-sm_120)):
213
-
214
- **s** — 96 × 8…48, opt 48
215
-
216
- | seq | texts/s |
217
- |--:|--:|
218
- | 8 | 72,587 |
219
- | 16 | 50,681 |
220
- | 24 | 37,228 |
221
- | 32 | 29,651 |
222
- | 40 | 23,495 |
223
- | 48 | 19,785 |
224
-
225
- **m** — 128 × 56…64, opt 56 · **l** — 128 × 72…80, opt 72
226
-
227
- | seq | texts/s |
228
- |--:|--:|
229
- | 56 | 15,853 |
230
- | 64 | 13,068 |
231
- | 72 | 11,302 |
232
- | 80 | 9,913 |
233
-
234
- **xl** — 256 × 88…128, opt 96
235
-
236
- | seq | texts/s |
237
- |--:|--:|
238
- | 88 | 8,537 |
239
- | 96 | 7,816 |
240
- | 104 | 7,027 |
241
- | 112 | 6,421 |
242
- | 120 | 5,907 |
243
- | 128 | 5,464 |
244
-
245
- Three things to take from that table when you build your own serving path:
246
-
247
- - **Cost is per token, not per text**, and it is superlinear: solo token throughput *falls*
248
- from 1.01M tok/s at seq 48 to 0.71M at seq 128. Batch size is not the lever — a 256×64
249
- engine measured **5.8% slower per text** than 128×64, because 96×48 already saturates the
250
- SMs.
251
- - **Padding is the lever.** A batch pays for its *longest* member, so sorting texts by length
252
- before batching — and dispatching each batch at its own length — was worth **+10.2%**
253
- end-to-end. Round lengths up to a multiple of 8: a non-multiple is slower than a *longer*
254
- multiple (seq 70 costs more than seq 72).
255
- - **Running the four engines concurrently does not add throughput** on one GPU. In parallel
256
- they measured *slower* than serially (1,487 ms vs 1,423 ms for the same work). The lanes
257
- exist to keep the GPU fed while the host works, not to multiply throughput.
258
-
259
- ### Attention precision differs by bucket on sm_120
260
-
261
- On RTX 50xx (sm_120) the **m, l and xl** engines run each attention core as **one fused fp16
262
- kernel**; the **s** engine does not, on purpose.
263
-
264
- An engine built straight from `model_int8qdt.onnx` runs attention in fp32: QKᵀ, softmax and ·V
265
- as separate kernels, with the score matrix written to memory in between. TensorRT has no fused
266
- kernel for fp32 attention at this configuration (12 heads × 64) on sm_120. The m / l / xl
267
- engines are built from the same graph with each of the four attention cores expressed as a
268
- native ONNX `Attention` op on fp16 Q, K, V and mask, its output cast back to fp32. Nothing else
269
- changes: every INT8 GEMM, LayerNorm and the fused pooling are identical, and so is the I/O
270
- contract.
271
-
272
- **s keeps fp32 attention because the fused kernel is slower at its shape.** One engine alone,
273
- real text, the two variants interleaved, minimum of 9 rounds:
274
-
275
- | bucket | batch × seq | fp32 attention | fused fp16 attention | | cos vs FP32 ONNX (mean / min) |
276
- |---|---|--:|--:|--:|---|
277
- | s | 96 × 48 | **20,272** | 18,577 | −8.4 % | 0.9772 / 0.9634 → 0.9769 / 0.9660 |
278
- | m | 128 × 64 | 12,771 | **14,188** | +11.1 % | 0.9776 / 0.9613 → 0.9777 / 0.9660 |
279
- | l | 128 × 80 | 9,525 | **10,772** | +13.1 % | 0.9776 / 0.9613 → 0.9774 / 0.9623 |
280
- | xl | 256 × 128 | 5,259 | **6,344** | +20.6 % | 0.9776 / 0.9613 → 0.9779 / 0.9663 |
281
-
282
- (texts/s at the full batch; the gain holds across each dynamic range — per seq cell m +7 to
283
- +16 %, l +11 to +13 %, xl +14 to +21 %.)
284
-
285
- **End to end**, a full index through the production indexer, the two engine sets alternated
286
- twice each: embedding wall time **−13.8 %** on a 24k-vector repository and **−10.8 %** on a
287
- 90k-vector Java repository (the smaller gain is the more tokenizer-bound pipeline; the GPU part
288
- of both fell by ~9 %). Long texts carry the gain — xl is a quarter to three quarters of the texts
289
- in a code corpus but half or more of the GPU time.
290
-
291
- **The vectors are interchangeable.** The two variants differ from each other by less than each
292
- differs from the FP32 graph: top-10 neighbours agree with the FP32 answer 0.855 of the time with
293
- fp32 attention and 0.859 with fused fp16 attention, and 0.859 when fused-attention queries are
294
- run against a store embedded with fp32 attention. An existing index does not need re-embedding.
295
-
296
- Engines for **sm_75 – sm_90** are built from the unmodified graph (fp32 attention); whether the
297
- fused variant helps on those architectures has not been measured.
298
-
299
- ### Without a discrete GPU — OpenVINO on CPU, integrated GPU and NPU
300
-
301
- Same model, no NVIDIA card involved. Measured on an **Intel Core Ultra 9 275HX** — its CPU
302
- cores, its integrated GPU, and its *AI Boost* NPU (13 TOPS) — with OpenVINO 2026.3 and Intel
303
- NPU driver 32.0.100.4841. Both versions matter for the NPU rows: the numbers moved by an order
304
- of magnitude across an earlier OpenVINO release, so treat them as version-stamped. **The IRs in
305
- this repository are built for OpenVINO 2026.4**; the same IRs timed under both runtimes on the
306
- same machine (default hints, one synchronous request, interleaved rounds) put 2026.4 within
307
- 2–5 % slower on the CPU — inside this machine's round-to-round spread — and 0–4 % faster on the
308
- iGPU and the NPU. An OpenVINO IR is
309
- reshaped to **one static shape** at build time (unlike the TensorRT engines, whose sequence
310
- dimension is a range), so each bucket is a single number per device:
311
-
312
- Texts embedded per second, per bucket:
313
-
314
- | bucket | CPU INT8 | iGPU INT8 | NPU INT4 |
315
- |---|--:|--:|--:|
316
- | s | 702 | **1,092** | 565 |
317
- | m | 509 | 847 | 430 |
318
- | l | 402 | 678 | 298 |
319
- | xl | 237 | 420 | 169 |
320
-
321
- Shapes: CPU and iGPU run batch 64, the NPU batch 16; seq 48 / 64 / 80 / 128 for s / m / l / xl.
322
-
323
- **All three at once.** These are solo numbers — one device, nothing else running. The three
324
- share one LPDDR5 controller, so they do not simply add up, but they come close: measured in a
325
- single shared window at 64 × 64, `CPU 416 + iGPU 750 + NPU 377 = 1,543` against `527 + 822 +
326
- 423 = 1,772` solo, i.e. **87 % of the sum**. The noisiest neighbour is also the fastest device
327
- (the iGPU costs the others ~13 %, the CPU ~7 %), so there is nobody worth switching off.
328
-
329
- End to end that lands at **~1,050 texts/s** on a real 20k-entity repository — the daemon runs
330
- all three workers concurrently and that figure includes tokenization, IPC and vector writes,
331
- not just inference.
332
-
333
- Reference point: the same buckets on the RTX 5060 run at 19,785 / 13,068 / 9,913 / 5,464
334
- texts/s, so the integrated GPU is **15–18× slower** than the discrete one. That still leaves
335
- a 100k-entity repository indexed in a few minutes on a machine with no dedicated GPU at all.
336
-
337
- Three notes if you deploy this path:
338
-
339
- - **INT8 on CPU and iGPU, INT4 only on the NPU.** At 128 × 64 the iGPU does 859 texts/s in
340
- INT8, 584 in FP16 — and **584 in INT4**, exactly the FP16 number. INT4 here is weight-only
341
- compression: the weights decompress to fp16 before the GEMM, so it is the same GEMM and the
342
- 4 bits buy file size, not speed. Only INT8, which the kernels execute natively, moves the
343
- number. The NPU is the exception because it requires INT4 with static shapes.
344
- - **Feed it the Q/DQ graph, not a calibrated one.** OpenVINO keeps the QAT scales as
345
- FakeQuantize; re-fitting them with a post-training pass measured hit@1 .200 → .133 on this
346
- model. See §4.5 for the two-line recipe (and the transformation that keeps the IR at 96 MB
347
- instead of 179 MB).
348
- - **The NPU pays for batch, not for tokens.** Its IRs are baked at batch 16 against 96–256
349
- elsewhere, which is why its per-text cost is the flattest across buckets and its per-batch
350
- latency the lowest (28–95 ms). It suits interactive single-query embedding better than bulk
351
- indexing.
352
-
353
- ### Retrieval quality
354
-
355
- **80 captured real agent queries** over a live indexed codebase, multi-positive, file-level,
356
- through a production hybrid retriever (dense + lexical, runtime reranker **off**):
357
-
358
- | metric | value |
359
  |---|--:|
360
- | hit@1 | **0.46** |
361
- | hit@3 | 0.74 |
362
- | hit@5 | **0.78** |
363
- | hit@10 | 0.80 |
364
- | mrr@10 | 0.59 |
365
- | ndcg@10 | 0.61 |
366
-
367
- This is the metric the model is optimized for. On a broader 2,441-query gate across four
368
- unrelated repositories, the 4-layer model trades about **4% relative hit@1** against its
369
- 6-layer parent for roughly **1.5× the engine speed**.
370
-
371
- ### CoIR — the out-of-domain reference
372
-
373
- Run on **this exact artifact** — `model_int8qdt.onnx`, full corpora (2.3M documents across the
374
- six tasks), NDCG@10, the same raw-SentencePiece tokenization the daemon uses:
375
-
376
- | CoIR task | NDCG@10 | Pattern |
377
- |---|--:|---|
378
- | synthetic-text2sql | **51.26** | NL → SQL |
379
- | stackoverflow-qa | 41.63 | short question → code |
380
- | codesearchnet (6-lang avg) | 39.02 | docstring / NL → code |
381
- | codefeedback-st | 38.55 | NL instruction → code |
382
- | codesearchnet-ccr (6-lang avg) | 36.07 | code → related code |
383
- | cosqa | 17.50 | NL question → code (noisy / hard) |
384
- | **Average** | **37.34** | |
385
-
386
- Per language — codesearchnet (NL→code): python **68.30**, go 46.15, java 34.64, ruby 28.76,
387
- js 28.33, php 27.95. codesearchnet-ccr (code→code): js **43.36**, ruby 42.88, java 36.82,
388
- php 31.59, go 31.06, python 30.68.
389
-
390
- **Read this as a lower bound, not as the headline.** CoIR queries are mostly docstrings and
391
- long problem statements — the opposite of what this model was tuned for, and the spread proves
392
- it: 68.30 on Python docstring→code against 17.50 on cosqa's noisy question→code. Four of
393
- CoIR's ten tasks (code↔code translation, multi-turn dialogue, long problem statements) exceed
394
- the 128-token scope and are not shown. A small share of out-of-domain retrieval pairs was
395
- present in training as diversity regularization; overlap with the test splits was not audited.
396
-
397
- ### Against 768-dimension encoders — read this before choosing the model
398
-
399
- Every number above compares this model to **its own earlier versions**. That answers *did it
400
- improve*, not *is it the right pick*. Measured 2026-09-11 on one laptop, vector-only cosine (no
401
- BM25, no fusion, no reranker), every model at the same 128-token budget.
402
-
403
- **Only 768-dimension models are compared.** A 384-dimension encoder is cheaper in the forward
404
- pass, in the index and at query time — a different product, not a faster one — so putting it in
405
- the same column would be a category error.
406
-
407
- **Accuracy**, nDCG@10 × 100 on one scale. Three CoIR tasks chosen for the queries this model
408
- serves (short question → code, code → code), and our own held-out golden set:
409
-
410
- | model | cosqa | stack-qa | code→code | our golden |
411
- |---|--:|--:|--:|--:|
412
- | **code-daemon-embed-v1** (INT8) | 18.5 | 41.7 | 30.7 | 42.7 |
413
- | CodeRankEmbed | 35.5 | 73.3 | — | 64.6 |
414
- | multilingual-e5-base | 29.8 | 79.4 | 57.7 | 60.7 |
415
- | gte-modernbert-base *(teacher)* | **36.6** | **81.4** | **82.5** | **70.5** |
416
-
417
- `codesearchnet` (docstring → code) is left out because it matches neither query the daemon
418
- issues — and it is the task this model scores *highest* on (68.3), so dropping it makes the table
419
- less flattering, not more.
420
-
421
- **Speed**, texts/s through one pipe — every model exported to ONNX with pooling baked in, run
422
- under onnxruntime CUDA at FP32, batch 64, minimum of five rounds, across the shipped bucket
423
- lengths. The mean serving text is 69.6 tokens, so the middle columns are the working point:
424
-
425
- | model | layers | 40 | 64 | 80 | 128 |
426
- |---|--:|--:|--:|--:|--:|
427
- | **code-daemon-embed-v1** | **4** | **5 392** | **3 457** | **2 644** | **1 457** |
428
- | multilingual-e5-base | 12 | 1 355 | 854 | 666 | 385 |
429
- | CodeRankEmbed | 12 | 1 249 | 723 | 572 | 338 |
430
- | gte-modernbert-base | 22 | 1 093 | 606 | 446 | 243 |
431
-
432
- **4.0× `multilingual-e5-base`, 4.3-4.8× `CodeRankEmbed`, 4.9-6.0× `gte-modernbert-base`.** At equal
433
- width the layer count predicts it — 4 against 12 is 3×, 4 against 22 is 5.5× — and the residual
434
- above that is the embedding table: 17.5 M rows against 192 M is a gather with far better
435
- locality. The shipped INT8 TensorRT engine is faster again (5 464 texts/s at seq 128).
436
-
437
- **So the trade, stated once:** four to six times the throughput of any public 768-d encoder, for
438
- 18 to 28 points of nDCG on our own queries. The teacher is 28 ahead of its student — that is the
439
- distillation gap, not a benchmark artefact.
440
-
441
- #### Language
442
-
443
- The backbone is multilingual; **this model is not.** The 34 held-out queries translated to
444
- Russian, same corpus, same gold, identical text for every model:
445
-
446
- | model | EN hit@1 | RU hit@1 | RU hit@5 |
447
- |---|--:|--:|--:|
448
- | multilingual-e5-base | 0.382 | **0.235** | **0.529** |
449
- | gte-modernbert-base | 0.559 | 0.147 | 0.294 |
450
- | CodeRankEmbed | 0.412 | 0.000 | 0.235 |
451
- | **code-daemon-embed-v1** | 0.265 | **0.000** | 0.029 |
452
-
453
- The cause is countable: the 250k → 22.7k vocabulary prune kept **942 Cyrillic pieces** against
454
- XLM-R's 31 671, so Russian fragments into byte-level pieces. n = 34 and the translations are ours
455
- (the same text goes to every model), and this is the dense channel alone — in a hybrid retriever a
456
- Russian query carrying English technical terms will still partly hit lexically. **If your queries
457
- are not in English, use `multilingual-e5-base`.**
458
-
459
- #### In a real index, by programming language
460
-
461
- A full `--reset` index of one large repository per language through the UltraCode daemon, read
462
- from its own log. Same engine, same laptop:
463
-
464
- | language | repository | entities | xl bucket | **texts/s** |
465
- |---|---|--:|--:|--:|
466
- | C/C++ | mysql-server | 1 144 040 | 24 % | **13 821** |
467
- | TypeScript | vscode | 478 925 | 44 % | **10 644** |
468
- | Java | netty | 96 547 | 69 % | **8 006** |
469
- | C# | roslyn | 403 494 | 71 % | **7 930** |
470
-
471
- **Throughput depends on the language, not just the model.** C# entity texts are long — 71 % land
472
- in the most expensive (seq 88-128) engine — while C/C++ ones are short and repeat, 23 % of them
473
- served free from in-batch deduplication. The 1.7× spread between the top and bottom rows is text
474
- length, not hardware.
475
-
476
- The **10.7k** in §3 is the mysql-server row, and it is a two-device number: above ~820 000 texts
477
- the daemon adds the Intel iGPU (OpenVINO) alongside the RTX 5060 (TensorRT). The model's own
478
- forward rate on that run was 5 680 texts/s; the other three repositories stayed below the
479
- threshold and ran on one device.
480
-
481
- **The same comparison inside the product.** `multilingual-e5-base` — this model's own
482
- ancestor — compiled to the same TensorRT INT8 and OpenVINO engines, the same bucket grid,
483
- selected by config and run through the same full index:
484
-
485
- | language | this model | e5-base | ratio |
486
- |---|--:|--:|--:|
487
- | C/C++ | 13 821 | 5 758 | 2.40× |
488
- | TypeScript | 10 644 | 4 620 | 2.30× |
489
- | Java | 8 006 | 3 562 | 2.25× |
490
- | C# | 7 930 | 3 435 | 2.31× |
491
-
492
- texts/s. The gap is **2.3×** here against 4× through onnxruntime FP32, and the engines say why:
493
- e5's quantized graph keeps attention in BF16, where TensorRT fuses it into one kernel, while this
494
- model's QAT graph keeps attention in FP32, where it cannot. If you compile e5 yourself, check the
495
- engine against its FP32 graph — a default INT8 build came out at cosine 0.69 and reported success.
496
-
497
- Harness, raw JSON and the full write-up ship in the UltraCode repo
498
- (`models/_distill_shared/bench_vs_generic.py`, `.autodoc/benchmarks.md`). The harness was
499
- validated first by reproducing two numbers from this card — stackoverflow-qa 41.63 → 41.65 and
500
- codesearchnet python 68.30 → 68.32.
501
-
502
- ## 4. Using the model
503
-
504
- ### 4.1 What is in this repository
505
-
506
- **Source of truth — always present:**
507
-
508
- - **`model_int8qdt.onnx`** — INT8 Q/DQ graph with QAT-trained scales. Every TensorRT and
509
- OpenVINO INT8 engine is built from this file.
510
- - **`model.onnx`** — the FP32 twin of the same weights, for lanes that cannot read Q/DQ and for
511
- fine-tuning. Derived from the file above by dropping its Q/DQ pairs, so the weights are
512
- identical — the 0.98 cosine between them is the quantization, not a different model.
513
- - **`model.safetensors`** + **`config.json`** — the same float weights under transformers names,
514
- exported from `model.onnx` and checked against it (max |Δ| 3e-7 on the pooled vector).
515
- `AutoModel` loads the encoder (`XLMRobertaModel`); the trained projection `proj.weight` is
516
- not part of that class, so apply it yourself: mean-pool over the attention mask → `proj` →
517
- L2. `config.json` → `ultracode` spells the head out. This pair is also what the Apple (MLX)
518
- build is prepared from.
519
- - **`sentencepiece.bpe.model`** — the tokenizer. Raw-SP ids: pad=0, unk=1, bos=2, eos=3. Its
520
- 22,739 pieces match the embedding table row for row.
521
- - **`tokenizer_config.json`** — HF-side metadata.
522
-
523
- **Prebuilt engines**, uploaded progressively per architecture:
524
-
525
- ```text
526
- TensorRT …-{s,m,l,xl}_{win_x64,linux_x64}_trt11.3_sm_{75,80,86,89,120}.engine
527
- …-{s,m,l,xl}_linux_x64_trt11.3_sm_90.engine
528
- (sm_120 m / l / xl: fused fp16 attention — §3; all others: fp32 attention)
529
- OpenVINO …-{s,m,l,xl}_ov2026.4_{cpu_int8,igpu_lnl_int8,npu_int4}_b*_s*.{xml,bin}
530
- TVM Vulkan …_{win_x64,linux_x64}_tvm0.25_vulkan.{dll,so}
531
- MLX (Apple) model_gpu_mlx0.32/
532
- ```
533
-
534
- `sm_90` (H100 / H200) is Linux-only. An INT4 IR for discrete Intel Arc (`igpu_arc_int4`) is
535
- declared by the daemon but not built yet.
536
-
537
- > If the engine you want is missing, build it from the ONNX — §4.4.
538
 
539
- ### 4.2 Taking a prebuilt engine
540
 
541
- The filenames are a loading contract, not decoration. A serialized TensorRT plan is keyed on
542
- **{GPU architecture × OS × TensorRT version}** and `deserializeEngine` has no compatibility
543
- fallback, so pick all four coordinates exactly:
544
 
545
  ```
546
- code-daemon-embed-v1-m_win_x64_trt11.3_sm_120.engine
547
- │ │ │ └── GPU arch: sm_75 Turing · sm_80 Ampere (A100, A30)
548
- │ │ │ sm_86 Ampere (RTX 30xx, A-series) · sm_89 Ada (RTX 40xx, L4)
549
- │ │ │ sm_90 Hopper (H100, H200) · sm_120 Blackwell (RTX 50xx)
550
- │ │ └── TensorRT 11.3 — a plan loads only on the TensorRT that built it
551
- │ └── OS/ABI
552
- └── length bucket: s | m | l | xl
553
  ```
554
 
555
- Bucket shapes (batch × seq): **s** 96×48, **m** 128×64, **l** 128×80, **xl** 256×128. Loading
556
- all four costs ~400 MB of VRAM; if you only want one, take **m** — it covers the fattest part
557
- of a typical corpus (25–40% of texts land in 49…64 tokens).
558
-
559
- Route each text to the first bucket whose sequence ceiling fits its token count, and pad the
560
- batch to that bucket's shape. Padding is masked in attention, so a padded batch and an
561
- unpadded one give the same vector (verified at cosine 1.000000) — provided the mask is right.
562
 
563
- ### 4.3 Running the ONNX directly
 
 
564
 
565
- Works anywhere ONNX Runtime does (CPU, CUDA, DirectML) with no build step:
566
 
567
  ```python
568
  import onnxruntime as ort, sentencepiece as spm, numpy as np
@@ -575,174 +144,68 @@ def embed(texts, max_len=128):
575
  L = max(len(x) for x in ids)
576
  inp = np.array([x + [0] * (L - len(x)) for x in ids], dtype=np.int64) # pad=0
577
  mask = (inp != 0).astype(np.int64)
578
- # pooled and unit-norm already — no post-processing
579
- return sess.run(None, {"input_ids": inp, "attention_mask": mask})[0] # [B, 768]
580
 
581
  D = embed(["function acquireLock in src/db.zig: zig\npath: src db"])
582
  Q = embed(["acquire database lock"])
583
- print(Q @ D.T) # inner product IS cosine here
584
  ```
585
 
586
- Two notes that cost real debugging time:
 
587
 
588
- - **Tokenize with SentencePiece, not a greedy-BPE merge loop.** The vocabulary is a
589
- **unigram** model; scoring it with pair-merge BPE produces a *different segmentation* than
590
- training used, and that train/serve skew silently costs retrieval quality.
591
- - **Pad with id 0 and mask 0.** Both inputs are `int64`; feeding int32 buffers to a
592
- hand-written runtime is the classic "second half of every batch is garbage" bug.
593
 
594
- ### 4.4 Building your own TensorRT engines
595
-
596
- TensorRT 11 reads precision **entirely from the ONNX Q/DQ nodes** — the per-precision flags
597
- (`--int8`, `--fp16`, `--calib`) were removed. Feed it the Q/DQ graph; strongly typed is the
598
- only mode (`--stronglyTyped` is accepted and has no effect since 11.3). Feed it an unquantized
599
- graph instead and you get an FP16 engine that builds
600
- cleanly, loads cleanly, is twice the size and a fraction of the speed — the size is the only
601
- visible symptom, so check it.
602
-
603
- Rectangular engine for one bucket (here **m**, 128×64):
604
 
605
  ```bash
606
- trtexec --onnx=model_int8qdt.onnx \
607
- --saveEngine=code-daemon-embed-v1-m.engine \
608
- --builderOptimizationLevel=5 \
609
- --timingCacheFile=timing.cache \
610
- --minShapes=input_ids:1x1,attention_mask:1x1 \
611
- --optShapes=input_ids:128x64,attention_mask:128x64 \
612
  --maxShapes=input_ids:128x64,attention_mask:128x64
613
  ```
614
 
615
- Dynamic-sequence engines (the shipped configuration, +10.2% end-to-end) keep the batch
616
- dimension rectangular and let `seq` range. Use these profiles:
617
-
618
- | bucket | batch | seq min | seq **opt** | seq max |
619
- |---|--:|--:|--:|--:|
620
- | s | 96 | 8 | 48 | 48 |
621
- | m | 128 | 56 | 56 | 64 |
622
- | l | 128 | 72 | 72 | 80 |
623
- | xl | 256 | 88 | 96 | 128 |
624
-
625
- Three rules behind those numbers:
626
-
627
- - **One dynamic engine per bucket, `opt` at that bucket's mean length** — never one global
628
- dynamic engine. The tax is paid for being *far from the opt point*, not for being dynamic:
629
- a single wide (16→64→128) engine costs +0.8% at seq 64 but **+15.4%** at seq 80.
630
- - **Sequence length must be a multiple of 8** at dispatch (seq 70 costs more than seq 72).
631
- - **Sort texts by length within a bucket and cut at batch boundaries** before dispatch.
632
- Without the sort the dynamic engines buy ~0%: any 128-text batch drawn from the 49–64 range
633
- almost surely contains a 64 and dispatches at 64 anyway.
634
-
635
- An engine built this way has **fp32 attention** (§3). On sm_120 the shipped m / l / xl engines
636
- fuse it instead: replace each attention core — `Mul(Q)`, `Mul(Kᵀ)` → `MatMul` → `Add(mask)` →
637
- `Softmax` → `MatMul(·V)` — with an opset-23 `Attention` op on fp16 Q, K, V and mask (default
638
- scale; the export's two `64^-¼` multipliers are exactly `1/√64`), cast its output back to fp32,
639
- and keep the **s** bucket on the plain graph. Clamp the mask's `-3.4e38` fill to `-10000` first:
640
- fp16 cannot hold it. Two shapes that look equivalent do **not** fuse on sm_120: an fp32
641
- `Attention` op (the build fails with "not supported by a dedicated kernel"), and fp16 Q/K/V
642
- cast back up to fp32 around the op.
643
-
644
- A dynamic build reports ~69 layers against a rectangular build's ~54 — a wider shape range
645
- costs fusions, and that is exactly where the small tax at the ceiling lives.
646
-
647
- ### 4.5 OpenVINO, TVM, MLX
648
-
649
- OpenVINO reads the Q/DQ graph directly — the trained scales survive as FakeQuantize, so there
650
- is **no calibration pass to run**:
651
-
652
- ```python
653
- import openvino as ov
654
- from openvino._offline_transformations import compress_quantize_weights_transformation
655
-
656
- m = ov.Core().read_model("model_int8qdt.onnx")
657
- compress_quantize_weights_transformation(m) # folds weights to i8: 179 MB -> 96 MB
658
- m.reshape({"input_ids": [128, 64], "attention_mask": [128, 64]}) # one bucket, static
659
- ov.save_model(m, "code-daemon-embed-v1-m_cpu.xml")
660
- ```
661
-
662
- That transformation is not optional bookkeeping: `read_model` leaves every weight as f32 behind
663
- a FakeQuantize, and the IR comes out nearly twice the size for the same arithmetic. Do **not**
664
- reach for NNCF post-training quantization here — it would replace the trained scales with
665
- fitted ones, which is the failure the warning in §2 describes.
666
-
667
- The NPU artifacts are the exception: they start from the FP32 twin and apply INT4 weight
668
- compression at batch 16, trading accuracy for size on purpose. TVM Vulkan modules and the MLX
669
- weights are also built from the FP32 twin, per bucket.
670
-
671
- ### 4.6 Feeding it well
672
-
673
- **Documents.** The model was trained on a compact, front-loaded "serve text": semantics
674
- first, identifiers after, everything inside the 128-token budget. Reproducing that shape on
675
- your own corpus is worth more than any inference tuning:
676
-
677
- ```
678
- {type} {name} in {file}: {lang}
679
- path: {directory tokens, space-separated}
680
- [async] [exported] [test]
681
- sig: ({params}) -> {return type}
682
- {doc comment, first ~200 chars}
683
- {one-to-two-sentence description}
684
- ```
685
-
686
- for example:
687
-
688
- ```
689
- function acquireProjectLock in src/storage/multi_db.zig: zig
690
- path: src storage multi db
691
- [exported]
692
- sig: (allocator: Allocator, project_hash: []const u8) -> !Lock
693
- Acquires the exclusive SQLite lock for one project.
694
- ```
695
-
696
- Cap the whole text around 768 characters; the raw function body is deliberately *not* part of
697
- it (it belongs in the lexical channel, where it measurably helps, not in the vector).
698
-
699
- **Queries.** Feed them raw, no prefix, no template. The model is tuned for short keyword bags
700
- and behaviour descriptions.
701
 
702
- **Text longer than 128 tokens.** Split into overlapping windows — window 128, stride 96 —
703
- embed each, then mean-pool the window vectors and L2-renormalize. That is what the production
704
- indexer does for long doc chunks.
 
 
 
 
 
 
705
 
706
- **Retrieval.** The vectors come out unit-norm, so inner product is cosine — no normalization
707
- step of your own. They are dense and 768-dimensional; an IVF/HNSW index over them behaves
708
- normally.
709
 
710
- ---
711
-
712
- ## Apple Neural Engine (Core ML)
713
-
714
- `coreml_ane/embed.mlpackage/` is a Core ML **multifunction** package that runs this
715
- embedding on the Apple Neural Engine. It is a bundle, not a file — four
716
- entries (`Manifest.json`, `shapes.json`, `Data/com.apple.CoreML/model.mlmodel`,
717
- `Data/com.apple.CoreML/weights/weight.bin`) that must keep their relative paths.
718
-
719
- **One compiled function per shape**, named `b<batch>_s<seq>`: `b96 s48`, `b128 s64`, `b128 s80`, `b256 s128`.
720
- Fixed shapes are not a simplification. `ct.EnumeratedShapes` converts and runs, and
721
- measures 233 emb/s against 2 873 on the same encoder, because the dynamic ops it
722
- injects push the graph off the Neural Engine. `shapes.json` lists what was compiled,
723
- so a caller can ask instead of assuming.
724
-
725
- Measured on an M4 through the daemon's Core ML wrapper: 2 597 rows/s at `b96 s48`, 1 546 at
726
- `b128 s64`, 1 106 at `b128 s80`, 594 at `b256 s128`. End to end on a real corpus the embed
727
- phase runs 1 096 emb/s against MLX's 423 for the same vectors (cosine 0.99997 against the
728
- torch F32 reference).
729
-
730
- Weights are fp16. The package is built from the MLX safetensors beside it, so a model
731
- is ANE-ready exactly when it is MLX-ready — there is no second set of source weights.
732
- Load it with `MLComputeUnits.cpuAndNeuralEngine`: plain `.all` lets Core ML place the
733
- graph on the GPU instead, which measured 809 emb/s against the ANE's 2 873.
734
-
735
- A shape the package does not carry is not an error — the caller is expected to fall
736
- back to the MLX graph, which takes any shape. That is what makes the fixed-shape
737
- package safe to ship alongside `model_gpu_mlx*/` rather than instead of it.
738
 
739
  ## License
740
 
741
- Released under the **MIT license**.
742
-
743
- The backbone (`intfloat/multilingual-e5-base`) is MIT; the teachers (`gte-modernbert-base`,
744
- `Qwen3-Reranker-4B`) are Apache-2.0. As is standard practice for distilled embedding models,
745
- the **weights are released under MIT**. Not legal advice.
746
 
747
  ## Attribution
748
 
 
22
 
23
  # code-daemon-embed-v1
24
 
25
+ A **4-layer, 46.8M-parameter code-embedding model** built for one job: embedding a whole
26
+ repository fast enough to **re-index it on every commit**, as the dense half of a hybrid
27
+ (vectors + BM25) code search. Short code units — signatures, docstrings, symbol names, one-line
28
+ descriptions — and short keyword-shaped queries land in one **768-dim** space.
29
+
30
+ **What makes it different**
31
+
32
+ - **Speed first.** 4–6× the throughput of any public 768-dim encoder we tested; a 1.1M-entity
33
+ C++ repository embeds in about 80 seconds on a laptop GPU.
34
+ - **A reranker's judgement baked into the vectors.** A 4B cross-encoder's ranking was distilled
35
+ into the bi-encoder at training time; in the system it was built for, a runtime reranker on
36
+ top of it measured net-negative.
37
+ - **Nothing to get wrong at the output.** Mean pooling and L2 normalization are inside the graph:
38
+ the model returns unit-norm `[B, 768]`, ready for a dot product.
39
+ - **INT8 from quantization-aware training**, so TensorRT and OpenVINO build an INT8 engine with no
40
+ calibration pass.
41
+
42
+ Queries and documents are encoded the same way — no `query:` / `passage:` prefix. Hard cap of
43
+ **128 tokens**. **English and code only.**
44
+
45
+ ## Choosing it — the trade
46
+
47
+ Vector channel alone, every model at the same 128-token budget. Quality is nDCG@10 × 100; speed
48
+ is texts/s through onnxruntime CUDA FP32, batch 64, at seq 64 (the mean serving text is 70 tokens).
49
+ Laptop RTX 5060, 2026-09-11.
50
+
51
+ | model | layers | texts/s | cosqa | stack-qa | code→code | our queries | Russian hit@1 |
52
+ |---|--:|--:|--:|--:|--:|--:|--:|
53
+ | **code-daemon-embed-v1** | **4** | **3 457** | 18.5 | 41.7 | 30.7 | 42.7 | 0.00 |
54
+ | multilingual-e5-base | 12 | 854 | 29.8 | 79.4 | 57.7 | 60.7 | **0.24** |
55
+ | CodeRankEmbed | 12 | 723 | 35.5 | 73.3 | — | 64.6 | 0.00 |
56
+ | gte-modernbert-base *(its teacher)* | 22 | 606 | **36.6** | **81.4** | **82.5** | **70.5** | 0.15 |
57
+
58
+ - **4.0–5.7× the throughput for 18–28 points of nDCG.** Pick it when indexing speed is the
59
+ constraint and a lexical channel runs beside it; pick `gte-modernbert-base` when vector-only
60
+ accuracy is.
61
+ - **Inside the hybrid search it was built for** (80 real agent queries, file level, runtime
62
+ reranker off): the right file is first **46 %** of the time and in the top 5 **78 %**.
63
+ - **Its own depth trade:** against its 6-layer parent it gives up ~4 % relative hit@1 for ~1.5×
64
+ the engine speed.
65
+ - **Not multilingual.** The vocabulary prune kept 942 of XLM-R's 31 671 Cyrillic pieces; for
66
+ non-English queries use `multilingual-e5-base`.
67
+ - **Not for long text, docstring paraphrase or general prose.** On the full CoIR suite (six
68
+ in-scope tasks) it averages 37.3 nDCG@10 — 68.3 on Python docstring→code, 17.5 on cosqa.
69
+
70
+ ### Throughput in a real index
71
+
72
+ A full index through the UltraCode daemon, laptop RTX 5060, TensorRT INT8, pinned 114 W:
73
+
74
+ | workload | texts/s |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  |---|--:|
76
+ | C/C++ — mysql-server, 1.1M entities | 13 800 |
77
+ | TypeScript — vscode, 479k | 10 600 |
78
+ | Java — netty, 97k | 8 000 |
79
+ | C# — roslyn, 403k | 7 900 |
80
+ | small incremental updates (a few hundred to 15k texts) | 1 900 – 5 500 |
81
+ | no discrete GPU — Intel CPU + iGPU + NPU together | ~1 050 |
82
+ | Apple M4, Neural Engine | ~1 100 |
83
+
84
+ The spread between languages is text length: 71 % of C# texts fall in the longest bucket against
85
+ 24 % for C/C++. Above ~820k texts the daemon adds the Intel iGPU beside the RTX card, so the
86
+ mysql-server row is a two-device number. The same daemon running `multilingual-e5-base` compiled
87
+ to the same INT8 engines is **2.3× slower** on every row.
88
+
89
+ ## How to use it
90
+
91
+ ### Pick a length bucket
92
+
93
+ Every engine family ships four length buckets. A batch pays for its longest member, so route
94
+ each text to the smallest bucket that fits it:
95
+
96
+ | bucket | batch | seq range (opt) | solo texts/s, RTX 5060 | typical content |
97
+ |---|--:|---|--:|---|
98
+ | **s** | 96 | 8 – 48 (48) | 19 800 at 48 | names, signatures, queries |
99
+ | **m** | 128 | 56 – 64 (56) | 13 100 at 64 | typical entity text — **take this one if you load only one** |
100
+ | **l** | 128 | 72 – 80 (72) | 9 900 at 80 | |
101
+ | **xl** | 256 | 88 – 128 (96) | 5 500 at 128 | long docstrings, doc chunks |
102
+
103
+ - **Sort by length, then batch**, and dispatch each batch at its own longest length rounded up to
104
+ a multiple of 8. The TensorRT engines take a dynamic sequence range for exactly this — worth
105
+ **+10 %** end to end.
106
+ - **Batch size is not the lever**: 96 × 48 already saturates the GPU, and a bigger batch was
107
+ slower per text. Running the four engines concurrently does not add throughput either.
108
+ - All four TensorRT engines together take ~400 MB of VRAM.
109
+ - **OpenVINO IRs are static shapes**: batch 64 on CPU and iGPU, batch 16 on the NPU. The NPU has
110
+ the lowest latency per batch (28–95 ms) and suits single interactive queries better than bulk
111
+ indexing.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
+ ### Shape the input
114
 
115
+ **Documents** — the model was trained on a compact, front-loaded text, and reproducing it is
116
+ worth more than any inference tuning:
 
117
 
118
  ```
119
+ function acquireProjectLock in src/storage/multi_db.zig: zig
120
+ path: src storage multi db
121
+ [exported]
122
+ sig: (allocator: Allocator, project_hash: []const u8) -> !Lock
123
+ Acquires the exclusive SQLite lock for one project.
 
 
124
  ```
125
 
126
+ That is `{type} {name} in {file}: {lang}`, the path as words, flags, the signature, then the first
127
+ ~200 characters of the doc comment and a one-sentence description; ~768 characters at most. Leave
128
+ the function body out — it belongs in the lexical channel.
 
 
 
 
129
 
130
+ **Queries** — raw, no prefix. Short keyword bags and behaviour descriptions are what it was tuned
131
+ for. **Longer than 128 tokens** — windows of 128, stride 96; mean-pool the window vectors and
132
+ re-normalize.
133
 
134
+ ### Run the ONNX
135
 
136
  ```python
137
  import onnxruntime as ort, sentencepiece as spm, numpy as np
 
144
  L = max(len(x) for x in ids)
145
  inp = np.array([x + [0] * (L - len(x)) for x in ids], dtype=np.int64) # pad=0
146
  mask = (inp != 0).astype(np.int64)
147
+ return sess.run(None, {"input_ids": inp, "attention_mask": mask})[0] # [B, 768], unit-norm
 
148
 
149
  D = embed(["function acquireLock in src/db.zig: zig\npath: src db"])
150
  Q = embed(["acquire database lock"])
151
+ print(Q @ D.T) # inner product = cosine
152
  ```
153
 
154
+ Tokenize with SentencePiece — the vocabulary is a **unigram** model, and a BPE merge loop
155
+ segments it differently from training. Both inputs are **int64**.
156
 
157
+ ### Building your own engines
 
 
 
 
158
 
159
+ Feed **`model_int8qdt.onnx` as it is**. TensorRT 11 reads the precision from its Q/DQ nodes;
160
+ OpenVINO keeps the trained scales as FakeQuantize (run `compress_quantize_weights_transformation`
161
+ before saving, or the IR comes out twice the size). **Never run a calibration / PTQ pass over
162
+ it**: it replaces the trained scales with fitted ones, and the engine builds and loads cleanly
163
+ and quietly retrieves worse. Use the bucket profiles from the table above, for example:
 
 
 
 
 
164
 
165
  ```bash
166
+ trtexec --onnx=model_int8qdt.onnx --saveEngine=embed-m.engine --builderOptimizationLevel=5 \
167
+ --minShapes=input_ids:128x56,attention_mask:128x56 \
168
+ --optShapes=input_ids:128x56,attention_mask:128x56 \
 
 
 
169
  --maxShapes=input_ids:128x64,attention_mask:128x64
170
  ```
171
 
172
+ ## How it was made
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
+ - **Backbone:** `intfloat/multilingual-e5-base` (XLM-RoBERTa, 12 layers, 278M), cut in depth
175
+ 12 → 8 → 6 → **4** with a healing pass after each cut.
176
+ - **Vocabulary pruned to code and English:** 250k → **22.7k** SentencePiece pieces, which takes
177
+ the embedding table from 192M to 17.5M parameters — the largest single saving.
178
+ - **Two teachers:** `gte-modernbert-base` for the vector space, and `Qwen3-Reranker-4B` for the
179
+ ranking — the student learned the cross-encoder's score distribution over hard negatives, not
180
+ only "positive above negative".
181
+ - **INT8 by quantization-aware training**; the E5 prefixes, the pooler and MLM heads and the
182
+ token-type input were dropped; pooling and L2 were fused into the export.
183
 
184
+ ## Files
 
 
185
 
186
+ | file | what it is |
187
+ |---|---|
188
+ | `model_int8qdt.onnx` | INT8 Q/DQ graph with the trained scales — the source of every engine |
189
+ | `model.onnx` | the FP32 twin, same weights, for runtimes that cannot read Q/DQ and for fine-tuning |
190
+ | `model.safetensors`, `config.json` | the float weights for `transformers`: `AutoModel` loads the encoder; mean-pool over the mask → `proj` → L2 yourself (`config.json` → `ultracode`) |
191
+ | `sentencepiece.bpe.model`, `tokenizer_config.json` | the tokenizer, raw SentencePiece ids |
192
+ | `…-{s,m,l,xl}_{win_x64,linux_x64}_trt11.3_sm_{75,80,86,89,120}.engine` | TensorRT, per bucket × OS × GPU; `sm_90` (H100/H200) Linux only |
193
+ | `…-{s,m,l,xl}_ov2026.4_{cpu_int8,igpu_lnl_int8,npu_int4}_b*_s*.{xml,bin}` | OpenVINO 2026.4 for Intel CPU, iGPU, NPU |
194
+ | `…_{win_x64,linux_x64}_tvm0.25_vulkan.{dll,so}` | TVM Vulkan, for non-NVIDIA GPUs |
195
+ | `model_gpu_mlx0.32/` | MLX, Apple GPU |
196
+ | `coreml_ane/embed.mlpackage/` | Core ML for the Apple Neural Engine — one function per bucket shape; load with `cpuAndNeuralEngine`, fall back to MLX for any other shape |
197
+
198
+ A TensorRT engine loads only on the exact GPU architecture and TensorRT version that built it:
199
+ `sm_75` Turing · `sm_80` A100/A30 · `sm_86` RTX 30xx · `sm_89` RTX 40xx/L4 · `sm_90` H100/H200 ·
200
+ `sm_120` RTX 50xx, all TensorRT 11.3. On `sm_120` the m / l / xl engines run attention as one fused
201
+ fp16 kernel (+11–21 % per bucket); their vectors are interchangeable with the other engines'. If
202
+ your combination is missing, build it from the ONNX.
 
 
 
 
 
 
 
 
 
 
 
203
 
204
  ## License
205
 
206
+ Released under the **MIT license**. The backbone (`intfloat/multilingual-e5-base`) is MIT; the
207
+ teachers (`gte-modernbert-base`, `Qwen3-Reranker-4B`) are Apache-2.0. As is standard practice for
208
+ distilled embedding models, the weights are released under MIT. Not legal advice.
 
 
209
 
210
  ## Attribution
211