> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Video understanding

> Find the moment in a video where something is shown or said, with one text query.

Find the moment in a video where something is shown or said, with one text query. Each 10-second segment carries a visual embedding and a transcript embedding, and the retriever ranks over both.

> [card] [Jump to the manifest](#the-manifest)
>
> `video-understanding.namespace.yaml`: apply it with one API call, then read the walkthrough below to change it.

## At a glance

| | |
| - | - |
| **Creates** | 1 namespace, 1 bucket, 1 collection, 1 retriever |
| **Extractors** | [`multimodal_extractor`](https://docs.mixpeek.com/docs/extract/extractors#multimodal) v1 |
| **Daily spend budget** | 2 USD, set on the namespace. Queries are not capped. |
| **Sample data** | 3 objects, uploaded to `videos` when you apply |

## How the pieces connect

Buckets hold what you upload, collections turn it into searchable documents, and retrievers answer queries over the collections.

```mermaid theme={null}
flowchart LR
  b0[("videos")]
  c1["video-moments<br/>multimodal_extractor v1"]
  r2{{"video-search"}}
  b0 --> c1
  c1 --> r2
```

## Deploy it

**1. Get the manifest**

```bash theme={null}
# Copy the manifest from the bottom of this page into video-understanding.namespace.yaml
```

**2. Validate it**

Validate runs every check apply runs and creates nothing. Fix each entry in `errors`, then run it again.

```bash theme={null}
curl -X POST https://api.mixpeek.com/v1/manifest/validate \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -F "manifest_file=@video-understanding.namespace.yaml"
```

**3. Apply it**

Apply creates every resource in one call. `wait_for_seed=true` also waits until the sample objects are processed, so the first query below has documents to return.

```bash theme={null}
curl -X POST "https://api.mixpeek.com/v1/manifest/apply?wait_for_seed=true" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -F "manifest_file=@video-understanding.namespace.yaml"
```

The response lists each resource with its outcome in `resources`. Apply refuses a resource that already exists and rolls the whole apply back, so to apply the file again over this namespace add `?mode=create_missing`, which creates only what is missing.

## Run the first query

Look up the namespace id by name, then run `video-search`. Check `status` and `warnings` along with `documents`: a run that times out still answers 200, with `status` `degraded`.

```bash cURL theme={null}
NAMESPACE_ID=$(curl -s https://api.mixpeek.com/v1/namespaces/video-understanding \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" | jq -r .namespace_id)

curl -X POST https://api.mixpeek.com/v1/retrievers/video-search/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"query": "a man shaving with an electric razor"}}' \
  | jq '{status, warnings, documents: [.documents[] | {document_id, score}]}'
```

```python Python theme={null}
import os, requests

AUTH = {"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}"}
ns = requests.get("https://api.mixpeek.com/v1/namespaces/video-understanding", headers=AUTH).json()

run = requests.post(
    "https://api.mixpeek.com/v1/retrievers/video-search/execute",
    headers={**AUTH, "X-Namespace": ns["namespace_id"]},
    json={"inputs": {"query": "a man shaving with an electric razor"}},
).json()

print(run["status"], run["warnings"])  # "completed" on a clean run
for doc in run["documents"]:
    print(doc["document_id"], doc["score"])
```

```javascript JavaScript theme={null}
const auth = { Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}` };
const ns = await fetch("https://api.mixpeek.com/v1/namespaces/video-understanding", { headers: auth }).then((r) => r.json());

const run = await fetch("https://api.mixpeek.com/v1/retrievers/video-search/execute", {
  method: "POST",
  headers: { ...auth, "X-Namespace": ns.namespace_id, "Content-Type": "application/json" },
  body: JSON.stringify({"inputs": {"query": "a man shaving with an electric razor"}}),
}).then((r) => r.json());

console.log(run.status, run.warnings); // "completed" on a clean run
for (const doc of run.documents) console.log(doc.document_id, doc.score);
```

## Add your own data

Each object you add to a bucket is processed by every collection that reads it. This adds one object to `videos`. `NAMESPACE_ID` is the id from the namespace lookup above.

```bash cURL theme={null}
curl -X POST "https://api.mixpeek.com/v1/buckets/videos/objects?auto_process=true" \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"title": "example", "category": "example", "blobs": [{"property": "video", "type": "video", "data": "https://example.com/clip.mp4"}]}'
```

```python Python theme={null}
import os, requests

