Executable programs and extensions

How can you search your local photos and recordings with EmbeddingGemma 2?

Search photos with text and compare documents and recordings in one embedding space.

EmbeddingGemma 2 maps text, code, images, video, and audio into a shared 768-dimensional embedding space. It creates vectors for retrieval; a separate LLM1 can summarize the results.

Searching beyond text documents

EmbeddingGemma 2 turns text, code, images, video, and audio into numerical embeddings for search. It retrieves documents, photos, or recordings related to a query; a separate LLM can summarize the results. All inputs share a 768-dimensional embedding space, so text can retrieve photos and descriptions can be compared with audio. Google model card

An embedding is an array of numbers representing the meaning of the original content. The model is trained so that semantically similar queries and items sit near one another. For example, a question about refund timing can retrieve a policy saying refunds take up to five business days. Korean retrieval quality depends on wording and domain, so evaluate it on your own materials.

A desk with a compact desktop and PC tower beside a monitor
Compare image or audio vectors with text queries in the same space.

Split documents and start with text retrieval

Split content into readable units, such as one FAQ entry or one manual section, instead of embedding an entire document as a single item. Store the document ID, title, text, and source location so a result can be opened and checked. Choose chunk boundaries that do not separate tables or code from their meaning.

The installation commands below are for bash/zsh on macOS or Linux. In Windows PowerShell, create a virtual environment2 and activate it with .\.venv\Scripts\Activate.ps1. Install the packages and run the example in that environment.

For text-only search, you can disable the image and audio encoders and load the 270M text configuration. Use the SearchQuery prompt3 for queries and Document for documents to be searched. Format a titled document as title: title | text: content. See the official developer guide.

Create the environment and install packages
python -m venv .venv
source .venv/bin/activate
python -m pip install -U sentence-transformers transformers
Compare query and document embeddings
from sentence_transformers import SentenceTransformer

model = SentenceTransformer(
    "google/embeddinggemma-2",
    config_kwargs={"vision_config": None, "audio_config": None},
)
documents = [
    "title: Refund policy | text: Refunds are processed within five business days after cancellation.",
    "title: Change delivery | text: You can change the delivery address before order preparation begins.",
]
query = "How long does a refund take?"
doc_vectors = model.encode(documents, prompt_name="Document", normalize_embeddings=True)
query_vector = model.encode(query, prompt_name="SearchQuery", normalize_embeddings=True)
scores = model.similarity(query_vector, doc_vectors)[0]
for index in scores.argsort(descending=True).tolist():
    print(f"{scores[index]:.3f}\t{documents[index]}")

Save the code as search.py and run it in the same virtual environment. The first search works when it prints both documents and ranks the refund policy first. Check whether expected items appear near the top using query-document pairs from your own data, then adjust chunking and titles.

Run the example
python search.py

Add multimodal queries to a text index

An existing index can be reused for image or audio queries only when vectors are compatible with the same EmbeddingGemma 2 checkpoint4, task setup, and dimensions. This does not mean vectors from another model such as Qwen or BGE can be mixed into it.

For photos or recordings, keep source paths, captions, and recording dates as metadata. Vectors do not replace source files; retain identifiers that let reviewers open the result.

Search photos and audio with text queries

First, place photos/lake.jpg, photos/street.jpg, and recordings/meeting.wav in the working folder, or change the paths below to your files. Install the multimodal encoders and media-processing libraries. Pass photos to encode() with the image key and recordings with the audio key. The example compares a text description with two image embeddings and ranks them by similarity.

Install multimodal input libraries
python -m pip install -U sentence-transformers transformers pillow soundfile torchcodec
Rank photos using a text query
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("google/embeddinggemma-2")
query = model.encode("A snowy mountain and lake landscape", prompt_name="SearchQuery")
photos = [{"image": "photos/lake.jpg"}, {"image": "photos/street.jpg"}]
photo_vectors = model.encode(photos)
scores = model.similarity(query, photo_vectors)[0]
print(scores.argsort(descending=True).tolist())

For audio, pass the file path as model.encode({"audio": "recordings/meeting.wav"}) and compare it with a text query. The example below ranks two questions by similarity to the meeting recording. Audio is resampled to 16 kHz internally. Video defaults to one sampled frame5 per second; adjust the frame count for denser scene retrieval. Google multimodal examples

Compare a recording with text queries
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("google/embeddinggemma-2")
audio = model.encode({"audio": "recordings/meeting.wav"})
queries = [
    "When did we schedule the meeting?",
    "How long does a refund take?",
]
query_vectors = model.encode(queries, prompt_name="SearchQuery")
scores = model.similarity(audio, query_vectors)[0]
for index in scores.argsort(descending=True).tolist():
    print(f"{scores[index]:.3f}\t{queries[index]}")
