Embed a query
This guide shows how you can create an embedding for a query using the Marengo 3.5 video understanding model. For complete specifications and input requirements, see the Marengo 3.5 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.
- Media source: One image, video, or audio input that the platform combines into your embedding.
Workflow
This guide shows how to combine text and media sources into a single embedding for retrieving matching content. This example combines text with an image and uploads the image as an asset. You can also pass a URL or base64-encoded data inline instead of creating an asset; both are shown as commented-out lines in the code examples. To upload other types of content, see Upload and processing methods.
The platform processes your request synchronously and returns the embedding in the response. Provide text, media sources, or both, and combine up to 10 media sources in one request.
Customize your embeddings
You can name a media source and reference it from your text, truncate text that exceeds the 2,000-token limit, and request a per-dimension uncertainty vector.
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 media files must meet the following requirements:
- Size and duration: Each media source can be up to 32 MB, and video and audio up to 30 seconds. This limit applies whether you provide a URL, base64-encoded data, or an asset identifier. For longer or larger files, see the Embed content at scale page.
- Model capabilities: See the complete input requirements for Marengo 3.5.
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 an image
Upload an image file to create an asset.
Function call: You call the assets.create function.
Parameters:
method: The upload method for your asset. Useurlfor a publicly accessible 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.
Check the status of the asset
Asset processing is asynchronous. Poll the status of the asset until it is ready before you use it.
Function call: You call the assets.retrieve function.
Parameters:
asset_id: The unique identifier of your asset.
Return value: An object of type Asset containing, among other information, a field named status representing the current status of the asset. Check this field until its value is ready.
Create an embedding for your query
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 embedding model to use. This example usesmarengo3.5. -
(Optional)
auto_truncate: Set this parameter totrueto truncate your text when it exceeds 2,000 tokens. Media sources do not count toward this limit. The default isfalse, which returns a400error instead. -
(Optional)
embedding_uncertainty: Set this parameter totrueto receive adata[].embedding_uncertaintyfield in the response, representing a per-dimension uncertainty vector with the same length as theembeddingarray. A higher value shows lower confidence in that dimension. Set this parameter totrueonly when your request embeds text only, or media only. A request that combines text with media sources returns a400error. -
multi_input: AMultiInputRequestobject containing the following properties:- (Optional)
input_text: The text to include in the embedding. To reference a specific media source, use the<@name>format, wherenamematches thenamefield of that media source. - (Optional)
media_sources: An array of up to 10MultiInputMediaSourceobjects. The platform processes them in the order they appear. Each object contains the following properties:media_type: The type of media. Valid values areimage,video, andaudio.- The source of the media file. Specify one of the following:
-
asset_id: The unique identifier of an asset from a previous upload. -
url: The publicly accessible URL of the media file. -
base_64_string: The base64-encoded media data.This example uses the identifier of the asset created in the previous step.
-
- (Optional)
name: A unique name for this media source. This property is required wheninput_textreferences this media source.
Provide
input_text,media_sources, or both. - (Optional)
Return value: An object of type EmbeddingSuccessResponse containing a field named data, which is a list of embedding objects. A request that combines text with media sources returns one embedding in this list. Each embedding object includes the following fields:
embedding: An array of floats representing the embedding vector.embedding_option: The type of embedding generated.
The response also contains a field named usage with the token counts for your request.