The Document Processing Challenge#
Building a document RAG (Retrieval-Augmented Generation) system sounds simple: extract text from PDFs, chunk it, embed it, and search. But production reality is messier:
- PDFs have tables, images, headers, and footers that need special handling
- Documents get updated and need re-processing
- You need to track which chunks came from which documents
- Embeddings need to stay in sync when documents change
- The pipeline needs to scale to thousands of documents
Pixeltable solves all of this with a declarative approach that handles extraction, chunking, embedding, and search in a single unified system.
Basic Document Pipeline#
Let's start with a simple but complete document processing pipeline. The application file declares a table for the documents and a view that splits them into chunks:
Create the tables:
Then insert documents and search them from Python:
Advanced: Handling Complex PDFs#
Real PDFs have tables, images, and complex layouts. Splitting a PDF by page keeps each page's extracted text next to an image of that page, and an LLM can clean up the text. The OpenAI columns from here on need pip install openai and OPENAI_API_KEY in the environment before the first pxt command, since the pxt daemon reads its environment once when it starts:
Smart Chunking Strategies#
Different documents need different chunking strategies. A view's base can be a filtered query, so each document type gets its own splitter:
Enriching Chunks with Metadata#
Add useful metadata to each chunk for better retrieval. Replace the Chunks class in app.py with this version and run pxt schema update app.py docs again. The update adds the new columns and the summary index, and computes them for the chunks already stored:
Search the summaries with app.Chunks.summary.similarity(string=query), or the text as before.
Complete RAG Pipeline with LLM#
Here's a full RAG system that retrieves relevant chunks and generates answers. Retrieval is a @pxt.query used as a computed column, so each question keeps the context its answer came from:
Run pxt schema update app.py docs, then ask questions. Retrieval and generation run on insert:
Handling Document Updates#
When a document changes, Pixeltable's incremental processing regenerates that document's chunks and recomputes their columns and index entries. Chunks of other documents stay as they are:
Scaling to Large Document Libraries#
Tips for handling thousands of documents:
Why Pixeltable vs Traditional RAG Stacks#
| Task | Traditional Stack | Pixeltable |
|---|---|---|
| Text extraction | PyPDF2, pdfplumber, unstructured | document_splitter: text, page images, headings, page numbers |
| Chunking | LangChain, custom code | Built-in document_splitter iterator |
| Embeddings | Separate embedding service | Computed column, stored with each chunk |
| Vector store | Pinecone, Weaviate, pgvector | Built-in embedding index |
| Orchestration | Airflow, Prefect, custom | Automatic with dependencies |
| Updates | Manual re-indexing | New, updated and deleted documents update their chunks and index on write |
| Lineage | External tracking | Built-in versioning |
Conclusion#
Building production document RAG systems doesn't have to be complex. With Pixeltable's declarative approach:
- Define your pipeline as computed columns
- Let Pixeltable handle extraction, chunking, and embedding
- Insert, update or delete a document, and its chunks, columns and index entries follow
- Scale from prototypes to production without changing code
The best part? Your entire document pipeline (from raw PDFs to searchable embeddings) lives in one place, fully versioned and queryable.
The class-based TableModel receipt for the same job is DocuVision.

