Concept · Builds on AIF-C01
Preparing documents for RAG
Chunking strategies, parsing, and metadata so a knowledge base retrieves the right passage.
You know from AI Practitioner
- Chunking splits long documents before embedding.
- There is no best size: test with your documents.
- Chunks are embedded and stored in a vector database.
Fixed-size
- How it cuts
- Max tokens plus overlap
- Pick it when
- A simple start
Hierarchical
- How it cuts
- Child chunks inside parents
- Pick it when
- Precise match, wide context
Semantic
- How it cuts
- Cuts where meaning shifts
- Pick it when
- Mixed topics in one file
Custom (Lambda)
- How it cuts
- Your own code
- Pick it when
- Special rules
| Strategy | How it cuts | Pick it when |
|---|---|---|
| Fixed-size | Max tokens plus overlap | A simple start |
| Hierarchical | Child chunks inside parents | Precise match, wide context |
| Semantic | Cuts where meaning shifts | Mixed topics in one file |
| Custom (Lambda) | Your own code | Special rules |
- 1Documents and their metadata files sit in S3.
- 2A parser extracts text, tables and figures.
- 3The chunker splits the text.
- 4An embedding model turns each chunk into a vector, stored with its metadata.
Step by step
- 1Documents and their metadata files sit in S3.
- 2A parser extracts text, tables and figures.
- 3The chunker splits the text.
- 4An embedding model turns each chunk into a vector, stored with its metadata.
Documents are parsed, chunked, embedded and stored.
What it is
Amazon Bedrock Knowledge Bases offer several chunking strategies. Fixed-size chunking sets a maximum number of tokens and an overlap percentage. Hierarchical chunking makes small child chunks inside larger parent chunks: search matches the precise child and the answer gets the parent for more context. Semantic chunking uses a foundation model to cut where the meaning shifts, at extra cost. No chunking keeps each file whole. Custom chunking runs your own AWS Lambda function on the files, for rules the built-ins cannot express. Smaller chunks match precisely but lose context. Larger chunks keep context but dilute the match. Overlap stops an idea from being cut in half.
What it is
AWS advises against hierarchical chunking when the store is an S3 vector bucket.
Parsing decides what text the chunker sees. The default parser reads plain text well but misses tables and figures. A foundation model parser, or Amazon Bedrock Data Automation, reads complex PDFs with tables, charts and images and returns structured text, at extra cost. Use it for scanned or table-heavy files.
What it is
Metadata makes retrieval precise. Put a file next to each document in S3 named like the document with .metadata.json added, holding attributes such as year, department or product. At query time, filter on those attributes, for example only documents from 2026 for one department. Extract metadata automatically with a Lambda function or Amazon Comprehend when files have none.
Remember
- Fixed-size: max tokens and overlap. Hierarchical: small child chunks match, bigger parent returns.
- Semantic chunking: cuts by meaning, extra model cost.
- Custom chunking: a Lambda function for your own rules.
- Parsers: default for text, foundation model or Data Automation for tables and figures.
Remember
- Metadata in a .metadata.json file beside each document, used as query filters.
On the exam
- “Precise matching but the answer needs surrounding context” points to hierarchical chunking.
- “PDF tables are lost during ingestion” points to a foundation model parser.
- “Return only documents from one department and year” points to metadata filtering.
In this task · 1.2
Glue ETL
DataBrew
EMR
Data Wrangler
SageMaker Processing
Athena
Feature Store
- Transforming streaming data
- Feature engineering techniques
- Embedding models for text and image
- Text pre-processing and tokenization
- Preparing documents for RAG
- Masking, redaction and anonymization
- Data for fine-tuning, continued pre-training and distillation