CLOUD CONCEPT

Text Chunking

Text chunking divides documents or other text into smaller, meaningful units for embedding, retrieval, and processing within model input limits.

Cloud Concepts Hub →

What is Text Chunking

Text chunking controls how much information is processed together and which context remains attached to each passage. In generative AI applications, effective chunking helps preserve evidence, improve retrieval relevance, and prevent information loss caused by oversized inputs or poorly chosen boundaries.

Text chunking is the division of text into smaller units that can be processed independently or combined selectively. It is commonly used during document ingestion for retrieval-augmented generation, or RAG, and when processing documents that exceed a foundation model's input capacity. Chunking is not the same as tokenization: tokenization converts text into model-specific tokens, while chunking groups text into useful processing units.

In a cloud-based RAG pipeline, documents are extracted, cleaned, divided into chunks, embedded, and stored in a searchable index. Each chunk should retain metadata such as its source identifier, document version, section heading, page number, and access-control attributes. At query time, the application retrieves relevant chunks and places selected evidence into the generation prompt. Stable identifiers and source offsets make it possible to diagnose missing passages and generate traceable citations.

Chunk boundaries should reflect both document structure and model constraints. Fixed-size splitting is predictable but can separate a definition from its qualifications. Structure-aware splitting respects paragraphs, headings, code blocks, and tables. Semantic splitting attempts to detect topic changes, while hierarchical approaches maintain relationships between small searchable passages and larger sections. For example, a support manual might use individual troubleshooting procedures as chunks rather than splitting every page at an arbitrary character count.

Chunk size creates a practical trade-off. Small chunks can improve retrieval precision but may omit essential context; large chunks can include useful explanations but dilute the embedding with unrelated topics. Overlap can preserve information near boundaries, but increases embedding cost, index size, and duplicate retrieval. A starting experiment might compare 400-token and 800-token chunks with modest overlap, but no size or overlap percentage is universally correct. Evaluate representative questions and document types rather than adopting a fixed setting without testing.

Token budgeting must consider the complete model request, not just retrieved text. Account for system instructions, conversation history, user input, tool definitions where applicable, formatting overhead, and the model's output allowance under its documented limits. Embedding models also have their own input limits and tokenizers. Character counts are only approximations, especially for multilingual text or code. Dynamic chunking can adapt boundaries and sizes to document structure and current processing budgets; query-time context packing separately determines which retrieved chunks fit in a generation request.

When information appears to be missing, distinguish explicit context-window errors from silent truncation introduced by application code, tokenizers, connectors, or model configuration. Record token counts, chunk counts, source coverage, ingestion failures, assembled prompt sizes, and relevant finish reasons without exposing sensitive content. Check whether the missing passage survived extraction, appeared in a chunk, reached the index, was retrieved, and remained in the final prompt. An output stopped by a generation-token limit is a different problem from omitted input evidence.

Chunking a long document does not ensure that every part is processed. For an exhaustive review, track all chunks through processing, retry failures, and reconcile results across boundaries. A contract review may require separate checks for obligations, exceptions, and definitions, followed by a consolidation step that links their source passages. Hierarchical summarization can reduce context requirements, but summaries are lossy and may remove details needed later. Preserve original chunks so important claims can be checked against source text.

Retrieval troubleshooting should separate chunking defects from extraction, embedding, and search defects. Inspect retrieved passages for representative queries and measure whether they contain the evidence required to answer. Check malformed text, repeated headers, broken tables, missing headings, and inconsistent preprocessing between ingestion and querying. Verify embedding-model compatibility, vector dimensions, similarity configuration, and model-specific normalization requirements. A valid vector does not prove that the source content was complete or semantically useful.

Monitor retrieval quality as document layouts, languages, query patterns, or embedding models change. Compare evidence recall, ranking quality, answer relevance, groundedness, latency, and cost against a labeled evaluation set. Changing chunk boundaries requires regenerating affected chunks and embeddings and removing stale entries; changing embedding models usually requires re-embedding indexed content. If retrieval finds the correct evidence but answers remain poor, investigate prompt organization, conflicting context, duplication, and generation behavior instead of assuming that chunk size is always the cause.

Key aspects of Text Chunking

Effective chunking preserves meaning, respects model limits, maintains source traceability, and is tuned through retrieval and end-to-end processing evaluations.

Meaning-preserving boundaries

Split around headings, paragraphs, procedures, or other meaningful structures whenever practical. Keep qualifications, table headers, and definitions attached to the passages that depend on them.

Model-aware token budgets

Size chunks using the relevant model's tokenizer and documented input limits. Budget the complete generation request, including instructions and history, and reserve an appropriate output allowance.

Size, overlap, and retrieval trade-offs

Balance narrow, precise passages against enough surrounding context to answer correctly. Test overlap against its additional storage, embedding, and duplicate-context costs.

Adaptive processing and complete coverage

Adapt chunk sizes to document structure and processing constraints rather than treating every input identically. For exhaustive tasks, track every chunk through processing and reconcile dependencies across boundaries.

Traceability and consistent indexing

Preserve source locations, document versions, chunk relationships, and authorization metadata. Rebuild affected embeddings and remove obsolete index entries when chunking rules or source documents change.

Evidence-driven diagnostics

Trace missing evidence from extraction through chunking, embedding, retrieval, and prompt assembly. Use labeled queries and operational metrics to distinguish chunking problems from vectorization errors, truncation, and changes in the document or query distribution.

Cloud services for Text Chunking

A document pipeline can use Amazon Textract to extract text and structure, then AWS Lambda to clean the results, preserve metadata, and create model-sized chunks. Knowledge Bases for Amazon Bedrock can manage supported ingestion and chunking workflows, while Amazon OpenSearch Service can provide the retrieval index. At inference time, retrieved passages are selected and packed into a prompt for a Bedrock model. Troubleshooting should inspect each boundary independently: extraction completeness, chunk coverage, embedding compatibility, retrieval relevance, and final prompt size. Managed components reduce implementation work but do not eliminate the need for evaluation, authorization checks, or truncation diagnostics.

Amazon Bedrock

Knowledge Bases for Amazon Bedrock supports managed ingestion and configurable chunking strategies for RAG workflows. Applications using Bedrock models must still account for model-specific input limits, retrieved-context size, and generation-token settings.

Open Amazon Bedrock →
Amazon OpenSearch Service image Amazon OpenSearch Service

Amazon OpenSearch Service can index chunk text, embeddings, and metadata for vector, keyword, or hybrid retrieval. Chunking quality affects ranking and index size, while vector mappings, similarity settings, filters, and query configuration require separate validation.

Open Amazon OpenSearch Service →
AWS Lambda image AWS Lambda

AWS Lambda can run custom preprocessing and chunking logic in event-driven ingestion pipelines. Functions can attach provenance metadata, enforce token limits, and emit diagnostics, with work partitioned to fit execution-time and memory limits.

Open AWS Lambda →
Amazon Textract image Amazon Textract

Amazon Textract extracts text and document structure from supported document inputs before chunking. Its layout and table information can help a downstream chunker preserve reading order and relationships that plain-text extraction might lose.

Open Amazon Textract →