Parsing Documents and Extracting Metadata for Retrieval
This lesson explains how document content, including tables, images and layout, is extracted correctly before chunking, and how metadata lets retrieval filter results and enforce boundaries.
Learning outcomes
After completing this lesson, you will be able to:
- Choose a parsing approach for complex documents.
- Attach metadata for filtering.
- Extract metadata automatically during ingestion.
Parsing options
Bedrock Knowledge Bases offers three parsing approaches. The default parser extracts text from supported formats such as PDF, Word, HTML, Markdown and CSV, and is cheapest. Amazon Bedrock Data Automation parses multimodal content, including tables, figures and images, into structured output. Foundation model parsing uses a multimodal FM with a parsing prompt to interpret complex layouts, nested tables and charts, at extra cost per page. Outside knowledge bases, Amazon Textract extracts text, forms and tables from scanned documents with its AnalyzeDocument features (TABLES, FORMS, LAYOUT, QUERIES).
Choose a parser
Metadata for filtering
Metadata describes each document: department, product, document type, date, language, access level. In a knowledge base with an S3 data source, metadata is supplied in a companion file named <document>.metadata.json in the same prefix. At query time, metadata filters restrict retrieval, for example product = 'X200' and year >= 2025, and implicit filtering can let a model derive filters from the question.
// s3://kb-docs/manuals/x200-service-guide.pdf.metadata.json
{
"metadataAttributes": {
"product": "X200",
"doc_type": "service_guide",
"year": 2026,
"audience": "technician"
}
}The following diagram shows how a metadata filter stops a support assistant from answering from the manual of the wrong product.

Metadata that is ignored
Extracting metadata automatically
Documents often arrive without the metadata that retrieval filters need, and it can be extracted automatically during ingestion. Amazon Comprehend detects entities, key phrases, language and custom classes, such as document type. Amazon Textract queries pull specific fields, such as a policy number, from forms. A foundation model can classify each document and summarise it. S3 object tags and folder paths provide the source and owner.
For finer control, a custom chunking Lambda function in a Bedrock knowledge base can attach metadata to each chunk, for example the section heading each chunk came from. The following table summarises the options.
| Need | Tool |
|---|---|
| Text from simple digital files | Default parser |
| Tables, figures, scanned pages in a knowledge base | Bedrock Data Automation or FM parsing |
| Fields and tables from scanned forms | Amazon Textract |
| Entities, language, document class | Amazon Comprehend (built-in or custom classifier) |
| Filter retrieval by attributes | .metadata.json files and metadata filters |
Where metadata comes from
Answers from the wrong product
A support knowledge base covers 40 router models with very similar manuals. Questions about the X200 often return passages from the X100 manual, and specification tables come back as jumbled text.
- Generate a
.metadata.jsonfile for each manual with product, version and document type, using the S3 path and a Comprehend custom classifier. - Switch the data source to FM parsing so specification tables are extracted as structured text.
- Pass
product = 'X200'as a metadata filter from the support portal, which already knows the customer's device.
Filtering removes look-alike passages from other products, and better parsing makes table values retrievable. A larger embedding model alone would not have separated near-identical manuals.
Where does a knowledge base read metadata for documents in S3?
Show answer
From a .metadata.json file next to each document.
Exam Tips
Remember for the exam
- Complex tables and images: FM parsing or Bedrock Data Automation.
- Scanned forms outside knowledge bases: Textract.
- Metadata comes from <document>.metadata.json files in S3 data sources.
- Metadata filters restrict retrieval by product, date or access level.
- Comprehend can classify documents and extract entities as metadata.