Multimodal Embeddings

Index and search images, audio, and video with native multimodal embeddings, precomputed descriptions, or your own vectors

Intermediate20 min
multimodalimagesaudiovideoembeddings
Prerequisites
  • Antfly installed and running
  • Antfly Inference with EmbeddingGemma 2 for native image, audio, or video embeddings

Antfly indexes images, audio, and video in one of three shapes, and the choice decides what runs at write time, what is stored durably, and which providers can maintain the index. EmbeddingGemma 2, the default embedder, puts text, images, audio, and video in one vector space, so a plain-language query can return a picture or a sound, and a picture can return its neighbors.

Choose the Ingestion Shape#

Antfly supports three explicit multimodal workflows:

  1. Native multimodal embeddings use the antfly index provider with a locally installed model such as EmbeddingGemma 2. A template turns a URL into a media part with remoteMedia, and the model embeds that part directly. Recordings and video go through a chunk enrichment that cuts the source into windows and embeds each one.
  2. Application-managed descriptions run OCR, captioning, or transcription before the write. Store the resulting text in a document field and use any managed text embedder supported for index creation. For recordings, the transcriber enrichment does this inside Antfly and keeps the timing; see Index Recorded Calls and Podcasts.
  3. Application-managed vectors create an external: true embeddings index and write vectors through _embeddings. This is the escape hatch for a model or provider that Antfly's managed indexing runtime does not execute.

EmbeddingsIndexConfig deliberately has no summarizer field. Keeping summarization outside the index definition avoids an implicit second provider call on every write and makes retries, cost, and durable intermediate output observable. It also prevents an index configuration from parsing successfully and failing only after ingestion starts.

Native Image, Audio, and Video Embeddings#

EmbeddingGemma 2 embeds text, images, audio, and video into one vector space. Install it once:

antfly inference pull hf:google/embeddinggemma-2:bf16-safetensors-bundle-v1

The running service discovers the newly installed model on its next model-list or inference request; no restart is needed.

Vectors have 768 dimensions by default. The model is Matryoshka-trained, so /ai/v1/embed can also return 512, 256, or 128 dimensions through its dimensions field when storage matters more than the last bit of recall. The model also takes a task type: Antfly embeds index writes as RETRIEVAL_DOCUMENT and search inputs as RETRIEVAL_QUERY, so an index needs no setting for either role.

Antfly learns which inputs a model accepts from its capabilities, which Antfly inference publishes for every model it serves, so the index needs no extra setting to embed images or audio. For a model whose capabilities Antfly cannot discover yet, such as one a provider released after your Antfly version, declare them on the embedder:

"embedder": {
  "provider": "antfly",
  "model": "some-new-multimodal-model",
  "inputs": ["text", "image"]
}

inputs replaces the discovered input types and takes text, image, and audio. Only the antfly (image, audio) and bedrock (image) providers accept media inputs; other providers reject them instead of silently dropping media. Video reaches EmbeddingGemma 2 through /ai/v1/embed and chunk enrichment, covered in Embed Video below.

Define the Source Field#

Link annotations make the remote-media intent visible in the table schema and available to tooling. The index template still controls when the URL is fetched.

antfly table create --table product_catalog \
  --schema '{
    "document_schemas": {
      "product": {
        "schema": {
          "type": "object",
          "properties": {
            "name": {"type": "string"},
            "description": {"type": "string"},
            "image_url": {
              "type": "string",
              "x-antfly-types": ["link"]
            }
          }
        }
      }
    }
  }'

Create the Managed Index#

antfly index create --table product_catalog \
  --index visual_search \
  --type embeddings \
  --coverage-policy partial \
  --template '{{#if image_url}}{{remoteMedia url=image_url}}{{/if}}' \
  --embedder '{
    "provider": "antfly",
    "model": "google/embeddinggemma-2:bf16-safetensors-bundle-v1"
  }' \
  --distance-metric cosine

partial treats documents without an image as intentional skips while still requiring every source document to reach a durable outcome. Antfly probes the model during index creation and records its dimension (768 for EmbeddingGemma 2), so omit dimension unless you want creation to verify an expected value. To guard against a silent model change, copy the model_identity hash from an /ai/v1/embed response into the embedder config; see Pin the model in an index.

For remote URLs, configure remote_content with the narrowest required host or object-store allowlist. An omitted allowlist leaves template fetches unrestricted rather than denied, so set one deliberately; private and special IP addresses remain blocked unless explicitly enabled. Data URIs do not require network access, but they are still subject to request and decoded-media limits.

Wait for existing documents to finish indexing before querying:

antfly index wait --table product_catalog \
  --index visual_search \
  --until searchable-artifacts=1 \
  --timeout 20m

Search with Text#

Because EmbeddingGemma 2 shares a vector space across modalities, ordinary text can retrieve matching images:

antfly query --table product_catalog \
  --semantic-search "brown leather jacket with zipper" \
  --indexes visual_search \
  --fields "name,description,image_url" \
  --limit 10

Search with an Image URL#

Use embedding_template to turn the query value into a media part using the same embedding model as the index:

curl -X POST http://127.0.0.1:8080/db/v1/query \
  -H "Content-Type: application/json" \
  -d '{
    "table": "product_catalog",
    "semantic_search": "https://images.example.com/query.jpg",
    "embedding_template": "{{remoteMedia url=this}}",
    "indexes": ["visual_search"],
    "fields": ["name", "description", "image_url"],
    "limit": 10
  }'

For an inline data URI, use {{media url=this}} instead. Avoid logging or persisting large data URIs in query histories.

Search Audio with Text#

