Practical Β· long-document dedup & search Β· WASM q8 Β· 150.34 MB

Long-Document Semantic Deduplicator & Document Finder

Policies, specs and contracts are long β€” and they often share pages of identical boilerplate. nomic-ai/modernbert-embed-base reads each document whole (up to 4,096 tokens in this browser build; the model itself was trained for 8,192), so two policies with the same preamble but different rules get different vectors. Run it side by side with a BERT-style 512-token clip and watch the clipped view call different documents β€œduplicates”.

1. Document set

Initialise ModernBERT Embed above to embed the document set on your device.

idle

2. Near-duplicates β€” full context vs 512-token clip

Every pair is scored twice from real embeddings: once with the whole document (up to the cap) and once with the first 512 tokens only β€” what a classic BERT/MiniLM embedder would see. A pair flagged clip false-dup is the truncation blind spot; clip missed dup means the clip saw a different opening and missed a real copy.

Northwind set: three policies come from a wiki template that puts the same ~600-token governance preamble first, so their 512-token clips are identical inputs (cosine 1.0000). Only full context can tell the incident policy apart from the retention family β€” and only full context links the re-exported copy whose opening was reformatted.

Documents–
Pairs scored–
Dup pairs Β· full–
Dup pairs Β· 512 clip–
Blind-spot pairs–
Embed time–
NaN count–

Duplicate clusters at Ο„ (full context)

Pairwise cosine β€” full context vs first 512 tokens (sorted by full-context cosine)
Pair Full 512 clip Ξ” Bars Verdict

3. Document finder β€” answers that live past token 512

Queries get the search_query: prefix, documents the search_document: prefix. The same query is ranked against the full-context and the clipped document vectors.

Full context

    Clipped at 512 tokens

      Recall@1 Β· full–
      Recall@1 Β· 512 clip–
      MRR Β· full–
      MRR Β· 512 clip–
      Labelled finder evaluation β€” first relevant rank per query
      Query Expected Top-1 full Rank full Top-1 clip Rank clip

      4. Export the review

      Exports are built from the snapshot currently on screen (same documents, cap and Ο„), with spreadsheet formula triggers neutralised and RFC 4180 quoting.

      Honest limits β€” measured, not claimed

      ModernBERT was trained with an 8,192-token context. In this browser build (ONNX Runtime Web, single-thread WASM, q8) one forward pass measured –. At 8,192 tokens the attention buffers exhausted the WASM heap (ORT error –), so the cap selector stops at 4,096. Cross-origin-isolated deployments can use more WASM threads and run faster.
      Show the code β€” full vs 512-clip pair comparison (modernbert-core.mjs) Lines 408–439

      References