Part 16 / Topic 4 of 5
Chunking
Embedding a whole manual into one vector averages everything into mush; retrieval wants chunks — passages big enough to carry a fact, small enough to stay on-topic. Overlap protects facts that straddle a boundary:
# examples/02_chunking_long_text_with_overlap.py (size 10, overlap 3, 25 words)
# 0 w1 ... w10
# 1 w8 ... w17 <- repeats the last 3 words of chunk 0
# 2 w15 ... w24
# 3 w22 ... w25
Practical defaults: a few hundred tokens per chunk, ~10–15% overlap, and — better than any fixed size — respect document structure: split on headings and paragraphs so chunks are self-contained thoughts, and keep metadata (title, section) attached for citations.
🧪 Quick quiz
- Why chunk with overlap?
Show the answer
So a fact split across a chunk boundary still appears whole in at least one chunk — measured: with size 10/overlap 3, each chunk repeats the previous one's last 3 words.
Done here? The practice set for Part 16 — 4 exercises with solutions — is on the part page.