← All models

feature-extraction Β· text + code Β· WebGPU Β· q4 175 MB

EmbeddingGemma 2 β€” instruction-tuned text embeddings in 768 dimensions

EmbeddingGemma 2 (Google DeepMind, 2026) maps text and code into a 768-dimensional space with instruction task prefixes. It is built from a 270M text backbone (130M transformer + 140M embedder) and released under Apache-2.0. Search across passages below, watch the similarity matrix, then shrink the vector to 128 dimensions via Matryoshka representation learning. Nothing leaves your device.

At a glance

Modelgoogle/embeddinggemma-2 Β· run via the onnx-community/embeddinggemma-2-ONNX build
Task / pipelinefeature-extraction (text encoder)
Parameters270M text backbone (130M transformer + 140M embedder)
Output768-d native, mean-pooled inside the graph plus a 512β†’768 projection. Vectors come back L2-normalized, so cosine similarity is a plain dot product.
Matryoshka dims768 β†’ 512 β†’ 256 β†’ 128; re-normalize after truncating (a sliced unit vector is not unit length any more).
ContextCard documents an 8K context window (8192 tokens) and a 1024-token sliding window; export config.json sets text_config.max_position_embeddings 262144 and text_config.sliding_window 512 (card and export config disagree; v1 verified at 2048).
PromptsTask-instruction prefixes β€” task: search result | query: …, task: classification | query: …, documents as title: … | text: … β€” the same convention as EmbeddingGemma 1.
Quantizationq4 (4-bit) by default; q8 (314 MB) available. fp16 is not offered β€” see the note below.
BackendWebGPU (required β€” see the measured note below)
Download175 MB (q4 text, decimal MB) Β· 314 MB (q8)
LicenseApache-2.0 β€” the first EmbeddingGemma release that is not under the Gemma Terms of Use
Languages100+ languages and code (+~14% on code retrieval vs EmbeddingGemma 1 on MTEB-code)
Web APIsWebGPU, Web Workers, <progress>, content-visibility β€” Baseline widely available apart from WebGPU

Two measured facts that shaped this page. (1) This export only runs on WebGPU. The q4/q8 builds block-quantize the 262,144-entry embedding table, and the ONNX Runtime Web WASM execution provider has no kernel for that op β€” session creation fails with GatherBlockQuantized … /model/embed_tokens/Gather_Quant. The fp32 export does load on WASM, but that is 1085 MB for the text encoder alone. The WASM path is therefore reported as blocked rather than papered over. (2) fp16 is off the table: the model card warns the activation range exceeds fp16's dynamic range and the model then returns NaN or silently degraded vectors instead of raising, and this adapter refuses fp16 outright (The device (webgpu) does not support fp16).

Run it

Put one passage per line. They are embedded in document mode (title: none | text: …); the query is embedded in query mode. The matrix is the cosine between every pair; the scatter is a 2D PCA of the 768-d vectors.

Cosine similarity matrix

2D map (PCA)

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

Each passage becomes one 768-number unit vector. Pick a passage to see the real numbers, its token count (card documents 8K context; export config permits longer), and its magnitude β€” the graph already normalized it, so β€–vβ€– is 1 by construction and cosine is a dot product.

Embed some passages above to inspect a vector.

Encoder budget β€” verified on-device footprint

The text backbone runs on-device at 175 MB (q4). Client-side browser inference is evaluated for the text encoder only.


Matryoshka β€” how much survives truncation?

The first 512 / 256 / 128 numbers of the vector are each trained to be a usable embedding on their own. Pick two passages, truncate both to each size, re-normalize, and compare β€” this is the same measurement Google publishes in the model card, on your own text.

Why it matters

On-device text embeddings usually require balancing model size, context length, and licensing. EmbeddingGemma 2 combines a compact 270M text backbone, Apache-2.0 licensing, instruction-tuned task prefixes, and flexible Matryoshka truncation, all running client-side on WebGPU.

Use cases

Basics

One cosine number β€” and how EmbeddingGemma 2's task prefixes change a vector depending on the job you give it.

Practical

Short bounded index (~250 tokens, ~8 chunks) with the free cached-vector Matryoshka re-rank to 128-d.

Wild

Cross-lingual retrieval: eight short passages in eight different languages retrieved by a query written in a different language, in one pass with no translation step, with the honest caveat that the measured top-1 may not be the intended cross-lingual target.

Multi-model

Two generations, one corpus: compare v1 and v2 text models over the same document index with sequential unloading.

How the API works

EmbeddingGemma 2 uses AutoModel with Transformers.js 4.3.1 on WebGPU to produce 768-dimensional embeddings from text with task-instruction prefixes:

import { AutoModel, AutoTokenizer } from "@huggingface/transformers@4.3.1";

const model_id = "onnx-community/embeddinggemma-2-ONNX";

const model = await AutoModel.from_pretrained(model_id, {
  device: "webgpu",
  dtype: { model: "q4" },          // fp16 is unsafe for this model β€” do not use it
});
const tokenizer = await AutoTokenizer.from_pretrained(model_id);

// Task prefixes are part of using the model correctly.
const texts = [
  "task: search result | query: Which planet is known as the Red Planet?",
  "title: none | text: Mars, known for its reddish appearance, is often referred to as the Red Planet.",
];
const { sentence_embedding } = await model(await tokenizer(texts, { padding: true, truncation: true }));
// -> [2, 768], already L2-normalized, so cosine similarity is a dot product.

// Matryoshka: keep the leading 256 numbers and re-normalize.
const small = sentence_embedding.slice(null, [0, 256]).normalize(2, -1);

Text passages and queries pass through AutoTokenizer and the model(...) call to produce 768-d unit embeddings. See the Wild page for cross-lingual retrieval across eight languages in one pass with no translation step and Multi-model for comparing v1 and v2 on the same corpus.

References