Use the TwelveLabs Video Understanding Platform to find specific moments in your video content using natural language queries or reference images. The platform analyzes videos by integrating images, audio, speech, and text, offering a deeper understanding than single-modal methods. It captures complex relationships between these elements, detects subtle details, and supports natural language queries and images for intuitive and precise use.
Key features:
Use cases:
For details on how your usage is measured and billed, see the Pricing page.
This section explains the key concepts and terminology used in this guide:
Upload and index your videos before you search them. The platform indexes videos asynchronously. You can search your videos after indexing completes. Search results show video segments that match your search terms.
Types of search queries
The platform supports three types of search queries:
For guidance on choosing the correct query type, see the Search with text, image, and composed queries page.
Search scope
You can search within a single index per request. You cannot search at the video level or across multiple indexes simultaneously.
Customize your search
You can customize your search in the following ways:
or or and operatorsTo 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:
If you wish to use images as queries, ensure that your image file meet the requirements.
Copy and paste the code below, replacing the placeholders surrounded by <> with your values.
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.
Indexes store and organize your video data, allowing you to group related videos. This guide shows how to create one, but you can also use an existing index.
Function call: You call the indexes.create function.
Parameters:
index_name: The name of the index.models: An array specifying your model configuration. This example enables the Marengo video understanding model and specifies that it analyzes visual and audio modalities.See the Indexes page for more details on creating an index and specifying the model configuration.
Return value: An object of type IndexesCreateResponse containing a field named id representing the unique identifier of the newly created index.
Upload a video to create an asset.
Function call: You call the assets.create function.
Parameters:
method: The upload method for your asset. Use url for a publicly accessible or direct to upload a local file. This example uses url.url or file: The publicly accessible URL of your video or an opened file object in binary read mode. This example uses url.Return value: An object of type Asset. This object contains, among other information, a field named id representing the unique identifier of your asset.
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.
You only need this step for URL uploads larger than 200 MB. The platform processes these files asynchronously.
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.
Index your video by adding the asset created in the previous step to an index. This operation is asynchronous.
Function call: You call the indexes.indexed_assets.create function.
Parameters:
index_id: The unique identifier of the index to which the asset will be indexed.asset_id: The unique identifier of your asset.enable_video_stream: Specifies whether the platform stores the video for streaming. When set to True, you can retrieve its URL by calling the indexes.indexed_assets.retrieve method.Return value: An object of type IndexedAssetsCreateResponse. This object contains a field named id representing the unique identifier of your indexed asset.
The platform requires some time to index videos. Check the status of the indexing process until it’s completed.
Function call: You call the indexes.indexed_assets.retrieve function.
Parameters:
index_id: The unique identifier of your video index.indexed_asset_id: The unique identifier of your indexed asset.Return value: An object of type IndexedAssetDetailed containing, among other information, a field named status representing the status of the indexing process. Wait until the value of this field is ready.
Perform a search within your index using a text or image query or a combination of both.
Function call: You call the search.query method.
Parameters:
index_id: The unique identifier of the index.
query_text: Your search query. Note that the platform supports full natural language-based search. The maximum length for a query is 500 tokens.
search_options: The modalities the platform uses when performing a search. This example searches using visual and audio cues. For details, see the Search options section.
(Optional) operator: Combines multiple search options using or (default) or and. Use and to find segments matching all search options. Use or to find segments matching any search option.
(Optional) transcription_options: Specifies how the platform matches your query against spoken words. This parameter applies only when transcription is included in search_options. Available options are lexical, semantic, or both (default). For details, see the Transcription options section.
Return value: An object of type SyncPager[SearchItem] that can be iterated to access search results. Each item contains the following fields, among other information:
video_id: The unique identifier of the video that matched your search terms.start: The start time of the matching video clip, expressed in seconds.end: The end time of the matching video clip, expressed in seconds.rank: The relevance ranking assigned by the model. Lower numbers indicate higher relevance, starting with 1 for the most relevant result.