Google's EmbeddingGemma Brings Private Local Search to Any Browser
ONNX build of Google's 300M EmbeddingGemma brings browser and edge-ready embeddings through Transformers.js, with quantized variants and a 768-dim Matryoshka output.
Takeaways
- ONNX Community published an ONNX build of Google's EmbeddingGemma-300m, approaching 800K downloads.
- 300M params, 2048 token context, 768-dim output truncatable to 512/256/128 via Matryoshka Representation Learning.
- Scores 68.36 MTEB English v2, 61.15 Multilingual v2, 68.76 Code v1 at 768d full precision.
- Q4_0 quantization loses under half a point on English MTEB, making int4 deployment practical.
- Runs in browsers via Transformers.js, in Python via ONNX Runtime, and server-side via Text Embeddings Inference.
- Activations require fp32, q8, or q4; fp16 is unsupported and will degrade embedding quality.
Google’s EmbeddingGemma checkpoint is a 300 million parameter text embedding model based on Gemma 3. The ONNX Community has packaged it as an ONNX build for browsers, Node.js, and Python applications that use ONNX Runtime. When checked, Hugging Face showed roughly 800,000 downloads for its displayed monthly window.
Embedding models convert text into vectors that can be compared for semantic similarity. Running that process locally supports browser search, offline retrieval, and the retrieval stage of client-side RAG without sending text to an embedding API.
The ONNX conversion expands the model’s deployment options. Transformers.js can execute the graph through WebGPU or WebAssembly, while Node.js and Python applications can use ONNX Runtime without loading PyTorch.
A 300M model, packaged once
The package preserves the underlying EmbeddingGemma architecture and exposes its outputs through ONNX-compatible runtimes. Its main characteristics are:
| Parameters | 300 million |
|---|---|
| Architecture | Gemma 3 with T5Gemma initialization |
| Context limit | 2,048 tokens |
| Native vector size | 768 dimensions |
| Smaller vectors | 512, 256, or 128 dimensions through Matryoshka Representation Learning |
| Languages | Training data covers more than 100 spoken languages |
| License | Gemma terms of use |
Matryoshka Representation Learning trains useful information into the leading dimensions of each vector. Applications can truncate a 768-dimensional embedding to a supported size and normalize it again, avoiding a second model for smaller indexes.
EmbeddingGemma does not support fp16 activations or related half-precision formats. Deployments should select the published fp32, q8, or q4 variants according to the target hardware. An fp16 configuration can produce severely degraded embeddings, so precision should be treated as a correctness requirement and covered by retrieval tests.
Run it in a browser
Transformers.js downloads the tokenizer and ONNX files from Hugging Face, then caches them through the browser. Install the library with:
npm install @huggingface/transformers
The following example embeds one query and two candidate passages, then calculates their similarity scores:
import {
AutoModel,
AutoTokenizer,
matmul,
} from "@huggingface/transformers";
const MODEL_ID = "onnx-community/embeddinggemma-300m-ONNX";
const tokenizer = await AutoTokenizer.from_pretrained(MODEL_ID);
const model = await AutoModel.from_pretrained(MODEL_ID, {
dtype: "fp32",
device: "webgpu",
});
const query =
"task: search result | query: Which planet is known as the Red Planet?";
const docs = [
"title: none | text: Venus is often called Earth's twin.",
"title: none | text: Mars is known for its reddish appearance.",
];
const inputs = await tokenizer([query, ...docs], {
padding: true,
truncation: true,
});
const { sentence_embedding } = await model(inputs);
const scores = await matmul(
sentence_embedding.slice(0, 1),
sentence_embedding.slice(1).transpose(1, 0),
);
console.log(scores.tolist()[0]);
Setting device: "webgpu" selects the browser’s WebGPU backend. Applications that need broader browser coverage can omit that option and use the WebAssembly path. Production code should also handle the initial model download, cache storage, unsupported hardware, and cancellation during page navigation.
Prefixes control retrieval behavior
EmbeddingGemma was trained with task-specific prompt templates. Retrieval queries use a prefix such as task: search result | query:, while candidate documents use title: ... | text:. Omitting those prefixes or applying the same template to both sides can reduce recall.
Classification, clustering, semantic similarity, fact checking, question answering, and code retrieval have their own templates. Applications should copy the exact format from the model guide and include template handling in evaluation code, data pipelines, and regression tests.
How quality scales down
Google reports the following full-precision results at the native 768 dimensions. Higher scores indicate stronger aggregate performance; the two mean columns use different weighting across tasks and task categories.
| Benchmark | Mean by task | Mean by task type |
|---|---|---|
| MTEB Multilingual v2 | 61.15 | 54.31 |
| MTEB English v2 | 68.36 | 64.15 |
| MTEB Code v1 | 68.76 | 68.76 |
Reducing the vector width produces a gradual decline on MTEB English v2. A 128-dimensional vector uses one-sixth as many float32 values as the native output and scores 3.27 points lower.
| Dimensions | Score | Float32 bytes per vector |
|---|---|---|
| 768 | 68.36 | 3,072 |
| 512 | 67.80 | 2,048 |
| 256 | 66.89 | 1,024 |
| 128 | 65.09 | 512 |
Smaller vectors reduce index memory, network transfer, and distance-computation work. Actual approximate nearest-neighbor latency still depends on the index algorithm, corpus size, hardware, and recall settings.
Quantization-aware results also remain close to fp32 at 768 dimensions: Q8_0 scores 68.13 and Q4_0 scores 67.91, compared with 68.36 for full precision. Weight quantization and vector truncation address separate budgets. Q4 and Q8 reduce the model’s storage and runtime footprint, while Matryoshka truncation reduces every stored embedding.
Good fits and hard limits
EmbeddingGemma’s size, language coverage, and runtime support suit several deployment patterns:
- Local semantic search across notes, messages, and files.
- Browser or Electron retrieval where text must remain on the device.
- Offline retrieval for desktop and mobile applications.
- Multilingual search using one shared embedding space.
- Code search, classification, clustering, duplicate detection, and fact verification with the correct task template.
- Shared browser and server pipelines that need compatible embeddings.
The 2,048-token context limit requires chunking for long documents. Chunk size, overlap, document titles, and metadata filtering can affect retrieval quality as much as the model choice, so they should be evaluated together.
The model files still occupy substantial download and cache space, especially at fp32. Browser deployments need to measure startup time, memory use, WebGPU availability, and quantized performance on representative devices. The model produces embeddings only; a complete RAG system still needs an index, retrieval logic, and a generator.
Legal, biomedical, and other jargon-heavy collections may benefit from domain-specific models or fine-tuning. Benchmark scores offer a baseline, while a labeled evaluation set from the target corpus provides a more reliable deployment decision. Redistribution and commercial use also remain subject to the Gemma license.
Portability is the payoff
ONNX provides a common graph for several execution environments. ONNX Runtime supports native CPU, CUDA, and DirectML providers, while ONNX Runtime Web supplies WebAssembly and WebGPU backends. Transformers.js handles model loading and tokenization for browser and Node.js applications, and Python services can load the same graph through onnxruntime.
Teams that need an HTTP embedding service can also use TEI, as documented by Hugging Face. That server path should be tested against the selected ONNX or source checkpoint to confirm matching templates, dimensions, normalization, and quantization.
A shared artifact simplifies systems that embed documents on a server and queries in a browser. Keeping the tokenizer, task prefixes, vector dimensions, normalization, and model revision aligned allows both sides to operate in the same embedding space while supporting local and hosted retrieval from one model family.