Skip to content

How to

How do I let an AI agent search my video library, images, and PDFs?

Give an AI agent search over a video library, images, or PDFs by passing media by reference. Each tool is a query that returns titles, timestamps, or chunk text. The agent fetches only those hits instead of stuffing files into the context window. Register the queries as tools in the agent framework you already use.

Updated · Part of How do I ... in Python?

Before you start

About 25 min.

  • Python 3.11+
  • pip install -U 'pixeltable[serve]'
  • pxt init in the project root
  • ffmpeg for video decoding
  • openai-whisper
  • torch and transformers for CLIP
  • sentence-transformers
  • spacy and tiktoken for sentence,token_limit splitting
  • pydantic-ai for the Pydantic AI tool
  • openai-agents for the Agents SDK tool
  • mcp Python SDK for the MCP tool
  • An OpenAI API key for gpt-4o-mini

1. Store video, images, and PDFs as typed columns

Put each clip, still, and document on a row the engine understands. A path string is not enough: frame extraction, CLIP, and PDF splitting need typed columns. Keep a title or caption so a hit can name the source without returning the file.

import pixeltable as pxt
from pixeltable.functions.document import document_splitter
from pixeltable.functions.huggingface import clip, sentence_transformer
from pixeltable.functions.video import extract_audio, frame_iterator
from pixeltable.functions.whisper import transcribe
TableModel = pxt.model_base()
clip_embed = clip.using(model_id='openai/clip-vit-base-patch32')
text_embed = sentence_transformer.using(model_id='all-MiniLM-L6-v2')
class Videos(TableModel, name='videos'):
title: pxt.String
video: pxt.Video
audio = extract_audio(video)
transcript = transcribe(audio, model='base').text.astype(pxt.String)
class Images(TableModel, name='images'):
title: pxt.String
image: pxt.Image
caption: pxt.String | None
class Docs(TableModel, name='docs'):
title: pxt.String
document: pxt.Document

2. Index frames, speech, stills, and PDF chunks

Sample stills from each clip and keep frame_attrs so a hit is a moment. CLIP places a sentence and a still in one space. Whisper plus a text embedding finds what was said. Split PDFs into sentence windows with a token limit, then index the passage text. A new file indexes only that file.

class Videos(TableModel, name='videos'):
title: pxt.String
video: pxt.Video
audio = extract_audio(video)
transcript = transcribe(audio, model='base').text.astype(pxt.String)
__indexes__ = [
pxt.EmbeddingIndex(transcript, string_embed=text_embed),
]
class Frames(
TableModel,
name='frames',
base=Videos,
iterator=frame_iterator(video=Videos.video, fps=1),
):
__indexes__ = [
pxt.EmbeddingIndex(frame, embedding=clip_embed),
]
class Images(TableModel, name='images'):
title: pxt.String
image: pxt.Image
caption: pxt.String | None
__indexes__ = [
pxt.EmbeddingIndex(image, embedding=clip_embed),
]
class Chunks(
TableModel,
name='chunks',
base=Docs,
iterator=document_splitter(
document=Docs.document,
separators='sentence,token_limit',
limit=300,
),
):
__indexes__ = [
pxt.EmbeddingIndex(text, string_embed=text_embed),
]
# pxt init
# pxt schema update app.py media -f

3. Return titles, timestamps, or chunk text, not the files

Each search is a plain Python function in search.py that runs one similarity query and collects the rows. Frame search returns the parent title and frame_attrs (time is the presentation timestamp in seconds). Transcript search returns the clip title. Image search returns the title and caption. PDF search returns the document title and passage. The agent then fetches only the hits it needs, instead of loading the library into the context window.

