google gemma embeddings 2

Updated

EmbeddingGemma 2 is a lightweight, open-source multimodal embedding model released by Google DeepMind. It is designed to map text, code, images, video, and audio into a single, unified 768-dimensional vector space, enabling cross-modal search and retrieval.

Key Specifications & Features

  • Architecture: Built on the Gemma 4 decoder architecture.
  • Parameters: The total model size is 740M parameters, but it features a modular design. You can load only the components you need:

* Text/Code Encoder: 270M parameters.

* Vision Encoder: 170M parameters (optional).

* Audio Encoder: 300M parameters (optional).

  • Matryoshka Representation Learning (MRL): Supports native truncation of the 768-dimensional output to 512, 256, or 128 dimensions. This allows for significant reductions in vector storage costs with minimal impact on retrieval quality.
  • Performance: Designed for on-device and edge hardware. It supports an 8K token context window and covers 100+ languages.
  • Licensing: Released under the Apache 2.0 license.

How to Use

  • Library: The recommended way to run the model is via the sentence-transformers and transformers libraries.
  • Task Prompts: For text tasks, it is highly recommended to use task-specific prefixes (prompts) during inference to condition the model. For example:

* Asymmetric Tasks (e.g., search/retrieval): Use SearchQuery for the query and Document for the content being searched.

* Symmetric Tasks (e.g., similarity/classification): Use the same prefix for both inputs.

  • Precision: Use bfloat16 or float32. Using float16 can lead to degraded embeddings or NaN values.
  • Normalization: Always use L2-normalization for your embeddings, especially when using Matryoshka truncation.

EmbeddingGemma 2 is available on Hugging Face, and it can be integrated into local RAG (Retrieval-Augmented Generation) pipelines to ensure data privacy by keeping sensitive information on-device.