← All models

feature-extraction Β· text Β· WASM Β· ~150 MB

GTE-ModernBERT β€” a long-context embedder on a newer backbone

Most in-browser embedders (GTE-small, MiniLM, BGE, E5) sit on the classic BERT encoder with its 512-token ceiling. This one is built on ModernBERT β€” a from-scratch redesign of the encoder (rotary positions, alternating local/global attention, an 8192-token context) β€” fine-tuned by Alibaba's GTE team into a 768-dimensional retriever that tops MTEB for its class. It also pools differently: the [CLS] token, not the mean. Paste a few passages to build a live similarity matrix, search by meaning, and inspect the vector. Nothing leaves your device.

At a glance

ModelAlibaba-NLP/gte-modernbert-base (Transformers.js ONNX build)
Task / pipelinefeature-extraction
BackboneModernBERT-base (~149M params) β†’ 768-dimensional sentence embedding
Context length8192 tokens (16Γ— the classic 512) β€” rotary position embeddings + local/global attention
PoolingCLS token (the [CLS] vector), then L2-normalize β€” contrast GTE-small's mean pooling. No instruction prefix.
StrengthContrastive fine-tuning β†’ strong MTEB retrieval, especially on long passages
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~150 MB, cached after first load
LicenseApache-2.0
Web APIsWebAssembly, Web Workers β€” all Baseline widely available

Run it

Put one passage per line (short or long β€” this model takes long ones). The matrix shows cosine similarity between every pair (1.00 = identical direction); the scatter is a 2D PCA of the 768-d vectors. Then type a query to rank the passages by meaning.

Cosine similarity matrix

2D map (PCA)

See inside β€” the CLS vector, long context, and the backbone contrast

ModernBERT emits one 768-number vector per token. GTE-ModernBERT takes the [CLS] token's vector as the whole-passage embedding (a learned summary slot) and L2-normalizes it β€” so cosine similarity is a plain dot product. Pick a passage to see its real vector, its pre-normalization magnitude, and how many tokens it spanned.

Embed some passages above to inspect a vector.

GTE-ModernBERT vs GTE-small on the same long passage

Two GTE recipes on two backbones: GTE-small (classic BERT, 512-token limit, mean pool, 384-d) and GTE-ModernBERT (ModernBERT, 8192-token, CLS pool, 768-d). Feed both a query and a long document whose answer sits deep in the text, and compare how each scores relevance. Loads GTE-small (~34 MB) on demand.

Why it matters

Embeddings power search, recommendations, deduplication, clustering and retrieval-augmented generation. GTE-ModernBERT's pitch is long context on a modern, efficient backbone: you can embed a whole document β€” a full support article, a contract clause, a long chat turn β€” without chopping it into 512-token windows and losing the thread, and get top-tier retrieval quality, all in a tab and all private.

Use cases

Basics

Do two passages mean the same thing? One cosine number β€” and the long-context angle.

Practical

Long-document semantic search and near-duplicate detection over your own passages.

Wild

Cluster a pile of mixed passages into themes with k-means over the 768-d vectors.

Multi-model

GTE-ModernBERT retrieves a shortlist, then a cross-encoder reranks the top hits.

How the API works

Feature-extraction with CLS pooling is the whole recipe β€” note it is cls, not mean, and there is no prefix:

import { pipeline } from "@huggingface/transformers";

const extract = await pipeline(
  "feature-extraction",
  "Alibaba-NLP/gte-modernbert-base",
); // downloads + caches ~150 MB once

// GTE-ModernBERT pools the [CLS] token and needs NO instruction prefix β€” up to 8192 tokens per input:
const out = await extract([
  "how do neural networks pay attention?",
  "Attention lets a model focus on the most relevant parts of the input…",
], { pooling: "cls", normalize: true });
const [q, d] = out.tolist();

// unit-length vectors β†’ cosine similarity is just the dot product:
const sim = q.reduce((s, x, i) => s + x * d[i], 0); // high β€” same meaning

This page asks the worker for the un-normalized CLS vectors so "See inside" can show the real pre-normalization magnitude, then normalizes them in JS. Inference runs in a Web Worker, so the matrix, projection and comparison never jank the page.

References