HEADERS = {"Authorization": f"Bearer {os.environ['MIXPEEK_API_KEY']}", "X-Namespace": os.environ["NAMESPACE_ID"]}

obj = requests.post(
    "https://api.mixpeek.com/v1/buckets/videos/objects",
    params={"auto_process": "true"},
    headers=HEADERS,
    json={
        "title": "example",
        "category": "example",
        "blobs": [
            {
                "property": "video",
                "type": "video",
                "data": "https://example.com/clip.mp4"
            }
        ]
    },
).json()
print(obj["object_id"], obj["status"])  # PENDING until processing finishes
```

```javascript JavaScript theme={null}
const headers = {
  Authorization: `Bearer ${process.env.MIXPEEK_API_KEY}`,
  "X-Namespace": process.env.NAMESPACE_ID,
  "Content-Type": "application/json",
};

const obj = await fetch("https://api.mixpeek.com/v1/buckets/videos/objects?auto_process=true", {
  method: "POST",
  headers,
  body: JSON.stringify({
    "title": "example",
    "category": "example",
    "blobs": [
      {
        "property": "video",
        "type": "video",
        "data": "https://example.com/clip.mp4"
      }
    ]
  }),
}).then((r) => r.json());
console.log(obj.object_id, obj.status); // PENDING until processing finishes
```

The object is `PENDING` until processing finishes, then `COMPLETED` or `FAILED`. [Buckets and objects](https://docs.mixpeek.com/docs/ingest/buckets.md) covers object states, retries and duplicates.

## Retrievers

### `video-search`

Type what a moment shows or what someone says in it, and get the matching 10-second segments, ranked over the frames and the transcript together.

**Stages:** [`feature_search`](https://docs.mixpeek.com/docs/retrieve/stages#feature-search)

**Searches:** `video-moments`

| Input | Type | Required | Description |
| - | - | - | - |
| `query` | text | yes | What the moment shows or what is said in it, in plain words |

## Collections

Each collection runs one extractor over a bucket, or over another collection's documents.

> [accordion] video-moments
>
> multimodal\_extractor\@v1 over bucket videos: one document per 10-second segment, with a visual embedding and a transcript embedding. Feeds video-search.
>
> **Reads** bucket `videos` with [`multimodal_extractor`](https://docs.mixpeek.com/docs/extract/extractors#multimodal) v1.
>
> **Inputs:** `video` ← `video`
>
> **Copied onto each document:** `title`, `category`

## The manifest

Every resource above comes from this file. Change it and apply it again with `?mode=upsert` to update what exists. [Manifests](https://docs.mixpeek.com/docs/manage/manifests.md) documents each field.

```yaml video-understanding.namespace.yaml expandable theme={null}
# video-understanding: a namespace that splits video into 10-second segments, embeds each
# segment twice (what it shows and what is said), and finds moments with one text query.
# Platform manifest schema (GET /v1/discovery/schema). Validate with POST /v1/manifest/validate,
# apply with POST /v1/manifest/apply?wait_for_seed=true.
# Applying a SECOND time, over a namespace this file already created: use
# POST /v1/manifest/apply?mode=create_missing to create only what is missing, or
# mode=upsert to also patch resources that have drifted from this file. The default,
# create_only, fails the whole apply and rolls it back if any resource already exists.
version: '1.0'
metadata:
  name: video-understanding
  description: "Video ingest with visual and speech embeddings per segment, and a retriever that finds moments by what is shown or said."
namespaces:
  - name: video-understanding
    description: "Everything below lives in this namespace."
    feature_extractors:
      - name: multimodal_extractor
        version: v1
    # Daily spend budget, in dollars of what you are charged (1,000 credits a dollar).
    # New batches pause once the namespace has spent this much today; queries are not capped.
    # Raise it later on the namespace: PATCH /v1/namespaces/<id> {"spend_budget": {"daily_usd": N}}.
    budget:
      daily_usd: 2

buckets:
  - name: videos
    namespace: video-understanding
    description: "One object per video: the file, a title and a category. Upload through the API or Studio."
    schema:
      properties:
        video:
          type: video
        title:
          type: string
        category:
          type: string

