---
title: "How do I let an AI agent search my video library, images, and PDFs?"
description: "Let an AI agent search a video library, images, and PDFs with tools that return titles, timestamps, or chunk text instead of stuffing files into context."
url: "https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools"
updated: "2026-11-23"
doc: "https://docs.pixeltable.com/howto/cookbooks/agents/llm-tool-calling"
---

# 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: 2026-11-23
Part of [How do I ... in Python?](https://www.pixeltable.com/learn/how-to).

## 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

## On this page

- [Before you start](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#before-you-start)
- [Store video, images, and PDFs as typed columns](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-1)
- [Index frames, speech, stills, and PDF chunks](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-2)
- [Return titles, timestamps, or chunk text, not the files](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-3)
- [Register a query as a Pydantic AI tool](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-4)
- [Register the same query in the OpenAI Agents SDK](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-5)
- [Register the query as an MCP tool](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#step-6)
- [Comparison](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#comparison)
- [Where Pixeltable fits](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#where-pixeltable-fits)
- [Questions](https://www.pixeltable.com/learn/how-to/give-an-ai-agent-multimodal-search-tools#questions)

## 1. Store video, images, and PDFs as typed columns {#step-1}

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.

```python
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 {#step-2}

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.

```python
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 {#step-3}

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.

```python
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 {#step-4}

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.

```python
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 {#step-5}

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.

```python
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 {#step-6}

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.

```python
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 {#comparison}

| 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 {#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.

```python
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)
```

## Concepts

- [What is agentic RAG?](https://www.pixeltable.com/learn/what-is-agentic-rag)
- [What is cross-modal search?](https://www.pixeltable.com/learn/what-is-cross-modal-search)
- [What is a retrieval UDF?](https://www.pixeltable.com/learn/what-is-a-retrieval-udf)

## Use case

- [AI Agents & MCP: Give Your Agents Persistent Multimodal Memory](https://www.pixeltable.com/use-cases/ai-agents-mcp)

## Questions {#questions}

### Why not put the video or PDF in the prompt? {#faq-1}

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? {#faq-2}

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? {#faq-3}

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? {#faq-4}

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? {#faq-5}

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? {#faq-6}

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.

## Related

- [What is agentic RAG?](https://www.pixeltable.com/learn/what-is-agentic-rag)
- [What is cross-modal search?](https://www.pixeltable.com/learn/what-is-cross-modal-search)
- [What is a retrieval UDF?](https://www.pixeltable.com/learn/what-is-a-retrieval-udf)
- [AI agents and MCP](https://www.pixeltable.com/use-cases/ai-agents-mcp)
- [Backend for AI agents](https://www.pixeltable.com/backend-for-ai-agents)
- [How do I index a video library and search it by text in Python?](https://www.pixeltable.com/learn/how-to/search-a-video-library-by-text)
- [How do I embed images for search in Python?](https://www.pixeltable.com/learn/how-to/embed-images-for-search)
- [How do I build an MCP server over my documents and media?](https://www.pixeltable.com/learn/how-to/build-an-mcp-server-over-your-media-files)
- [Let your Pydantic AI agent search your media files](https://www.pixeltable.com/blog/let-your-pydantic-ai-agent-search-your-media-files)
- [Retrieval UDF: the database as an AI tool](https://www.pixeltable.com/blog/retrieval-udf-database-ai-tool)
- [Mixpeek alternatives: Pixeltable vs Mixpeek](https://www.pixeltable.com/compare/pixeltable-vs-mixpeek)
- [Pixeltable vs Twelve Labs](https://www.pixeltable.com/compare/pixeltable-vs-twelve-labs)
- [Use tool calling and MCP servers with LLMs](https://docs.pixeltable.com/howto/cookbooks/agents/llm-tool-calling)
