liveBook · Manning

Text chunk

As explained in Build an Advanced RAG Application (From Scratch)

A chunking strategy is a method for dividing source text or documents into smaller units for processing or retrieval.

Text chunking divides a long document into smaller, focused units before embedding and retrieval. It addresses embedding-model context limits: text beyond the model’s context window may be ignored. In a retrieval-augmented generation pipeline, chunks let search retrieve relevant evidence for a response rather than treating a full document as one undifferentiated unit. section 6.0 section 6.3

A useful chunk preserves a semantically coherent piece of information while staying within the allowed size. Splitting a hotel description into accommodation, dining, and spa chunks lets a query for spa services retrieve the spa chunk without unrelated details. This improves retrieval precision by making the embedded unit match the information sought. section 6.3.5

Choose a strategy by balancing semantic coherence, size limits, and processing cost:

  • Use paragraph-based splitting for structured documents when preserving complete thoughts and procedures matters, while watching for oversized chunks in dense papers. section 6.3.6
  • Use recursive chunking for dense or long-form text. Try large natural boundaries first, then fall back through smaller boundaries until the chunk fits. section 6.3.6
  • Use semantic chunking when topic boundaries and conceptual shifts should determine chunks, accepting added computation and domain-specific tuning. section 6.3.6

Recursive split with overlap

A recursive splitter can target 1,024 characters, attempting paragraphs, newlines, words, and punctuation before a character-level fallback. Add the last 50 characters of the preceding split to each later chunk to preserve continuity across boundaries. Applied to 479 research-paper records, this process produces 657 chunks ready for embedding, vector storage, and similarity search. section 6.4

Figure 6.4 Comparison of LLM Text Chunking Strategies

Compare chunking strategies visually to relate splitting choices to semantic boundaries and context constraints. section 6.3.6

How Build an Advanced RAG Application (From Scratch) covers it

How deep it goes
Explains context-limit motivation and strategy trade-offs, then implements recursive splitting with separator fallbacks and overlap.
Examples
Demonstrates hotel dining and spa segments, then splits research-paper abstracts into 657 overlapping chunks.
What it assumes
Assumes a vector-database and embedding workflow while grounding the need for splitting in embedding context limits.
What you can do after
Build it from scratch with a recursive Python splitter that prepares overlapping chunks for embedding and vector search.
How it connects
Connects document chunking to embeddings, vector databases, semantic search, retrieval-augmented generation, and context windows.

Also explained in

Compare how 24 books explain text chunk →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an Advanced RAG Application (From Scratch). The section links point to the parts of the book it draws on.