Skip to main content
Back to Dispatches
AI & LLM Systems 10 min read

RAG Chunking Strategies: Recursive, Semantic & Markdown Splitting for Vector Search

Master document chunking for Retrieval-Augmented Generation (RAG): recursive character splitting, token overlap mathematics, markdown-aware hierarchy, and vector retrieval benchmarking.

TB
TitanByte
August 28, 2026

In Retrieval-Augmented Generation (RAG) architectures, developers often spend weeks fine-tuning embedding models, testing vector databases, or adjusting LLM prompt templates.

However, systematic 2026 AI benchmarks reveal a surprising truth: your document chunking strategy often has a greater impact on retrieval precision and hallucination rates than the choice of embedding model itself.

If a chunk is too large, the embedding vector gets diluted with irrelevant noise; if a chunk is too small, critical semantic context is severed across boundaries.

In this guide, we break down the mathematics of token overlap, compare recursive character splitting vs semantic chunking, and demonstrate how to structure documents for high-accuracy vector retrieval.


1. The Chunking Spectrum: Finding the Sweet Spot

┌─────────────────────────────────────────────────────────────┐
│ 🔴 Tiny Chunks (< 100 tokens): Context Fragmentation        │
│    "The user clicked checkout." (Who? What price? Which item?)│
├─────────────────────────────────────────────────────────────┤
│ 🟢 Sweet Spot (256 – 512 tokens + 10% Overlap): Balanced   │
│    Complete paragraph + relevant entity metadata preserved. │
├─────────────────────────────────────────────────────────────┤
│ 🔴 Massive Chunks (> 2000 tokens): Semantic Dilution        │
│    Vector embedding averages 15 unrelated topics together.  │
└─────────────────────────────────────────────────────────────┘

The Two Major Retrieval Failure Modes:

  1. The Context Fragmentation Trap (< 100 tokens): Slicing text into isolated sentences loses pronouns, antecedents, and conditional clauses. When queried, the vector database returns an isolated fragment that the LLM cannot confidently interpret.
  2. The Context Cliff (> 2,000 tokens): Dense vector embeddings (e.g. OpenAI text-embedding-3-small, Cohere embed-v3) map text to a fixed-dimensional space (e.g. 1536 dimensions). When embedding an entire 3,000-word chapter, specific facts get drowned out in the centroid average.

2. The 4 Core Chunking Strategies Compared

StrategySplitting MechanismComputational CostBest Suited For
1. Fixed-Size SplittingHard character/token slice every $N$ unitsInstant (O(1))Uniform raw byte streams, simple benchmarks
2. Recursive Character SplittingCascading delimiters (\n\n\n. )Fast (Zero model cost)Default choice for 85% of production RAG
3. Structure-Aware (Markdown/HTML)Splits on #, ##, tables, and code blocksFast (DOM / AST parsing)API docs, technical RFCs, legal agreements
4. Semantic ChunkingSplits when cosine distance between sentences spikesHigh (Requires per-sentence embeddings)Dense philosophical prose, unstructured transcripts

3. The Mathematics of Token Overlap

Why do we need overlap? If a crucial piece of information (e.g. “The discount code SUMMER20 grants 25% off all annual plans”) falls directly on the boundary between Chunk #1 and Chunk #2, cutting it in half destroys the meaning in both chunks.

$$\text{Overlap Length} = \text{Chunk Size} \times \text{Overlap Percentage (10% - 20%)}$$

Document Text: [ ... Sentence A ... Sentence B ... Sentence C ... Sentence D ... ]
Chunk 1:       [ ... Sentence A ... Sentence B ... Sentence C ]
Chunk 2:                            [ Sentence B ... Sentence C ... Sentence D ... ]
                                    ▲────────────────────────▲
                                         Overlap Zone (~50 Tokens)
  • 512 Tokens with 50 Tokens Overlap (10%): The industry standard baseline for general documentation.
  • 256 Tokens with 30 Tokens Overlap (12%): Ideal for FAQ search, customer support tickets, and short chat histories.

Want to experiment with chunk sizes, token overlap percentages, and preview boundary overlap highlights on your own text? Use our interactive RAG Document Chunker & Splitter Studio.


4. Structure-Aware Markdown Splitting

For developer documentation, markdown headers (#, ##, ###) carry immense semantic weight. Slicing blindly through a markdown table or code block breaks downstream LLM comprehension.

Production Structure-Aware Algorithm:

  1. Parse top-level <h1> and <h2> markdown sections into parent chunks.
  2. If a section exceeds the target token limit (e.g. > 512 tokens), recursively split the paragraphs inside while prepending the section title as metadata:
{
  "chunk_id": "doc_jwt_sec_3",
  "metadata": {
    "document": "jwt-architecture.md",
    "section": "Algorithm Confusion Prevention",
    "parent_heading": "## 3. Cryptographic Validation"
  },
  "content": "To prevent algorithm confusion attacks where an attacker replaces RS256 with HS256, the server must explicitly verify the 'alg' header against a whitelist of approved algorithms..."
}

5. Summary Implementation Checklist

  1. Start with Recursive Character Splitting: Set chunk size to 512 tokens with 50 tokens of overlap (monitor token density with our Universal AI Token Counter).
  2. Always Attach Rich Metadata: Include source filename, section title, and timestamp.
  3. Preserve Code & Tables: Never split code blocks or markdown tables across chunk seams.
  4. Implement Hybrid Search: Combine dense vector embeddings with keyword BM25 search to capture both exact token matches and conceptual semantics.
TB

TitanByte

Founder & Author

Founder of WebCraftKit, IT Analyst, Gamer, Tech Lover and Father

Architecting fast, 100% browser-native developer utilities. Passionate about client-side cryptography, zero-latency system performance, cybersecurity, and practical software engineering.

Topics: #RAG #AI #Vector Search #Embeddings #LLM #Python #TypeScript