sentence-similarity · feature-extraction · text · WASM q8 · 23.17 MB

MDBR-LEAF-IR — 23 MB Asymmetric Semantic Search

MongoDB Research's mdbr-leaf-ir distills a 23M-parameter MiniLM-L6-v2 encoder via LEAF (teacher-aligned knowledge distillation) to rank #1 on BEIR among models ≤100M parameters (53.55 nDCG@10; 54.03 asymmetric) — running completely offline in a Web Worker in ~62 ms with 384-d Matryoshka vectors.

At a glance

Model (Upstream & ONNX) MongoDB/mdbr-leaf-ir
Task / pipeline sentence-similarity via Transformers.js feature-extraction (pooling: "mean", normalize: true)
Architecture BertModel (MiniLM-L6-v2 LEAF backbone) · 23M params · 6 layers · 12 heads · 384-d ONNX output (64d–384d MRL) · 512 max tokens · 30,522 WordPiece vocab (SentenceTransformers adds an optional 2_Dense 384→768 teacher projection)
Asymmetric prompt Queries: "Represent this sentence for searching relevant passages: " · Passages: no prefix
Quantization & size q8 ONNX (model_quantized.onnx 0.22 MB + model_quantized.onnx_data 22.95 MB = 23.17 MB)
Backend CPU WebAssembly (wasm) via shared lib/webai.js — no WebGPU required
License Apache-2.0
Web APIs WebAssembly, dedicated module Web Workers, Cache Storage, FileReader/Blob — all Baseline widely available

Run it — Live Asymmetric Semantic Search Explorer

Type a search question and compare it against candidate passages locally on your CPU. Toggle MongoDB's asymmetric query prefix to measure the real cosine separation gain between relevant answers and distractors.

Initialise MDBR-LEAF-IR above to embed the query and passages live on your device.

Top-1 cosine –
Pos/Neg margin –
Prefix boost –
Latency –
Output vector –

    See inside — 384-d unit vector & diagnostics

    The browser ONNX graph (onnx/model_quantized.onnx) outputs a 384-dimensional L2-normalized vector (norm = 1.0000) directly from the MiniLM-L6-v2 LEAF backbone without the separate SentenceTransformers 2_Dense (384→768) projection layer. Dashed guides at 64d, 128d, and 256d mark Matryoshka (MRL) truncation boundaries probed live in Basics.

    Tensor & runtime telemetry

    L2 norm –
    Min / Max –
    NaN count –
    Query tokens –

    Strongest query dimensions

    Top 6 coordinates by absolute magnitude in the live query vector.

    Why it matters

    23 MB, BEIR #1 under 100M params: At 23.17 MB quantized (smaller than a short video clip), mdbr-leaf-ir outperforms models 2× its size on standard retrieval benchmarks and runs on any CPU via WebAssembly in tens of milliseconds — making private, offline semantic search genuinely practical in every browser tab.

    Use-case ladder

    How the API works

    In Transformers.js, load MongoDB/mdbr-leaf-ir as a feature-extraction pipeline on wasm with dtype: "q8". Prepend the search prompt to queries only, then call the pipeline with pooling: "mean" and normalize: true:

    import { pipeline } from "@huggingface/transformers";
    
    const extractor = await pipeline("feature-extraction", "MongoDB/mdbr-leaf-ir", {
      device: "wasm",
      dtype: "q8",
    });
    
    const PREFIX = "Represent this sentence for searching relevant passages: ";
    const out = await extractor(
      [PREFIX + "How do I persist large ML weights offline?", "OPFS lets workers stream binary weights locally."],
      { pooling: "mean", normalize: true },
    );
    // out.dims => [2, 384], unit-length float32 vectors; cosine similarity = dot product
    Show the code — Web Worker embedding forward pass (worker.js) Lines 189–264

    References