liveBook · Manning

Text chunk

As explained in Grokking AI Applications

A contiguous portion of text created by splitting a larger document into smaller units for processing or retrieval.

A text chunk is a contiguous portion of a larger document, split out for processing or retrieval. Think of it as a passage selected from a document: a question-answering system can retrieve a few relevant passages instead of passing the whole document to a language model. section 4.1 section 4.2

In a retrieval-augmented generation (RAG) workflow, chunks move through three stages:

  • Ingest: extract plain text from documents, split it into chunks, convert each chunk into a numeric embedding, and store the embeddings in a vector database. section 4.2
  • Retrieve: when a question arrives, search the database for the most relevant chunks using vector similarity. section 4.2
  • Generate: provide the retrieved chunks to a language model as context for its answer. Ingestion runs at setup and when documents change; retrieval and generation run for each question. section 4.1 section 4.5

A restaurant assistant

A restaurant PDF contains opening hours, delivery information, and menu prices. Its text can be split and embedded during setup. When a customer asks a question, the assistant searches for relevant chunks and uses them to generate an answer. section 4.2

Figure 4.13 The raw text is split into chunks, partially overlapping each other.

This diagram shows text split into chunks that partially overlap. section 4.2

Chunk size is a practical trade-off. Chunks that are too small may omit information needed for an answer; chunks that are too large can make context unwieldy and may be represented less effectively by their embeddings. Adjust chunk size and overlap, then compare responses. section 4.3

Also consider top k, the number of chunks returned by similarity search. Too few may exclude critical information, while too many may confuse the language model. Retrieval can only help when the selected chunks contain useful information. section 4.3 section 4.1

How Grokking AI Applications covers it

How deep it goes
Explains ingestion and retrieval stages and discusses chunk-size, overlap, and result-count tuning.
Examples
Uses a restaurant PDF with opening hours, delivery information, and menu prices to build a question-answering assistant.
What you can do after
Apply it via Langflow to split document text and tune chunk size and overlap for retrieval.
How it connects
Connects chunking to embeddings, vector databases, similarity search, and retrieval-augmented generation.

Also explained in

Compare how 20 books explain text chunk →

Related concepts

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