Audio goes through the same template and the same model. An index over a clip_url field holds sound clips in the vector space the text queries use:

antfly index create --table sound_library \
  --index sound_search \
  --type embeddings \
  --coverage-policy partial \
  --template '{{#if clip_url}}{{remoteMedia url=clip_url}}{{/if}}' \
  --embedder '{
    "provider": "antfly",
    "model": "google/embeddinggemma-2:bf16-safetensors-bundle-v1"
  }' \
  --distance-metric cosine

A description of the sound finds it:

antfly query --table sound_library \
  --semantic-search "rain on a tin roof" \
  --indexes sound_search \
  --fields "title,clip_url" \
  --limit 10

An audio clip can be the query too: send its URL with "embedding_template": "{{remoteMedia url=this}}", as in the image example above, and an index that mixes photos and recordings returns both. For spoken content where the words matter more than the sound, transcribe it instead; see Index Recorded Calls and Podcasts.

Embed Video#

EmbeddingGemma 2 embeds MP4, MOV, and WebM video as a media part, sampled at 1 FPS up to 32 frames. A request to /ai/v1/embed returns one vector for the clip, in the same space as the text, image, and audio vectors:

{
  "model": "google/embeddinggemma-2:bf16-safetensors-bundle-v1",
  "input": [
    {"content": [{"type": "media", "mime_type": "video/mp4", "data": "<base64 MP4>"}]}
  ]
}

To index long recordings, declare a chunk enrichment with EmbeddingGemma 2 as its boundary model. Antfly cuts the source into windows, embeds each window, and can transcribe the same windows in the same pass. Resumable Media Enrichment has the configuration. See the inference guide for CUDA video codecs, hardware requirements, and clip limits.

Audio windows read from a remote WebM Opus source use the container's seek preroll, with a minimum of 80 ms and a maximum supported declaration of two seconds. This preserves sample positions and makes each window repeatable across retries. The PCM after a seek can differ from uninterrupted decoding, even at the same sample positions.

Rerank with Images#

A reranker template accepts the same media and remoteMedia helpers as an embedding template. Each candidate is then sent to the reranker as its text plus its images, so a multimodal reranker can score page scans and product photos directly:

curl -X POST http://127.0.0.1:8080/db/v1/query \
  -H "Content-Type: application/json" \
  -d '{
    "table": "product_catalog",
    "semantic_search": "brown leather jacket with zipper",
    "indexes": ["visual_search"],
    "reranker": {
      "provider": "antfly",
      "model": "vidore/colqwen2-v1.0",
      "template": "{{name}}{{#if image_url}}{{remoteMedia url=image_url}}{{/if}}",
      "candidate_count": 50
    },
    "limit": 10
  }'

The model must accept images: a ColQwen-style late-interaction reranker or the qualified Qwen3-VL reranker bundle. A text-only reranker, a Cohere or Vertex reranker, or a remote inference server older than this feature rejects the query with a 400 instead of silently dropping the images. Candidates whose template renders no image are scored on their text. Image fetches follow the same content security policy as embedding templates.

Precomputed Descriptions for Text Retrieval#

If users search for detailed attributes that a joint embedding model does not capture well, generate a caption or transcript in the application and store it as a normal field:

{
  "_type": "product",
  "name": "Vintage Leather Jacket",
  "image_url": "https://images.example.com/jacket.jpg",
  "media_description": "Brown leather motorcycle jacket with an asymmetric zipper"
}

Then index only the durable text:

antfly index create --table product_catalog \
  --index media_description_search \
  --type embeddings \
  --field media_description \
  --embedder '{
    "provider": "openai",
    "model": "text-embedding-3-small"
  }'

This shape is efficient for repeated rebuilds: captioning runs once, the description can be inspected or corrected, and changing the embedding model does not repeat vision inference.

Application-Managed Vectors#

Use an external index when the application already calls Gemini, Vertex, Cohere, OpenRouter, or another embedding service that is not executable by managed index creation:

antfly index create --table product_catalog \
  --index application_vectors \
  --type embeddings \
  --external \
  --dimension 768 \
  --distance-metric cosine

Write each vector with the document under the index's _embeddings entry. The application owns provider retries, batching, and vector-space consistency; Antfly owns storage and retrieval. Do not mix vectors from different models or model revisions in one index.

Managed index creation accepts antfly, ollama, openai, openrouter, cohere, gemini, vertex, and bedrock.

Documents and Scans#

To index PDFs, Office documents, scanned pages, and photos of documents as text, use a document_extraction enrichment, which extracts native text and reads the rest with OCR. Index PDFs and Scanned Documents walks through it. remotePDF remains a deprecated template helper; prefer durable extraction.

Operational Guidance#

  • Keep remote_content allowlists narrow and use dedicated read-only object storage credentials.
  • Use partial coverage when media fields are optional; use strict when every source document must produce a vector.
  • Store durable captions, transcripts, or extracted pages when they are costly to reproduce.
  • Use cosine for EmbeddingGemma 2 and other models trained for cosine similarity. The database default remains l2_squared, so select the model's metric explicitly when it differs.
  • Keep one model, dimension, and task profile per index. Rebuild the index when any of them changes; vectors from different settings are not comparable.
  • Monitor index status and wait for the required coverage before serving a new index to users.

Use Agent Skills#

Everything above is also encoded in the Antfly skill, so a coding agent can execute this guide for you:

npx skills add antflydb/antfly-skills

Then prompt it with the outcome, for example "Add an EmbeddingGemma 2 image index over the photo_url field of my products table and search it by description", and use this page to judge the result.

Next Steps#