liveBook · Manning

Chunk granularity

As explained in AI Agents and Applications

Chunk size is the amount of text contained in each document chunk produced for separate processing or retrieval.

Chunk granularity controls how much text each independently processed or retrieved chunk contains. Smaller chunks focus on precise topics; larger chunks preserve broader context but reduce fine-grained focus. section 8.1.1 section 8.3

Choose granularity by matching the expected query and document characteristics:

  • Use smaller chunks for detailed questions that need precise semantic matches, accepting that surrounding context may be missing. section 8.3
  • Use larger chunks for broad questions that need background context, accepting less precise retrieval. section 8.3
  • Split by hierarchy when preserving coherent topics or related text, tables, and images matters; use fixed character, token, sentence, or word sizes for consistency. section 8.3.1 section 8.3.2
  • Test a range of fixed sizes because consistent chunk lengths can still split sentences and lose context. section 8.3.1

Parent and child chunks

A hybrid design stores larger parent chunks for answer context and embeds smaller child chunks for precise matching. In one configuration, a 3,000-character parent splitter and 500-character child splitter feed ParentDocumentRetriever; child matches retrieve the context-rich parent. section 8.4.1

Figure 8.3 Impact of chunk size on answer accuracy. Coarse chunks provide more context but less focus, and they are suitable for broader questions. Granular chunks provide less context but more focus, and they are suitable for more detailed questions.
figure

Compare coarse chunks, which provide context for broad questions, with granular chunks, which provide focus for detailed questions. section 8.3

Listing 8.3 Parent and child splitters for coarse and granular chunks
parent_splitter = RecursiveCharacterTextSplitter(
    chunk_size=3000)   #1
child_splitter = RecursiveCharacterTextSplitter(
    chunk_size=500)   #2

child_chunks_collection = Chroma(  #3
    collection_name="uk_child_chunks",
    embedding_function=OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY),
)

child_chunks_collection.reset_collection()   #4

doc_store = InMemoryStore()   #5

parent_doc_retriever = ParentDocumentRetriever(   #6
    vectorstore=child_chunks_collection,
    docstore=doc_store,
    child_splitter=child_splitter,
    parent_splitter=parent_splitter
)

Inspect a concrete LangChain configuration that separates parent and child splitter sizes and connects child embeddings to parent documents. section 8.4.1

How AI Agents and Applications covers it

How deep it goes
Explains retrieval trade-offs, splitting strategies, metadata considerations, and parent-child implementation, while deferring exhaustive size optimization to testing.
Examples
Uses hierarchical and fixed-size splitting, then demonstrates 3,000-character parents with 500-character children in ParentDocumentRetriever.
What it assumes
Assumes document retrieval and embeddings, while establishing the basic relationship between chunk size, query type, context, and focus.
What you can do after
Apply it via document splitters and ParentDocumentRetriever, then test sizes against query breadth, context needs, and retrieval precision.
How it connects
Connects chunk granularity to vector indexing, embeddings, document splitting, metadata search, and retrieval.

Also explained in

Compare how 3 books explain chunk granularity →

Related concepts

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