---
title: "Build a RAG pipeline"
description: "Create a retrieval-augmented generation system that answers questions using your documents as context."
url: "https://www.pixeltable.com/notebooks/pattern-rag-pipeline"
updated: "2026-04-10"
---

# Build a RAG pipeline

Create a retrieval-augmented generation system that answers questions using your documents as context.

- **Type:** Notebook
- **Group:** Agents

## How it works

You build a pipeline that: (1) embeds documents, (2) finds relevant chunks for a query, and (3) generates an answer using those chunks as context.

## What it covers

- Embed and index documents for retrieval
- Create a query function that retrieves context
- Generate answers grounded in your documents

## What it uses

- **Install:** `pip install pixeltable openai`
- **Environment variables it names:** `OPENAI_API_KEY`
- **Pixeltable calls:** `openai.chat_completions()`, `pxt.create_table()`, `@pxt.query`, `@pxt.udf`, `add_embedding_index()`, `insert()`, `similarity()`, `add_computed_column()`

## A look at the code

```python
# Add embedding index for semantic search
chunks.add_embedding_index(
    column='chunk_text',
    string_embed=embeddings.using(model='text-embedding-3-small'),
)
```

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/agents/pattern-rag-pipeline.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/cookbooks/agents/pattern-rag-pipeline
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/agents/pattern-rag-pipeline.ipynb
