Skip to content

Search Videos

Shows how to search across indexed videos using a text query.

This example assumes using TwelveLabs; is in scope and apiKey contains your TwelveLabs API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
using var client = new TwelveLabsClient(apiKey);

// Retrieve the first index to use for searching.
var indexes = await client.SubpackageIndexes.ListAsync(
    xApiKey: apiKey);
var indexId = indexes.Data?.FirstOrDefault()?.Id
    ?? throw new AssertInconclusiveException("No indexes found. Create an index and upload videos first.");

// Search for video segments matching a text query using visual search.
var results = await client.SubpackageSearch.CreateAsync(
    xApiKey: apiKey,
    indexId: indexId,
    queryText: "a person walking",
    searchOptions: [SearchPostRequestBodyContentMultipartFormDataSchemaSearchOptionsItems.Visual]);

// The response contains matching video clips with timestamps and relevance ranking.
foreach (var item in results.Data!)
{
    Console.WriteLine($"Video: {item.VideoId}, Start: {item.Start}s, End: {item.End}s, Rank: {item.Rank}");
}