Agentic search

This recipe shows you how to perform agentic search over a knowledge store. Jockey interprets your query, reasons across the content, and returns structured results that you can shape and refine. Each result can include an item reference, timestamp, description, and relevance. Use the results in a search interface or a processing pipeline.

For a direct, single-call search that retrieves ranked matches, see Search a knowledge store. Use agentic search when your query is interpretive or subjective, or when you want Jockey to explain and refine the results.

Use cases:

  • Interpretive queries: Search for moments that need interpretation, ranking, or judgment
  • Explained results: Receive a description and a relevance explanation for each match
  • Custom output: Shape the results into a structure your application consumes

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.
  • Structured output: A JSON schema you provide with your request. Jockey constrains its output to match your schema, so you retrieve machine-readable results instead of plain text. For a guide on designing schemas and parsing responses, see the Structured output page.

Workflow

This recipe combines two elements: a JSON schema that defines the result data structure and a prompt that describes what you want to find. Jockey reasons across your knowledge store, matches moments against visual content, audio, and semantic meaning, and returns structured search results. You can adapt this recipe to search for different content types or match different criteria.

Prerequisites

  • You’ve already created a knowledge store with at least one item in ready status. See the Quickstart page for details.
  • You’re familiar with the request and response format. See the Create a response page for details.

Complete example

Copy and paste the code below, replacing the placeholders surrounded by <> with your values. The example pairs a result schema with a prompt that searches for presentations. Adapt the schema and prompt to match what you want to find.

1import json
2from twelvelabs import TwelveLabs, TextParam
3from twelvelabs.types.text_param_format import TextParamFormat_JsonSchema
4
5client = TwelveLabs(api_key="<YOUR_API_KEY>")
6STORE_ID = "<YOUR_KNOWLEDGE_STORE_ID>"
7
8# Define a JSON schema for the search results
9search_schema = {
10 "type": "object",
11 "properties": {
12 "results": {
13 "type": "array",
14 "items": {
15 "type": "object",
16 "properties": {
17 "item_reference": {"type": "string", "description": "The plain UUID of the source item"}, # Source item identifier
18 "timestamp": {"type": "string"}, # When the moment occurs
19 "description": {"type": "string"}, # What happens at this moment
20 "relevance": {"type": "string"}, # Why this matches the query
21 },
22 },
23 },
24 "total_results": {"type": "integer"}, # Number of matches found
25 "query_interpretation": {"type": "string"}, # How Jockey interpreted the query
26 },
27}
28
29# Run the search
30response = client.responses.create(
31 knowledge_store_id=STORE_ID,
32 input=[{"type": "message", "role": "user", "content": "Find all moments where someone is presenting to an audience"}],
33 text=TextParam(format=TextParamFormat_JsonSchema(name="search_results", schema_=search_schema)),
34)
35
36# Parse and read the results
37for output in response.output:
38 if output.type == "message":
39 for content in output.content:
40 search = json.loads(content.text)
41 print(f"Found {search['total_results']} results")
42 print(f"Interpreted as: {search['query_interpretation']}\n")
43 for r in search["results"]:
44 print(f" [{r['timestamp']}] {r['item_reference']}")
45 print(f" {r['description']}")
46 print(f" Relevance: {r['relevance']}\n")

Code explanation

To run an agentic search, call the responses.create method with a text parameter that describes your result schema and a prompt that describes what to find.
Parameters:

  • knowledge_store_id: The unique identifier of the knowledge store to search.
  • input: An array of input items. Each item is a message you send to Jockey. This example searches for moments where someone presents to an audience.
  • text: An object that specifies the response format. To return structured JSON, set the format field: its schema_ field defines the structure the results must match, and its name field identifies the schema. Design the schema to fit your use case; the inline comments in the example describe each field. For the schema rules, see the Structured output page.

Return value: An object of type ResponseObject containing, among other information, the following fields:

  • id: The unique identifier of the response.
  • knowledge_store_id: The knowledge store this response was generated against.
  • session_id: The session identifier. Pass it in a follow-up request to continue the conversation.
  • status: The status of the response. The possible values are completed, failed, in_progress, and incomplete.
  • output: The response output items. The text field of each content part in a message item is a JSON string that matches your schema. Parse it with json.loads(), then iterate the results array to read each match.
  • usage: Token usage statistics, including the input_tokens and output_tokens fields.

Example response

The text field inside each content part is a JSON string that matches your schema. After parsing, a typical result looks like this:

1{
2 "results": [
3 {
4 "item_reference": "069eb4e8-aeb0-7e83-8000-86413fcc296a",
5 "timestamp": "05:22-07:14",
6 "description": "Speaker walks to the front of the room and begins a slide presentation",
7 "relevance": "Very high. Presenter addressing a seated audience with visual aids"
8 },
9 {
10 "item_reference": "069e1e97-27f8-7a8e-8000-bf32ecd7fc8c",
11 "timestamp": "12:45-14:30",
12 "description": "Keynote speaker demonstrates product features on stage",
13 "relevance": "High. Live presentation to a large audience with product demo"
14 }
15 ],
16 "total_results": 2,
17 "query_interpretation": "Find moments where a person is actively presenting or speaking to a group of people"
18}
Note

The item_reference field is the unique identifier of the knowledge store item that contains the match, as a plain UUID. The timestamp field gives the matching range in MM:SS-MM:SS format. Re-add the ksi_ prefix to this value to use it with the knowledge store items endpoints.

Variations

Change the prompt and schema to adapt this recipe for different search scenarios. Jockey matches against visual content, audio, and semantic meaning.

  • Search by visual description: Change the prompt to describe a scene, such as “outdoor scenes with water” or “product being held up to camera.”
  • Search by audio or speech: Search for spoken content, such as “someone laughing” or “mentions of quarterly revenue.”
  • Search by tone or mood: Describe the feel of a moment, such as “heated discussion” or “celebratory reactions.”
  • Rank results: Ask Jockey to rank matches: “Find and rank the top 5 most visually striking moments.”
  • Narrow the scope: Add the instructions parameter to constrain the search. For example, “Only search the first 2 minutes of each video.”
  • Refine with follow-up turns: Use a multi-turn session to adjust results: “Show me more like the third result.”

Jupyter notebook

Open In Colab

See also