← All models

feature-extraction Β· text (100+ languages) Β· WASM Β· ~300 MB

EmbeddingGemma β€” Google's on-device embedder

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.

At a glance

Modelgoogle/embeddinggemma-300m Β· run via the onnx-community/embeddinggemma-300m-ONNX Transformers.js build
Task / pipelinefeature-extraction
BackboneGemma 3 (~308M params) β†’ 768-dimensional sentence embedding. A Gemma decoder repurposed as an encoder, not a BERT.
Languages100+ β€” trained multilingual; an English query can retrieve a passage in another language.
PromptsInstruction-prompted. Queries β†’ task: search result | query: …; documents β†’ title: none | text: …. The worker applies these.
PoolingMean over token embeddings, then L2-normalize β†’ cosine = dot product.
Matryoshka dims768 β†’ 512 β†’ 256 β†’ 128 β€” truncate + re-normalize for smaller, cheaper vectors.
Context length2048 tokens
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~300 MB, cached after first load
LicenseGemma Terms of Use (custom; review before production use)
Web APIsWebAssembly, Web Workers β€” all Baseline widely available

Run it

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.

Cosine similarity matrix

2D map (PCA)

See inside β€” the mean vector, and Matryoshka shrinking

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.

Embed some passages above to inspect a vector.

Matryoshka β€” how much accuracy survives truncation?

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.

Why it matters

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.

Use cases

Basics

Do two passages mean the same thing? One cosine number β€” plus why queries and documents get different prefixes.

Practical

On-device semantic search with a live Matryoshka size dial: watch retrieval hold up as the vector shrinks.

Wild

Cross-lingual search: one query, a corpus in many languages, ranked by meaning not words.

Multi-model

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

How the API works

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.

References