Learn/Generative AI, RAG & Agents/MODULE 2: RETRIEVAL AUGMENTED GENERATION (RAG)
Lesson 17 of 37 · 2 min read

2.6 Document Chunking Strategies

Why do we chunk documents instead of embedding them whole? And how do we chunk well?

Why Chunk?

Three big reasons:

  1. Embedding models have input limits. Most can only handle a few thousand tokens at a time. A 50-page legal document is far too long to embed as one vector.
  2. Retrieval precision. If you embed a whole 50-page document as one vector, that vector represents an average of everything in the document. When someone asks about a specific topic covered on page 23, the document-level vector may not be particularly relevant — it's been "diluted" by the other 49 pages.
  3. Prompt economy. You only want to pass the relevant part to the LLM, not entire documents. Chunks of, say, 500 words let you precisely include only what's needed.

Chunking Strategies

There's no single best way.

Common strategies:

Fixed-size chunking. Just split the document every N characters or tokens (e.g., every 1,000 characters).

Simple but crude — it can cut a sentence in the middle.

Sentence- or paragraph-based chunking. Split at natural language boundaries.

Better, but paragraphs can vary wildly in length.

Recursive chunking. Try to split at large boundaries (sections), then medium (paragraphs), then small (sentences), as needed to fit a target chunk size.

This is a popular default.

Semantic chunking. Use an embedding model to detect topic changes and chunk at those boundaries.

More expensive to compute but can produce higher-quality chunks.

Structure-aware chunking. For HTML, Markdown, or code, leverage the structure (headers, lists, function definitions) to split intelligently.

Overlap

A common refinement: have chunks overlap each other by some amount (often 10–20% of the chunk size).

For example, if your chunks are 1,000 characters, each chunk might include the last 100 characters of the previous chunk.

This helps when a relevant piece of information sits right on a chunk boundary — at least one chunk will contain it fully.

Chunk Size Trade-offs

  • Small chunks (~200–500 tokens): more precise retrieval, but each chunk has less context. You might retrieve the right sentence but miss the surrounding setup.
  • Large chunks (~1,000–2,000 tokens): more context per chunk, but less precise. You might retrieve a chunk that contains the answer mixed with lots of unrelated material.

Many RAG systems use medium chunks (~500–1,000 tokens) with some overlap and adjust based on testing.

Keep going with a free account

A free account saves your progress across lessons and lets you pick up where you left off.