Concepts / Multimodal Embedding Models

Multimodal Embedding Models

Multimodal data is data in more than one form, and it can be retrieved either through metadata such as titles, tags, and captions, or through its content.

  • Programming

A Photo Collection and a Sentence

Suppose you have a large collection of photographs, and you want to find the ones that match a sentence you type, such as a request for a picture of a dog on a beach. The photographs are one kind of data and the sentence is another. Data that comes in more than one form, such as images and text, is called multimodal data. Retrieving it means finding the items in a collection that are relevant to a query, even when the query and the items are in different forms.

The central question is how a system decides that a photograph and a sentence belong together. There are two broad answers. The first relies on the words that already describe the image. The second relies on the visual content of the image itself. This article takes these two answers in turn, and then shows how a single model makes the second answer work for text queries.

What do you think happens?

Suppose a system can only read the words attached to each photo. One photo has a caption about a dog on a beach and another photo has no caption at all. Which photo can the system find for the query a dog on a beach?

  • Both photos, because the system can see the dog in each one

  • Only the captioned photo, because the system has no words to judge for the uncaptioned photo

  • Neither photo, because the system cannot read captions

Reveal answer
Answer:

Only the captioned photo.

A system that works only with the text describing an image never examines the image. If there is no caption, there is no text for the system to judge against the query, so that photo cannot be retrieved this way.

Metadata Versus Content

The first route uses metadata. Metadata is information attached to an item that describes it. For images, the common forms are titles, tags, and captions. If an image carries a caption, the system can retrieve the image whenever that caption is judged relevant to the query. The image itself is never examined. The system works only with the text that describes it, so this route is essentially a text-matching problem applied to the descriptions.

The second route uses the content of the image. If you want to retrieve images based on what they actually show, you need a way to compare images to queries. When the queries are text, that comparison requires a multimodal embedding model, one that can generate embeddings for both images and texts. An embedding is a representation of an item as a set of numbers. A model that produces embeddings for both kinds of data places images and sentences in a form that can be compared directly.

Titles, tags,captionsImage or contentitselfText matched to queryMultimodal embeddingmodelImage not examinedEmbedding comparisonjudged for relevanceimage skippedembeddedcompared to query
What the system examines in each route: the words attached to an item, or the image or content itself.
QuestionMetadata routeContent route
What is examined?Titles, tags, and captionsThe image or content itself
What is needed for a match?Relevant descriptive textEmbeddings for both images and texts
What fails if the item has no description?The item cannot be judgedThe item can still be represented from its content

Two ways a system can decide that a photograph and a query belong together

Why Images and Sentences Need a Shared Space

Think about what a comparison without a translator would require. A sentence can be compared to another sentence, and a picture can be compared to another picture. But a sentence and a picture have no shared form unless something translates between them. A multimodal embedding model acts as that translator. It turns an image into an embedding and a text into an embedding, and both embeddings live in a form the system can compare against each other.

The source uses CLIP, described by Radford and colleagues in 2021, as its example of such a model. The defining property of CLIP, as the source describes it, is that it can generate embeddings for both images and texts. That is why the retriever is built around it. Once every item and every query is represented by CLIP embeddings, the retrieval problem becomes a problem of comparing embeddings.

PhotographCLIP modelImage embeddingShared embeddingspaceSentence queryText embeddinginputinputproducesproducesplaced inplaced in
A photograph and a sentence each pass through the same model, producing two kinds of embedding that sit in one shared space where they can be compared.

Three Steps of the CLIP Retriever

The retriever has three steps. The first step happens once, before any queries arrive: generate CLIP embeddings for all of your data, both texts and images, and store them in a vector database. A vector database is a database designed to store and query embeddings. The second step happens each time a query arrives: generate the CLIP embedding of that query. The third step is the search: query the vector database for all images and texts whose embeddings are close to the query embedding.

Photos and textsCLIP embeds each itemVector databasestores embeddingsText query arrivesCLIP embeds the querySearch for closeembeddingsMatching itemsreturnedstep 1storedlaterstep 2step 3results
The indexing phase runs once and fills the vector database. The query phase runs each time a query arrives and reads from that database.

