
Deploy in Studio
Creates every resource below in your organization, with sample data.
Download the manifest
contextual-video-match.namespace.yaml, the file Studio and the API apply.Template page
The demo and the use case on mixpeek.com.
At a glance
How the pieces connect
Buckets hold what you upload, collections turn it into searchable documents, and retrievers answer queries over the collections.Deploy it
- API
- Studio
1
Get the manifest
2
Validate it
Validate runs every check apply runs and creates nothing. Fix each entry in
errors, then run it again.3
Apply it
Apply creates every resource in one call. The response lists each resource with its outcome in
wait_for_seed=true also waits until the sample objects are processed, so the first query below has documents to return.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 runscene-search. Check status and warnings along with documents: a run that times out still answers 200, with status degraded.
Add your own data
Each object you add to a bucket is processed by every collection that reads it. This adds one object tovideos. NAMESPACE_ID is the id from the namespace lookup above.
PENDING until processing finishes, then COMPLETED or FAILED. Buckets and objects covers object states, retries and duplicates.
Retrievers
contextual-match
Matches scene-transcripts and video-scenes against a document from article-text and article-multimodal, with no query-time embedding.
Stages: feature_search → deduplicate → code_execution
Searches: scene-transcripts, video-scenes, article-text, article-multimodal
scene-search
Type what a scene should show or say and get the matching seconds of video, ranked over the frames and the transcript together.
Stages: feature_search
Searches: video-scenes, scene-transcripts
Collections
Each collection runs one extractor over a bucket, or over another collection’s documents.video-scenes
video-scenes
multimodal_extractor@v1 over bucket videos. Feeds scene-transcripts, contextual-match, scene-search.Reads bucket
videos with multimodal_extractor v1.Inputs: video ← contentCopied onto each document: file_location, segment_id, start_time, end_time, tenant_idarticle-multimodal
article-multimodal
multimodal_extractor@v1 over bucket articles. Feeds contextual-match.Reads bucket
articles with multimodal_extractor v1.Inputs: text ← contentCopied onto each document: article_url, published_at, tenant_idscene-transcripts
scene-transcripts
text_extractor@v1 over collection video-scenes. Feeds contextual-match, scene-search.Reads collection
video-scenes with text_extractor v1.Inputs: text ← transcriptionCopied onto each document: segment_id, video_segment_url, start_time, end_timearticle-text
article-text
text_extractor@v1 over bucket articles. Feeds contextual-match.Reads bucket
articles with text_extractor v1.Inputs: text ← contentCopied onto each document: article_url, published_at, tenant_idAlso created
Alertscontextual-match-returning-nothing: Emails the org notifications address (Settings -> Notifications; unset means opted out) when contextual-match has come back empty on its last five runs: the articles are matching no scene, so the video index or the article documents need a look.
Cost estimate at list price
Cost estimate at list price
At 10,000 items a month (2 minutes or 10 pages each) and 100,000 queries, this template costs about 7,301.11 USD a month (730.09 USD per 1,000 items). The namespace’s daily spend budget pauses new batches before you pass it.
The manifest
Every resource above comes from this file. Change it and apply it again with?mode=upsert to update what exists. Manifests documents each field.
contextual-video-match.namespace.yaml
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 athttps://mixpeek.com/docs/templates/contextual-video-match.md.
Prompt
How it works
Each video becomes a set of segment documents and each article one document, embedded by the same two models.contextual-match compares an article’s stored vectors with the segments’, so no embedding runs at query time.
The video side
video-scenes runs multimodal_extractor@v1, which cuts each video into 10-second segments. Each segment gets a 1408-dimension Vertex AI frame vector, its speech in transcription, on-screen text in ocr_text, and one Gemini call whose response_shape writes entities, keywords and iab_categories.
scene-transcripts reads video-scenes as its source and embeds each transcript with text_extractor (1024 dimensions), so speech and frame matches come from two separate indexes.
The article side
article-text embeds each whole article with text_extractor. article-multimodal embeds the same text with the Vertex AI multimodal model, in the same space as the frame vectors, so an article’s text can find a segment by what it shows.
How contextual-match ranks
You call contextual-match with the two document ids of one article:
searchruns thearticle-textvector againstscene-transcriptsand thearticle-multimodalvector againstvideo-scenes, and merges the lists withrrfinto 30 documents.deduplicatekeeps the first document for each pair ofsource_video_urlandstart_time.scoreruns Python that writes ascoringobject onto each document, adding four terms:
The total is multiplied by 0.7 when the segment is entertainment and the article is news or politics.
scoring also lists what matched, so you can show why a video was picked.
The alert contextual-match-returning-nothing emails your organization when contextual-match returns nothing 5 runs in a row.
Call contextual-match
The retriever needs the article’s document_id in article-text and in article-multimodal. Both come from one bucket object, so list each collection by source_object_id, with OBJECT_ID set to one article’s object_id:
cURL
From the template to a production player
The rest of this page builds what a publisher runs behind a video player. Steps 1 to 4 editcontextual-video-match.namespace.yaml; apply once at the end. Steps 5 to 7 are calls from your own code.
1. Sync the video library from S3
Set up the IAM role as Object storage describes, and store its ARN and external id as organization secrets, which apply reads as${{ secrets.NAME }}.
cURL
Upload a video with its metadata
videos bucket schema, and replace the commented storage_connections and bucket_syncs blocks with these. source_path starts with the S3 bucket name.
contextual-video-match.namespace.yaml: the videos bucket
contextual-video-match.namespace.yaml: connection and sync
is_shared arrives as a string, and transform: lowercase makes True and true the same value, so step 4 compares against "true". Each sync run submits a batch that runs every collection on videos; for a library of thousands of videos, read Buckets on batch ingestion first.
2. Copy the player’s fields onto every document
playlist filters segments on publisher_id, is_shared and channel_id. Append them to video-scenes’ field_passthrough, and declare a keyword payload index for each, which a filter inside a vector search needs.
contextual-video-match.namespace.yaml: video-scenes field_passthrough
contextual-video-match.namespace.yaml: the namespace
article_id, title, publisher_id, article_url and published_at as string properties to the articles schema. Append article_id, title and publisher_id to article-text’s field_passthrough, and article_id to article-multimodal’s.
3. Label articles and videos at ingest
Each collection runs a labeling retriever on every new document as a retriever enrichment. The retriever selects that document withattribute_filter and asks Gemini for structured output with llm_enrich.
label-articles returns iab_categories, entities and keywords with the same instructions as video-scenes’ response_shape, plus sentiment and brand_safety. label-scenes returns only sentiment and brand_safety, and include_media: true sends the segment’s clip with the prompt. Add both to retrievers:
contextual-video-match.namespace.yaml: label retrievers
retriever_enrichments sits beside source and feature_extractor. Add this to video-scenes:
contextual-video-match.namespace.yaml: video-scenes enrichment
article-text:
contextual-video-match.namespace.yaml: article-text enrichment
retriever_id takes the retriever’s name, and apply resolves it to the id.
An enrichment runs only on documents written after it is attached, so the sample documents carry no
brand_safety and playlist leaves them out. To label existing documents, run their objects again in a batch with dedup_strategy: replace, which charges the extraction again; see Reprocess existing content.4. Add the playlist retriever
playlist takes an article and returns up to 5 segments the publisher may show, best first. It searches only video-scenes, which carries the brand-safety and rights fields:
contextual-video-match.namespace.yaml: the playlist retriever
top_k: 100 counts only segments that pass it; brand_safety in [safe, sensitive] also drops unlabeled segments. A segment qualifies when it belongs to the publisher or is_shared is "true". one_per_video keeps the best segment of each video, and rank sorts on the score stage’s result.
Now apply the file with ?mode=upsert. It creates the new resources and adds bucket properties, appended field_passthrough entries and payload indexes; create_missing would skip those. A changed parameters block on a collection that holds documents is refused and named in refused.
5. Send articles and look them up
Write each article toarticles when it is published, with plain text (no page markup) in content:
cURL
article_id and store what the player needs in your CMS. One lookup per article is enough:
cURL
unsafe article altogether.
6. Call the playlist from the player, behind a flag
The player runsplaylist with the stored article fields and the publisher’s id; excluded channels go in filters. Fall back to your current playlist when the flag is off, the call fails, the run is degraded, or too few videos come back.
player.js
playlistFor in your own endpoint. To test the call by hand:
cURL
7. Send viewer events back
Record each video’s outcome as an interaction with the run’sexecution_id and retriever_id: impression, play, long_view or skip, and editors’ verdicts as positive_feedback or negative_feedback. feature_id is the segment’s document_id, and position its place in the playlist, from 0.
cURL
POST /v1/retrievers/interactions/batch. They land in your namespace’s system collections, where you can build an evaluation set and test ranking changes against real viewing.
Next steps
Retriever enrichments
How a retriever labels each new document and writes fields back.
Filters
Every operator for rights, recency and brand-safety rules.

