EmbeddingGemma 2 - Run Locally
Run EmbeddingGemma 2 locally and fine-tune the model with Unsloth.
EmbeddingGemma 2 is Google’s new embedding model for text, code, images, video and audio. The model has 740M parameters, combining a 270M parameter text model with modular vision (170M) and audio (300M) encoders. It supports an Apache 2.0 license, 100+ languages and an 8K context window for tasks like semantic search, RAG and classification. For text and code only, you can load the smaller 270M text model.
You can run EmbeddingGemma 2 locally via our GGUFs using Unsloth Desktop or even fine-tune the model via Unsloth. embeddinggemma-2-GGUF
⚙️ Usage Guide
Parameters
740M total (can choose which to use):
270M text + 170M vision + 300M audio
Inputs
Text, code, images, video, audio and mixed inputs
Context length
8,192 tokens, shared across all inputs
Embedding dimensions
768, 512, 256 or 128
Recommended Settings
Precision: BF16 on supported hardware, or FP32 elsewhere.
Dimensions: Start with 768. Use 512 or 256 to reduce vector storage; evaluate 128 for text workloads.
Normalization: L2-normalize vectors, including after truncating them.
Prompts: Use a search prompt for queries and document formatting for the content you index.
Run EmbeddingGemma 2 Guide
🦥 Use EmbeddingGemma 2 in Unsloth Desktop
Use EmbeddingGemma 2 to index and search your documents locally on macOS, Windows and Linux.
Install Unsloth
The easiest way to get started is by downloading the Unsloth Desktop app. Works on macOS, Windows, and Linux.
Or, if you prefer to install manually:
MacOS, Linux, WSL:
Windows PowerShell:
For more ways to run EmbeddingGemma 2 with Unsloth, follow the Python or GGUF guides below.
📓 Try our notebooks
Run and train EmbeddingGemma 2 in Google Colab with our step-by-step notebooks.
Try search across text, images, video and audio.
Fine-tune text embeddings for your data.
Train on images and captions, then compare retrieval quality.
Train on audio and captions, then compare retrieval quality.
🦙 Run EmbeddingGemma 2 GGUFs in llama.cpp
Run EmbeddingGemma 2 locally with Unsloth GGUFs. Use a llama.cpp build containing EmbeddingGemma 2 support; the commands below build the latest source for text and code embeddings.
Build llama.cpp and download your GGUF
Install Git, CMake and a C++ compiler, then run these commands in a new working directory. They build the latest llama.cpp source and download Unsloth’s 176 MB UD-Q4_K_XL GGUF:
Start the embedding server
This example serves text and code embeddings, starting with a 2,048-token context:
For inputs longer than 2,048 tokens, increase --ctx-size, --batch-size and --ubatch-size together, up to 8192. Each input must fit in a single physical batch.
Request embeddings
Add the task prefixes yourself when calling the API:
The embeddings endpoint returns normalized vectors. Check that each vector has 768 finite values before building your index.
🛠️ Fine-tune EmbeddingGemma 2 with Unsloth
Fine-tuning can improve search for your documents, code and terminology. Train with pairs of questions and relevant documents, then compare search results before and after training.
Run and train EmbeddingGemma 2 in Google Colab with our free step-by-step notebooks.
Try search across text, images, video and audio.
Fine-tune text embeddings for your data.
Train on images and captions, then compare retrieval quality.
Train on audio and captions, then compare retrieval quality.
Prepare the model
Save the text model from the Python example:
Start a fresh Python session and import Unsloth first. Load the saved model in 4-bit and add LoRA adapters for training:
Train and evaluate
Follow our embedding fine-tuning guide to prepare your dataset and run SentenceTransformerTrainer.
Apply the query and document prefixes once, as in the Python search example.
Start with
MultipleNegativesRankingLossand a batch sampler that avoids duplicates.Set
bf16=Trueandfp16=False.Test search quality on queries you kept out of training.
The guide’s EmbeddingGemma 300M notebook covers the earlier model. Use it as a workflow reference.
Save your adapters
After training, save the LoRA adapters:
See the linked guide for merging adapters into a standalone model. Training on images, video or audio requires a separate workflow.
🚀 Run EmbeddingGemma 2 in Python
This example searches three documents and ranks them by how closely they match your question. It loads only the text model to save memory.
Install SentenceTransformers and Transformers with EmbeddingGemma 2 support:
The example automatically selects your device and a supported precision.
Higher scores mean a closer match. Replace the question and documents with your own content.
Adjust your embeddings
Save storage: Set embedding_dim to 256 to use one-third of the embedding storage, with some loss in search accuracy. Use the same dimension for queries and documents.
Choose a prompt: The example uses SearchQuery for the question and Document for searchable content. For code searches, use CodeRetrieval for the query. To compare two texts for similarity, use SentenceSimilarity for both.
🖼️ Embed images, video and audio
Combine text and media into one searchable item. This example creates a single embedding for a product description, two photos and a video.
Run it after the setup above, replacing the filenames with your own files. Your installation also needs the model processor’s image and video dependencies.
Replace the filenames with your own images and video, keeping the placeholders in the same order. The model combines them into one embedding you can search with text.
Text and media share the 8K context limit. Images, video and audio don’t need task prefixes.
Last updated
Was this helpful?



