IamBishal
FeaturedRAG

Cut Here: RAG Chunking Strategies, Measured

My chunking article ends by telling you to measure recall@k on questions you labelled yourself. So I did, eight ways.

Eight chunking strategies on one structured corpus, 204 labelled questions, recall@k and end-to-end answers on Claude Haiku and Sonnet. The heading path did most of the work; the common default was hard to beat.

recall@5 from adding the heading path
25% → 87%
heading-dependent questions answered
0% → 100%
recall@5 for semantic chunking
25%
answer cost: 510-token vs heading-path chunks
2.5×
  • Experiment
  • 7 min read
  • Evals & AgentOps
  • Python
  • RAG
  • Chunking
  • Embeddings
Figure 1. Recall@5 by chunking strategy and retriever

Overview

In "RAG Chunking Strategies: How to Choose, and How to Measure the Choice" I argued that chunking is a retrieval-design decision, not a number to copy, and that you should choose between options by measuring recall@k on questions you labelled yourself. This experiment runs that method.

The corpus is 47 Markdown documents built by code from the Kestrel Outfitters data in my Agentic AI book series: 40 product pages with specification tables, a shipping guide with a rate table for every carrier and region, two warehouse stock tables and the company's real policy documents. The spec tables share their column names, and so do the rate tables, so a row means nothing without its heading. That is the article's "Pro vs Enterprise rate limit" problem, many times over.

Each of the 204 questions records where its answer sits and what a chunk must also carry for the answer to be usable: the product name, the warehouse, the carrier and the region. Eight strategies index the same corpus: fixed-size with and without overlap, recursive splitting, semantic chunking, structure-aware splitting with and without the heading path, and contextual retrieval, where Claude Haiku writes a short context for each chunk. Retrieval runs locally (a small open embedding model, BM25 and a hybrid), so it is free to rerun. Claude Haiku 5.5 and Sonnet 5.5 then answer every question from the top five chunks of four strategies. The paid steps cost USD 3.78.

The heading path did most of the work. Structure-aware chunks without it scored 25% recall@5: the right row came back, but never said whose it was. The same chunks with the path prefixed scored 87%, 95% with dense retrieval, and 100% on questions that depend on headings. Semantic chunking also scored 25%, because cutting where sentence similarity drops split the tables apart. Overlap added chunks and no recall.

The common default was harder to beat than I expected. Plain 510-token chunks with 15% overlap matched the heading path on recall and beat it end to end, 96% against 88% on Sonnet. On these short pages a 510-token chunk is about a whole page, so the context rides along, and the model stitched together what one chunk lacked from the other four. That cost 2.5 times as much per answer, and some of those right answers rested on guesses the passages didn't support. Contextual retrieval helped hybrid and keyword search but hurt dense search, because the model copied facts from elsewhere in the document into neighbouring chunks.

Did it hold up?

Full results

The hypothesis, written down before the first run, and what the results said.

  1. Partly

    Structure-aware chunks with the heading path beat fixed-size and recursive splitting on recall@5, mostly on tables and headings.

    Beat 256-token fixed (87% vs 79%) and recursive (78%), only matched 510-token fixed (88%) with hybrid retrieval; led clearly with dense (95%).

  2. Confirmed

    Without the heading path, small chunks fail on tables.

    The same chunks went from 0% to 100% on heading-dependent questions and 0% to 78% on table rows when the path was added.

  3. Wrong

    Overlap raises fixed-size recall but roughly doubles the chunk count.

    50% overlap added 7% more chunks and no recall (79% both ways); on short pages there were few boundaries to protect.

  4. Confirmed

    Semantic chunking is no better than structure-aware with the heading path, at a higher index-time cost.

    25% recall@5 against 87%, with the most chunks (386) and the slowest free index; it split tables into loose rows.

  5. Partly

    Contextual retrieval reduces failures on top of the heading path, but by less than Anthropic's 35%.

    Failures fell 19% with hybrid and 30% with BM25, but rose 160% with dense: contexts copied facts into neighbouring chunks.

  6. Partly

    Recall@5 predicts end-to-end answer accuracy, with the same ranking.

    Recursive was last on both, but 510-token chunks went from second on recall to first on answers (Sonnet 96%).

