Text and image embeddings
This guide shows how to create a combined embedding from up to 10 images with optional text using the Marengo video understanding model. For a list of available versions, complete specifications, and input requirements, see the Marengo page.
The Marengo video understanding model generates embeddings for all modalities in the same latent space. This shared space enables any-to-any searches across different types of content.
For details on how your usage is measured and billed, see the Pricing page.
Key concepts
This section explains the key concepts and terminology used in this guide:
- Asset: Your uploaded content. Once created, you can reference the same asset across multiple operations without uploading the file again.
- Embedding: Vector representation of your content.
Workflow
This guide shows how to upload your images as assets and create a combined embedding synchronously. You can also pass images inline as a URL or base64-encoded data instead of creating assets; both are shown as commented-out lines in the code examples.
Use these embeddings for similarity search, content classification, clustering, recommendations, or Retrieval-Augmented Generation (RAG).
Prerequisites
-
To use the platform, you need an API key:
-
Depending on the programming language you are using, install the TwelveLabs SDK by entering one of the following commands:
-
Your image files must meet the requirements.
Complete example
Copy and paste the code below, replacing the placeholders surrounded by <> with your values.
Code explanation
Python
Node.js
Import the SDK and initialize the client
Create a client instance to interact with the TwelveLabs Video Understanding Platform.
Function call: You call the constructor of the TwelveLabs class.
Parameters:
api_key: The API key to authenticate your requests to the platform.
Return value: An object of type TwelveLabs configured for making API calls.
Upload your images
Upload one or more image files to create assets. For details about the available upload methods and the corresponding limits, see the Upload methods page.
Function call: You call the assets.create function.
Parameters:
method: The upload method for your asset. Useurlfor a publicly accessible URL ordirectto upload a local file. This example usesurl.urlorfile: The publicly accessible URL of your image file or an opened file object in binary read mode. This example usesurl.
Return value: An object of type Asset. This object contains, among other information, a field named id representing the unique identifier of your asset.
Repeat this step for each image you want to include. In the next step, you can assign a name to each image source to reference it in your text using <@name> placeholders.
Create text and image embeddings
Function call: You call the embed.v_2.create function.
Parameters:
input_type: The type of content. Set this parameter tomulti_input.model_name: The model you want to use. This example usesmarengo3.0.multi_input: AMultiInputRequestobject containing the following properties:media_sources: A list of up to 10 image sources. Each source accepts the following properties:- (Optional)
name: A unique identifier for this image. Required when using<@name>placeholders ininput_text. media_type: The type of media. Set to"image".- Exactly one of the following:
asset_id: The unique identifier of an asset from a previous upload. This example uses the asset ID from the previous step.url: The publicly accessible URL of the image file.base_64_string: The base64-encoded image data.
- (Optional)
input_text: The text for which you wish to create an embedding. Provide plain text for context, or use<@name>placeholders to reference specific images. When using placeholders, set a matchingnamefield on each image source.
Return value: An object of type EmbeddingSuccessResponse containing a field named data, which is a list of embedding objects. Each embedding object includes the following fields:
embedding: An array of floats representing the embedding vector.embedding_option: The type of embedding generated.