collections:
  - name: video-moments
    namespace: video-understanding
    description: "multimodal_extractor@v1 over bucket videos: one document per 10-second segment, with a visual embedding and a transcript embedding. Feeds video-search."
    source:
      type: bucket
      bucket: videos
    feature_extractor:
      name: multimodal_extractor
      version: v1
      parameters:
        split_method: time
        time_split_interval: 10
        # Visual index: mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding
        run_multimodal_embedding: true
        # Speech index: mixpeek://multimodal_extractor@v1/multilingual_e5_large_instruct_v1.
        # Both flags default to false; without them the speech index stays empty.
        run_transcription: true
        run_transcription_embedding: true
        enable_thumbnails: true
      input_mappings:
        video: video
      field_passthrough:
        - source_path: title
        - source_path: category
    enabled: true

retrievers:
  - name: video-search
    namespace: video-understanding
    description: "Type what a moment shows or what someone says in it, and get the matching 10-second segments, ranked over the frames and the transcript together."
    collections:
      - video-moments
    input_schema:
      query:
        type: text
        required: true
        description: "What the moment shows or what is said in it, in plain words"
    stages:
      - stage_name: hybrid_search
        stage_id: feature_search
        parameters:
          searches:
            - feature_uri: "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding"
              query:
                input_mode: text
                value: "{{INPUT.query}}"
              top_k: 50
              weight: 0.6
            - feature_uri: "mixpeek://multimodal_extractor@v1/multilingual_e5_large_instruct_v1"
              query:
                input_mode: text
                value: "{{INPUT.query}}"
              top_k: 50
              weight: 0.4
          # dbsf normalizes each search's scores before it applies the weights, so the
          # 0.6/0.4 split holds across two embedding models with different score ranges.
          fusion: dbsf
          final_top_k: 20
    tags:
      - guide:video-understanding

# Three public-domain television commercials (60, 65 and 85 seconds) from the starter
# sample set, about 3.5 minutes of video in all.
seed:
  - bucket: videos
    max_objects: 3
    objects:
      - blobs: {video: samples/starter/videos/norelco-speed.mp4}
        title: "Norelco Speedshaver commercial"
        category: grooming
      - blobs: {video: samples/starter/videos/folgers-coffee.mp4}
        title: "Folgers Coffee commercial"
        category: food-and-drink
      - blobs: {video: samples/starter/videos/amc-jeep.mp4}
        title: "AMC Jeep commercial"
        category: automotive
acceptance:
  max_cost_usd: 1
  steps:
    - name: segments-indexed
      kind: documents
      collection: video-moments
      expect: {min_documents: 3}
    - name: moments-answer-a-typed-search
      kind: query
      retriever: video-search
      inputs: {query: a man shaving with an electric razor}
      expect: {min_results: 1}
```

## Hand it to an agent

Paste this prompt into Claude Code, Cursor or another coding agent. To give the agent this whole page instead, use **Copy page** in the menu at the top of the page, or point it at the page's Markdown at `https://mixpeek.com/docs/templates/video-understanding.md`.

```text Prompt theme={null}
Set up the Mixpeek "Video understanding" template in my organization. My API key is in MIXPEEK_API_KEY.
1. Save the manifest at the bottom of https://mixpeek.com/docs/templates/video-understanding as video-understanding.namespace.yaml.
2. POST it to https://api.mixpeek.com/v1/manifest/validate as the multipart field manifest_file, with the header Authorization: Bearer $MIXPEEK_API_KEY. Fix every entry in errors and validate again.
3. POST the same file to https://api.mixpeek.com/v1/manifest/apply?wait_for_seed=true. Every entry in resources should be created.
4. GET https://api.mixpeek.com/v1/namespaces/video-understanding and keep namespace_id. Send it as the X-Namespace header on every call below.
5. POST {"inputs": {"query": "a man shaving with an electric razor"}} to https://api.mixpeek.com/v1/retrievers/video-search/execute. Read documents, check that status is completed, and print warnings.
Reference for this template: https://mixpeek.com/docs/templates/video-understanding.md
```

## How it works

Each video in `videos` becomes one document per 10-second segment in `video-moments`. Every document carries the segment's `start_time` and `end_time` in seconds, its `transcription`, a `thumbnail_url`, the source video's URL in `source_video_url`, and the bucket object's `title` and `category`.

One `multimodal_extractor@v1` run writes two vector indexes per segment:

| Index | Feature URI | Built from | Answers |
| - | - | - | - |
| Visual | `mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding` | The segment's frames, 1408 dimensions | What the segment shows |
| Speech | `mixpeek://multimodal_extractor@v1/multilingual_e5_large_instruct_v1` | The segment's transcript, 1024 dimensions | What is said in the segment |

