Lesson 2 of 4 Amazon Bedrock Knowledge Bases

Choosing Parsing and Chunking Strategies

This lesson explains how a knowledge base's parsing and chunking options decide what a search result contains, and how to choose them so tables, images and answers are not lost or split.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose a parser for complex documents.
  • Choose between default, fixed-size, hierarchical and semantic chunking.
  • Customize chunking with a Lambda function.

Parsing options

The default parser extracts text from common formats such as text, HTML, Markdown, Word and text-based PDF. Documents with complex layouts, tables, charts or scanned pages need advanced parsing. The Bedrock Data Automation parser handles multimodal content such as tables, figures and images in documents. The foundation model parser uses a multimodal model with a customisable parsing prompt, for example to convert tables to Markdown or describe charts. Extracted images can be stored in a supplemental S3 location for multimodal retrieval. Advanced parsing adds cost per page, so it is applied to the data sources that need it.

The following diagram compares the original ingestion with the corrected one.

Fixing specification tables split across chunks. The default parser flattened tables and chunking cut them, so a retrieved chunk held rows without column headers. An advanced parser that extracts tables as Markdown and chunking that keeps each table whole with its heading fix it, in a new data source with a full sync.
Advanced parsing adds cost per page, so it is applied only where needed.
Scenario questions

Choosing a parser

Exam skills 1.5.1 · 1.3.2

Choose the parsing option for each document set.

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

Chunking strategies

Default chunking splits text into chunks of about 300 tokens, respecting sentence boundaries. Fixed-size chunking sets a maximum number of tokens per chunk and an overlap percentage between consecutive chunks, so sentences near boundaries appear in both. Hierarchical chunking creates large parent chunks and smaller child chunks inside them; search runs on child chunks for precision, and the matching parent chunks are returned for context. Semantic chunking uses embeddings to split where meaning changes, controlled by a maximum chunk size, a buffer size (surrounding sentences considered) and a breakpoint percentile threshold. No chunking treats each file as one chunk, for content already split upstream.

"chunkingConfiguration": {
  "chunkingStrategy": "HIERARCHICAL",
  "hierarchicalChunkingConfiguration": {
    "levelConfigurations": [{"maxTokens": 1500}, {"maxTokens": 300}],
    "overlapTokens": 60
  }
}

The following diagram shows how the three strategies divide the same document.

Three chunking strategies. Fixed-size chunking caps chunk length and overlaps consecutive chunks so boundary sentences appear in both. Hierarchical chunking searches small child chunks for precision and returns their larger parent for context. Semantic chunking splits where the meaning changes, so chunks follow topics.
Chunk sizes are schematic.

300tokens

About the size of a default chunk

Sort into groups

Choose the chunking strategy

Exam skills 1.5.1

Choose the chunking strategy that suits each document collection.

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

Custom chunking with Lambda

A custom transformation Lambda function runs during ingestion when built-in strategies do not fit, for example to split on document headings, keep each FAQ question with its answer, keep tables whole, prepend section titles to chunks or add computed metadata. The knowledge base writes intermediate files to an S3 bucket, invokes the function, and reads the transformed chunks back. Custom chunking can be combined with built-in chunking or used instead of it.

The chunking strategy of a data source cannot be changed after the data source is created. Changing it requires a new data source (or knowledge base) and a full ingestion, so the choice should be evaluated during the proof of concept. The following table summarises the strategies.

StrategyHow it splitsBest for
DefaultAbout 300 tokens, sentence awareGeneral text; quick start
Fixed-size with overlapMax tokens plus overlap percentageUniform prose; predictable sizes
HierarchicalChild chunks searched, parent chunks returnedPrecise matching with rich context
SemanticBreaks where meaning changesDocuments mixing many topics
NoneWhole file is one chunkPre-split content such as single FAQ entries
Custom LambdaAny logic you implementHeadings, tables, Q&A pairs, special formats
True or false

Custom chunking

Exam skills 1.5.1

Check three claims about custom chunking in Bedrock Knowledge Bases.

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

Tables split across chunks

Product manuals contain specification tables. Answers about specifications are often wrong, and inspection shows that retrieved chunks contain half a table with no column headers.

Two fixes are needed: an advanced parser (Bedrock Data Automation or the foundation model parser) to extract tables faithfully, for example as Markdown, and custom chunking (or hierarchical chunking with large parents) that keeps each table whole with its heading. Because chunking cannot be changed in place, a new data source is created and synced.

Check yourself

Which chunking strategy returns precise matches with enough surrounding context?

Show answer

Hierarchical chunking, which searches small child chunks and returns their larger parent chunks.

Exam Tips

Remember for the exam

  • Complex layouts, tables and images: Bedrock Data Automation or foundation model parser.
  • Precise matches with enough context: hierarchical chunking.
  • Headings, Q&A pairs or whole tables: custom Lambda chunking.
  • Chunking cannot be changed on an existing data source.