CLOUD CONCEPT

Hierarchical Chunking

Hierarchical chunking divides documents into linked parent and child segments so retrieval can locate precise passages while supplying broader context to a foundation model.

Cloud Concepts Hub →

What is Hierarchical Chunking

Hierarchical chunking organizes document segments at multiple levels of detail, such as sections containing smaller passages. In retrieval-augmented generation, this separates the unit used to find relevant information from the unit supplied as context, helping preserve definitions, qualifications, and surrounding explanations.

Hierarchical chunking is a document segmentation strategy that preserves relationships between larger and smaller pieces of content. A parent chunk might represent a section of a technical manual, while its child chunks represent individual passages within that section. Retrieval can search the smaller chunks for precise matches and then provide their parent content to a foundation model. This addresses a common retrieval-augmented generation problem: a passage can match a question closely but omit information necessary to interpret the answer correctly.

For example, an operational runbook might contain a section about database failover, with separate passages covering prerequisites, execution, and recovery checks. A question about initiating failover may match the execution passage. Returning its parent section can also expose the prerequisite that replication lag must remain below a specified threshold. The hierarchy therefore supports both precise discovery and context preservation, rather than forcing one chunk size to serve both purposes.

During ingestion, a custom pipeline can parse headings, paragraphs, tables, and other structural elements before constructing parent and child records. Each child should retain a parent identifier, document identifier, source location, and document version. Embeddings commonly represent child passages, while parent text remains accessible through a document store or the retrieval system. Some implementations also index larger levels, but embedding every level is not a requirement of hierarchical chunking.

In cloud architectures, object storage can hold source documents and processed content, compute functions can implement segmentation, and a vector search service can locate relevant children. Retrieval logic then resolves parent identifiers, removes duplicate parents, and selects context within the model's token budget. Amazon Bedrock Knowledge Bases offers managed hierarchical chunking with parent and child token sizes and configurable overlap. Its retrieval behavior replaces retrieved child chunks with their parents, so the returned result count can be lower than the requested number of results.

Managed token-based hierarchy should not be confused with understanding a document's logical structure. If requirements demand that chunks follow policy clauses, Markdown headings, or complete procedures, custom processing may be necessary. AWS Lambda can implement fixed-size chunking as a baseline or execute custom hierarchy-building logic. Splitting text into equal token windows alone is not hierarchical chunking unless the implementation also establishes and uses relationships between levels.

The main trade-off is between retrieval specificity and context expansion. Small child chunks can isolate useful evidence, but excessively short passages may lack enough meaning for effective embeddings. Large parents can preserve qualifications but increase model input cost, consume context capacity, and introduce distracting material. Overlap can protect boundary-spanning statements, although it increases duplication and indexing work. Parent deduplication prevents several matching children from repeatedly adding the same section to a prompt.

Evaluate the strategy against fixed-size segmentation using representative questions, including questions that require exceptions, definitions, or adjacent procedural steps. Measure evidence retrieval, answer correctness, citation accuracy, latency, and context token consumption. Apply authorization checks to expanded parent content, not only matched children, so expansion cannot disclose restricted material. Keep related chunks consistent during updates and deletions. Hierarchical chunking is neither a guarantee of better answers nor a substitute for semantic chunking: hierarchy describes relationships between segments, while semantic segmentation describes how boundaries are chosen.

Key aspects of Hierarchical Chunking

Hierarchical chunking combines linked document segments, precise retrieval, controlled context expansion, and consistent metadata to balance answer quality with operational cost.

Linked levels of detail

Maintain explicit relationships between broad parent segments and smaller child passages. Stable identifiers let retrieval resolve a matching passage to its surrounding section without relying on text similarity alone.

Separate retrieval and context units

Use small passages for precise matching and larger segments for model context when appropriate. Deduplicate shared parents and enforce a context budget before assembling the prompt.

Structure-aware segmentation

Custom processing can respect headings, clauses, paragraphs, and table boundaries. Token limits still matter, so oversized structural units may need further subdivision while retaining their relationships.

Configurable size and overlap

Tune parent size, child size, and overlap to the document collection and expected questions. Compare configurations empirically rather than assuming that larger parents or more overlap always improve retrieval.

Traceability and access control

Preserve source locations, document versions, and authorization metadata across the hierarchy. Verify access to expanded parent content and remove obsolete descendants when a source changes.

Quality and cost evaluation

Assess whether context expansion improves evidence coverage and answer correctness relative to simpler segmentation. Track additional context tokens, indexing overhead, and retrieval latency alongside quality.

Cloud services for Hierarchical Chunking

Amazon S3 can hold source documents, while AWS Lambda parses their structure and produces linked parent and child segments. In a custom retrieval architecture, Amazon OpenSearch Service searches child embeddings, and application logic resolves matching children to authorized parent content before invoking a foundation model through Amazon Bedrock. Alternatively, Amazon Bedrock Knowledge Bases can manage hierarchical chunking and parent substitution using its supported configuration. In either approach, engineers must tune segmentation, prevent duplicate context, preserve source references, and evaluate answer quality against token consumption and latency.

Amazon Bedrock

Amazon Bedrock Knowledge Bases supports managed hierarchical chunking using parent and child chunk sizes. At retrieval time, matching child chunks are replaced with parent chunks, which can reduce the number of distinct returned results.

Open Amazon Bedrock →
AWS Lambda image AWS Lambda

AWS Lambda can run custom document processing that identifies structural boundaries and creates parent-child relationships. It can also implement fixed-size segmentation for comparison; fixed-size splitting does not create a hierarchy by itself.

Open AWS Lambda →
Amazon OpenSearch Service image Amazon OpenSearch Service

Amazon OpenSearch Service can index child embeddings and metadata for vector or hybrid retrieval. In a custom architecture, application logic uses parent identifiers from search results to fetch broader context; the search index does not create those relationships automatically.

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

Amazon S3 can store original documents and processed parent content for an ingestion pipeline. Custom retrieval applications can use stored object references to resolve parent text while preserving source and version information.

Open Amazon S3 →