A workspace with two compact desktops connected by cable
Encode queries and documents with their matching task prompts.

Distinguish text-only and full multimodal loading

The official card lists a 270M text-only selective configuration and a 740M configuration with text, vision, and audio encoders. Enable only the modalities you need, and record the library options and actual memory use.

Do not treat the full-model specification from the earlier introduction as the memory requirement for a text-only path. The first run downloads weights; use the documented text-only configuration for text retrieval comparisons.

Choose an embedding dimension and review the license

EmbeddingGemma 2 returns 768-dimensional vectors by default. Sentence Transformers can truncate them to 512, 256, or 128 dimensions to reduce index storage, but retrieval quality still needs checking. Google reports quality close to the default down to 256 dimensions and recommends 128 dimensions for text-only workloads. Encode queries and documents at the same dimension, and normalize after truncation.

When changing dimensions, re-embed the stored documents and rebuild the index. Queries and corpus items must use the same dimension. The model uses the Apache 2.0 license, which permits use, modification, and redistribution subject to its terms; retain the license and copyright notices when redistributing. Model card and license

Create matching 256-dimensional vectors
from sentence_transformers import SentenceTransformer

model = SentenceTransformer("google/embeddinggemma-2")
query = "How long does a refund take?"
document = "title: Refund policy | text: Refunds are processed within five business days after cancellation."
query_vector = model.encode(
    query, prompt_name="SearchQuery", truncate_dim=256, normalize_embeddings=True
)
document_vector = model.encode(
    document, prompt_name="Document", truncate_dim=256, normalize_embeddings=True
)
print(model.similarity(query_vector, document_vector))

Match query instructions and document formatting

For text search, prefix queries with task: search result | query: ... and format documents as title: ... | text: .... Do not add text prefixes to image, video, or audio inputs. Use title: none when no document title exists.

The official Sentence Transformers example uses SearchQuery and Document task names to apply the corresponding prompts. Choose either the library prompt or manual prefixes; do not apply both and duplicate the instruction.

Troubleshoot runtime and memory errors

If you see ModuleNotFoundError, check that the Python running search.py is the same virtual environment where you installed the packages. Run python -m pip show sentence-transformers to confirm; activate the environment and install again if needed.

If an image or audio file cannot be opened, check its relative path from the current working directory. Try the absolute file path to separate a path issue from a model issue. If memory runs out, use the text-only configuration or close other apps and models before retrying.

A meeting table with a laptop, microphone, and notebooks
Evaluate retrieval on your data with labeled queries.

Update a folder index incrementally and measure its size

Store file IDs, hashes, and modification times so only changed documents and media are re-embedded, and remove vectors for deleted files. For photo or audio folders, link captions to source files so the index points back to the right item.

Truncating to 128, 256, 512, or 768 dimensions can reduce raw vector storage but may affect quality. Compare ranks on the same queries and base storage decisions on the full database index and metadata, not raw arrays alone.

Evaluate each modality and verify sources separately

Create separate query sets for the directions you will use, such as text-to-image, image-to-text, or audio-to-text. Record whether the gold file ID appears in the top k. Success in one direction does not establish performance for every modality pair.

Open the retrieved documents, photos, and recordings to confirm they contain the evidence. Separate retrieval misses from parsing or caption errors. This guide reports no run on reader data; measure accuracy, latency, and memory on your own files.

Terminology notes

  1. Large language model — A model trained on large text datasets to learn language patterns and process or generate text in context.

    Back to the text
  2. Python virtual environment — An isolated space for installing Python packages per project, helping reduce package-version conflicts.

    Back to the text
  3. Prompt — The input text sent to a model. For generative models it describes the desired result and strongly shapes the output.

    Back to the text
  4. Checkpoint — A file containing saved model weights and related state. Versions or tasks in one model family may use different checkpoints.

    Back to the text
  5. Frame — A single image that makes up part of a video.

    Back to the text

Frequently asked questions

What should you check first in this article?
EmbeddingGemma 2 maps text, code, images, video, and audio into a shared 768-dimensional embedding space. It creates vectors for retrieval; a separate LLM can summarize the results.
How much memory does it need?
The official card lists a 270M text-only selective configuration and a 740M configuration with text, vision, and audio encoders. Enable only the modalities you need, and record the library options and actual memory use.
Where can you check the conditions and sources?
EmbeddingGemma 2 turns text, code, images, video, and audio into numerical embeddings for search. It retrieves documents, photos, or recordings related to a query; a separate LLM can summarize the results. All inputs share a 768-dimensional embedding space, so text can retrieve photos and descriptions can be compared with audio. [Google model card](https://huggingface.co/google/embeddinggemma-2)