Basics · Inside ModernBERT Embed · nomic-ai/modernbert-embed-base · WASM q8 · 150.34 MB

Inside ModernBERT Embed: Matryoshka retention, prefix ablation & the similarity matrix

Three mechanics decide how well modernbert-embed-base retrieves: how much of the 768-d vector you keep (Matryoshka), whether you add the search_query: / search_document: prefixes it was trained with, and the cosine geometry between every pair of texts. Each is measured live below from one set of on-device embeddings.

1. Query & passages

Initialise ModernBERT Embed above to run the lab on your device.

Texts embedded–
Forward passes–
NaN count–
Mean ‖v‖ after norm–

2. Matryoshka retention curve (64d → 768d)

Slice the first d dimensions of every live 768-d vector, re-normalise, and re-rank — no extra model passes. The card validates 256d (61.17 vs 62.62 MTEB average at 768d); the other points are measured right here on your passages.

Retention, rank agreement with 768d, and storage per vector
Dim Best relevant Best distractor Margin 1st relevant rank Same rank as 768d float32 / int8 / binary

3. Prefix ablation

The model card says the prefixes are required. Here is what each combination does to the margin between the expected answers and the best distractor (768d).

Query prefix × document prefix
Query Documents Best relevant Best distractor Margin Top-1 correct

Run the lab to see the ablation.

4. N×N cosine similarity matrix

Every pair among Q (the prefixed query) and the prefixed passages, at 768d. Click a cell, use the arrow keys on the focused canvas, or pick a pair below.

Run the lab to inspect exact cosine pairs.

The code behind the numbers

Show the code — masked mean pooling of token_embeddings (modernbert-core.mjs) meanPoolHidden()
Show the code — Matryoshka retention curve (modernbert-core.mjs) computeMrlRetentionCurve()
Show the code — one forward pass in the Web Worker (worker.js) embedOne()

References