Recommended resources
The freely available resources this lesson will direct you to.
Hello! Welcome back to our course on building AI and LLM systems.
In our last lesson, we introduced Retrieval-Augmented Generation (RAG) as a powerful pattern for making LLMs more factual and reliable. We broke down the RAG pipeline into its key stages, noting that the offline ingestion process begins with loading and preparing documents for a knowledge base.
Today, we'll dive into the first and one of the most critical steps of that ingestion process: document chunking. How you split your documents has a significant impact on your RAG system's performance. By the end of this lesson, you will be able to compare common document chunking strategies, understanding their mechanics, trade-offs, and ideal use cases.
The Core Challenge: Finding the Right Balance
Before we get into specific strategies, let's understand the fundamental challenge of chunking. When you split a document, you're making a trade-off between retrieval precision and context preservation.
- Small Chunks: Lead to more precise retrieval. The embedding for a small chunk is very specific, making it easier to match a user's query. However, the chunk might lack the surrounding context needed to fully answer the question.
- Large Chunks: Preserve more context, ensuring that related ideas stay together. However, the embedding can become "diluted" or too general, making it harder to find a precise match for a specific query.
The goal of a good chunking strategy is to create chunks that are small enough for accurate retrieval but large enough to contain semantically complete information.
To frame this, let's start with a high-level overview. This article from the Databricks community clearly outlines why chunking is so important.
Mastering Chunking Strategies for RAG - Databricks Community
This article, 'Mastering Chunking Strategies for RAG', explains the foundational reasons why a thoughtful chunking strategy is essential for any high-performing RAG system.
Read the section titled 'Why Chunking Matters in RAG'. Focus on the four key reasons provided: Context Window Constraints, Improved Retrieval Efficiency, Computational Optimization, and Enhanced Relevance.
Now, let's explore the most common strategies for achieving this balance.
Strategy 1: Fixed-Size Chunking
The most straightforward approach is fixed-size chunking. You simply decide on a chunk size (e.g., 500 characters) and split the document accordingly.
- Concept: Segment text into pieces of a fixed length. This can be based on character count or, more effectively, token count, as tokens are the units LLMs and embedding models actually process.
- Overlap: To mitigate the risk of cutting a sentence or idea in half, a "chunk overlap" is often used. This means the end of one chunk is repeated at the beginning of the next, creating a sliding window that helps preserve continuity.
The following video provides a clear demonstration of both character-based and token-based fixed-size chunking.
The BEST Way to Chunk Text for RAG
In this video, 'The BEST Way to Chunk Text for RAG', Adam Lucek demonstrates the simplest chunking methods and explains the important distinction between character and token counting.
Watch from 03:42 to 10:06. The first part (until 06:28) covers character-based splitting and overlap. The second part explains why token-based splitting is often preferred and shows how it works.
Fixed-Size Chunking: Pros and Cons
- Advantages:
- Simple and very fast to implement.
- Creates predictable chunk sizes, which can simplify batch processing.
- Disadvantages:
- Completely ignores the document's structure and semantic meaning.
- Frequently cuts sentences or even words in half, destroying context.
Best Fit: Useful for quick prototyping or for processing highly uniform, unstructured text where semantic boundaries are less critical.
Strategy 2: Recursive Chunking
A more intelligent approach is recursive chunking. This has become the go-to starting point for most RAG applications because it balances simplicity with a respect for document structure.
- Concept: This method uses a prioritized list of separators to split the text. It first tries to split by the highest-priority separator (e.g., paragraph breaks
\n\n). If any of the resulting chunks are still too large, it "recursively" applies the next separator in the list (e.g., line breaks\n, then sentences., then words) to those oversized chunks until all are within the specified size limit.
This flowchart provides a great visual model of the process.

