Sentence, Paragraph and Sliding Window Chunking

Three simple, natural chunking methods with code, and when each one fits your documents.

Last Updated: 27, Nov 2026

Search Tutorials

--Ads--

Module 4 · Lesson 3 of 10 · Intermediate

Sentence, Paragraph and Sliding Window Chunking

Three simple, natural chunking methods with code, and when each one fits your documents.

Fixed-size chunking counts characters or tokens; structure-aware chunking follows headings. Between them sit three simple methods that follow the natural units of prose: sentence-based, paragraph-based and sliding window chunking. They are easy to implement, easy to explain to colleagues, and often a strong choice for articles, policies, emails and transcripts.

What you will learn

  • How to split text into sentences reliably and group them into chunks
  • How to chunk by paragraphs, merging short ones and splitting long ones
  • How sliding window chunking works and when overlap helps
  • How to choose between the three

Prerequisites

Sample text

TEXT = """Remote work policy. Employees may work from home up to two days per week. Managers must approve the schedule in advance.

Equipment. The company provides a laptop and headset. Employees are responsible for a reliable internet connection. Internet costs are reimbursed up to 1,500 rupees per month.

Availability. Remote employees must be reachable on chat between 10:00 and 16:00. Meetings with clients should be held on camera."""

1. Sentence-based chunking

Split the text into sentences, then group consecutive sentences until a size limit is reached. No sentence is ever cut in half. Splitting on full stops alone fails on abbreviations ("Dr.", "e.g.", "Rs. 1,500"), so use a sentence tokenizer such as NLTK's Punkt or spaCy for real documents.

pip install nltk
natural_chunkers.py
import nltk

nltk.download("punkt_tab", quiet=True)          # sentence tokenizer data (newer NLTK versions)
from nltk.tokenize import sent_tokenize

def sentence_chunks(text: str, max_chars: int = 300, max_sentences: int = 5) -> list[str]:
    chunks, current = [], []
    for sentence in sent_tokenize(text):
        if current and (len(" ".join(current + [sentence])) > max_chars or len(current) >= max_sentences):
            chunks.append(" ".join(current))
            current = []
        current.append(sentence)
    if current:
        chunks.append(" ".join(current))
    return chunks

Older NLTK versions use the resource name punkt instead of punkt_tab; if sent_tokenize reports a missing resource, download the name it asks for.

2. Paragraph-based chunking

Authors already group related sentences into paragraphs, so a paragraph is often a natural chunk. Real paragraphs vary in length, so merge very short ones with their neighbours and split very long ones by sentences:

def paragraph_chunks(text: str, min_chars: int = 150, max_chars: int = 1200) -> list[str]:
    paragraphs = [p.strip() for p in text.split("\n\n") if p.strip()]
    chunks, buffer = [], ""
    for p in paragraphs:
        if len(p) > max_chars:                       # too long: split this paragraph by sentences
            if buffer:
                chunks.append(buffer)
                buffer = ""
            chunks.extend(sentence_chunks(p, max_chars=max_chars))
            continue
        buffer = f"{buffer}\n\n{p}" if buffer else p
        if len(buffer) >= min_chars:                 # long enough to stand alone
            chunks.append(buffer)
            buffer = ""
    if buffer:
        if chunks and len(buffer) < min_chars:
            chunks[-1] += "\n\n" + buffer            # attach a short tail to the previous chunk
        else:
            chunks.append(buffer)
    return chunks

3. Sliding window chunking

A sliding window takes a fixed number of sentences, then moves forward by a smaller step, so consecutive chunks overlap. With a window of 3 sentences and a step of 2, sentence 3 appears in chunks 1 and 2. Every sentence appears with context on at least one side, which helps when facts depend on neighbouring sentences.

def sliding_window_chunks(text: str, window: int = 3, step: int = 2) -> list[str]:
    if step > window:
        raise ValueError("step must not be larger than window, or sentences would be skipped")
    sentences = sent_tokenize(text)
    chunks = []
    for start in range(0, len(sentences), step):
        chunks.append(" ".join(sentences[start:start + window]))
        if start + window >= len(sentences):
            break
    return chunks

Compare the three

for name, fn in [("sentences", sentence_chunks), ("paragraphs", paragraph_chunks),
                 ("sliding window", sliding_window_chunks)]:
    chunks = fn(TEXT)
    print(f"{name:15} {len(chunks)} chunks, sizes {[len(c) for c in chunks]}")
sentences       3 chunks, sizes [263, 199, 128]
paragraphs      3 chunks, sizes [133, 183, 130]
sliding window  4 chunks, sizes [208, 189, 150, 128]

The exact numbers depend on the tokenizer, but the pattern is typical: paragraph chunks follow the author's topics exactly, sentence chunks are cut by size, and the sliding window produces more, overlapping chunks.

When to use which

MethodBest forWatch out for
Sentence-basedDense factual text; FAQ-style answers; short chunks for precise matchingPronouns ("it", "this") losing their referent; add headers or use small-to-big retrieval
Paragraph-basedWell-written articles, policies, emailsVery uneven paragraph lengths; text without blank lines between paragraphs
Sliding windowTranscripts and narrative text where context flows across sentencesMore chunks and duplicated text; deduplicate before sending to the LLM

Measure on your own questions with the harness from Evaluating Chunking Strategies.

Key takeaways

  • Sentence chunking groups whole sentences up to a limit; use a proper sentence tokenizer.
  • Paragraph chunking follows the author's structure; merge short and split long paragraphs.
  • Sliding windows overlap consecutive chunks so every sentence keeps nearby context.

Frequently asked questions

Is a sliding window the same as chunk overlap?

It is overlap measured in sentences instead of characters, with sentence boundaries always respected.

Which is best?

For well-formatted prose, paragraph chunking is a strong default. For transcripts, try sliding windows. Always confirm with an evaluation.

Practice exercises

  1. Run all three chunkers on a long article and compare retrieval hit rates on ten questions.
  2. Add a contextual header (document title) to every chunk and measure the change.

Related tutorials