Lesson 2.2 · 7 min read · about 50 min to master at a very slow pace
Chunking Documents
Documents are split into chunks before embedding. Why chunk size matters, how overlap and structure-aware splitting work, how many chunks a corpus produces, and the metadata every chunk should carry.
Why split at all
An embedding is one vector for a whole piece of text. Embed a 40-page contract as one vector and its meaning is averaged into mush: a query about the termination clause cannot find it. So documents are split into chunks, each embedded and retrieved on its own.
The size trade-off
| Chunks too small (e.g. one sentence) | Chunks too large (e.g. five pages) |
|---|---|
| Precise matches, but lose context ("it", "the above", "this fee") | Keep context, but the vector is diluted and matches poorly |
| Need many chunks to answer one question | Fill the prompt with irrelevant text and cost more |
A common starting point is 300 to 800 tokens per chunk with 10–20% overlap, then tune with your eval set.
Overlap
With overlap, each chunk repeats the end of the previous one, so a sentence cut at a boundary still appears whole in at least one chunk. With chunk size and overlap , each new chunk advances by tokens, so a document of tokens gives about
Worked example
A 10,000-token manual, chunk size 500, overlap 100: chunks. Without overlap it would be 20. Overlap costs 25% more chunks here, in exchange for fewer broken sentences.
Split on structure, not on character counts
The best boundaries are the ones the author made: headings, sections, paragraphs, list items, table rows. A good splitter tries the largest structural unit first and only cuts smaller if the piece is too big (recursive splitting). Never cut a table in half without repeating its header.
Metadata on every chunk
Store alongside each chunk: source document and URL, title and section heading, page number, date or version, and access permissions. You will need them to cite, to filter ("only 2026 policies"), to re-index one changed document, and to enforce who may see what.
Garbage in
Most RAG failures in client work start at parsing: scanned PDFs without text, two-column layouts read across columns, headers and footers repeated on every page, tables flattened into nonsense. Look at your parsed text before you tune anything else.
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passShould I prepend the document title or heading to each chunk?
Often yes. A chunk that says "The fee is €40" means little alone; "Returns policy › Late returns: The fee is €40" embeds and retrieves far better, and the model knows what it is reading. This is sometimes called contextual chunking.
Going deeperIs there one best chunk size?
No. FAQs suit small chunks (one question and answer each); contracts and manuals suit larger, section-based chunks. Build a small retrieval eval set, try two or three sizes, and keep the one with the best recall at the number of chunks you can afford to send.
Cheatsheet
Number of chunks
Chunking defaults
Chunk metadata
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.