To see this in action, the next video offers a detailed walkthrough of recursive character text splitting.
The 5 Levels Of Text Splitting For Retrieval
In this segment from 'The 5 Levels Of Text Splitting', Greg Kamradt gives an excellent, in-depth explanation of recursive character text splitting, which he calls 'Level 2'. He also demonstrates a visualizer tool that makes the concept very intuitive.
Watch from 15:58 to 20:59. Pay close attention to how the list of separators works and why this method is better at preserving the natural structure of the text compared to fixed-size chunking.
Recursive Chunking: Pros and Cons
- Advantages:
- Preserves natural semantic boundaries (paragraphs, sentences) where possible.
- More context-aware than fixed-size chunking.
- Still relatively simple and fast to implement.
- Highly effective for a wide range of text documents (articles, reports, etc.).
- Disadvantages:
- Results in variable chunk sizes, which can be less convenient for batching.
Best Fit: The recommended default strategy for most RAG applications involving general text documents. It offers a great balance of performance and simplicity.
A Glimpse at More Advanced Strategies
Fixed-size and recursive chunking are the most common methods, but the field is evolving. It's useful to be aware of more advanced, specialized strategies.

-
Document-Specific Chunking: For structured content like code or Markdown, you can use splitters that understand that specific structure. For example, a Python-aware splitter would try to keep entire functions or classes in a single chunk, which is much more effective than splitting them randomly. LangChain's
RecursiveCharacterTextSplitterhas built-in support for many languages. -
Semantic Chunking: This is a more advanced, computationally intensive method. Instead of splitting by character count or separators, it splits based on meaning.
- How it works: The document is first split into sentences. Each sentence is embedded, and the semantic similarity between consecutive sentences is calculated. When there's a sharp drop in similarity (a "semantic breakpoint"), it indicates a topic shift, and a new chunk is created.
- Trade-off: This creates highly coherent chunks but is slower and more expensive, as it requires making API calls to an embedding model during the chunking process itself.
Comparison and Choosing a Strategy
So, which strategy should you use? There is no single "best" answer; the optimal choice depends on your documents, your queries, and your project constraints (budget, latency).
The Firecrawl blog provides an excellent summary of research and a practical decision framework.
Best Chunking Strategies for RAG in 2025 - Firecrawl
This article, 'Best Chunking Strategies for RAG in 2025', synthesizes findings from recent benchmarks and offers a clear, actionable framework for choosing a strategy.
Please read the sections 'What the Research Says About RAG Chunking Strategies' and 'Decision Framework'. The table in the decision framework is particularly useful for comparing strategies at a glance.
Here is a summary table to help you compare the main strategies we've discussed:
| Strategy | Simplicity & Speed | Context Preservation | Cost | Best For |
|---|---|---|---|---|
| Fixed-Size | Very High | Low | Very Low | Quick prototypes, uniform/unstructured text. |
| Recursive | High | Medium | Low | Default starting point. Most text documents. |
| Document-Specific | Medium | High (for its domain) | Low | Code, Markdown, structured reports. |
| Semantic | Low | High | High | Dense, unstructured text where accuracy is critical. |
Conclusion
In this lesson, we've explored the fundamental task of document chunking and compared the most common strategies.
Key Takeaways:
- Chunking is a trade-off between retrieval precision (smaller chunks) and context preservation (larger chunks).
- Fixed-Size Chunking is the simplest method but often breaks the semantic flow of a document.
- Recursive Chunking is the recommended starting point for most applications, as it respects natural document boundaries (paragraphs, sentences) while being efficient.
- Advanced strategies like Semantic and Document-Specific chunking offer higher performance for specific use cases but come with increased complexity and cost.
- The right strategy depends on your specific data and application requirements. Always start with a simple baseline (like recursive) and evaluate its performance before moving to more complex methods.
In our next lesson, we'll put this knowledge into practice. You'll write the code to implement a complete, basic RAG pipeline: chunking documents, ingesting them into a vector store, retrieving them based on a query, and generating a final, fact-grounded answer.