`video-search` sends the same text query to both indexes and fuses the two ranked lists into one. A query like "a man shaving with an electric razor" finds the segment by its frames. A query that repeats a line from the voice-over finds the segment by its transcript, even when the frames show something else.

> [!WARNING]
>
> `run_transcription` and `run_transcription_embedding` both default to `false`. Leave either one out and the speech index stays empty: the second search returns nothing and every result comes from the frames alone. The manifest sets both to `true`.

### Why these parameters

* **`split_method: time` with `time_split_interval: 10`** cuts every video into fixed 10-second segments. Shorter segments give tighter timestamps; longer ones cost the same per minute and return coarser moments.
* **`fusion: dbsf`** rescales each search's scores to 0 to 1 before it applies the weights. The two indexes come from different models with different score ranges.
* **`weight: 0.6` and `weight: 0.4`** let the frames lead. Swap them for spoken-word video such as interviews, lectures or podcasts.

Video costs 0.20 USD a minute to process, so the 3.5 minutes of seed video cost about 0.70 USD. The namespace's `budget.daily_usd` of 2 pauses new batches once a day's spend reaches 2 USD.

## Change the fusion

Edit the `hybrid_search` stage and apply again with `?mode=upsert`, which patches the retriever's stages in place.

> [tab] Rank fusion
>
> `rrf` ranks by position in each list and ignores the raw scores. Use it when you do not want to tune weights.
>
> ```yaml video-understanding.namespace.yaml theme={null}
>       fusion: rrf
>       final_top_k: 20
> ```

> [tab] Speech first
>
> For talking-head video, let the transcript lead.
>
> ```yaml video-understanding.namespace.yaml theme={null}
>       searches:
>         - feature_uri: "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding"
>           query:
>             input_mode: text
>             value: "{{INPUT.query}}"
>           top_k: 50
>           weight: 0.3
>         - feature_uri: "mixpeek://multimodal_extractor@v1/multilingual_e5_large_instruct_v1"
>           query:
>             input_mode: text
>             value: "{{INPUT.query}}"
>           top_k: 50
>           weight: 0.7
>       fusion: dbsf
>       final_top_k: 20
> ```

> [tab] Drop weak matches
>
> `min_score` drops a search's candidates below the threshold before fusion. Start low and raise it while the results you expect still come back.
>
> ```yaml video-understanding.namespace.yaml theme={null}
>         - feature_uri: "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding"
>           query:
>             input_mode: text
>             value: "{{INPUT.query}}"
>           top_k: 50
>           weight: 0.6
>           min_score: 0.1
> ```

A field upsert cannot change is reported in the response's `refused`, with the resource and the field named.

## Filter at query time

Pass `filters` with the execute call to narrow one run without changing the retriever. This one keeps only segments from automotive videos:

```bash cURL theme={null}
curl -X POST https://api.mixpeek.com/v1/retrievers/video-search/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": {"query": "a car driving off road"},
    "filters": {"AND": [{"field": "category", "operator": "eq", "value": "automotive"}]}
  }' \
  | jq '{status, warnings, documents: [.documents[] | {title, start_time, end_time, score}]}'
```

Segment times are filterable the same way. To search only the part of each video after its first 30 seconds, replace the filter with this one:

```json Filter by time theme={null}
{"AND": [{"field": "start_time", "operator": "gte", "value": 30}]}
```

