feature-extraction · text · WASM q8 · 54.61 MB · 8,192-token ModernBERT · Apache-2.0

Granite Embedding Small English R2 — 8,192-token vectors in 55 ms

IBM's 47M-parameter ModernBERT bi-encoder turns anything from a short search query to an entire 8,192-token technical specification into one 384-dimensional unit vector — 16× longer than classic 512-token BERT encoders, trained exclusively on enterprise-cleared open datasets, and running 100% privately on CPU WebAssembly in your browser.

At a glance

Model architecture, pooling, quantization, and runtime specifications
Upstream model ibm-granite/granite-embedding-small-english-r2 (7.11M monthly HF downloads · arXiv:2508.21085)
Browser ONNX build onnx-community/granite-embedding-small-english-r2-ONNX
Task / pipeline feature-extraction (dense bi-encoder retrieval & similarity)
Architecture ModernBertModel · 47M params · 12 layers (4 global RoPE θ=80k + 8 sliding-window w=128 RoPE θ=10k) · 12 heads · 384-d · 50,368 vocab
Context window 8,192 tokens (16× BERT's 512-token limit; 32× MiniLM's 256-token training window)
Pooling discipline pooling: "cls" (leading [CLS] token id 50281, not mean pooling) + L2 normalization
Quantization & size q8 ONNX · 54.61 MB (0.60 MB graph + 51.89 MB .onnx_data + 2.13 MB tokenizer), cached after first download
Backend & runtime WebAssembly (CPU WASM via shared Transformers.js — runs universally, no WebGPU required)
License Apache-2.0 (enterprise-cleared open training corpus)

Live 8,192-Token CLS Embedding & Similarity Studio

CLS pooling matters: Unlike older Sentence-BERT checkpoints that average every token, Granite Embedding R2 trains its leading [CLS] vector (token 50281) to aggregate all 8,192 tokens through alternating global attention layers. Every run below calls pipe(texts, { pooling: "cls", normalize: true }) in a Web Worker.

Cosine similarity matrix

Unit-length [CLS] vectors: cosine equals the exact dot product. Click any cell to inspect the pair.

2D PCA constellation (384-d → 2D)

Deterministic Gram-matrix power iteration onto the top two principal components.

See inside: ModernBERT alternating RoPE & [CLS] vector

Granite Embedding Small English R2 reaches 8,192 tokens on CPU without quadratic slowdown by interleaving 4 full global attention layers (RoPE θ=80,000) with 8 sliding-window local layers (window=128, RoPE θ=10,000). Global layers L0, L3, L6, and L9 funnel distant facts directly into the leading [CLS] slot.

Embed your texts above to inspect exact ModernBERT token counts and the 384-d [CLS] norm readout.

Why 8,192-token local embeddings matter

Classic 512-token browser embedders force aggressive chunking that splits legal clauses, API specifications, and incident runbooks apart before retrieval even begins. At 54.61 MB with an Apache-2.0 license and ~55 ms CPU WASM inference, Granite Embedding Small English R2 lets web apps index complete multi-page documents directly inside the user's tab with zero cloud vector APIs.

Use-case ladder

How the worker API works

Granite R2 runs through the standard Transformers.js feature-extraction pipeline with one essential requirement: always pass pooling: "cls" and normalize: true.

Show the code: off-main-thread CLS embedding in worker.js

References