egemma2: EmbeddingGemma 2 in Rust, for Python
An unofficial, 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
stris text, aPathis a file (image,.wavaudio, 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_nametakes 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 ofgoogle/embeddinggemma-2via huggingface_hub. - Other options:
device="cpu" | "cuda" | "cuda:N",precision=None | "tf32" | "bf16",max_tokens=Nto 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| egemma2-0.3.1.tar.gz | 190.5 kB | With provenance | Details for egemma2-0.3.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| egemma2-0.3.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for egemma2-0.3.1-py3-none-win_amd64.whl |
| egemma2-0.3.1-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for egemma2-0.3.1-py3-none-manylinux_2_28_x86_64.whl |
Total release size: 7.2 MB
Release files / egemma2-0.3.1.tar.gz
| Download URL | egemma2-0.3.1.tar.gz |
|---|---|
| Size | 190.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e600bb659ac54269085ff2b86da14c2ffe7604f3a586232e79827ac538ed2dde
|
|
BLAKE2b-256 checksum How to use checksums |
e575df6a84da2b3d606ab10f6231665fe7ac6669114c3ae47a62a67605c8d1aa
|
| 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 logRelease files / egemma2-0.3.1-py3-none-win_amd64.whl
| Download URL | egemma2-0.3.1-py3-none-win_amd64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f6fbbe45eade2b6f8e610fe4342a57caf506b9d0e321b0703aeccf68091a63f8
|
|
BLAKE2b-256 checksum How to use checksums |
3d38392d169a1909f0619888de5f4eaf963678ed3f7dc648535bfe8507b0a8ec
|
| 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 logRelease files / egemma2-0.3.1-py3-none-manylinux_2_28_x86_64.whl
| Download URL | egemma2-0.3.1-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 |
034962073adb0069a55a0597d5bdfc7ef47ab6c875856116ff9f731d314271d9
|
|
BLAKE2b-256 checksum How to use checksums |
2699db8c2138f2cb77efbce2d80d334a17d4ee30d0fdf47c798b6c54a5a5bc3a
|
| 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 logSecurity for egemma2 0.3.1
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.
Attestation for egemma2-0.3.1.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 logA 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.