Track entities across videos

This recipe shows you how to follow a subject across multiple videos and build a chronological timeline of appearances. The response includes timestamps, video references, locations, and context for each sighting, ready for your tracking dashboard or analysis pipeline.

Note

Cross-video entity tracking is in research preview. Behavior and accuracy may change as the feature develops.

Use cases:

  • Security investigations: Track a person across multiple camera angles or footage sources
  • Timeline construction: Build a chronological record of a subject’s appearances
  • Content auditing: Identify every moment where a specific entity appears in a collection

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 appearance data structure, instructions that give Jockey a specific role and domain guidance, and a prompt that describes the subject to track. Jockey reasons across your knowledge store and returns structured tracking results. You can then continue the conversation using the session identifier from the response. For example, drill into a specific appearance or ask about the surrounding context. You can adapt this recipe to track different subjects or focus on different appearance details.

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 tracking timeline
9tracking_schema = {
10 "type": "object",
11 "properties": {
12 "subject": {"type": "string"}, # Description of the tracked subject
13 "timeline": {
14 "type": "array",
15 "items": {
16 "type": "object",
17 "properties": {
18 "timestamp": {"type": "string"}, # When the appearance occurs
19 "video_reference": {"type": "string"}, # Source video identifier
20 "location": {"type": "string"}, # Where in the scene
21 "action": {"type": "string"}, # What the subject is doing
22 },
23 },
24 },
25 "summary": {"type": "string"}, # Overall tracking summary
26 },
27}
28
29# Track the subject
30response = client.responses.create(
31 knowledge_store_id=STORE_ID,
32 instructions="You are a security analyst. Prioritize temporal accuracy. Flag any low-confidence identifications.",
33 input=[{"type": "message", "role": "user", "content": "Track the person in the blue hoodie across all cameras. Give me a chronological timeline."}],
34 text=TextParam(format=TextParamFormat_JsonSchema(name="entity_tracking", schema_=tracking_schema)),
35)
36
37# Parse and read the timeline
38for output in response.output:
39 if output.type == "message":
40 for content in output.content:
41 data = json.loads(content.text)
42 print(f"Subject: {data['subject']}")
43 print(f"Summary: {data['summary']}\n")
44 for entry in data["timeline"]:
45 print(f" [{entry['timestamp']}] {entry['video_reference']}")
46 print(f" Location: {entry['location']}")
47 print(f" Action: {entry['action']}")
48
49# Refine with a follow-up turn
50follow_up = client.responses.create(
51 knowledge_store_id=STORE_ID,
52 session_id=response.session_id,
53 input=[{"type": "message", "role": "user", "content": "Tell me more about what happened at the third timestamp. What was happening around the subject?"}],
54)
55
56# Read the follow-up response
57for output in follow_up.output:
58 if output.type == "message":
59 for content in output.content:
60 print(content.text)

Code explanation

1

Track the subject

Search the collection for the subject and return a structured timeline of appearances.
Function call: You call the responses.create method with tracking instructions, a prompt, and a text parameter that describes your timeline schema.
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 describes the subject to track and requests a chronological timeline.
  • instructions: A per-request system prompt that shapes Jockey’s behavior for a domain or task. This example uses a security analyst role that prioritizes temporal accuracy.
  • 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.
Describe your subject with specific physical details. Clothing, features, and distinguishing characteristics improve tracking accuracy.

Return value: An object of type ResponseObject. Read the session_id field to continue the conversation, and the output items for the timeline. The response also includes id, status, and usage.

2

Process the results

The text field of each content part in a message item of the output array is a JSON string that matches your schema. Parse it with json.loads(), then iterate the timeline array to read each appearance.

3

Refine with a follow-up turn

Continue the conversation with the session_id from the first response. Jockey retains the full context from the previous turn, so you can drill into a specific appearance without repeating the original prompt.
Function call: You call the responses.create method again with the session_id.
Parameters:

  • knowledge_store_id: The unique identifier of the knowledge store. Must match the store from the first request.
  • session_id: The session identifier from the first response.
  • input: An array of input items. Each item is a message you send to Jockey. This example asks for more detail about a specific timestamp.

Return value: An object of type ResponseObject. This turn omits the text parameter, so the text field of each content part in a message item is plain text. Read it directly.

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 "subject": "Person in blue hoodie",
3 "timeline": [
4 {
5 "timestamp": "02:15-03:40",
6 "video_reference": "069eb4e8-aeb0-7e83-8000-86413fcc296a",
7 "location": "Building lobby, near the front entrance",
8 "action": "Enters through the main door and walks toward the elevator"
9 },
10 {
11 "timestamp": "05:42-06:10",
12 "video_reference": "069e1e97-27f8-7a8e-8000-bf32ecd7fc8c",
13 "location": "Third floor hallway",
14 "action": "Exits the elevator and walks down the corridor"
15 }
16 ],
17 "summary": "Subject appears in 2 videos over a 3-minute span, moving from the lobby to the third floor."
18}
Notes
  • The video_reference field contains the asset identifier of the knowledge store item.
  • The timestamp field is a range in MM:SS-MM:SS format indicating when the appearance starts and ends.
  • If Jockey cannot find the subject in the collection (for example, because the footage does not contain a match or the subject description is ambiguous), it returns an empty array named timeline and explains the result in the summary field.
  • Jockey identifies subjects visually and does not match by voice.
  • Each request tracks one subject. To track multiple subjects, make separate requests.
  • Tracking accuracy depends on video quality, camera angles, lighting, and how distinctive the subject appears.

Variations

Change the instructions and prompt to adapt this recipe for different tracking scenarios.

  • Change the analytical perspective: Set the instructions parameter to “documentary researcher” or “video editor” for different emphasis.
  • Track objects instead of people: Change the prompt to track a vehicle, branded object, or recurring visual element.
  • Multi-episode tracking: Track a recurring character or subject across an episode series.

See also