At a glance
| 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] 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.
[CLS] norm readout.
First 96 of 384 [CLS] dimensions (indigo = positive, amber = negative, stronger tint = larger magnitude):
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.
- Long-document retrieval without blind spots — keep late addenda, footnotes, and code definitions inside a single embedding vector.
- Zero-server enterprise privacy — embed internal policies, support tickets, or source files locally without data egress.
- Compact 384-d footprint — half the storage and RAM of 768-d models while matching strong BEIR, COIR, and LongEmbed retrieval quality.
Use-case ladder
Basics · 8K Needle-in-a-Haystack
Compare full 8,192-token vs 256-token-truncated Granite embeddings on long handbooks with buried clauses.
Practical · Semantic Dedup & Search
Batch-embed multi-paragraph docs or uploaded files, tune cosine clustering thresholds, and export formula-safe CSV/JSON.
Wild · Live Drift Trajectory Canvas
Edit or step through a morphing paragraph and watch its 384-d vector trace a live trajectory across a 2D anchor constellation.
Multi-model · Granite R2 vs MiniLM
Head-to-head long-context duel: Granite R2 (8,192 tok) vs all-MiniLM-L6-v2 (256/512 tok) on identical ~820-token documents.
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.