Choosing a Chunk Size
Not too big, not too small.
There's no perfect chunk size. Small chunks match precisely, but may lack context. Big chunks carry more context, but blur meaning, and fill the prompt. Let's see how size changes our index.

- Small: precise
- Big: more context
- Find the balance
Trying three sizes
We load all fourteen pages, and split them with three different chunk sizes. For each size, we print how many chunks we get, and their average length. Run it. Smaller sizes give many more, shorter chunks.
from pathlib import Path
from langchain_text_splitters import RecursiveCharacterTextSplitter
texts = [p.read_text() for p in sorted(Path("data/rag/northwind").glob("*.md"))]
for size in [100, 300, 1000]:
splitter = RecursiveCharacterTextSplitter(chunk_size=size, chunk_overlap=0)
chunks = [c for t in texts for c in splitter.split_text(t)]
print(f"size {size:4}: {len(chunks):3} chunks, average {sum(map(len, chunks)) // len(chunks)} characters")size 100: 111 chunks, average 62 characters size 300: 44 chunks, average 158 characters size 1000: 14 chunks, average 500 characters
Rules of thumb
For short help pages like ours, two hundred to five hundred characters works well. For long reports, try larger chunks. The real answer comes from testing, which we'll do in the evaluation section, by measuring which size finds the right answers most often.
| key | value |
|---|---|
| Help pages | 200–500 chars |
| Long reports | larger |
| Tables | keep whole |
| Decide by | measuring |
Summary
Chunk size is a trade off between precision and context. Start around three hundred characters, then measure. Next, metadata on chunks.
Key takeaways- Small: precise
- Big: context
- Measure to decide