AWS Shows Document Preprocessing Before a Bedrock Knowledge Base

Published · Updated • news
Amazon BedrockRAGAWS

Raw retrieval-augmented generation pipelines break on real enterprise documents. AWS Professional Services published a reference architecture on September 4, 2026, showing how Amazon Textract can serve as a preprocessing layer before documents enter an Amazon Bedrock Knowledge Base — directly addressing the hallucination and incomplete-extraction failures that occur when LLMs ingest unstructured PDFs, spreadsheets, and images without prior OCR normalization.

Why Naive RAG Fails on Complex Documents

The motivating scenario involves customer service teams processing high volumes of utility bills across six file formats: PDF, DOCX, TXT, HTML, XLSX, and PNG. Feeding raw files directly into a RAG model produced three failure categories. First, incomplete extraction: the LLM missed critical fields such as due dates, payment amounts, and account numbers. Second, hallucination: the model generated plausible but incorrect responses when it could not parse table structure or dense layout. Third, format inconsistency: performance degraded unevenly across document types because each format presents structurally different content to a tokenizer expecting linear text.

This example motivates checking document representation before retrieval. It does not establish that prompt changes or different models cannot improve the same task. As the case for pipeline architecture over model substitution continues to gain traction, this implementation is a concrete example of why preprocessing stages matter.

The Extraction and Enrichment Pipeline

The solution interposes Amazon Textract between raw document storage and the knowledge base. An S3 bucket named with the pattern document-<stack-name>-<partial-stack-id> receives uploads into a raw_files folder. That upload event triggers a document-parser Lambda function, which dispatches Amazon Textract jobs against the raw files. Correction, 22 October 2026: Textract's operation limits list JPEG, PNG, PDF and TIFF. The earlier wording incorrectly implied native Word and Excel input support. Confirm the reference implementation's parsing or conversion path for other source formats.

Processed output lands in a parsed_files folder; a second Lambda function converts that output to TXT format and writes the final artifacts to a parsed_kb_documents folder. The key value Textract adds is threefold: layout-aware extraction rather than linear tokenization, contextual labeling so table cells carry structural metadata rather than being flattened into undifferentiated text, and noise removal before embedding. Only the cleaned, labeled output reaches the Bedrock Knowledge Base sync operation, which uses an Amazon OpenSearch Serverless cluster as its vector store.

Infrastructure Composition and Deployment

The entire stack deploys through a single shell script (bash custom_kb_deployment_setup.sh) that invokes AWS CloudFormation. The stack provisions these resources:

Resource Type Role in Pipeline
Lambda Execution Role IAM Role Execution permissions for Lambda; inspect the actual policy
Lambda Layer Lambda Layer Shared dependency package for both functions
document-parser function AWS Lambda Triggers Textract jobs on S3 upload events
Second Lambda function AWS Lambda Converts Textract output to TXT for KB ingestion
S3 Bucket Amazon S3 Stores raw_files, parsed_files, parsed_kb_documents
OpenSearch Serverless Cluster Amazon OpenSearch Serverless Vector store backing the Bedrock Knowledge Base
Bedrock Knowledge Base Amazon Bedrock Managed RAG retrieval and generation endpoint
Bedrock KB IAM Role IAM Role Grants Knowledge Base access to S3 and OpenSearch

Once the stack is live, a manual sync of the data source inside the Bedrock console completes ingestion. Testing uses the Amazon Nova Micro model, selected within the Knowledge Base console's configuration panel. Model availability is region-dependent and should be verified against the Supported Models by AWS Region table in the Bedrock documentation.

Guardrails and Production Hardening

The extraction pipeline alone cannot eliminate all risk. Amazon Bedrock Guardrails provides configurable controls for filtering harmful content, blocking denied topics, and redacting sensitive information from both model inputs and outputs. A grounding validation feature evaluates whether generated responses are actually supported by the retrieved source chunks — a direct mitigation for residual hallucination that can occur even after Textract preprocessing normalizes the input. The authors recommend enabling these controls explicitly for production deployments rather than relying on base model behavior. This reflects the infrastructure governance framing for safe agent deployment: safety properties are engineered into the surrounding stack, not assumed from the model itself.

The pattern generalizes beyond utility bills. Any domain where documents carry dense tabular data — insurance claims, financial statements, regulatory filings — faces the same extraction-before-embedding requirement. Event-driven OCR normalization feeding a managed vector store is CloudFormation-repeatable, meaning organizations can adapt it across document types without redesigning the retrieval layer each time. Preprocessing, retrieval and model behavior can all affect downstream accuracy. Compare changes on a fixed evaluation set rather than assigning all improvement to one stage.

Frequently asked questions

What file formats does the Amazon Textract–Bedrock Knowledge Base pipeline support?

The reference post lists several source formats, but Textract's operation limits list JPEG, PNG, PDF and TIFF. Do not send DOCX or XLSX directly to an operation that does not accept them; verify the separate parser or conversion path.

What AWS resources does the CloudFormation stack deploy?

The stack creates an IAM Lambda Execution Role, a shared Lambda Layer, two Lambda functions (document-parser and a TXT-conversion function), one S3 bucket, one Amazon OpenSearch Serverless cluster, an Amazon Bedrock Knowledge Base, and an IAM role for the Knowledge Base.

Which model is used to test the Bedrock Knowledge Base in this solution?

Testing uses the Amazon Nova Micro model, selected within the Knowledge Base console's configuration panel. Model availability is region-dependent and should be verified against the Supported Models by AWS Region table in the Bedrock documentation.

How does the solution reduce hallucinations in RAG responses?

Hallucinations are addressed at two stages. First, Amazon Textract normalizes document input — performing layout-aware extraction and contextual labeling — before content reaches the knowledge base. Second, Amazon Bedrock Guardrails provides a grounding validation feature that evaluates whether generated responses are actually supported by the retrieved source chunks.

How is document processing triggered in this architecture?

Uploading a file to the raw_files folder of the S3 bucket (named document-<stack-name>-<partial-stack-id>) triggers the document-parser Lambda function, which dispatches Amazon Textract jobs. Processed output lands in a parsed_files folder, a second Lambda converts it to TXT, and the final artifacts are written to a parsed_kb_documents folder.

Free interactive tools for the decisions this piece raises.

Related Reading