Video embeddings
This guide shows how you can create video embeddings 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.
- Embedding task: An asynchronous operation for processing your content and creating embeddings. Contains a status and the resulting embeddings when complete.
Workflow
This guide shows how to create embeddings for a video file, one for each segment and one for the whole file, so your queries can match its content. The example uploads the video 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.
The platform processes your files asynchronously, one file per request. This example embeds one video; repeat the request for each file in your collection. To embed a query instead, see the Embed a query guide.
Customize your embeddings
You can configure the types of embeddings (visual and audio), the output format (separate, fused, or both), the scope (clip or asset), and the segmentation strategy (dynamic or fixed). You can also fold your own time-aligned text into the fused embedding and request a per-dimension uncertainty vector.
Use these embeddings for similarity search, content classification, clustering, recommendations, or Retrieval-Augmented Generation (RAG).
Retention policy
Embeddings created with the asynchronous method are stored for seven days. After this, you must recreate them to obtain the results again.
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 video files must meet the following requirements:
- Upload limits: Public video URLs up to 4 GB or local video files up to 200 MB. For local files up to 4 GB, see the Upload and processing methods 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 a video
Upload a video 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 video 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.
Note
For local files larger than 200 MB, use multipart uploads. Multipart uploads support automatic retry, progress tracking, parallel chunk uploads, and improved reliability, performance, and observability.
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 task
Create an embedding task to start processing your video.
Function call: You call the embed.v_2.tasks.create function.
Parameters:
input_type: The type of content. Set this parameter tovideo.model_name: The embedding model to use. This example usesmarengo3.5.- (Optional)
embedding_uncertainty: Set this parameter totrueto receive adata[].embedding_uncertaintyfield in the response. This field is a per-dimension uncertainty vector with the same length as theembeddingarray. A higher value shows lower confidence in that dimension. To use this parameter, exclude theassetscope from theembedding_scopefield. For example, setembedding_scopeto["clip"]. The field defaults to["clip", "asset"], so a request that keeps the default returns a400error. video: An object containing the following properties:-
media_source: An object specifying the source of the video file. You can specify one of the following:-
asset_id: The unique identifier of an asset from a previous upload. -
url: The publicly accessible URL of the video file. -
base_64_string: The base64-encoded video data.This example uses the identifier of the asset created in the previous step.
-
-
(Optional)
start_sec: The start time in seconds for processing the video file. By default, the platform processes videos from the beginning. -
(Optional)
end_sec: The end time in seconds for processing the video file. By default, the platform processes videos to the end of the video file. -
(Optional)
embedding_option: The types of embeddings to generate. Valid values are the following:visual: Generates embeddings based on visual content (scenes, objects, actions).audio: Generates embeddings based on audio content (speech, music, and non-dialog audio).transcription: Generates embeddings based on transcribed speech (the actual words spoken in the video). Legacy value that requires Marengo 3.0.
You can specify multiple values to generate different types of embeddings. With Marengo 3.5 the default value is
["visual", "audio"]. -
(Optional)
embedding_scope: The scope for which to generate embeddings. Valid values are the following:clip: Generates one embedding for each segment.asset: Generates one embedding for the entire video file. Use this scope for videos up to 10-30 seconds to maintain optimal performance.
You can specify multiple scopes to generate embeddings at different levels. The default value is
["clip", "asset"]. -
(Optional)
segmentation: An object that specifies how the platform divides the video into segments. Nest the strategy under thetemporalfield. You can use one of the following strategies:temporal.dynamic: Divides the video into segments that adapt to scene changes. Requires a property nameddynamicwith amin_duration_secfield specifying the minimum duration in seconds for each segment.temporal.fixed: Divides the video into segments of a fixed length. Requires a property namedfixedwith aduration_secfield specifying the exact duration in seconds for each segment.
-
(Optional)
embedding_type: An array specifying how to structure the embedding. Use this parameter only whenembedding_optionspecifies two or more values. Valid values are the following:separate_embedding: Returns separate embeddings for each modality specified inembedding_option.fused_embedding: Returns a single combined embedding that integrates all modalities into one vector. With Marengo 3.5, this value requires thetime_based_metadatafield.
To receive both types in the same response, set this to
["separate_embedding", "fused_embedding"]. -
(Optional)
time_based_metadata: An array of your own time-aligned text entries, such as a stats feed or scene descriptions. The platform folds each entry into the fused embedding of the segments it overlaps in time, and it affects only that embedding. This parameter requires thefused_embeddingvalue in theembedding_typeparameter. Each entry contains the following properties:start: The start time of the entry in seconds, measured from the beginning of the asset.end: The end time of the entry in seconds. Set the same value asstartfor an event that happens at a single point in time.text: The text to fold into the fused embedding of the overlapping segments.
-
Return value: An object of type TasksCreateResponse containing, among other information, a field named id, which represents the unique identifier of your embedding task. You can use this identifier to track the status of your embedding task.
Monitor the status
The platform requires some time to process videos. Poll the status of the embedding task until it is ready. This example uses a loop to check the status every 5 seconds.
Function call: You repeatedly call the embed.v_2.tasks.retrieve function until the task completes.
Parameters:
task_id: The unique identifier of your embedding task.
Return value: An object of type EmbeddingTaskResponse containing, among other information, the following fields:
status: The current status of the task. The possible values are:processing: The platform is creating the embeddings.ready: Processing is complete. Embeddings are available in thedatafield.failed: The task failed.
data: When the status isready, this field contains a list of embedding objects. Each embedding object includes:embedding: The embedding vector (a list of floats).embedding_uncertainty: A per-dimension uncertainty vector with the same length as theembeddingarray. A higher value shows lower confidence in that dimension. Present when the request setsembedding_uncertaintytotrue.embedding_option: The type of embedding. Possible values arevisual,audio,transcription, andfused. The platform returnsfusedonly whenembedding_typeincludesfused_embedding.embedding_scope: The scope of the embedding (cliporasset).start_sec: The start time of the segment in seconds.end_sec: The end time of the segment in seconds.