---
title: "What is a retrieval UDF?"
description: "A retrieval UDF packages a similarity query so an agent or another column can call retrieval as a function."
url: "https://pixeltable.com/learn/what-is-a-retrieval-udf"
updated: "2026-09-29"
vertical: "Retrieval"
doc: "https://docs.pixeltable.com/datastore/embedding-index"
---

# What is a retrieval UDF?

A retrieval UDF packages a similarity query so an agent or another column can call retrieval as a function.

Updated: 2026-09-29
Part of [What is RAG?](https://pixeltable.com/learn/what-is-rag).

## On this page

- [How it works](https://pixeltable.com/learn/what-is-a-retrieval-udf#how-it-works)
- [What it is not](https://pixeltable.com/learn/what-is-a-retrieval-udf#what-it-is-not)
- [Comparison](https://pixeltable.com/learn/what-is-a-retrieval-udf#comparison)
- [Where Pixeltable fits](https://pixeltable.com/learn/what-is-a-retrieval-udf#where-pixeltable-fits)
- [Questions](https://pixeltable.com/learn/what-is-a-retrieval-udf#questions)

## How it works {#how-it-works}


- The function names the query, the limit, and the columns to return.
- Callers pass a question and get rows.
- Agents can see it as a tool because it is a function, not an ad-hoc script.

## What it is not {#what-it-is-not}

It is not raw SQL pasted into a prompt, and it is not a retriever object with no table underneath.

## retrieval UDF: this, and the thing it is confused with {#comparison}

|  | This | Not this |
| --- | --- | --- |
| Interface | A function | A SQL string in the prompt |
| Data | Rows of a real table or view | A vector client with no source schema |
| Reuse | HTTP, agents, and other columns | Copy-pasted into each handler |

## Where Pixeltable fits {#where-pixeltable-fits}

Pixeltable uses @pxt.query for that function. pxt.tools() can expose it to an agent.

## Questions {#questions}

### How does retrieval UDF work? {#faq-1}

The function names the query, the limit, and the columns to return. Callers pass a question and get rows. Agents can see it as a tool because it is a function, not an ad-hoc script.

### What is retrieval UDF often confused with? {#faq-2}

It is not raw SQL pasted into a prompt, and it is not a retriever object with no table underneath.

## In the blog

- [The @pxt.query Decorator: Building Reusable Database Queries for AI Agents and RAG Systems](https://pixeltable.com/blog/reusable-query-patterns-pxt-query)
- [Convex Developers' Guide to Pixeltable: Queries, Mutations, Actions, and Where the Mental Models Diverge](https://pixeltable.com/blog/convex-developers-guide-to-pixeltable)
- [Turn Any Database Table into an AI Tool: Introducing pxt.retrieval_udf()](https://pixeltable.com/blog/retrieval-udf-database-ai-tool)

## Related

- [Documentation](https://docs.pixeltable.com/datastore/embedding-index)
- [Turn Any Database Table into an AI Tool: Introducing pxt.retrieval_udf()](https://pixeltable.com/blog/retrieval-udf-database-ai-tool)
- [The @pxt.query Decorator: Building Reusable Database Queries for AI Agents and RAG Systems](https://pixeltable.com/blog/reusable-query-patterns-pxt-query)
- [AI agents and MCP](https://pixeltable.com/use-cases/ai-agents-mcp)
- [Pixeltable vs LangChain](https://pixeltable.com/compare/pixeltable-vs-langchain)
