Lesson 1 of 5 Preparing Data for Generative AI

Chunking Documents for Retrieval Augmented Generation

This lesson explains how documents are split into chunks before embedding for RAG, one of the strongest levers on RAG quality, since chunks that are too small lose context and chunks that are too large dilute relevance.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why chunk size matters.
  • Choose a chunking strategy in Bedrock Knowledge Bases.
  • Test chunking strategies against real questions.

Why chunk size matters

Each chunk becomes one vector. A small chunk produces a precise vector for one idea, which retrieves well, but it may lack the surrounding context needed to answer. A large chunk carries more context, but its vector averages several ideas and matches queries less sharply, and every retrieved chunk adds input tokens to the prompt. Chunks must also fit within the embedding model's input limit. Overlap between consecutive chunks keeps sentences that span a boundary available in both.

Sort into groups

Too small or too large?

Exam skills 1.2.7

Decide whether each symptom points to chunks that are too small or too large.

Log in to try this activity Interactive activities are free with an account.

Chunking strategies in Bedrock Knowledge Bases

Bedrock Knowledge Bases offers several strategies, chosen per data source. Fixed-size chunking splits by a maximum number of tokens with an overlap percentage; it is predictable and a good default. Hierarchical chunking creates large parent chunks and small child chunks; search runs on children for precision, and the parent is returned for context. Semantic chunking uses an embedding model to split where meaning changes, keeping related sentences together at extra cost. No chunking treats each file as one chunk, for documents that are already small. Custom chunking runs your own Lambda function, for example to split by legal clause or by heading.

The chunking configuration of a data source cannot be changed after it is created, so changing it means creating a new data source and re-ingesting. The following table summarises the strategies.

StrategyBest forTrade-off
Fixed-size with overlapGeneral documents, a reliable defaultMay split mid-idea
HierarchicalLong structured documents needing contextReturns fewer, larger passages
SemanticUnstructured text with topic shiftsExtra embedding cost at ingestion
No chunkingPre-split or very short documents (FAQs)Large files become one weak vector
Custom (Lambda)Domain structure such as clauses or codeCode to maintain
Match the pairs

Bedrock chunking strategies

Exam skills 1.2.7 · 3.2.7

Match each Bedrock Knowledge Bases chunking strategy with when to use it.

Log in to try this activity Interactive activities are free with an account.

Choosing and testing a strategy

The right chunking strategy depends on the structure of the documents and the questions users ask. Frequently asked questions with short answers need small chunks, or no chunking at all, so each answer is retrieved on its own. Manuals in which answers span several sections benefit from hierarchical chunking, which retrieves small chunks but passes their larger parent sections to the model. Contracts with numbered clauses suit custom chunking that splits on clause boundaries.

Strategies should be compared with evidence rather than chosen by intuition. A test set of questions with known source passages is built, each strategy is evaluated with retrieval metrics such as recall at k, and the best performer is used in production.

The following diagram compares what three chunking strategies return for a question about step 4 of a multi-step procedure.

What each chunking strategy returns for a question about step 4 of a procedure. Fixed 200-token chunks retrieve step 4 alone, so the answer is incomplete. Fixed 1,500-token chunks return the whole procedure plus an unrelated section, at seven times the tokens. Hierarchical chunking matches the small child chunk for step 4 and returns its parent, the whole procedure.
The procedure's layout is illustrative.
Put in order

Test a chunking change

Exam skills 1.2.7 · 2.3.10

Arrange the steps for choosing a chunking strategy with evidence.

Log in to try this activity Interactive activities are free with an account.
Worked example

Technical manuals

A RAG assistant for 300-page equipment manuals uses fixed 200-token chunks. Users complain that answers describe step 4 of a procedure without steps 1 to 3.

Strategy            Retrieved passage                      Answer quality
Fixed 200 tokens    Step 4 only                            Incomplete
Fixed 1,500 tokens  Whole procedure + unrelated section    Complete but noisy, 7x tokens
Hierarchical        Child: step 4 (match) -> parent:       Complete and focused
(parent 1,500 /      whole procedure (returned)
 child 300)

Hierarchical chunking keeps precise matching on small children while returning the full procedure as context. Because chunking cannot be changed on the existing data source, the team creates a new data source with hierarchical chunking, syncs it and switches after the evaluation confirms the gain.

Check yourself

When is hierarchical chunking better than fixed-size chunks?

Show answer

When answers need wider context than the matched text: small chunks are matched and their larger parent is returned.

Exam Tips

Remember for the exam

  • Default: fixed-size chunking with overlap.
  • Answers need wider context than the matched text: hierarchical chunking.
  • Split where topics change: semantic chunking (extra cost).
  • Domain-specific boundaries: custom chunking with Lambda.
  • Chunking cannot be changed on an existing data source; re-ingest into a new one.