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 pxtfrom pixeltable.functions.document import document_splitterfrom pixeltable.functions.huggingface import clip, sentence_transformerfrom pixeltable.functions.video import extract_audio, frame_iteratorfrom pixeltable.functions.whisper import transcribeTableModel = 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.Stringvideo: pxt.Videoaudio = extract_audio(video)transcript = transcribe(audio, model='base').text.astype(pxt.String)class Images(TableModel, name='images'):title: pxt.Stringimage: pxt.Imagecaption: pxt.String | Noneclass Docs(TableModel, name='docs'):title: pxt.Stringdocument: 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.Stringvideo: pxt.Videoaudio = 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.Stringimage: pxt.Imagecaption: 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 pxtdef 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 Agentfrom search import search_chunks, search_frames, search_images, search_speechagent = Agent('openai:gpt-4o-mini')@agent.tool_plaindef 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_plaindef 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_plaindef search_stills(query: str, limit: int = 5) -> list:"""Search stills by a sentence. Returns titles, captions, scores."""return search_images(query, limit)@agent.tool_plaindef 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_toolfrom search import search_frames@function_tooldef 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 MCPServerfrom search import search_framesmcp = 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
| Option | What you get | When to pick it |
|---|---|---|
| Mixpeek | Managed multimodal retrieval API, with an MCP server on their site | You want a hosted retrieval API and no local models |
| Twelve Labs | Hosted video-understanding models and their Jockey MCP | Their video models are the product, not a table you own |
| VideoDB | Hosted video database and their MCP | You already store clips in their service |
| Vector DB plus glue | Qdrant or pgvector, FFmpeg, an object store, and workers you write | Those services are already the contract |
| Queries as tools | Typed media, indexes, and search tools in Python | The 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 pxtfrom pixeltable.functions.document import document_splitterfrom pixeltable.functions.huggingface import clip, sentence_transformerfrom pixeltable.functions.video import extract_audio, frame_iteratorfrom pixeltable.functions.whisper import transcribeTableModel = 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.Stringvideo: pxt.Videoaudio = 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.Stringimage: pxt.Imagecaption: pxt.String | None__indexes__ = [pxt.EmbeddingIndex(image, embedding=clip_embed),]class Docs(TableModel, name='docs'):title: pxt.Stringdocument: pxt.Documentclass 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?
Is this an agent framework?
Do I need Mixpeek, Twelve Labs, or VideoDB?
Do I still need a vector database?
What should the tool return?
Can one agent search video, images, and PDFs?
Next step
Copy the commands into an agent, or run them locally with pip install pixeltable.