Skip to content
Go back

Deep Dive into Semantic Chunking for RAG

Updated:

Semantic chunking for RAG blog post cover featuring a digital scuba diver navigating through glowing data blocks, illustrating AI context window preparation and data retrieval.

generated by nano

In the previous article, Different Chunking Methods for RAG, we explored several strategies used to split documents before feeding them into a Retrieval-Augmented Generation (RAG) pipeline.

In this chapter, we cover Semantic Chunking, a technique that improves retrieval accuracy in modern RAG systems.

What this post covers:


Why traditional chunking often fails

Most early RAG pipelines relied on fixed-size chunking, where documents are split into chunks of predefined size (for example, 500 tokens with a 50 token overlap).

While this approach is simple, it introduces a fundamental problem:

it ignores the semantic structure of the text.

For example, imagine a paragraph discussing transformer architectures, followed by another paragraph explaining reinforcement learning. A fixed-size splitter might cut the text in the middle of the explanation, creating chunks that contain partial or mixed topics.

This leads to two common issues:

  1. Context fragmentation. Important ideas get split across chunks.
  2. Noisy retrieval. Chunks contain unrelated information.

When these chunks are retrieved during query time, the LLM receives incomplete or irrelevant context, which directly reduces answer quality.


What is semantic chunking?

Semantic chunking is a strategy that splits documents based on meaning rather than size.

Instead of arbitrarily cutting text every few hundred tokens, semantic chunking groups sentences that discuss the same topic.

The goal is simple:

Each chunk should represent a coherent semantic idea.

For example, consider the following sequence of sentences:

Sentence 1: Explanation of transformers Sentence 2: Attention mechanism in transformers Sentence 3: Multi-head attention architecture Sentence 4: Reinforcement learning algorithms

A semantic chunker would produce:

Chunk 1 → Sentences 1–3 (transformer topic) Chunk 2 → Sentence 4 (new topic)

This ensures that each chunk represents a complete concept, which significantly improves retrieval relevance.


How semantic chunking works

Most semantic chunking implementations follow a similar pipeline.

Step 1: Sentence segmentation

The document is first split into sentences.

Example:

The document is split into individual sentences:
Sentence1, Sentence2, Sentence3, Sentence4

This allows the algorithm to analyze semantic similarity at a granular level.


Step 2: Generating sentence embeddings

Each sentence is converted into a vector representation using an embedding model.

Common embedding models include:

Each sentence is now represented as a high-dimensional vector capturing its meaning.


Step 3: Computing similarity between sentences

Next, the algorithm calculates cosine similarity between consecutive sentences.

Example:

similarity(S1, S2)
similarity(S2, S3)
similarity(S3, S4)

High similarity indicates the sentences belong to the same topic, while low similarity suggests a topic shift.


Step 4: Detecting topic boundaries

If the similarity between sentences drops below a predefined threshold, a new chunk boundary is created.

Example rule:

similarities between consecutive sentences are above 0.75; below 0.65 a new chunk starts

This dynamically segments the document based on semantic transitions.


Step 5: Building semantic chunks

Finally, sentences are grouped into chunks that maintain topic continuity.

Unlike fixed chunking, semantic chunks may vary in size, but they maintain contextual coherence.


High-level pipeline showing how documents are segmented, embedded, and grouped into semantic chunks before being stored in a vector database for RAG retrieval.

generated by nano

Why semantic chunking improves RAG performance

Semantic chunking improves RAG pipelines in several important ways.

1. Better context integrity

Each chunk contains a complete explanation of a concept, which helps the LLM reason more effectively.


2. Higher retrieval precision

Vector similarity search works best when chunks represent clear semantic topics rather than mixed content.


3. Reduced hallucination

When retrieved context is precise and coherent, the LLM is less likely to generate unsupported information.


4. Improved answer grounding

Because chunks are semantically aligned, answers are better supported by retrieved documents.


Accuracy comparison with other chunking methods

Semantic chunking tends to outperform fixed-size and recursive chunking on retrieval precision in our own work. The exact gap depends on the corpus.

Chunking methodRetrieval precisionContext qualityImplementation effort
Fixed tokenMediumLowEasy
RecursiveMedium to highMediumModerate
SemanticHighHighAdvanced

On long-form documents like research papers, legal documents, and technical documentation, the difference in answer quality is the most visible.


Practical challenges

Despite its advantages, semantic chunking is not always trivial to implement.

Some practical challenges include:

Higher compute cost Generating embeddings for every sentence can be expensive for large document sets.

Threshold tuning The similarity threshold must be tuned carefully to avoid overly small or overly large chunks.

Variable chunk sizes Chunks can become uneven, which sometimes requires adding a maximum token limit.


Production best practices

In most production RAG systems, semantic chunking is combined with token limits and overlap strategies.

A common configuration looks like this:

Semantic similarity threshold: 0.75
Max chunk size: 800 tokens
Overlap: 50 tokens

This keeps chunks on topic and within the model’s context window.


What’s next

Semantic chunking handles documents with stable topics. When the topic keeps shifting, or the chunk should carry metadata that updates over time, a different approach takes over. The next chapter covers Agentic Chunking, where the LLM decides how to group information based on meaning.

Next: Agentic Chunking.


Share this post on:

Previous Post
Docling: an AI-powered document pipeline for LLMs and RAG
Next Post
Different Chunking Methods for RAG