Assemble highlight reels

This recipe shows you how to find and sequence clips from a video collection based on a theme, topic, or set of criteria. The response includes clip references with video identifiers, timestamps, and assembly notes, ready for your editing tool or pipeline.

Use cases:

  • Marketing highlight reels: Select product demos and customer reactions for promotional videos
  • Event recaps: Pull the best moments from conference or event footage
  • Training compilations: Assemble instructional clips by topic or skill level
  • Content repurposing: Find and sequence clips for social media or internal communications

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: Additional guidance that shapes Jockey’s behavior for a specific domain or task.
  • 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 three elements: a JSON schema that defines the clip data structure, instructions that give Jockey a specific role and domain guidance, and a prompt that describes what you want in the highlight reel. Jockey reasons across your knowledge store, finds the best matching moments, and returns structured clip references in the order it recommends. You can adapt this recipe to target different editorial styles or content themes.

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.

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 clip references
9clip_schema = {
10 "type": "object",
11 "properties": {
12 "assembly_title": {"type": "string"}, # Title for the highlight reel
13 "clips": {
14 "type": "array",
15 "items": {
16 "type": "object",
17 "properties": {
18 "video_reference": {"type": "string"}, # Source video identifier
19 "start_time": {"type": "string"}, # Clip start timestamp
20 "end_time": {"type": "string"}, # Clip end timestamp
21 "description": {"type": "string"}, # What happens in the clip
22 "relevance_reason": {"type": "string"}, # Why Jockey selected this clip
23 },
24 },
25 },
26 "total_estimated_duration": {"type": "string"}, # Combined duration of all clips
27 "assembly_notes": {"type": "string"}, # Sequencing and editorial guidance
28 },
29}
30
31# Assemble the reel
32response = client.responses.create(
33 knowledge_store_id=STORE_ID,
34 instructions="You are a video editor assembling a highlight reel. Select clips that flow well together with good pacing and variety.",
35 input=[{"type": "message", "role": "user", "content": "Find the best clips showing product demos and customer reactions. I need a 2-minute highlight reel."}],
36 text=TextParam(format=TextParamFormat_JsonSchema(name="highlight_reel", schema_=clip_schema)),
37)
38
39# Parse and read the clips
40for output in response.output:
41 if output.type == "message":
42 for content in output.content:
43 assembly = json.loads(content.text)
44 print(f"Assembly: {assembly['assembly_title']}")
45 print(f"Duration: {assembly['total_estimated_duration']}")
46 print(f"Notes: {assembly['assembly_notes']}")
47 for i, clip in enumerate(assembly["clips"], 1):
48 print(f" {i}. [{clip['start_time']}-{clip['end_time']}] {clip['description']}")
49 print(f" Why: {clip['relevance_reason']}")

Code explanation

To assemble a highlight reel, call the responses.create method with editorial instructions, a prompt, and a text parameter that describes your result schema.
Parameters:

  • knowledge_store_id: The unique identifier of the knowledge store to reason over.
  • input: An array of input items. Each item is a message you send to Jockey. This example describes the highlight reel: what clips to find, how long the reel should be, and the thematic criteria.
  • instructions: A per-request system prompt that shapes Jockey’s behavior for a domain or task. This example uses a video editor role that prioritizes pacing and variety.
  • text: An object that specifies the response format. To return structured JSON, set the format field: its schema_ field defines the structure the output 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 clips array to read each selection in order.
  • 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 "assembly_title": "Product Demo Highlights Q1",
3 "clips": [
4 {
5 "video_reference": "069eb4e8-aeb0-7e83-8000-86413fcc296a",
6 "start_time": "01:22",
7 "end_time": "01:45",
8 "description": "Close-up product walkthrough with feature callouts",
9 "relevance_reason": "Strong visual demonstration of core feature"
10 },
11 {
12 "video_reference": "069e1e97-27f8-7a8e-8000-bf32ecd7fc8c",
13 "start_time": "03:10",
14 "end_time": "03:38",
15 "description": "Customer describing their positive experience",
16 "relevance_reason": "Authentic testimonial with emotional impact"
17 }
18 ],
19 "total_estimated_duration": "01:51",
20 "assembly_notes": "Opens with product demo for context, transitions to customer reactions for social proof"
21}
Notes
  • The video_reference field contains the asset identifier of the knowledge store item.
  • The start_time and end_time fields use MM:SS format for videos under one hour and HH:MM:SS for longer content.
  • Jockey returns clip references (video identifiers and timestamps), not rendered video files. Use these references with your video editing tool or pipeline to assemble the final reel.

Variations

Change the instructions and prompt to adapt this recipe for different editorial styles and content focuses.

  • Change the editorial style: Set the instructions parameter to “documentary editor”, “social media creator”, or “training video producer.”
  • Change the content focus: Change the prompt to request “funny moments”, “technical deep dives”, or “executive summaries.”
  • Refine with follow-up turns: Use a multi-turn session to adjust the results: “Replace the second clip with something more energetic.”

Jupyter notebook

Open In Colab

See also