The diagram shows the retriever as two phases that meet at the vector database. The indexing phase fills the database. The query phase reads from it. Notice that the query is embedded with the same kind of model used for the collection. That shared model is what allows the query embedding to be compared with the stored embeddings of images and texts.

Tracing the Dog-on-a-Beach Collection

Worked example

Indexing three items and answering one query

The collection holds three items: a photograph with the caption about a dog on a beach, a second photograph with no caption, and a short text note that reads a dog runs along the sand. A user then types the query a dog on a beach. Trace what the retriever does with each item and then with the query.

  1. 1
    Index the captioned photograph

    CLIP generates an embedding of the photograph itself, and that embedding is stored in the vector database. The caption is not needed for this step because CLIP represents the image's content.

  2. 2
    Index the uncaptioned photograph

    CLIP still generates an embedding from the image content, so this photograph is stored too. A metadata-only system would have nothing to judge for this item.

  3. 3
    Index the text note

    CLIP generates an embedding of the sentence, which is stored in the same database as the image embeddings. Now the database holds embeddings for both kinds of data.

  4. 4
    Embed the query

    When the query a dog on a beach arrives, CLIP generates its embedding using the same model that produced the stored embeddings.

  5. 5
    Search for close embeddings

    The vector database is searched for the stored embeddings closest to the query embedding. Because the embeddings share one space, the query can be compared directly with photographs and with the text note.

Result

The retriever returns the stored items whose embeddings are close to the query embedding. The uncaptioned photograph can be returned because its match depends on its visual content, not on any caption.

What Changes When a Query Arrives

After indexing, the vector database holds one embedding for each item in the collection. Nothing about the query exists yet. When a query arrives, the database itself does not change. What changes is that a new embedding, the query embedding, is produced and used for comparison. The search then returns the stored items whose embeddings are close to it.

Photo with captionPhoto with captionPhoto without captionPhoto without captionText noteText noteQuery: dog on a beachReturned matchescompared
Before the query, the database holds only the stored item embeddings. After the query arrives, its embedding is added for comparison and the closest stored items are returned.

Mistakes Beginners Make

  • Common mistake

    Assuming the metadata route looks inside the image

    What it looks like

    A captionless photograph is expected to appear for the query a dog on a beach because it clearly shows a dog.

    Why it fails

    The metadata route works only with the text attached to an item. It never examines the image, so with no caption there is nothing for it to judge.

    Do this instead

    Use the content route, with a multimodal embedding model, when the match depends on what the image shows.

  • Common mistake

    Embedding the collection and the query with different models

    What it looks like

    Photographs are embedded with CLIP, while the query is embedded with a text-only model.

    Why it fails

    The embeddings must be comparable directly. The same model must embed both the collection and the query.

    Do this instead

    Embed every item and every incoming query with the same multimodal model, such as CLIP.

  • Common mistake

    Believing the query is stored in the database during indexing

    What it looks like

    A learner expects the database to already contain the dog-on-a-beach query before any user types it.

    Why it fails

    Indexing happens once, before queries arrive. The query embedding is generated only when the query arrives.

    Do this instead

    After indexing, the database holds the item embeddings. Each query adds a new embedding for comparison at search time.

  • Common mistake

    Treating a sentence and a picture as comparable without a translating model

Predicting a Mismatched Setup

MEDIUM

A colleague embeds every photograph in a collection with CLIP and stores the results in a vector database. For queries, the colleague uses a different text-only embedding model. Explain what goes wrong when a query arrives, and describe the change that fixes it.

Hints
  • Think about what the search step requires: it compares the query embedding with the stored embeddings.
  • Recall why the same model must embed both the collection and the query.
  • The fix involves which model is used for the query, not the database.

Key Takeaways

  • Metadata retrieval matches a query against titles, tags, and captions, and never examines the image itself.
  • Content retrieval of images for text queries needs a multimodal embedding model such as CLIP, which generates embeddings for both images and texts in a form that can be compared directly.
  • The CLIP-based retriever embeds and stores all data in a vector database, embeds each incoming query with the same model, and searches for embeddings close to the query embedding.
  • After indexing, the vector database holds the embeddings of the collection; when a query arrives, its embedding is produced and compared against those stored embeddings.

More concepts starting with M