Skip to content

Day 2 -- Chunking & Ingestion: From Whole Documents to Retrievable Pieces

Embedding a 50-page PDF into a single vector and expecting it to answer a question about paragraph 3 on page 17 is like trying to find a specific sentence by reading a whole book at once. The embedding averages everything together and the signal dissolves into noise. Chunking is the answer: split documents into pieces small enough that a vector can represent them meaningfully, but large enough that each piece still carries the context needed to answer a question.

By the end of today you will have built every major chunking strategy from scratch against pgvector, and you will know exactly which one to reach for when the naive approach stops working.

What you'll have by the end of today

  • A working intuition for the chunk-size tradeoff: why bigger is not better and smaller is not safer
  • Three chunking strategies in production-ready Python: fixed-size, semantic, and recursive
  • Overlap and context-window techniques that keep information from falling through the cracks
  • A metadata schema that attaches source, page number, and section to every chunk, with pgvector WHERE clauses that filter before vector search
  • Code you can drop into your own RAG pipeline today

Before you start

You need the same PostgreSQL + pgvector setup from Day 1. If you skipped Day 1, go back and set it up -- we are building on the same tables and embedding functions.

Lessons

  1. The Chunking Problem -- why embedding whole documents fails, the chunk-size tradeoff, and how to think about retrieval quality before writing a single line of splitting code
  2. Fixed-Size Chunking -- splitting by character or token count, the simplest strategy that works, and why overlap matters more than you think
  3. Semantic Chunking -- splitting on sentence and paragraph boundaries, using embeddings to find natural break points, and when the model should decide where to cut
  4. Recursive Chunking -- hierarchical splitting with parent-child relationships, small chunks for retrieval with large chunks for context, and the multi-pass architecture behind production chunking pipelines
  5. Metadata & Filtering -- attaching source, page number, and section to every chunk, filtering with pgvector WHERE clauses, and why metadata is the difference between a demo and a system people trust

Previous: Day 1 -- Embeddings & Vector StoresNext: Day 3 -- Retrieval Quality & Ranking