import pixeltable as pxt
def search_frames(query: str, limit: int = 5) -> list[dict]:
frames = pxt.get_table('media.frames')
sim = frames.frame.similarity(string=query)
rows = (
frames.order_by(sim, asc=False)
.limit(limit)
.select(title=frames.title, frame_attrs=frames.frame_attrs, score=sim)
.collect()
)
return list(rows)
def search_speech(query: str, limit: int = 5) -> list[dict]:
videos = pxt.get_table('media.videos')
sim = videos.transcript.similarity(string=query)
rows = videos.order_by(sim, asc=False).limit(limit).select(title=videos.title, score=sim).collect()
return list(rows)
def search_images(query: str, limit: int = 5) -> list[dict]:
images = pxt.get_table('media.images')
sim = images.image.similarity(string=query)
rows = (
images.order_by(sim, asc=False)
.limit(limit)
.select(title=images.title, caption=images.caption, score=sim)
.collect()
)
return list(rows)
def search_chunks(query: str, limit: int = 5) -> list[dict]:
chunks = pxt.get_table('media.chunks')
sim = chunks.text.similarity(string=query)
rows = chunks.order_by(sim, asc=False).limit(limit).select(title=chunks.title, text=chunks.text, score=sim).collect()
return list(rows)

4. Register a query as a Pydantic AI tool

After schema update, wrap each search function with @agent.tool_plain. Each call returns rows: titles, timestamps, captions, or passage text, plus a score. Pydantic AI is the agent loop. These queries are the retrieval tools it calls. A Harness catalog capability is a different, catalog-wide path covered in the related blog.

from pydantic_ai import Agent
from search import search_chunks, search_frames, search_images, search_speech
agent = Agent('openai:gpt-4o-mini')
@agent.tool_plain
def search_video_frames(query: str, limit: int = 5) -> list:
"""Search sampled video frames by a sentence. Returns titles, timestamps, scores."""
return search_frames(query, limit)
@agent.tool_plain
def search_transcripts(query: str, limit: int = 5) -> list:
"""Search clip transcripts by a sentence. Returns titles and scores."""
return search_speech(query, limit)
@agent.tool_plain
def search_stills(query: str, limit: int = 5) -> list:
"""Search stills by a sentence. Returns titles, captions, scores."""
return search_images(query, limit)
@agent.tool_plain
def search_pdfs(query: str, limit: int = 5) -> list:
"""Search PDF chunks by a sentence. Returns titles, passage text, scores."""
return search_chunks(query, limit)

5. Register the same query in the OpenAI Agents SDK

from agents import function_tool is the public decorator. Pass the decorated function in Agent(tools=...). The SDK is the loop. The table is still the store. LangGraph and other frameworks follow the same split: wrap the query, do not copy the files into the prompt.

from agents import Agent, function_tool
from search import search_frames
@function_tool
def search_video_frames(query: str, limit: int = 5) -> list:
"""Search sampled video frames by a sentence. Returns titles, timestamps, scores."""
return search_frames(query, limit)
media_agent = Agent(name='Media search', tools=[search_video_frames])

6. Register the query as an MCP tool

MCPServer from the MCP Python SDK advertises a tool a client such as Claude or Cursor can call. Return a formatted string of titles and timestamps, as the JFK files sample does. Hosted Cloud MCP is a different server: it operates a signed-in organization and does not run these queries. The next guide covers both MCP paths.

from mcp.server.mcpserver import MCPServer
from search import search_frames
mcp = MCPServer('MediaSearch')
@mcp.tool()
def search_video_frames(query: str, limit: int = 5) -> str:
"""Search sampled video frames by a sentence. Returns titles, timestamps, scores."""
hits = search_frames(query, limit)
lines = [
f"{i}. score={row['score']:.4f} title={row['title']} time={row['frame_attrs']['time']}"
for i, row in enumerate(hits)
]
return '\n'.join(lines) if lines else 'No results found.'
if __name__ == '__main__':
mcp.run(transport='streamable-http', stateless_http=True)

Agent video and media search, last reviewed November 2026

Agent video and media search, last reviewed November 2026
OptionWhat you getWhen to pick it
MixpeekManaged multimodal retrieval API, with an MCP server on their siteYou want a hosted retrieval API and no local models
Twelve LabsHosted video-understanding models and their Jockey MCPTheir video models are the product, not a table you own
VideoDBHosted video database and their MCPYou already store clips in their service
Vector DB plus glueQdrant or pgvector, FFmpeg, an object store, and workers you writeThose services are already the contract
Queries as toolsTyped media, indexes, and search tools in PythonThe agent should search files you own, by reference

Where Pixeltable fits

