liveBook · Manning

Hierarchical chunking

As explained in Generative AI in Action

Hierarchical chunking is a chunking method that divides text according to nested structural levels such as chapters, sections, and subsections.

Hierarchical chunking divides text according to nested structural levels, such as chapters, sections, and subsections. It treats document organization as a guide for creating retrieval units. section 7.7.2

Use structural boundaries alongside other chunking choices:

  • Compare nested section boundaries with sentence, fixed-length, token-based, and semantic splitting. section 7.7.2
  • Account for trade-offs: fixed-length splitting can cut information and lose context, while structural breaks preserve document organization but may produce variable chunk sizes. section 7.7.2
Table 7.3 Chunking approaches
Chunking approach
Description
Fixed length
Divide documents into chunks of a fixed number of words or tokens. This is straightforward but may sometimes split information that ideally should be kept together.
Sliding window
Use a fixed-sized sliding window with or without overlapping data. This can ensure that important boundaries within the text are not missed, but it can also lead to redundancy if there’s significant overlap.
Punctuation based
Divide the text based on punctuation, such as paragraphs or sections. This is less arbitrary than fixed-length chunking and often preserves the semantic integrity of the content. However, it can result in variable chunk sizes.
Topic or section breaks
In structured documents such as Wikipedia articles, natural breaks like sections or subsections can be used to define chunks. This method ensures that the content within a chunk is semantically coherent.
Adaptive
Use algorithms or models that adaptively determine the best way to chunk documents based on their content. This can be more complex but might yield semantically cohesive chunks.

Compare hierarchical or topic-based boundaries with fixed-length, sliding-window, and punctuation-based approaches when selecting a retrieval strategy. section 7.7.2

How Generative AI in Action covers it

How deep it goes
Defines nested structural splitting and contrasts alternatives, but does not provide hierarchical implementation details.
Examples
Uses the UK Constitution article from Wikipedia to illustrate how different chunking strategies affect context and information boundaries.
What you can do after
Evaluate/understand how document structure can guide chunk boundaries and how alternatives affect context preservation.
How it connects
Connects hierarchical chunking with retrieval-augmented generation, semantic chunking, sentence splitting, fixed-length splitting, and token-based splitting.

Also explained in

Compare how 2 books explain hierarchical chunking →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.