[Filters](https://docs.mixpeek.com/docs/retrieve/retrievers.md) lists every operator.

## Return moments instead of segments

Adjacent segments often match the same query: a shaving scene that runs 25 seconds spans three 10-second segments. The `moment_group` stage merges matching segments of the same video into one time range. Add it after `hybrid_search` in the retriever's `stages`, then apply with `?mode=upsert`.

```yaml video-understanding.namespace.yaml theme={null}
      - stage_name: moments
        stage_id: moment_group
        parameters:
          parent_field: source_object_id
          time_field: start_time
          merge_tolerance_ms: 2000
          max_moments_per_parent: 3
          score_strategy: max
          output_mode: annotated
```

`time_field: start_time` reads each segment's own start and end in seconds, which is the right source for a text query. `annotated` keeps the best segment per video and attaches a `moments` array of merged ranges to it. Gaps up to `merge_tolerance_ms` (2 seconds here) are bridged. See [Moment group](https://docs.mixpeek.com/docs/retrieve/stages.md#moment-group).

## Rerank by what was said

A cross-encoder scores the query against each segment's transcript, which separates close matches better than vector similarity. Add a `rerank` stage after `hybrid_search`:

```yaml video-understanding.namespace.yaml theme={null}
      - stage_name: rerank_transcript
        stage_id: rerank
        parameters:
          query: "{{INPUT.query}}"
          document_field: transcription
          max_candidates: 20
          top_k: 10
```

Each scored document adds latency, so keep `max_candidates` near the number of results you show. A segment with no transcript is left out of the scoring, with a warning in the response. See [Rerank](https://docs.mixpeek.com/docs/retrieve/stages.md#rerank).

## Search with a reference image

The visual index embeds images and text into one space, so a photo can be the query. Add this second retriever to the manifest's `retrievers` list and apply with `?mode=upsert`, which creates it beside `video-search`:

```yaml video-understanding.namespace.yaml theme={null}
  - name: video-search-by-image
    namespace: video-understanding
    description: "Give an image URL and get the segments that look most like it."
    collections:
      - video-moments
    input_schema:
      query_image:
        type: image
        required: true
        description: "Public URL of the reference image"
    stages:
      - stage_name: image_search
        stage_id: feature_search
        parameters:
          searches:
            - feature_uri: "mixpeek://multimodal_extractor@v1/vertex_multimodal_embedding"
              query:
                input_mode: content
                value: "{{INPUT.query_image}}"
              top_k: 50
          final_top_k: 10
```

Query it with a photo of a car. The AMC Jeep segments should rank first:

```bash cURL theme={null}
curl -X POST https://api.mixpeek.com/v1/retrievers/video-search-by-image/execute \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"query_image": "https://upload.wikimedia.org/wikipedia/commons/0/0b/2016_Mustang_GT%2C_San_Francisco%2C_United_States_%28Unsplash%29.jpg"}}' \
  | jq '{status, warnings, documents: [.documents[] | {title, start_time, score}]}'
```

## Split video a different way

Upsert changes an extractor's `parameters` only on an empty collection. Once `video-moments` holds documents, apply refuses the change and names the collection, because the stored segments were cut with the old settings. To try another split, add a second collection over the same bucket.

This one cuts at scene changes, with each scene capped at 30 seconds:

```yaml video-understanding.namespace.yaml theme={null}
  - name: video-scenes
    namespace: video-understanding
    description: "multimodal_extractor@v1 over bucket videos, split at scene changes."
    source:
      type: bucket
      bucket: videos
    feature_extractor:
      name: multimodal_extractor
      version: v1
      parameters:
        split_method: scene
        scene_detection_threshold: 0.5
        max_segment_duration: 30
        run_multimodal_embedding: true
        run_transcription: true
        run_transcription_embedding: true
      input_mappings:
        video: video
      field_passthrough:
        - source_path: title
        - source_path: category
    enabled: true
```

Add it under `collections`, apply with `?mode=upsert`, then process the videos already in the bucket. This bills the same 0.20 USD a minute again for the new collection.

```bash cURL theme={null}
curl -X POST https://api.mixpeek.com/v1/collections/video-scenes/trigger \
  -H "Authorization: Bearer $MIXPEEK_API_KEY" \
  -H "X-Namespace: $NAMESPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{}'
```

Point a retriever at it by adding `video-scenes` to its `collections`. Other splits: `silence` cuts at pauses in the audio, which suits lectures, and `whole` keeps one segment per video. [Multimodal extractor](https://docs.mixpeek.com/docs/extract/extractors.md#multimodal) documents every parameter, including `run_ocr` for on-screen text and `run_video_description` with `response_shape` for structured labels per segment.

## Next steps

> [card] [Ingest video from S3](https://docs.mixpeek.com/docs/templates/ingest-video-from-s3.md)
>
> Feed the same pipeline from an S3 prefix with a continuous sync.

> [card] [Feature search](https://docs.mixpeek.com/docs/retrieve/stages.md#feature-search)
>
> Every search, fusion and query mode the retriever stage accepts.

> [card] [Tag segments](https://docs.mixpeek.com/docs/enrich/taxonomies.md)
>
> Label segments such as "product demo" or "interview" with a taxonomy.

> [card] [Find recurring scenes](https://docs.mixpeek.com/docs/enrich/clusters.md)
>
> Cluster segment embeddings to group visually similar footage.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.