Context and retrieval
Chunking Lab
Retrieval works on chunks, not whole documents. Chunk too large and retrieval brings irrelevant text; too small and a chunk loses the context that makes it meaningful. The lab runs nine chunking methods on your text and shows the boundaries, sizes, overlap, and which chunks a sample question retrieves.
Fixed vs Semantic Chunking1:01 · intermediate Chunk Size and Overlap Explained0:51 · intermediate
The trade-offsBeginner
Smaller chunks give more precise matches but carry less context. Overlap repeats text at boundaries so a fact split across two chunks still appears whole in one, at the cost of more tokens to embed and store.
| Larger chunks | Smaller chunks |
|---|---|
| More context per hit | More precise hits |
| Fewer embeddings | More embeddings |
| More irrelevant text in the prompt | Facts can be split across chunks |
Structure-aware chunkingIntermediate
Markdown-aware chunking splits at headings and keeps the heading path with each chunk; code-aware chunking keeps functions and classes whole. Structure-aware methods usually retrieve better than fixed sizes on structured documents.
Semantic chunkingIntermediate
Semantic chunkers start a new chunk where the topic changes, usually detected by comparing sentence embeddings. The lab’s version compares shared words instead (it calls no embedding model), which shows the idea but misses synonyms.
Hierarchical and contextual chunksAdvanced
Parent-child chunking retrieves small chunks but sends their larger parent section to the model. Contextual chunking prepends a short description of where the chunk came from (document title, section) before embedding, which helps retrieval of chunks that make little sense alone.
Key takeaways
- Chunk by structure when the document has it.
- Overlap trades tokens for recall.
- Test chunking with real questions.