What it does

  • A structured corpus built by code from the Kestrel dataset, committed so anyone can read it
  • 204 questions with exact answer spans and the context a usable chunk must carry
  • Eight chunking strategies, from fixed-size to structure-aware with a heading path and contextual retrieval
  • Dense, BM25 and hybrid retrieval on a local open embedding model: free to rerun, no GPU
  • Strict grading: a hit needs the answer's span and what disambiguates it in the same chunk
  • End-to-end answers from Claude Haiku and Sonnet, exact-match graded in code
  • Cached contexts and answers with a hard cost cap, so a rerun costs nothing

How it's built

  1. Inputs

    • Kestrel Docs47 generated Markdown documents
    • 204 labelled questionsAnswer span plus required context
  2. Chunk, index, retrieve

    • 8 chunking strategies
    • Heading path and table-header rules
    • Contextual retrieval (Claude Haiku)
    • Dense, BM25 and hybrid retrieval
    • Top-5 answersHaiku and Sonnet
  3. Outputs

    • Retrieval rowsRank and miss reason per question
    • Code-only graderSpan plus context, exact match
    • Scorecard and chartsRecall, accuracy, cost
chunkers/structure.py and grading.py
# structure.py: the one-line prefix that took recall@5 from 25% to 87%
prefix = (" > ".join(sec.path) + "\n\n") if heading_path and sec.path else ""
# -> "Ridgeline 40L pack > Specifications\n\n## Specifications\n| Specification | Value | ..."


# structure.py: a table that doesn't fit is split by rows, header repeated in every piece,
# because "| POST /v1/exports | 120 |" means nothing without its column names.
def _table_pieces(text, start, end, limit):
    header, rows = lines[:2], lines[2:]
    pieces, current = [], []
    for row in rows:
        if current and count(join(header + current + [row])) > limit:
            pieces.append(header + current)
            current = []
        current.append(row)
    if current:
        pieces.append(header + current)
    return pieces


# grading.py: a hit needs the answer's span AND what disambiguates it.
def hit(chunk, q):
    return chunk.doc == q.doc and chunk.covers(q.start, q.end) and all(c in chunk.embed_text for c in q.context)

Figures

Figure 1. Recall@5 by chunking strategy and retriever1 of 4

What I learned

  • A chunk that doesn't say what it is about can't be found or used. The heading path is one line of code and took recall@5 from 25% to 87%.
  • Splitting by structure without carrying the structure is worse than not splitting: plain structure-aware chunks scored below 256-token fixed chunks.
  • Semantic chunking has no idea what a table is. On documentation it scored 25%, the same as the worst strategy.
  • Overlap is insurance for boundaries. On short pages there were few to insure, so it added chunks and no recall.
  • Measure end to end as well as retrieval. Big chunks matched on recall and won on answers, because a reader combines passages, at 2.5 times the answer cost.
  • Contextual retrieval can backfire on dense search: the contexts copied facts into neighbouring chunks, and those outranked the real source.
  • Grade retrieval strictly. Counting "the right number came back" would have hidden every failure that mattered here.

Next steps

  • A long-document corpus, where big fixed chunks lose the advantage of covering a whole page
  • Add the heading path to fixed-size chunks too, to separate chunk size from carrying the heading
  • A reranker over a top-20 candidate pool
  • Contexts that describe a chunk without copying facts into it, to see whether dense recall recovers

Run it yourself

Everything on this page comes from code and data in the repository. The dry run is free and needs no API key. A full live rerun costs about USD 4 (retrieval is free).

Terminal
git clone https://github.com/bishal-saha/ai-lab-code.git
cd ai-lab-code/rag-chunking-benchmark
uv sync
uv run cut-here --retrieval          # 7 strategies x 3 retrievers x 204 questions, offline, $0
mv cache cache-published && mv results results-published
cp .env.example .env                 # then add your ANTHROPIC_API_KEY
uv run --env-file .env cut-here --contextualize --max-usd 1
uv run cut-here --retrieval
uv run --env-file .env cut-here --answer --max-usd 5
uv run python -m cut_here.report

Bishal SahaLet's build together

Have a system to design, or an AI feature to get right?

Tell me about the problem. You'll get a clear, honest view of the best way forward.

  • Reply within 24 hoursOn business days, with my honest view and a next step.
  • Accepting select engagementsArchitecture, AI features and full builds.
  • Remote, worldwideWorking with startups, SMEs and enterprises.