Search a knowledge store

The KnowledgeStores class provides the search method to search across the items in a knowledge store using natural language.

Methods

Search a knowledge store

Description: This method searches a knowledge store using natural language and returns matching video clips and images ranked by relevance.

Provide your natural-language query in the query.text field. Use the filter parameter to choose which items to search: by type of item (the assetType field) or by specific items (the itemId field). Use the optional searchOptions parameter to control how videos are matched (by visual content, audio, or both). If you omit it, videos are matched on their visual content. Images are always matched on their visual content.

By default, each result is an individual match: a video clip or an image. Set the groupBy parameter to item to group clips under their parent item.

Note

This method is rate-limited. For details, see the Rate limits page.

Function signature and example:

1search(
2 knowledgeStoreId: string,
3 request: TwelvelabsApi.SearchKnowledgeStoreRequest,
4 requestOptions?: KnowledgeStores.RequestOptions
5): Promise<TwelvelabsApi.SearchKnowledgeStoreResponse>

Parameters

NameTypeRequiredDescription
knowledgeStoreIdstringYesThe unique identifier of the knowledge store.
queryKnowledgeStore
SearchQuery
YesThe search query.
filterSearchKnowledge
StoreFilter
NoNarrows results to specific items in the knowledge store. Omit the filter to search all items.
searchOptionsSearchKnowledge
StoreOptions
NoSpecifies how videos are matched. If you omit this field, videos are matched on their visual content. Images are always matched on their visual content and have no options to configure.
groupBySearchKnowledge
StoreRequestGroupBy
NoControls how the platform groups matches in the response.
- none: Returns individual matches ordered by relevance.
- item: Groups matches under their parent item. Default: none.
pageSizenumberNoThe maximum number of results per page. A result is one entry in the data array. With the groupBy parameter set to its default of none, each result is an individual match: a video clip or an image. When set to item, each result is one item: a video with all its matching clips, or an image. Default: 10. Max: 50.
pageTokenstringNoPagination token used to retrieve the next page of results. Omit it on the first request. To fetch the next page, set it to the nextPageToken field returned in the previous response and send the request again. A malformed or unrecognized token returns a 400 error. A token that has expired returns a 410 error (make a new search request to obtain a fresh page token).
includeMetadatabooleanNoSet to true to include metadata in each result. Each result includes a metadata object with a system field (platform-derived file properties such as duration and resolution) and a user field (metadata you attached to the item).
requestOptionsKnowledgeStores.
RequestOptions
NoPer-call SDK settings such as timeout, retries, and headers. For all fields, see Request options.

The KnowledgeStoreSearchQuery object contains the following property:

NameTypeRequiredDescription
textstringYesDescribe what you’re searching for in natural language (Examples: A person cooking pasta or aerial shots of a city at night).

The SearchKnowledgeStoreFilter object narrows results to specific items in the knowledge store. Filter by type of item or by specific identifiers. When you specify both fields, the platform applies all conditions together. It contains the following properties:

NameTypeRequiredDescription
assetTypeAssetTypeFilterNoNarrows results by type of item. Provide exactly one operator: eq (a string) to match one type, or in (an array) to match any of the listed types. Values: video, image.
itemIdItemIdFilterNoNarrows results to specific items. Provide exactly one operator: eq (a string) to match one item, or in (an array) to match any of the listed items.

The SearchKnowledgeStoreOptions object contains the following property:

NameTypeRequiredDescription
videoVideoSearchOptionsNoOptions that control how videos are matched. By default, videos are matched on their visual content.

The VideoSearchOptions object contains the following properties:

NameTypeRequiredDescription
modalitiesVideoSearch
Modality[]
YesThe video modalities used for searching.
- visual: Searches visual content.
- audio: Searches audio content, including speech and non-speech sounds.
You can combine multiple modalities to broaden your search. For guidance, see Search options.

Return value

Returns a SearchKnowledgeStoreResponse object. The SearchKnowledgeStoreResponse object contains the following properties:

NameTypeDescription
dataSearchKnowledge
StoreHit[]
Search results, ordered by relevance.
nextPageTokenstringPagination token for the next page. Pass this value as the pageToken parameter in your next request to retrieve more results. Absent when no more pages exist.
effectiveSearchOptionsSearchKnowledge
StoreOptions
The video options applied to this search, including any defaults. When the search includes videos, this object contains a video field with the modalities used. When the search is limited to images, this object is empty.

Each entry in the data array is a SearchKnowledgeStoreHit. The fields present depend on the assetType field:

NameTypeDescription
assetType"video" | "image"The type of item that matched.
ranknumberThe relevance ranking assigned by the model.
itemIdstringThe unique identifier of the matching item.
metadataKnowledgeStore
SearchItemMetadata
Metadata for the item. Returned when the includeMetadata parameter is set to true.
matchesVideoMatch[]The matching clips within the video. Present only when assetType is video.

The VideoMatch object contains the following properties:

NameTypeDescription
startSecnumberThe clip start offset, in seconds, within the source video.
endSecnumberThe clip end offset, in seconds, within the source video.
modalitiesVideoSearch
Modality[]
The modalities that matched in this clip.
transcriptionstringThe spoken words in the clip. Returned when spoken-word data is available for the clip, regardless of which modalities matched.

API Reference

Search a knowledge store.