Search a knowledge store
This guide shows you how to search a knowledge store with a natural-language query. The search matches both videos and images: a video result is a clip with a time range, and an image result is the whole image. Each result is ranked by relevance. Use the results in a search interface or a processing pipeline.
Use direct search when a literal query describes what you need and you want the matching clips and images to display or process. For interpretive or subjective queries, or to have Jockey explain and refine the results, see agentic search instead.
Key features:
- Natural-language queries: Searches videos and images with a single natural-language query.
- Video and image results: Returns a clip with a time range for each video match and the whole image for each image match.
- Relevance ranking: Ranks every result by relevance.
- Modality control: Matches videos by visual content, audio, or both. Images always match on their visual content.
Use cases:
- In-app search features: Build content search into your application.
- Content retrieval: Find specific moments and images across a large collection without manual review.
- Targeted lookups: Filter to a type of item or specific items, then page through the results.
Key concepts
- Knowledge store: A persistent store of your videos and images plus the understanding the platform derives from them — spatiotemporal context, a typed ontology, and embeddings — that together enable corpus-level reasoning.
- Modalities: The sources of information the platform searches within a video: visual content and audio (both speech and non-speech sounds). The platform searches images by their visual content. For guidance, see the Modalities page.
Prerequisites
You’ve already added at least one asset to a knowledge store, and the knowledge store item has reached the ready status. See the Add assets to a knowledge store page for details.
Example
Copy and paste the code below, replacing the placeholders surrounded by <> with your values. The example searches both videos and images with a single query, then pages through the results and prints every match.
Code explanation
Python
Node.js
Send the request
Search both videos and images with a single natural-language query. This example matches on visual content and audio.
Function call: You call the knowledge_stores.search method.
Parameters:
knowledge_store_id: The unique identifier of the knowledge store to search.query: An object that specifies the search query. Pass the natural-language text in itstextfield.search_options: An object that controls how videos are matched: by visual content (visual) or audio (audio, covering both speech and non-speech sounds). Setmodalitiesto a subset such as["visual"]to match on visual content only. Images always match on their visual content.- (Optional)
filter: An object that narrows results to one type of item ({"asset_type": {"eq": "image"}}) or to specific items (anitem_idcondition). Omit to search all items. - (Optional)
group_by: Set to"item"to return one result per item, with all matching clips of a video ranked together. Defaults to individual matches. - (Optional)
page_size: The number of results per page. Default 10, maximum 50. - (Optional)
include_metadata: Set totrueto return the system and user metadata of each item.
Return value: An object of type SearchKnowledgeStoreResponse with a field named data, which is an array of matches ranked by relevance, and a field named next_page_token that appears when more results remain.
Process the results
Read each match from the data array. The asset_type field identifies each match as a video or an image: a video match includes a matches array whose clips have the start_sec, end_sec, and modalities fields; an image match has no clip. This example prints each match to the standard output.
Request the next page
Each response returns up to page_size results (10 by default). When the response includes a next_page_token field, more results remain.
Function call: You call the knowledge_stores.search method again with the same request, adding the page_token field.
Parameters:
page_token: Thenext_page_tokenvalue from the previous response.
Return value: The next page of results. Stop when a response omits the next_page_token field.
Example response
For a query such as “a rocket lifting off the launch pad”, a typical response with a video result and an image result looks like this:
Note
For a video result, the item_id field identifies the source video, and the start_sec and end_sec fields give the start and end offsets of the matching clip, in seconds. Together they locate the exact clip. For an image result, the item_id field identifies the whole image. Use these identifiers to play, preview, or display the match in your search results.