Introduction
In our last lesson, we established the "why" and "what" of Retrieval-Augmented Generation (RAG). You learned that RAG overcomes an LLM's limitations—like knowledge cutoffs and hallucinations—by connecting it to an external knowledge base at the moment of inference. We outlined the two core phases: an offline indexing pipeline to prepare the knowledge and an online retrieval pipeline to use it.
Today, we take our first concrete step into the indexing pipeline. The goal of this lesson is to learn how to implement various document chunking strategies, considering the trade-offs between chunk size and overlap. This is arguably one of the most critical steps in building a high-performing RAG system. How you break down your documents directly determines what the system can find and, ultimately, the quality of the answers it generates. Think of it as organizing your "open book" before the exam; poor organization makes finding the right information impossible, no matter how smart the student.
The Fundamental Trade-off: Precision vs. Context
Before diving into specific methods, it's crucial to understand the central dilemma of chunking. Every strategy navigates a trade-off between retrieval precision and context preservation.

Let's break this down:
-
Small Chunks (e.g., 128-256 tokens):
- Pro: They are dense with specific information. When a user asks a factual question, a small, focused chunk is more likely to be a highly relevant match, leading to better precision.
- Con: They lack broader context. An LLM might receive a single sentence or two and not have enough surrounding information to understand nuance, relationships, or the bigger picture.
-
Large Chunks (e.g., 1024+ tokens):
- Pro: They preserve significant context, helping the LLM understand complex relationships and generate more comprehensive answers.
- Con: They can be "noisy." A large chunk might contain the answer, but it could be buried among paragraphs of less relevant text. This dilutes the semantic signal of the chunk's embedding, making it harder for the retrieval system to identify it as the best match.
Finding the right balance is key and depends on your documents and the types of questions you expect users to ask.
Core Concepts: Chunk Size and Overlap
Two parameters govern nearly all chunking strategies: chunk_size and chunk_overlap.

