Skip to main content

egemma2: EmbeddingGemma 2 in Rust, for Python

An open-source, from-scratch Rust implementation of Google's EmbeddingGemma 2: text, images, audio and video embedded into one 768-d space (Matryoshka cuts to 512 / 256 / 128), on the CPU or an NVIDIA GPU. This package installs the egemma2 binary plus a small Python client that keeps it loaded, so Python code gets the speed without PyTorch:

Workload (RTX A3000 laptop GPU, bf16) PyTorch + sentence-transformers egemma2
short query 52.3 ms 2.5 ms
2,208-token document 136 ms 47.6 ms
16 images per call, per image 99.9 ms 51.4 ms
9.3 s audio clip 91.0 ms 18.9 ms

Embeddings match the PyTorch reference: up to 1e-6 apart in float32, and within cosine 0.99996 in bf16 mode. Texts are not truncated, as in sentence-transformers.

Install

pip install "egemma2[hub]"     # with huggingface_hub, to download the model on first use (~1.5 GB, once)
pip install egemma2            # or just the binary and the client, for a model you already have

Wheels: Windows and Linux x64, any Python 3.8+. The GPU path needs an NVIDIA driver and the CUDA 13 runtime libraries (cuBLAS, NVRTC) on PATH, for example from the CUDA Toolkit; bf16 needs compute capability 8.0+ (Ampere or newer). Without them egemma2 runs on the CPU.

Use

from pathlib import Path
from egemma2 import Egemma2

with Egemma2(precision="bf16") as model:            # device="auto": CUDA if available, else the CPU
    docs = model.embed(["Mars is red.", "Oceans are blue."], prompt_name="Document")
    query = model.embed("which planet is red?", prompt_name="SearchQuery")[0]
    scores = [sum(q * d for q, d in zip(query, doc)) for doc in docs]   # cosine similarity

    pages = model.embed([Path("page1.png"), Path("page2.png")])          # files, by extension
    mixed = model.embed([{"text": "Figure 3:", "image": pil_image}])     # one interleaved input
    matrix = model.embed_numpy(texts, dimensions=256)                    # (n, 256) float32
  • Inputs: a str is text, a Path is a file (image, .wav audio, video file or frame directory). Images can also be Pillow images, HxWx3 uint8 numpy arrays or encoded bytes; audio can be (samples, sample_rate). A dict such as {"text": ..., "image": ...} is one input whose parts follow the dict's order, like sentence-transformers' dict inputs.
  • Prompts: prompt_name takes the model's sentence-transformers prompts (SearchQuery, Document, QuestionAnswering, CodeRetrieval, ...).
  • Model directory: Egemma2(model_dir=...), else $EGEMMA2_MODEL_DIR, else ./models/embeddinggemma-2, else a download of google/embeddinggemma-2 via huggingface_hub.
  • Other options: device="cpu" | "cuda" | "cuda:N", precision=None | "tf32" | "bf16", max_tokens=N to cut long texts.

The client starts egemma2 serve once and sends it JSON lines, so the model loads once; a short query takes 2.6 ms round trip. Requests from several threads are queued safely.

Command line and HTTP server

The same install gives you the egemma2 command (also python -m egemma2):

egemma2 --model-dir <dir> embed --prompt-name SearchQuery --text "which planet is red?"
egemma2 --model-dir <dir> --bf16 serve --http 127.0.0.1:8080     # OpenAI-compatible /v1/embeddings

Any OpenAI-style client (the openai SDK, LangChain, LlamaIndex) can use the HTTP server:

from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="unused")
r = client.embeddings.create(model="embeddinggemma-2", input=["a document"], extra_body={"prompt_name": "Document"})

More

Documentation, benchmarks, the parity tests and the source: https://github.com/Dalailalama/embeddinggemma2-rust. Not affiliated with or endorsed by Google; the model weights are Google's (Apache-2.0). Code: Apache-2.0. If it saves you time, you can buy me a coffee.

Metadata

Release files for egemma2 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for egemma2 0.3.2
File Size Uploaded Provenance Actions
egemma2-0.3.2.tar.gz 190.5 kB With provenance Details for egemma2-0.3.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for egemma2 0.3.2
File Interpreter ABI Platform Actions
egemma2-0.3.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for egemma2-0.3.2-py3-none-win_amd64.whl
egemma2-0.3.2-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for egemma2-0.3.2-py3-none-manylinux_2_28_x86_64.whl

Total release size: 7.2 MB

Release files / egemma2-0.3.2.tar.gz

Download URL egemma2-0.3.2.tar.gz
Size 190.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a3fbc8d6049581f907adbff795d27985b65aa6633da371fa7de96980215caf56
BLAKE2b-256 checksum
How to use checksums
c1e5d3f01859d1cc90312c4ab485ff1d24cce3e7b084c5d4daeb6a47620bbf94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / egemma2-0.3.2-py3-none-win_amd64.whl

Download URL egemma2-0.3.2-py3-none-win_amd64.whl
Size 3.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
25de207b4b72e3511b1df58fd48856c38af68f71a6ee6fc2047997adea6d1799
BLAKE2b-256 checksum
How to use checksums
33bc6897e9b98e8eaa49076293154745589950513051ab572716cf122357094b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / egemma2-0.3.2-py3-none-manylinux_2_28_x86_64.whl

Download URL egemma2-0.3.2-py3-none-manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
7c113f2b0f9ebd40274bda3384adf7397ed97203be06116ec008ce57f337b2d8
BLAKE2b-256 checksum
How to use checksums
877aa7d767bccae24274298bfa8e1db91d958b66fab4aa7d0e6544fa972c9d6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for egemma2 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 3 files in this release have been uploaded with provenance metadata.

Select from 3 files

Attestation for egemma2-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.2 This release

3 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page