Wild Β· nomic-ai/modernbert-embed-base Β· 768-d Β· WASM q8 Β· 150.34 MB

Long-Doc Topic Map & Needle-in-a-Long-Document Locator

Two experiments you could not run in a browser tab before: project a whole knowledge base into a living 2D map and steer it with a query compass β€” then hide one relevant sentence at 10%, 50%, or 90% of a long report and watch whether ModernBERT Embed still finds it, compared with a BERT-style encoder that stops reading at token 512.

1 Β· Topic map with a live query compass

Every document is embedded with the required search_document: prefix, your query with search_query: . The 768-d vectors (optionally Matryoshka-truncated) are projected onto their top two principal components; rays connect the query star to its nearest documents by real cosine.

The model initialises above; the map is drawn as soon as it is ready.

Docs mapped–
2D PCA variance–
Strongest ray–
Map dims–
Embed time–
NaN count–

Click a node to inspect it. Keyboard: focus the map, then ←/β†’ (or ↑/↓) step through documents, Home/End jump, Enter fires the compass from the selected document, Escape returns to the query compass.

No document selected yet.

Selected document

Map the collection to inspect any document.

Compass rays

    2 Β· Needle in a long document

    One relevant sentence (the needle) is inserted into an otherwise unrelated long document at different depths. Each variant is embedded twice: once with ModernBERT's long context (up to the cap you choose) and once clipped at 512 tokens, the way every original-BERT embedder is forced to read. A needle-free copy gives the baseline.

    Choose a document and run the sweep. Each long variant takes a few seconds on a single WASM thread.

    Doc tokens–
    512 horizon at–
    Best full-ctx lift–
    Lift at deepest pos (clip)–
    Sweep time–
    NaN count–

    Needle at Sentence # β‰ˆ Token pos Doc tokens Full read cos full Ξ” vs base cos 512-clip Ξ” vs base 512-clip sees needle?
    Run the sweep to fill this table with live measurements.

    β€œβ‰ˆ Token pos” is a proportional estimate (needle character offset Γ— real token count). β€œ512-clip sees needle?” is measured, not estimated: when the needle sits past the horizon, the clipped embedding is bit-for-bit identical to the needle-free baseline.

    Why this is wild

    Long context changes what β€œrelevant” means. A 512-token encoder judges a report by its first page or two. ModernBERT Embed was trained for 8,192 tokens; in this tab it reads up to 4,096 (8,192 aborted inside ONNX Runtime Web's WASM heap when we measured it), so a fact buried on page five can still move the document's vector.

    Show the code

    Needle placement β€” buildNeedleDocument() (modernbert-core.mjs) Lines 445–460
    Deterministic 2D PCA + out-of-sample projection β€” fitPca2D() / projectPca2D() Lines 466–608

    References