-
Chunk Size: This determines the target size of each chunk. It's usually measured in characters or, more appropriately for LLMs, in tokens. Aligning your chunk size with the token limits of your embedding model and the context window of your LLM is a critical consideration.
-
Chunk Overlap: This defines how many characters or tokens are repeated between consecutive chunks. Overlap is a simple but powerful technique to mitigate the risk of losing important context that falls at the boundary of a split. For example, if a sentence that bridges two ideas is split in half, having overlap ensures that the complete sentence is present in at least one of the chunks, and its full context is preserved across two. A common starting point is an overlap of 10-20% of the chunk size.
To see these concepts in action, let's watch a segment from a practical walkthrough.
The 5 Levels Of Text Splitting For Retrieval
The video 'The 5 Levels Of Text Splitting For Retrieval' by Greg Kamradt provides a fantastic introduction to the mechanics of chunk size and overlap. He even built a visualizer to make it intuitive.
Watch from 06:49 to 13:25. Focus on how changing the chunk_size and chunk_overlap parameters affects the final chunks. Note the problem he points out with simple character splitting: it can cut words and sentences in half.
A Survey of Chunking Strategies
Now that you understand the basic parameters, let's explore the hierarchy of common chunking strategies, from the most basic to the most advanced.
1. Size-Based Chunking (Character or Token)
This is the most straightforward method, as you saw in the video. You simply set a fixed size (in characters or tokens) and split the document accordingly.
- Character Splitting: Counts characters. It's fast but naive, as it has no concept of words or sentences.
- Token Splitting: Counts tokens using a specific tokenizer (e.g.,
cl100k_basefor OpenAI models). This is more aligned with how models process text and is generally preferred over character splitting.
Best Chunking Strategies for RAG in 2025
The article 'Best Chunking Strategies for RAG in 2025' from Firecrawl provides concise explanations and code examples for each strategy. Let's start with their section on Size-Based Chunking.
Read the section 'Size-Based Chunking'. Pay attention to the distinction between character-based and token-based splitting and the provided LangChain implementation examples.
When to use it: Excellent for quick prototyping or when your documents are very uniform and unstructured. However, its disregard for semantic boundaries makes it a poor choice for most production systems.
2. Recursive Character Splitting
This is the workhorse of RAG and the recommended starting point for most applications. Instead of a hard cut-off, it tries to split text along a prioritized list of separators.
The default hierarchy in frameworks like LangChain is typically:
- Paragraphs (
\n\n) - Lines (
\n) - Sentences (
.) - Words (
) - Characters (
'')
The splitter tries to create chunks of your desired size, but it will "recursively" move down the separator list to find a natural breaking point. This keeps related content, like paragraphs and sentences, together as much as possible.
The 5 Levels Of Text Splitting For Retrieval
Let's return to Greg Kamradt's video for a clear explanation of how the recursive splitter intelligently uses document structure.
Watch from 15:58 to 20:59. Notice how this method is much better at preserving semantic units (like paragraphs) compared to the fixed-size character splitter from the previous segment. Greg's endorsement of this as his 'go-to splitter' is a strong signal of its practical value.
When to use it: This is your default strategy. It offers a great balance of simplicity, speed, and performance by respecting the natural structure of the text.
3. Content-Aware Splitting (Sentence, Page, etc.)
These methods go a step further by using the specific format of the document to guide chunking.
- Sentence Splitting: Uses NLP libraries (like NLTK or spaCy) to accurately identify sentence boundaries. It then groups these sentences into chunks. This is excellent for conversational data or Q&A pairs where preserving the full sentence is critical.
- Page-Level Splitting: For documents like PDFs, it treats each page as a chunk. This is highly effective for visually structured documents (e.g., financial reports, presentation slides) where a page represents a coherent unit of information.
The Firecrawl article you looked at earlier has great sections on both of these.
Best Chunking Strategies for RAG in 2025
Let's quickly review the sections on Sentence-Based and Page-Level chunking in the Firecrawl article to understand their specific use cases.
Skim through the sections 'Sentence-Based Chunking' and 'Page-Level Chunking'. Note the different libraries used (LlamaIndex for sentence, Unstructured.io for page) and the types of documents each is best suited for.
When to use them: When your document format has clear semantic boundaries (sentences in a chat log, pages in a report) that you want to preserve perfectly.
4. Semantic Chunking
This is the most sophisticated approach. Instead of relying on character counts or structural markers, semantic chunking aims to split the text based on its meaning.
The process generally works by:
- Breaking text into smaller units (e.g., sentences).
- Embedding each unit.
- Calculating the cosine similarity between adjacent units.
- Identifying points where the similarity drops significantly, indicating a "topic shift." These points become the chunk boundaries.
This ensures that each chunk is as semantically coherent as possible.
The BEST Way to Chunk Text for RAG
The video 'The BEST Way to Chunk Text for RAG' by Adam Lucek provides an excellent summary of semantic chunking and its more advanced variants, drawing from the influential Chroma DB research.
Watch from 16:04 to 27:44. This segment covers three key ideas: Standard Semantic Chunker: Using embedding similarity to find topic breaks. Cluster Semantic Chunker: A more global optimization approach. LLM-Based Chunker: Using an LLM itself to decide where to split the text. Focus on the core concept behind each, as these represent the cutting edge of chunking research.
When to use it: When retrieval accuracy is your absolute top priority and you can afford the additional computational cost and complexity. It works best on dense, unstructured text where topic shifts are subtle.
The "So What?": A Data-Driven Decision Framework
You've now seen a spectrum of strategies, from simple and fast to complex and powerful. Which one should you choose? As an engineer, you know the answer is "it depends." The best choice is a trade-off between performance, cost, and complexity, and it's highly dependent on your data.
Fortunately, research from teams like Chroma provides empirical data to guide this decision. Their work is a fantastic "Anchor Resource" for this topic.
Evaluating Chunking Strategies for Retrieval | Chroma Research
The technical report 'Evaluating Chunking Strategies for Retrieval' by Chroma is the definitive research in this area. We won't read the whole paper, but understanding its conclusions is crucial for making informed decisions.
First, skim the section 'Chunking Algorithms' to see the list of methods they tested. Then, carefully review the 'Results' section and the main results table. Notice which strategies perform best on metrics like Recall and IoU (Intersection over Union). Pay attention to the surprising effectiveness of RecursiveCharacterTextSplitter with smaller chunk sizes and no overlap.
Based on this research and practical experience, here is a decision framework to guide your choice. This is adapted from the excellent Firecrawl article.
| Your Situation | Use This Strategy | Why |
|---|---|---|
| Default / Starting Point | Recursive Character Splitting | Best balance of performance, speed, and simplicity. Handles most text well. (Consistently high performer in Chroma's research). |
| Working with PDFs, reports, or slides | Page-Level Chunking | Preserves visual layout and structure. (Highest accuracy in NVIDIA's 2024 benchmarks for structured docs). |
| Max accuracy is critical, budget allows | Semantic Chunking | Can improve recall by detecting subtle topic shifts. (Chroma's Cluster and LLM variants showed top recall scores). |
| Quick Prototyping / MVP | Token-Based Splitting | Fastest to implement, but expect lower quality. |
| Processing code files | Recursive Splitting (with code separators) | Can be configured to respect function/class boundaries. |
| Conversational data / Q&A | Sentence-Based Splitting | Preserves complete conversational turns or question-answer pairs. |
General Recommendation:
Start with RecursiveCharacterTextSplitter with a chunk size of 200-512 tokens and an overlap of 10-20%. Measure your retrieval performance, and only move to more complex strategies like semantic chunking if you have a clear performance need and the budget for the increased computational cost.
Test your understanding!
You are building a RAG system for two different use cases:
- A chatbot for financial analysts that needs to answer questions based on 100-page quarterly earnings reports (PDFs) filled with tables, charts, and text. Accuracy is paramount.
- An internal documentation helper that answers developer questions based on a large collection of Markdown files (
.md) from your company's Confluence space. Speed and cost-effectiveness are important.
For each use case, which chunking strategy would you choose as your starting point and why? Justify your choice based on the trade-offs we've discussed.
Show answer
-
Financial Analyst Chatbot (PDFs): The best starting strategy here would be Page-Level Chunking.
- Reasoning: Financial reports are highly structured, with pages often corresponding to logical sections (e.g., Balance Sheet, Income Statement, Management's Discussion). Page-level chunking preserves this crucial visual and structural context, which is vital for correctly interpreting tables and charts. A simpler method like recursive splitting might break a table in half, rendering it useless. Given that accuracy is paramount, starting with a strategy that respects the document's inherent structure is the most robust approach.
-
Internal Documentation Helper (Markdown): The best starting strategy here is Recursive Character Splitting.
- Reasoning: Markdown files have a clear textual structure (headings, paragraphs, lists, code blocks) that the prioritized separators of a recursive splitter (
\n\n,\n, etc.) are perfectly designed to handle. This strategy is fast, computationally cheap, and highly effective for this type of semi-structured text. It provides a strong performance baseline without the cost and complexity of semantic chunking, aligning with the need for speed and cost-effectiveness.
- Reasoning: Markdown files have a clear textual structure (headings, paragraphs, lists, code blocks) that the prioritized separators of a recursive splitter (
Conclusion
You've now taken a deep dive into the art and science of document chunking. This isn't just a trivial preprocessing step; it's a fundamental engineering decision that profoundly impacts your RAG system's performance.
Key Takeaways:
- The Core Trade-off: Chunking always balances precision (from small chunks) against context (from large chunks).
- A Spectrum of Strategies: Methods range from simple Size-Based Splitting to structure-aware Recursive Splitting, and finally to meaning-aware Semantic Chunking.
- A Robust Default: For most applications involving unstructured or semi-structured text, Recursive Character Splitting is the recommended starting point due to its excellent balance of performance and efficiency.
- Data-Driven Decisions: The optimal strategy is dictated by your document type (PDF vs. text), query patterns (factual vs. analytical), and performance/cost constraints. Always start with a reasonable baseline and iterate based on evaluation metrics.
What's Next?
We've successfully broken our documents into meaningful, context-rich chunks. But these chunks are still just text. To perform the "retrieval" part of RAG, we need to convert them into a format that a machine can search through based on semantic meaning.
In the next lesson, you will learn how to generate high-quality embeddings for text chunks using sentence-transformer models. This will be our bridge from the world of text to the world of vectors, setting the stage for building our searchable knowledge base.