Course contentsShow
← Machine Learning and Deep Learning
Lesson 1985 of 3,53842. Retrieval-Augmented Generation: FoundationsFree lesson

Overlapping Chunks

Adding overlap between consecutive chunks to preserve context at boundaries and improve retrieval coverage.

Overlapping Chunks

What You'll Learn

You'll learn how adding overlap between consecutive chunks helps preserve context at boundaries and improves retrieval accuracy in RAG systems.

The Problem with Hard Boundaries

When you split documents using Fixed-Size Chunking (the previous concept), you create hard boundaries. Imagine cutting a sentence in half: "The mitochondria is the powerhouse of the | cell." If a user asks "What is the powerhouse of the cell?", the left chunk might not contain enough context to answer properly.

The Core Idea

Overlapping chunks means each chunk shares some tokens with its neighbors. Instead of:

Chunk 1: [tokens 0-99]
Chunk 2: [tokens 100-199]
Chunk 3: [tokens 200-299]

You create:

Chunk 1: [tokens 0-99]
Chunk 2: [tokens 80-179]    ← 20 tokens overlap with Chunk 1
Chunk 3: [tokens 160-259]   ← 20 tokens overlap with Chunk 2

This sliding window approach ensures that information near boundaries appears in multiple chunks.

Why This Improves Retrieval

  1. Context preservation: Complete sentences and concepts near boundaries stay intact in at least one chunk
  2. Redundancy helps ranking: If a query matches boundary content, multiple chunks may retrieve, increasing confidence
  3. Recovery from poor splits: Even if one chunk cuts awkwardly, the overlapping neighbor likely captures the full context

The Trade-off

More overlap means more chunks, higher storage costs, and longer retrieval times. Typical overlap ranges from 10-20% of chunk size—enough redundancy without excessive duplication.

Think of it like photographing a panorama: you overlap each photo slightly so you can stitch them seamlessly later.

Key Takeaway: Overlapping chunks add redundancy at boundaries to ensure important context isn't lost between consecutive chunks, improving retrieval coverage at the cost of storage and compute.