Search
The TwelveLabs Video Understanding 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:
- Improved accuracy: Multimodal integration enhances accuracy.
- Easy interaction: Natural language queries simplify searches.
- Advanced search: Enables image-based queries for precise results.
- Fewer errors: Multi-faceted analysis reduces misinterpretation.
- Time savings: Quickly finds relevant clips without manual review.
Use cases:
- Spoken word search: Find video segments where specific words or phrases are spoken.
- Visual element search: Locate video segments that match descriptions of visual elements or scenes.
- Action or event search: Identify video segments that depict specific actions or events.
- Image similarity search: Find video segments that visually resemble a provided image.
To understand how your usage is measured and billed, see the Pricing page.
Note
You can only perform searches at the individual index level, meaning you can only search within one index per request and cannot search at the video level or across multiple indexes simultaneously.
Prerequisites
-
To use the platform, you need an API key:
-
Ensure the pre-release version of the TwelveLabs SDK is installed on your computer:
-
The videos you wish to use must meet the following requirements:
-
Video resolution: Must be at least 360x360 and must not exceed 3840x2160.
-
Aspect ratio: Must be one of 1:1, 4:3, 4:5, 5:4, 16:9, 9:16, or 17:9.
-
Video and audio formats: Your video files must be encoded in the video and audio formats listed on the FFmpeg Formats Documentation page. For videos in other formats, contact us at support@twelvelabs.io.
-
Duration: Must be between 4 seconds and 2 hours (7,200s).
-
File size: Must not exceed 2 GB.
If you require different options, contact us at support@twelvelabs.io.
-
-
If you wish to use images as queries, ensure that your images meet the following requirements:
- Format: JPEG and PNG.
- Dimension: Must be at least 64 x 64 pixels.
- Size: Must not exceed 5MB.
Complete example
This complete example shows how to create an index, upload a video, and perform search requests using text and image queries. Ensure you replace the placeholders surrounded by <>
with your values.
Step-by-step guide
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.
Specify the index containing your videos
Indexes help you organize and search through related videos efficiently. This example creates a new index, but you can also use an existing index by specifying its unique identifier. See the Indexes page for more details on creating an 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 thevisual
andaudio
model options.
Return value: An object containing, among other information, a field named id
representing the unique identifier of the newly created index.
Upload videos
To perform any downstream tasks, you must first upload your videos, and the platform must finish indexing them.
Function call: You call the tasks.create
function.
Parameters:
index_id
: The unique identifier of your index.video_url
orvideo_file
: The publicly accessible URL or the path of your video file.
Return value: An object of type TasksCreateResponse
that you can use to track the status of your video upload and indexing process. This object contains, among other information, the following fields:
id
: The unique identifier of your video indexing task.video_id
: The unique identifier of your video.
Note
You can also upload multiple videos in a single API call. For details, see the Cloud-to-cloud integrations page.
Monitor the indexing process
The platform requires some time to index videos. Check the status of the video indexing task until it’s completed.
Function call: You call the tasks.wait_for_done
function.
Parameters:
sleep_interval
: The time interval, in seconds, between successive status checks. In this example, the method checks the status every five seconds.task_id
: The unique identifier of your video indexing task.callback
: A callback function that the SDK executes each time it checks the status.
Return value: An object of type TasksRetrieveResponse
containing, among other information, a field named status
representing the status of your task. Wait until the value of this field is ready
.
Perform a search request
Perform a search within your index using a text or image query.
Text queries
Image queries
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.search_options
: The modalities the platform uses when performing a search. This example searches using visual and audio cues.- (Optional)
operator
: The logical operator, eitheror
orand
, specifies how your search combines multiple sources of information; it defaults toor
. Use this parameter when thesearch_options
parameter lists more than one source of information. For example, when you set this parameter toand
, the search returns video segments matching all specified sources of information.
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.score
: A quantitative value determined by the platform representing the level of confidence that the results match your search terms.confidence
: A quantitative value determined by the platform representing the level of confidence that the results match your search terms.