At a glance
| Model (upstream & ONNX) |
nomic-ai/modernbert-embed-base
— the same repo ships the ONNX export (onnx/model_quantized.onnx)
|
|---|---|
| Task / pipeline | sentence-similarity via Transformers.js feature-extraction (pooling: "mean", normalize: true) |
| Architecture | ModernBertModel · 149M params · 22 layers · 12 heads · hidden 768 · RoPE · global attention every 3rd layer, 128-token local window elsewhere · 50,368-token BPE vocab |
| Required prefixes | Queries: "search_query: " · Documents: "search_document: " (the card says the model requires them) |
| Context | Trained for 8,192 tokens. In-browser WASM we measured 512 tok → 2.0 s, 2,048 → 12.8 s, 4,096 → 38.0 s per forward pass (single thread); 8,192 aborted with ONNX Runtime error 314398768, so pages here cap at 4,096 (default 2,048) and report real token counts. |
| Matryoshka (MRL) | 768-d output; card reports 768 and 256 (61.17 vs 62.62 MTEB avg). This page also measures 64 / 128 / 512 live — slice, then re-normalise. |
| Quantization & size | q8 ONNX · model_quantized.onnx = 150,336,419 B (150.34 MB) + tokenizer |
| Backend | CPU WebAssembly (wasm) via shared lib/webai.js (Transformers.js 3.7.5) — no WebGPU required |
| License | Apache-2.0 |
Run it — long-context search & Matryoshka explorer
Rank multi-paragraph documents against your question. Documents are separated by a --- line and embedded
whole (up to 2,048 tokens each). Flip the prefixes off to see why the card insists on them, and drag the
Matryoshka dimension down to watch storage shrink while the ranking holds.
Initialise ModernBERT Embed above to embed the query and documents on your device.
768d · 3,072 B per float32 vector
See inside — the 768-d query vector
The ONNX graph returns token_embeddings of shape [1, T, 768]; the worker averages
the non-padding rows (mean pooling) and L2-normalises, exactly like the pipeline's
pooling: "mean", normalize: true. Dashed guides mark the 64 / 128 / 256 / 512 Matryoshka cut
points — the leading dimensions carry the most signal.
Tensor & runtime telemetry
Strongest query dimensions
Top 6 coordinates by magnitude in the live query vector.
Pipeline parity check
Runs the stock pipe(text, { pooling: "mean", normalize: true }) next to the worker's manual
pooling on the current query and reports the largest per-dimension difference.
Why it matters
- Private document search — index manuals, notes or policies on-device; nothing leaves the browser.
- 3× smaller indexes for free — keep the first 256 dimensions (card-validated) and store 1,024 B instead of 3,072 B per float32 vector.
- Long-document dedup — tell apart revisions that share a long boilerplate preamble (see Practical).
- Stage 1 of a RAG stack — recall candidates fast, then rerank with a cross-encoder (see Multi-model).
Use-case ladder
Basics — Matryoshka retention & prefix ablation
Measure cosine, margin and rank agreement at 64d→768d, see what dropping the prefixes does, and read an N×N similarity matrix.
Practical — long-document dedup & finder
Compare full-context vs 512-token-clipped similarity on real policy revisions, find near-duplicates, export CSV/JSON.
Wild — topic map & needle locator
Project a document collection onto a 2D PCA map with query rays, and move a key sentence from 10% to 90% of a long document.
Multi-model — recall then rerank
ModernBERT Embed (150.3 MB) shortlists at 256d and 768d, MS MARCO MiniLM (23.1 MB) reranks; watch the bump chart.
How the API works
Load nomic-ai/modernbert-embed-base as a feature-extraction pipeline on
wasm with dtype: "q8". Prefix every query and every document, then mean-pool and
normalise. For Matryoshka, slice the vector and re-normalise:
import { pipeline } from "@huggingface/transformers";
const extractor = await pipeline("feature-extraction", "nomic-ai/modernbert-embed-base", {
device: "wasm",
dtype: "q8",
});
const q = await extractor(["search_query: What is TSNE?"], { pooling: "mean", normalize: true });
const d = await extractor(
["search_document: TSNE is a dimensionality reduction algorithm created by Laurens van Der Maaten"],
{ pooling: "mean", normalize: true },
);
// q.dims => [1, 768]; cosine = dot product of unit vectors.
// Matryoshka 256-d: keep q.data.slice(0, 256), then divide by its L2 norm.
Measured here with the q8 export: the card's example pair scores 0.6481 (the card's fp32 value is 0.7214) — quantisation shifts absolute cosines, while rankings stay stable.