Benchmarks/Chunking
Five chunking strategies on real docs
Which chunking strategy retrieves best?
0.785hit@1, heading-aware + heading path
Short answer: Heading-aware chunks with the heading path added scored 0.785 hit@1, against 0.389 for fixed 800/100 chunks, which crossed a section boundary 58.8% of the time.
- hit@1
- hit@5
What the numbers say
- Splitting at headings first, then packing paragraphs, raised hit@1 from 0.389 to 0.712.
- Adding the heading path to each chunk raised it again to 0.785.
- A size-matched fixed chunker (530/100) still trailed at 0.481, so the gain is not just smaller chunks.
All results
| Fixed 800/100 | 2,142 | 770 | 58.8% | 7.3% | 0.389 | 0.611 | 0.477 |
| Fixed 530/100 (size-matched) | 3,446 | 516 | 47.5% | 6.1% | 0.481 | 0.766 | 0.598 |
| Paragraph-packed 800 | 1,737 | 835 | 57.2% | 3.6% | 0.375 | 0.576 | 0.455 |
| Heading-aware | 2,713 | 534 | 0.0% | 2.1% | 0.712 | 0.933 | 0.804 |
| Heading-aware + heading path | 2,713 | 534 | 0.0% | 2.1% | 0.785 | 0.966 | 0.859 |
Setup
FastAPI English docs (151 Markdown files, 1.45M characters), 773 queries, BM25 retrieval (k1=1.5, b=0.75), Python 3.11. Full script at the end.
Reproduce it
The complete script is at the end of the write-up.