feature-extraction Β· text (100+ languages) Β· WASM Β· ~300 MB
The built embedders here sit on the classic BERT encoder (MiniLM, GTE, BGE, E5) or ModernBERT. EmbeddingGemma-300m is different: it is the first embedding model on Google's Gemma 3 backbone (2025), trained for retrieval across 100+ languages, it is instruction-prompted (queries and documents get different task prefixes), and it is a Matryoshka model β its 768-d vector can be truncated to 512 / 256 / 128 and still work, so you can store 4Γ smaller vectors on-device. Paste passages to build a live similarity matrix, search across languages, and watch the vector shrink. Nothing leaves your device.
| Model | google/embeddinggemma-300m Β· run via the onnx-community/embeddinggemma-300m-ONNX Transformers.js build |
|---|---|
| Task / pipeline | feature-extraction |
| Backbone | Gemma 3 (~308M params) β 768-dimensional sentence embedding. A Gemma decoder repurposed as an encoder, not a BERT. |
| Languages | 100+ β trained multilingual; an English query can retrieve a passage in another language. |
| Prompts | Instruction-prompted. Queries β task: search result | query: β¦; documents β title: none | text: β¦. The worker applies these. |
| Pooling | Mean over token embeddings, then L2-normalize β cosine = dot product. |
| Matryoshka dims | 768 β 512 β 256 β 128 β truncate + re-normalize for smaller, cheaper vectors. |
| Context length | 2048 tokens |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~300 MB, cached after first load |
| License | Gemma Terms of Use (custom; review before production use) |
| Web APIs | WebAssembly, Web Workers β all Baseline widely available |
Put one passage per line. They're embedded in document mode (EmbeddingGemma's document prefix); the query below is embedded in query mode. The matrix shows cosine similarity between every pair; the scatter is a 2D PCA of the 768-d vectors. Then type a query to rank the passages by meaning.
Gemma 3 emits one 768-number vector per token; EmbeddingGemma mean-pools them into a whole-passage embedding and we L2-normalize it β so cosine similarity is a plain dot product. Pick a passage to see its real vector, its pre-normalization magnitude, and its token count.
First 128 of 768 dimensions (blue = positive, orange = negative, brighter = larger magnitude):
EmbeddingGemma is trained so the first 512 / 256 / 128 numbers of its 768-d vector are each a usable embedding on their own. Pick two passages; we truncate both to each size, re-normalize, and show the cosine. Notice how little it moves β that's why you can store 128-d vectors on-device (4Γ less space) and still retrieve well. Embed some passages above first.
Embeddings power search, recommendations, deduplication, clustering and retrieval-augmented generation. EmbeddingGemma's pitch is a small, multilingual, storage-flexible embedder built for the device: it runs on a phone-class footprint, retrieves across languages without a translation step, and lets you dial vector size down to 128-d when storage or compute is tight β all in a tab, all private.
Do two passages mean the same thing? One cosine number β plus why queries and documents get different prefixes.
On-device semantic search with a live Matryoshka size dial: watch retrieval hold up as the vector shrinks.
Cross-lingual search: one query, a corpus in many languages, ranked by meaning not words.
EmbeddingGemma retrieves a shortlist, then a cross-encoder reranks the top hits.
Feature-extraction with mean pooling β the one thing to get right is EmbeddingGemma's task prefixes:
import { pipeline } from "@huggingface/transformers";
const extract = await pipeline(
"feature-extraction",
"onnx-community/embeddinggemma-300m-ONNX",
); // downloads + caches ~300 MB once
// EmbeddingGemma is instruction-prompted: wrap queries and documents differently.
const query = "task: search result | query: how do neural networks pay attention?";
const doc = "title: none | text: Attention lets a model focus on the most relevant parts of the inputβ¦";
const out = await extract([query, doc], { pooling: "mean", 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
// Matryoshka: the first 128 numbers are a usable smaller embedding (re-normalize after slicing).
const small = (v) => { const h = v.slice(0,128); const n = Math.hypot(...h); return h.map(x => x/n); };
This page asks the worker for the un-normalized mean 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 Matryoshka comparison never jank the page.