liveBook · Manning

Text chunk

As explained in AI Agents and Applications

A text splitter is a component that divides large text into smaller chunks or document objects.

A text chunk is a smaller piece of a larger text. In LangChain, a text splitter can turn one Document into a list of smaller Document objects. This lets an application process text that would be too large to send to a model at once. section 7.1.1 section 1.2.1

For a question-answering chatbot, chunking happens during ingestion: load content, split it, create an embedding for each chunk, and store the chunks and embeddings in a vector store. At query time, retrieval selects relevant chunks to supply as context. Smaller pieces also keep a search from matching only a large section with mixed relevance. section 6.1.3

Start with a searchable collection

For travel documents, create a RecursiveCharacterTextSplitter with chunk_size=500 and chunk_overlap=0. Pass loaded Documents to split_documents(), then add the resulting chunks to Chroma with an embedding model. This is a starting configuration, not a universally best size. section 7.2.1

Choose boundaries and size for the questions users will ask:

  • Use smaller chunks for precise questions. They are more focused, but may omit context needed for a complete answer. section 8.3
  • Use larger chunks for broad questions. They carry more context, but can obscure fine details during retrieval. section 8.3
  • Consider structure as well as size. An HTMLSectionSplitter can split a travel page at H1 and H2 headings; a RecursiveCharacterTextSplitter can produce coarser chunks instead. section 8.3.4
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 how coarse and granular chunks trade surrounding context for focus when answering different kinds of questions. section 8.3

When neither size works well alone, split large parent chunks into smaller child chunks. Search embeddings of the children, then return their context-rich parent chunks. ParentDocumentRetriever demonstrates this arrangement with separate document and vector stores. Chunk overlap and metadata are further choices to test when retrieval misses useful information. section 8.4.1 section 8.2

How AI Agents and Applications covers it

How deep it goes
Works through splitter configuration, document ingestion, size trade-offs, structural splitting, and parent–child retrieval rather than stopping at a definition.
Examples
Uses a token-split novel, searchable travel documents, HTML travel-page sections, and parent–child chunks.
What it assumes
Introduces the Document and TextSplitter roles before using Python notebooks, package installation, and an API key in worked implementations.
What you can do after
Apply it via LangChain splitters to create and compare searchable chunks, then retrieve larger parent context when small chunks prove insufficient.
How it connects
Connects chunks to Documents, embedding models, vector stores, retrievers, metadata, and retrieval-augmented generation.

Also explained in

Compare how 19 books explain text chunk →

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.