AWS Builder Center
RAG from Basics to Advanced (Part 4): Chunking Strategies

RAG from Basics to Advanced (Part 4): Chunking Strategies

Why chunk size and overlap quietly determine retrieval quality, and how to choose between fixed-size, recursive, semantic, structure-aware, and agentic chunking.

Series: RAG from Basics to Advanced (8 articles)

  1. …
  2. 4
    RAG from Basics to Advanced (Part 4): Chunking Strategies This article
AWS DevOps Engineer | 7+ Yrs Cloud Automation | EKS, ECS, IaC | GenAI & AIOps Expert
This is Part 4 of a series that builds up Retrieval Augmented Generation (RAG) from the ground up.
Parts 2 and 3 covered what happens once a document is already indexed. embedding, retrieval, reranking. This part goes one step earlier: before any of that can happen, a document has to be split into chunks. It's easy to treat this as a boring preprocessing detail. It isn't chunk quality quietly caps how good your retrieval can ever be.

Why Chunking Is Necessary in the First Place

Question comes in mind: why not just embed the entire document as one vector?
  1. Embedding models have a context limit. Most embedding models cap out at a fixed token limit (commonly around 8,000 tokens). A 50-page document simply won't fit.
  1. Semantic dilution. If you compress an entire document into a single vector, that vector ends up representing an "average meaning." If the document covers ten different sub-topics, the embedding blends all of them together and matching it precisely against a specific query becomes much harder.
  1. Precision. When a user asks "what's the refund policy," they need the 2–3 relevant paragraphs not the entire 50-page document. Chunking is what makes that level of precision possible.
The one-line answer: chunking exists because retrieval needs to be precise you want to retrieve the smallest unit of text that fully answers the query, not the whole document.

The Core Trade-off: Chunk Size

This is the most common question asked about chunking: should chunks be small or large?
Smaller chunks (roughly 100–200 tokens):
  • Higher precision retrieval returns specific, targeted information.
  • Less noise reaching the LLM.
  • Risk of context loss if an answer spans two paragraphs, a small chunk may capture only half of it, handing the LLM an incomplete picture.
  • More chunks overall means more embeddings, more storage, more compute.
Larger chunks (roughly 1,000–2,000 tokens):
  • More context per chunk a full explanation is more likely to be captured intact.
  • Fewer total chunks, so lighter indexing and storage.
  • Risk of semantic dilution a large chunk can span multiple sub-topics, making its embedding "blurry" and harder to match precisely against a specific query.
  • More noise in what gets retrieved irrelevant content rides along with the relevant part, adding token cost and reintroducing the "lost in the middle" risk from Part 3.
The honest answer: there's no universal best chunk size. It depends on document structure and query patterns. A reasonable starting point is 300–500 tokens, tuned from there based on retrieval evaluation.

Chunk Overlap

When documents are split sequentially chunk 1 covers tokens 1–500, chunk 2 covers 501–1000 there's a real risk that an important sentence gets cut exactly at the boundary. A sentence like "customers can claim a refund within 30 days" split across two chunks leaves both chunks with incomplete context.
The fix is overlap each new chunk repeats a portion of the previous one:
Chunk 1: tokens 1–500
Chunk 2: tokens 400–900 (100-token overlap with Chunk 1)
Chunk 3: tokens 800–1300 (100-token overlap with Chunk 2)
The trade-off is straightforward: more overlap protects boundary information better, but increases redundant storage and raises the chance of retrieving duplicate content.

Chunking Strategies

1. Fixed-Size Chunking

The simplest approach, split at a fixed token or character count, with optional overlap, without looking at content structure at all.
  • Simple, fast, predictable.
  • Can arbitrarily cut a sentence, a table row, or a code block in half.
Use when: documents are unstructured, or you're building a quick prototype.

2. Recursive Character/Text Splitting

A smarter default, it tries to split at natural boundaries first (paragraphs, then sentences, then words), and only falls back to a hard character-level split if a chunk is still too large.
Priority order: paragraph break → line break → sentence → word
  • Respects natural breakpoints most of the time.
  • Still doesn't understand deeper structure like headers or sections.
Use when: as a general-purpose default. This is the most common choice in practice (LangChain's RecursiveCharacterTextSplitterRecursiveCharacterTextSplitter is popular for exactly this reason) a good balance of simplicity and quality.

3. Semantic Chunking

A more advanced technique that uses embeddings to decide where chunk boundaries should fall. It computes embeddings for consecutive sentences and breaks the chunk wherever semantic similarity drops sharply i.e., where the topic actually shifts.
  • Produces chunks that are genuinely topic-coherent each chunk centers on one idea.
  • Computationally expensive (extra embedding calls happen at chunking time), and more complex to implement.
Use when: document structure varies a lot (long-form articles, research papers) and retrieval quality is critical enough to justify the added cost and complexity.

4. Document-Structure-Aware Chunking

This respects the document's actual structure splitting a Markdown document along its ## headers, or a PDF along its sections and pages.
  • Produces logically meaningful chunks (one section = one chunk), and comes with useful metadata for free (e.g., "this chunk is from the Refund Policy section").
  • Only works when the source document is well-structured; it breaks down on raw unstructured text.
Use when: source documents are well-formatted company wikis, structured manuals, Markdown docs. This tends to give the best combination of retrieval quality and citation accuracy.

5. Agentic / LLM-Based Chunking

An LLM is used to intelligently decide where chunk boundaries should go, based on actual understanding of the content.
  • Produces the highest-quality, most context-aware chunks.
  • The most expensive and slowest option only worth it when chunking quality is genuinely critical.
Use when: high-stakes domains (legal, medical) where a badly placed chunk boundary carries real cost.

Metadata: The Often-Skipped Part

Every chunk should be stored with more than just its text, it needs metadata:
  • Source document name
  • Page number / section heading
  • Position within the document
  • Last-updated timestamp
This matters for two reasons: it enables proper citations ("Source: Refund Policy, Page 3"), and it enables metadata filtering narrowing a search to a specific document type or date range before the vector search even runs.

Summary

Strategy
Best For
Trade-off
Fixed-size
Quick prototypes, unstructured text
Can cut mid-sentence
Recursive
General-purpose default
Doesn't understand deep structure
Semantic
Long-form, topic-varied content
Expensive, complex
Structure-aware
Well-formatted docs (Markdown, wikis)
Fails on unstructured text
Agentic/LLM-based
High-stakes domains
Very expensive, slow
The closing point worth remembering:
Chunking is the step most people underestimate but retrieval quality is bottlenecked by chunk quality. A perfect embedding model and a great reranker can't recover an answer that a bad chunk boundary already cut in half.


Next in this series (Part 5): Evaluation how do you actually know whether a RAG system is good? Precision, recall, faithfulness, groundedness, and the frameworks (like RAGAS) used to measure them.

Series: RAG from Basics to Advanced (8 articles)

  1. …
  2. 4
    RAG from Basics to Advanced (Part 4): Chunking Strategies This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article