Pixeltable is the unified multimodal AI backend for this job: typed Video, Image, and Document columns, a frame_iterator view, CLIP EmbeddingIndex, Whisper, document_splitter, and search functions that return titles, timestamps, or chunk text. Wrap those functions as tools in Pydantic AI, the OpenAI Agents SDK, or an MCP server. Mixpeek, Twelve Labs, and VideoDB are managed video APIs with their own MCP servers; pricing is on their sites. Last reviewed November 2026. A Qdrant or pgvector store plus FFmpeg plus an object store is the glue stack when those services are already the contract. Pixeltable is not an agent framework; it is the data and retrieval layer those tools sit on. Compare Pixeltable vs Mixpeek and Pixeltable vs Twelve Labs.

import pixeltable as pxt
from pixeltable.functions.document import document_splitter
from pixeltable.functions.huggingface import clip, sentence_transformer
from pixeltable.functions.video import extract_audio, frame_iterator
from pixeltable.functions.whisper import transcribe
TableModel = pxt.model_base()
clip_embed = clip.using(model_id='openai/clip-vit-base-patch32')
text_embed = sentence_transformer.using(model_id='all-MiniLM-L6-v2')
class Videos(TableModel, name='videos'):
title: pxt.String
video: pxt.Video
audio = extract_audio(video)
transcript = transcribe(audio, model='base').text.astype(pxt.String)
__indexes__ = [
pxt.EmbeddingIndex(transcript, string_embed=text_embed),
]
class Frames(
TableModel,
name='frames',
base=Videos,
iterator=frame_iterator(video=Videos.video, fps=1),
):
__indexes__ = [
pxt.EmbeddingIndex(frame, embedding=clip_embed),
]
class Images(TableModel, name='images'):
title: pxt.String
image: pxt.Image
caption: pxt.String | None
__indexes__ = [
pxt.EmbeddingIndex(image, embedding=clip_embed),
]
class Docs(TableModel, name='docs'):
title: pxt.String
document: pxt.Document
class Chunks(
TableModel,
name='chunks',
base=Docs,
iterator=document_splitter(
document=Docs.document,
separators='sentence,token_limit',
limit=300,
),
):
__indexes__ = [
pxt.EmbeddingIndex(text, string_embed=text_embed),
]
def search_frames(query: str, limit: int = 5) -> list[dict]:
frames = pxt.get_table('media.frames')
sim = frames.frame.similarity(string=query)
rows = (
frames.order_by(sim, asc=False)
.limit(limit)
.select(title=frames.title, frame_attrs=frames.frame_attrs, score=sim)
.collect()
)
return list(rows)

Questions

Why not put the video or PDF in the prompt?

A context window cannot hold a library. Pass media by reference: the tool returns titles, timestamps, or chunk text, and the agent fetches only the hits it needs. Stuffing files into the prompt describes one clip; it does not rank a library, and it gets more expensive as the library grows.

Is this an agent framework?

No. It is the data and retrieval layer the agent tools sit on. Pydantic AI, the OpenAI Agents SDK, LangGraph, and MCP clients are the loops. The queries are the tools those loops call. Pixeltable vs LangChain is that split.

Do I need Mixpeek, Twelve Labs, or VideoDB?

Pick them when you want a managed video API and their hosted models, and you do not want to run CLIP or Whisper. Last reviewed November 2026; pricing is on their sites. Pick queries as tools when the clip, the timestamp, and the agent tool should live in one schema you own. See Pixeltable vs Mixpeek and Pixeltable vs Twelve Labs.

Do I still need a vector database?

You need an embedding index so similar frames, stills, or passages can be ranked. That index can live on the column that holds the source. A separate Qdrant or pgvector store is optional when those services are already the contract. Pixeltable vs Pinecone is that split.

What should the tool return?

References, not files. Frame search returns a title and frame_attrs time. Transcript search returns the clip title. Image search returns a title and caption. PDF search returns the document title and chunk text. The agent can then open only those rows.

Can one agent search video, images, and PDFs?

Yes. Each modality is a query on its own index. Register all four tools on the same agent. Cross-modal search is CLIP on frames and stills; transcript and PDF search are text indexes on the same backend.

Next step

Copy the commands into an agent, or run them locally with pip install pixeltable.