Fixed-Size Chunks
Size and overlap.
The simplest way to chunk is by size. Take a fixed number of characters, then the next, and so on. An overlap repeats a little text between neighbours, so an idea cut at the edge appears in both.

- Fixed number of characters
- Then the next
- With a little overlap
Chunking by characters
Chunk steps through the text, taking size characters each time, and moving forward by size minus overlap. We split the returns page into chunks of one hundred and twenty characters, with twenty overlapping. Run it. It works, but look at the edges. Words and sentences are cut in half.
from pathlib import Path
def chunk(text, size, overlap):
step = size - overlap
return [text[i:i + size] for i in range(0, len(text), step)]
text = Path("data/rag/northwind/returns.md").read_text()
pieces = chunk(text, size=120, overlap=20)
print(len(pieces), "chunks")
for p in pieces[:3]:
print(repr(p))7 chunks '# Returns and refunds\n\n## Change of mind\nYou can return any unused item within 30 days of delivery for a full refund.\nBi' 'or a full refund.\nBikes must be unridden, with the original packaging and all reflectors and manuals.\nWe charge a £25 co' '.\nWe charge a £25 collection fee to pick up a returned bike. Parts can be posted back at your own cost.\n\n## Faulty items'
Size and overlap
Chunk size controls how much text each piece holds. Overlap helps when an idea crosses a boundary, but too much overlap creates near duplicates. A common start is a few hundred characters, with ten to twenty percent overlap.
| key | value |
|---|---|
| Size | how much per chunk |
| Overlap | repeat at edges |
| Too much overlap | duplicates |
| Start with | 300 chars, 15% |
Summary
Fixed size chunking is simple, but it cuts words and sentences. Next, recursive splitting, which respects paragraphs.
Key takeaways- size
- overlap
- Cuts mid-word