A RAG application can use a powerful embedding model and a well-configured vector database and still retrieve poor results.
One reason is often overlooked: how the original documents were divided before being stored.
This process is called chunking. It breaks large documents into smaller pieces that can be embedded, indexed, and retrieved when a user asks a question.
The challenge is deciding where to split the content. Chunks that are too small may lose important context, while chunks that are too large can contain unrelated information and make retrieval less precise.
There is no universally best chunking strategy. The right choice depends on your documents, search requirements, and the type of questions your RAG system needs to answer.
1. Fixed-Size Chunking
Fixed-size chunking divides documents into pieces using a predefined token or character limit.
For example, a document can be divided into chunks of 500 tokens, with an overlap of 50 tokens between consecutive chunks.
The overlap helps preserve information near boundaries that might otherwise be separated.
Imagine a paragraph explaining database connection pooling. If a chunk ends immediately after introducing a problem and the next chunk contains its solution, retrieving only one of them may provide incomplete context.
Overlap allows some information to appear in both chunks.
Advantages:
- Simple to implement.
- Predictable chunk sizes.
- Low processing overhead.
- Useful as an initial retrieval baseline.
Limitations:
- Can split sentences, paragraphs, or related explanations.
- May separate important information from its context.
- Overlap creates duplicate content and additional storage.
Fixed-size chunking is a reasonable starting point for relatively uniform text collections. However, it should be evaluated before being used across complex documents.
2. Recursive Chunking
Recursive chunking attempts to preserve natural text boundaries while respecting a maximum chunk size.
Instead of cutting the document at arbitrary positions immediately, the splitter tries increasingly smaller separators.
A typical splitting order is:
- Paragraph boundaries.
- Line breaks.
- Spaces between words.
- Individual characters when necessary.
For example, consider a technical article containing several paragraphs.
If an entire paragraph fits within the chunk limit, the splitter keeps it together. If it is too large, the splitter breaks it into smaller sections, trying to preserve sentence and word boundaries.
LangChain's RecursiveCharacterTextSplitter follows this general approach using a configurable list of separators. <Cite refs={["turn843564search9"]}/>
Advantages:
- Preserves natural text boundaries better than arbitrary fixed-size splitting.
- Works well with general articles and documentation.
- Maintains a configurable maximum chunk size.
- Relatively inexpensive compared with embedding-based semantic splitting.
Limitations:
- Does not fully understand the meaning of a document.
- Can still separate related information when size limits are reached.
- Results depend on the separators and chunk-size configuration.
For general-purpose RAG applications, recursive chunking is often a practical starting point because it balances implementation simplicity with better content boundaries.
3. Semantic Chunking
Semantic chunking focuses on meaning rather than fixed boundaries.
Instead of deciding chunk boundaries only through character counts or separators, it uses embeddings to identify changes in the meaning of the text.
Consider these sentences:
- "A database connection pool maintains reusable connections."
- "Applications borrow connections from the pool when executing queries."
- "Unused connections can be returned for subsequent requests."
- "Kubernetes manages container workloads across multiple nodes."
The first three sentences discuss the same concept. The fourth introduces a different subject.
A semantic chunker can identify this change and use it as a potential boundary.
A typical workflow looks like this:
- Divide the document into smaller sentence-level units.
- Generate embeddings for those units.
- Compare the semantic similarity of neighbouring units.
- Identify significant changes in meaning.
- Group related sentences into larger chunks.
Advantages:
- Can preserve meaningful groups of information.
- Useful when topic boundaries matter more than uniform chunk sizes.
- Can improve retrieval for documents containing multiple subjects.
Limitations:
- Requires additional embedding computation.
- More complex to configure and maintain.
- Chunk sizes can become inconsistent.
- Semantic boundaries are not always obvious or perfectly detected.
Semantic chunking is useful when a simple splitter repeatedly breaks related ideas apart. However, it is not automatically more accurate. Its value should be established through retrieval evaluation.
4. Document-Aware Chunking
Document-aware chunking uses the structure and format of a document to determine where content should be divided.
This is particularly useful because documents are not always continuous blocks of text. They contain headings, sections, tables, lists, code blocks, and other structural elements.
Consider a Markdown document:
# Database Performance
## Connection Pooling
Connection pooling allows applications
to reuse database connections.
## Query Optimization
Indexes help databases retrieve
records more efficiently.
A basic fixed-size splitter might combine part of Connection Pooling with Query Optimization.
A document-aware splitter recognises the heading hierarchy and keeps the content associated with its corresponding section.
Different formats require different parsing approaches:
- Markdown: Split using headings, sections, and code blocks.
- HTML: Use headings, paragraphs, and document structure.
- PDF: Preserve page content, headings, tables, and logical sections.
- Source code: Keep related functions, classes, and syntactic blocks together.
Document-aware chunking can also attach metadata such as document title, section heading, page number, and source location.
This makes retrieved results more useful because the application retains information about where each passage came from.
Advantages:
- Preserves document hierarchy.
- Useful for structured technical and enterprise documents.
- Improves traceability and source attribution.
- Helps avoid separating tables, code, and related sections unnecessarily.
Limitations:
- Requires format-specific parsing.
- Poorly structured documents can still be difficult to process.
- Complex layouts, especially PDFs, may require additional preprocessing.
For knowledge bases containing technical documentation, manuals, and structured reports, document-aware chunking is often worth considering.
5. Comparing the Four Strategies
| Strategy | Main approach | Best suited for |
|---|---|---|
| Fixed-size | Token or character limits | Simple, relatively uniform text |
| Recursive | Hierarchical text separators | Articles and general documentation |
| Semantic | Embedding-based meaning boundaries | Topic-changing content |
| Document-aware | Document structure and format | PDFs, Markdown, HTML, and code |
These strategies are not necessarily mutually exclusive.
For example, a document-aware pipeline can first separate a Markdown article by headings and then use recursive chunking inside each section to enforce size limits.
Similarly, semantic boundaries can be combined with a maximum chunk size so that one large topic does not become an excessively large chunk.
6. How to Choose the Right Strategy
A practical way to select a chunking strategy is to start with the documents your application actually processes.
For general articles and plain text: Start with recursive chunking. It offers a useful balance between simplicity and preserving natural boundaries.
For structured technical documentation: Use document-aware chunking to preserve headings, code blocks, tables, and section context.
For content with frequent topic changes: Evaluate semantic chunking, particularly when simpler methods consistently produce chunks containing unrelated ideas.
For simple datasets and initial prototypes: Fixed-size chunking can provide a useful baseline before introducing more complex preprocessing.
The important thing is to avoid selecting a strategy based only on popularity.
7. Evaluate Chunking Before Production
A chunking strategy should be evaluated using the same types of questions that real users will ask.
Create a representative test dataset containing questions that require different levels of context, exact facts, technical terminology, and information spread across multiple sections.
Then compare the resulting retrieval quality.
Pay particular attention to:
- Recall@K: Are the relevant chunks appearing in the retrieved results?
- Precision@K: How many retrieved chunks are actually relevant?
- Context completeness: Does the retrieved content contain enough information to answer the question?
- Latency and cost: How much processing and retrieval overhead does the strategy introduce?
Also inspect the actual chunks produced by each method. Automated scores alone may not reveal when a heading has been separated from its content or when a table has lost its column relationships.
For a fair comparison, keep the embedding model, retrieval configuration, evaluation questions, and ranking settings consistent.
A change in retrieval results should be attributable to the chunking strategy rather than several simultaneous architecture changes.
Conclusion
Chunking is one of the most important decisions in a RAG pipeline because it shapes the information available to the retrieval system.
Fixed-size chunking provides a simple baseline, recursive chunking preserves natural boundaries, semantic chunking groups content by meaning, and document-aware chunking respects the original document structure.
Each approach solves a different problem.
The best chunking strategy is not the one that produces the most sophisticated chunks. It is the one that consistently retrieves the information your application needs without introducing unnecessary complexity.



