CLOUD CONCEPT

Document Chunking

Document chunking divides source documents into smaller, context-preserving units for indexing, retrieval, and language-model processing.

Cloud Concepts Hub →

What is Document Chunking

In retrieval-augmented generation (RAG), document chunking determines which passages are embedded, searched, and supplied to a language model as supporting evidence. Effective chunking balances retrieval precision, contextual completeness, model token limits, and operational cost while preserving metadata needed for filtering and citations.

Document chunking is a preprocessing step that turns documents into retrievable passages. A typical RAG ingestion pipeline extracts text, removes unwanted formatting, divides the text into chunks, attaches metadata, generates embeddings, and writes the results to a searchable index. At query time, the application retrieves relevant chunks and supplies their text to a language model. Chunking is not summarization: it generally partitions source content rather than replacing it with a shorter interpretation.

Fixed-size chunking divides text using a token or character limit, often with overlap between adjacent chunks. Token-based limits are useful because embedding and generation models enforce token budgets, although different models can use different tokenizers. Structure-aware chunking follows headings, paragraphs, sentences, or document sections. Semantic chunking identifies boundaries based on changes in meaning. Hierarchical chunking creates smaller child passages within larger parent sections so retrieval can locate precise evidence while returning broader context.

For example, a maintenance manual might describe an error code in one paragraph and its required safety precautions in the next. Splitting exactly between those paragraphs could retrieve the repair procedure without the warning. Preserving the section or adding controlled overlap can keep the instructions together. Tables require similar care: a row of values without its column headers or units may be misleading. Scanned documents often need optical character recognition and layout extraction before useful chunk boundaries can be selected.

Small chunks can isolate relevant facts, but they may lose definitions, qualifications, or relationships that span passages. Large chunks preserve more context but can dilute embedding relevance and consume more of the generation model's context window. Overlap reduces boundary-related information loss, yet increases embedded text volume, storage, and potentially redundant retrieval results. There is no universally correct chunk size or overlap percentage. A starting configuration such as 500-token chunks with 50-token overlap is an experiment, not a standard.

Metadata should preserve provenance and useful retrieval constraints. Common fields include the source URI, document identifier, title, heading path, page number where available, version, timestamp, language, and access-control labels. Document-level metadata can be inherited by chunks, while section or page metadata may need extraction during parsing. Metadata filters can restrict results to the correct product version or tenant, but sensitive-content access must be enforced through trusted authorization logic rather than relying on the model to ignore unauthorized passages.

In a cloud implementation, object storage can hold source files while managed ingestion or custom compute performs parsing and chunking. A vector database stores chunk embeddings together with text and metadata, or references to that text. Configure the vector field dimension to match the embedding model and select supported indexing and similarity settings appropriate to that model. Chunk size and embedding dimensionality are separate decisions: changing the number of tokens in a chunk does not change the model's output vector dimension.

Amazon Bedrock Knowledge Bases supports fixed-size, semantic, hierarchical, and no-chunking configurations for supported ingestion paths. No chunking treats each document as one chunk; it does not remove embedding-model input limits. Select the strategy when configuring the data source, because its chunking configuration cannot subsequently be changed in place. A different strategy requires a new data source and re-ingestion. With hierarchical retrieval, replacing matching child chunks with their parents can produce fewer returned results than the requested retrieval count.

Evaluate chunking with representative questions and known supporting passages. Measure evidence recall, answer correctness, citation quality, latency, and cost while varying chunk boundaries, overlap, retrieval count, metadata filters, and reranking. Retrieving more chunks does not automatically improve answers: duplicates and irrelevant context can crowd out useful evidence. Version the parsing and chunking configuration, and reprocess affected documents when it changes so the index remains consistent with the intended retrieval behavior.

Key aspects of Document Chunking

Effective document chunking preserves meaning and provenance while balancing retrieval quality, model constraints, and ingestion and query costs.

Context-preserving boundaries

Choose boundaries that keep related statements, qualifications, and document structure together. Preserve table headers, section titles, and other context that makes a passage understandable on its own.

Size and overlap control

Set chunk limits with the embedding model's input budget and expected question types in mind. Use overlap selectively to protect boundary-spanning information without creating excessive duplication.

Multiple chunking strategies

Use fixed-size chunking for predictable processing, structure-aware or semantic chunking for coherent passages, and hierarchical chunking when precise matching requires broader surrounding context. Validate the choice against the actual document collection.

Metadata and provenance

Attach source identifiers, versions, section information, and relevant filter attributes to each chunk. Keep authorization metadata trustworthy and preserve enough provenance to support useful citations.

Embedding and index compatibility

Ensure each chunk fits the embedding model's input constraints and the index accepts that model's vector dimensions. Store retrievable text and metadata alongside vectors or maintain reliable references to them.

Measured retrieval optimization

Tune chunking together with retrieval count, filtering, and reranking using representative questions. Track retrieval quality and answer quality separately, because finding relevant evidence does not guarantee that the model uses it correctly.

Cloud services for Document Chunking

Amazon S3 holds source documents and associated metadata. Amazon Textract can extract text and layout from scanned inputs, while AWS Lambda can apply custom cleanup, metadata enrichment, or chunking where needed. Amazon Bedrock Knowledge Bases can manage supported ingestion and embedding workflows, with a supported vector store such as an appropriately configured Amazon OpenSearch Service deployment holding searchable chunk representations. During retrieval, the application applies authorized metadata filters, selects relevant passages, and passes their text and provenance to the generation model. Evaluate the complete pipeline together: improved extraction or chunk boundaries can help retrieval, but incorrect vector configuration, stale metadata, or poor context selection can still produce weak answers.

Amazon Bedrock

Amazon Bedrock Knowledge Bases manages document ingestion, configurable chunking, embedding generation, and retrieval using supported vector stores. Engineers configure the data source's chunking strategy and metadata, then tune retrieval filters, result counts, and supported reranking options.

Open Amazon Bedrock →
Amazon OpenSearch Service image Amazon OpenSearch Service

Amazon OpenSearch Service can index chunk text, metadata, and embeddings for vector and lexical retrieval. Its vector fields, search configuration, and metadata filtering must align with the embedding model and application requirements; chunk creation can occur upstream.

Open Amazon OpenSearch Service →
Amazon Simple Storage Service image Amazon S3

Amazon S3 stores original documents and preprocessing outputs for RAG ingestion. When used as a Bedrock Knowledge Bases data source, supported metadata sidecar files can supply document attributes that become available for retrieval filtering.

Open Amazon S3 →
Amazon Textract image Amazon Textract

Amazon Textract extracts text and structured information from scanned documents and images. Its layout and table information can help preprocessing logic preserve meaningful boundaries instead of splitting an unstructured OCR text stream arbitrarily.

Open Amazon Textract →
AWS Lambda image AWS Lambda

AWS Lambda can run custom document transformation and chunking logic, including supported custom transformation integrations with Bedrock Knowledge Bases. Processing must fit Lambda's execution and resource limits; large documents or expensive transformations may require a different compute environment.

Open AWS Lambda →