Chunking Strategies for RAG: Fixed, Recursive, Semantic and Structure-Aware

How to split documents for retrieval: chunk size and overlap, recursive and structure-aware splitting, semantic chunking, parent-child chunks and testing.

Published December 1, 2026

Chunking decides what a "piece of knowledge" is in your retrieval system. Chunks that are too large dilute the meaning of their embeddings and waste context; chunks that are too small lose the surrounding information needed to answer. Good chunking is often the single cheapest improvement to a RAG system.

The concept

Fixed-size chunking splits text every N tokens with some overlap. It is simple but cuts across sentences, tables and code. Recursive splitting tries large separators first (sections, paragraphs) and falls back to smaller ones (sentences, words) only when needed, keeping natural units intact. Structure-aware chunking uses the document's own structure: Markdown headings, HTML sections, code functions, table rows.

Semantic chunking groups consecutive sentences whose embeddings are similar and starts a new chunk when the topic shifts. Parent-child (small-to-big) retrieval indexes small precise chunks for matching but returns their larger parent section to the model for context. Adding a short contextual header to each chunk (document title, section path) also improves retrieval noticeably.

Chunking strategies

StrategyHowProsCons
Fixed size + overlapEvery N tokens, overlap MSimple, predictableBreaks structure
RecursiveSplit by sections → paragraphs → sentencesKeeps natural unitsUneven sizes
Structure-awareHeadings, code blocks, tablesBest for docs and codeNeeds parsers per format
SemanticBreak where embedding similarity dropsTopic-coherent chunksSlower, more tuning
Parent-childMatch small, return parentPrecise match + full contextMore storage and logic

Structure-aware, parent-child chunks

Guide: Billing## Refunds## Invoices## Taxesrefund windowhow to requestinvoice PDFGST rates
Structure-aware chunks follow the document outline; parents give context to children.

Chunk size is a trade-off

128 tokensrecall 62%512 tokens78%1024 tokens74%2048 tokens65%
Illustrative retrieval recall by chunk size on one corpus. The best size depends on your data; measure it.

Practical examples

Recursive splitting with overlap (LangChain text splitters)

A sensible default for prose.

from langchain_text_splitters import RecursiveCharacterTextSplitter
splitter = RecursiveCharacterTextSplitter(chunk_size=1200, chunk_overlap=150,
                                          separators=["\n## ", "\n### ", "\n\n", "\n", ". ", " "])
chunks = splitter.split_text(markdown_doc)

Add a contextual header to each chunk

Embedding "where this came from" improves matching.

def with_context(doc_title, heading_path, text):
    return f"Document: {doc_title}\nSection: {' > '.join(heading_path)}\n\n{text}"

Parent-child retrieval

Search children, return parents.

hits = vector_search(question_embedding, table="child_chunks", k=20)
parent_ids = list(dict.fromkeys(h.parent_id for h in hits))[:5]   # dedupe, keep order
context = [parents[pid].text for pid in parent_ids]

Common mistakes

  • One chunk size for every document type (code, tables and prose need different handling).
  • Splitting tables row-by-row without headers.
  • No overlap, so answers spanning a boundary are lost.
  • Choosing chunk size without measuring recall on real questions.

Key takeaways

  • Chunking defines the unit of retrieval; it strongly affects quality.
  • Prefer recursive or structure-aware splitting over naive fixed size.
  • Contextual headers and parent-child retrieval are high-value upgrades.
  • Tune size and overlap against an evaluation set.

FAQ

What is a good default chunk size?

Roughly 300-800 tokens with 10-20% overlap is a common starting point for prose. Validate on your own data.

How should code be chunked?

By function, class or logical block using a language-aware parser, with file path and signature in a header.

Should PDFs be converted first?

Yes. Convert to clean text or Markdown with layout-aware tools so headings and tables survive before chunking.

More AI articles