Create a response

This guide shows you how to generate a response from a knowledge store and customize Jockey’s behavior for a specific domain. You can also use this endpoint for agentic search: have Jockey reason over your content to find and explain matches. For direct, single-call retrieval of ranked clips and images instead, use Search a knowledge store.

Key features:

  • Corpus-level reasoning: Answers questions by reasoning across every item in a knowledge store.
  • Domain-specific behavior: Adapts responses to your domain or task through per-request instructions.
  • Multi-turn sessions: Maintains conversation context across follow-up requests.
  • Streaming: Returns tokens in real time instead of waiting for the full response.
  • Structured output: Returns typed JSON responses when you provide a JSON Schema.
  • Intermediate outputs: Returns Jockey’s reasoning steps alongside the final answer.

Use cases:

  • Corpus overview: Generate responses that reason across all your videos and images.
  • Entity extraction: Identify people, places, objects, and other entities across a knowledge store.
  • Search and discovery: Find moments in videos and matching images by describing what you want in natural language.
  • Content organization: Categorize videos and images by themes, topics, formats, or other useful dimensions.
  • Cross-video tracking: Track a subject across multiple videos and reconstruct a timeline of appearances.
  • Content enrichment: Analyze existing content through a specific domain lens or schema.

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.
  • Instructions: A system-level prompt that shapes Jockey’s behavior for a specific domain or task. Same endpoint, different results depending on the instructions you provide.

Prerequisites

  • You’ve already uploaded your content, and the asset has reached the ready status. See the Upload content page for details.
  • You’ve already created a knowledge store. See the Create a knowledge store page for details.
  • 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.

1from twelvelabs import TwelveLabs
2
3client = TwelveLabs(api_key="<YOUR_API_KEY>")
4
5# Create a response
6response = client.responses.create(
7 knowledge_store_id="<YOUR_KNOWLEDGE_STORE_ID>",
8 input=[{"type": "message", "role": "user", "content": "What are the main themes across these videos and images?"}],
9 # session_id=..., # Optional. Continue a multi-turn conversation. See Multi-turn sessions.
10 # instructions=..., # Optional. Add a per-request system prompt. See Customize behavior with instructions.
11 # include=..., # Optional. Return intermediate reasoning steps. See Inspect intermediate outputs.
12 # selections=..., # Optional. Restrict the request to specific items or item collections.
13 # text=..., # Optional. Return typed JSON output. See Structured output.
14)
15
16# Read the response
17print(f"ID: {response.id}")
18print(f"Session: {response.session_id}")
19
20for output in response.output:
21 if output.type == "message":
22 for content in output.content:
23 print(content.text)
24
25print(f"Tokens: {response.usage}")

Code explanation

To generate a response, call the responses.create method with a natural-language message in the input array and the knowledge store to reason over. This example prints the response identifier, session identifier, generated text, and token usage to the standard output.
Parameters:

  • knowledge_store_id: The unique identifier of the knowledge store to reason over. Every request requires exactly one.
  • input: An array of input items. Each item is a message you send to Jockey.
  • (Optional) session_id: Continues a multi-turn conversation. Pass the identifier from a previous response. See the Multi-turn sessions page.
  • (Optional) instructions: Adds a per-request system prompt that shapes Jockey’s behavior for your domain or task. See the Customize behavior with instructions section for details.
  • (Optional) include: An array of extra items to include in the response. Pass intermediate_outputs to return Jockey’s reasoning steps in the output array. See the Inspect intermediate outputs section for details.
  • (Optional) selections: An array that restricts the request to specific knowledge store items or item collections. Omit to run against every item.
  • (Optional) text: An object that specifies the response format. Provide a JSON Schema to return typed JSON output. See the Structured output page for details.

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

  • id: The unique identifier of the response.
  • session_id: The session identifier. Pass it in a follow-up request to continue the conversation. See the Multi-turn sessions page for details.
  • status: The status of the response. The possible values are completed, failed, in_progress, and incomplete.
  • output: The response output items. Iterate the array and read the text field of each content part in a message item to extract the generated text.
  • usage: Token usage statistics, including the input_tokens and output_tokens fields.

To stream the response as it is generated, call the create_stream method instead. See the Streaming page for details.

Example response

The response object contains the generated text along with the session identifier and token usage:

1{
2 "id": "resp_abc123",
3 "session_id": "sess_xyz789",
4 "status": "completed",
5 "output": [
6 {
7 "type": "message",
8 "content": [{"type": "output_text", "text": "The main themes across your videos and images include..."}]
9 }
10 ],
11 "usage": {"input_tokens": 1250, "output_tokens": 340}
12}

Customize behavior with instructions

Add the instructions field to specialize Jockey for your domain. Same endpoint, different results depending on what you provide.

1response = client.responses.create(
2 knowledge_store_id="<YOUR_KNOWLEDGE_STORE_ID>",
3 instructions="You are a sports analyst. Focus on player performance, tactics, and key moments.",
4 input=[{"type": "message", "role": "user", "content": "Summarize the key plays from this game"}],
5)

Swap the instructions field to reshape Jockey for different contexts:

DomainExample instructions
Security”You are a security analyst. Prioritize temporal accuracy and flag low-confidence identifications.”
Media”You are an editorial assistant. Focus on visual quality, pacing, and narrative arc.”
Compliance”You are a compliance reviewer. Identify claims, disclaimers, and required disclosures.”
Education”You are a learning designer. Analyze pedagogical effectiveness, teaching methods, and assessment opportunities.”

Inspect intermediate outputs

Jockey performs multi-step reasoning internally: searching, analyzing, and synthesizing across your videos and images. Add "intermediate_outputs" to the include array to see these reasoning steps alongside the final answer. This is useful for debugging or understanding how Jockey produced the answer.

1response = client.responses.create(
2 knowledge_store_id="<YOUR_KNOWLEDGE_STORE_ID>",
3 input=[{"type": "message", "role": "user", "content": "What are the main themes?"}],
4 include=["intermediate_outputs"],
5)

Capabilities

The Responses API handles many tasks through the same endpoint. These examples are not exhaustive.

CapabilityExample promptRecipe
Corpus overview”Give me a comprehensive overview of these videos and images”Generate a corpus overview
Entity extraction”List every person, place, and object across all videos and images”Extract entities
Search and discovery”Find all moments where someone is presenting to an audience”Agentic search
Content organization”What are the best ways to organize these videos and images?”Find organization axes
Cross-video tracking”Track the person in the blue jacket across all footage”Cross-video entity tracking
Content enrichment”Analyze these videos and images through the lens of brand perception”Enrich content

Common pitfalls

  • Index at least one item before you query. A knowledge store with no items in the ready state has no content for the request to draw on.
  • Include the knowledge store identifier. Every request must include the knowledge_store_id field.

Next steps

Jupyter notebook

Open In Colab