LESSON 39 Β· CHUNKING

Sentence Chunking

Sentence chunking splits documents around sentence boundaries so each chunk keeps complete thoughts together. It is a simple structure-aware approach that can improve retrieval quality compared with arbitrary fixed windows.

30 min readβ€’Beginnerβ€’Generative AI

By the end of this lesson, you will be able to:

  • Explain what sentence chunking is and why sentence boundaries matter.
  • Split text into complete sentences with Python.
  • Combine sentences into chunks using a target size.
  • Understand sentence overlap and its effect on retrieval context.
  • Compare sentence chunking with fixed-size and recursive approaches.
  • Evaluate whether sentence boundaries are helping your RAG system.
1

What Is Sentence Chunking?

Sentence chunking divides a document into chunks using sentence boundaries instead of cutting text at an arbitrary character position.

The basic idea is simple: detect complete sentences first, then group one or more sentences into a chunk. This helps a chunk preserve a complete thought when the source document has normal prose.

DocumentLong source text
β†’
Sentence splitFind complete sentences
β†’
GroupCombine sentences
β†’
ChunksReady for embeddings
Key idea:sentence chunking respects a natural language boundary, but it does not automatically understand whether two neighboring sentences belong to the same topic.
2

Why Sentence Boundaries Matter

Imagine a policy sentence says that a refund is available within 30 days if the product is returned unused. Splitting in the middle of that sentence can separate the condition from the rule.

ARBITRARY CUT

Meaning can be split

Chunk 1: β€œA refund is available within 30 days if the product is returned…”

Chunk 2: β€œβ€¦unused and in its original packaging.”

β†’
SENTENCE BOUNDARY

Complete thought

The complete sentence stays together, making the retrieved chunk easier for an embedding model and downstream LLM to interpret.

This does not mean every sentence should become its own chunk. Very short chunks may lose useful context, so sentence chunking usually means grouping several sentences into a practical window.

3

Sentence Chunking vs Fixed-size Chunking

FIXED-SIZELength firstSplits every N characters, words, or tokens.
SENTENCEBoundary firstStarts by finding complete sentences.
FIXED-SIZE RISKHard cutsA chunk may end in the middle of a sentence or idea.
SENTENCE BENEFITReadable contextComplete sentences are easier to preserve as retrieval units.
Important: sentence chunking still needs a size rule. If you keep adding sentences forever, the chunks become too large for efficient retrieval.
4

Step 1: Split Text into Sentences

For a learning example, a small regular expression can split ordinary English prose on sentence-ending punctuation. This is useful for understanding the algorithm, but real production text can contain abbreviations, decimals, quotations, headings, and other edge cases.

</> Python
import re

text = "RAG retrieves external knowledge. The retrieved text is added to the prompt. The model then generates an answer."

sentences = re.split(r'(?<=[.!?])\s+', text.strip())

for number, sentence in enumerate(sentences, start=1):
    print(f"Sentence {number}: {sentence}")
Learning point:the regular expression looks for whitespace after sentence-ending punctuation. It is intentionally simple rather than a complete natural-language sentence detector.
5

Step 2: Group Sentences into Chunks

After splitting the document into sentences, we can keep adding sentences until a target word count is reached. The boundary is checked between sentences, not in the middle of one.

</> Python
sentences = [
    "RAG retrieves external knowledge.",
    "The retrieved text is added to the prompt.",
    "The model then generates an answer.",
    "Good chunking can improve retrieval quality."
]

max_words = 12
chunks = []
current = []
current_words = 0

for sentence in sentences:
    words = len(sentence.split())

    if current and current_words + words > max_words:
        chunks.append(" ".join(current))
        current = []
        current_words = 0

    current.append(sentence)
    current_words += words

if current:
    chunks.append(" ".join(current))

for number, chunk in enumerate(chunks, start=1):
    print(f"Chunk {number}: {chunk}")

The result is a set of chunks made from complete sentences. The target is a guide, not a guarantee that every chunk has exactly the same number of words.

6

Sentence Chunk Size

There are two different decisions: where a sentence ends and how many sentences should be grouped together. A useful starting point is to choose a maximum word or token budget and add complete sentences until the next sentence would exceed it.

SMALL

1–2 sentences

Precise retrieval, but may lack surrounding context.

MEDIUM

3–6 sentences

Often provides a useful balance for ordinary explanatory text.

LARGE

Many sentences

More context, but potentially less precise retrieval and more tokens.

There is no universal best size.Start with a measurable configuration, then evaluate retrieval quality on your own documents and queries.
7

Sentence Chunking and Overlap

Overlap means repeating some sentences at the beginning of the next chunk. This can preserve context when an important idea spans a chunk boundary.

Chunk 1Sentence A + B + C
β†’
OverlapRepeat sentence C
β†’
Chunk 2Sentence C + D + E
Trade-off: overlap can improve continuity, but it duplicates text, increases storage and embedding work, and can make retrieval results more repetitive.
8

Python: Sentence Overlap

A simple sentence-window approach can move forward by fewer sentences than the chunk contains.

</> Python
sentences = [
    "Sentence one explains the problem.",
    "Sentence two adds important context.",
    "Sentence three gives the rule.",
    "Sentence four explains the exception.",
    "Sentence five gives an example."
]

chunk_size = 3
overlap = 1
step = chunk_size - overlap

chunks = [
    " ".join(sentences[i:i + chunk_size])
    for i in range(0, len(sentences), step)
]

for number, chunk in enumerate(chunks, start=1):
    print(f"Chunk {number}: {chunk}")

Here, the last sentence of one window is repeated in the next window. Production systems should also prevent unnecessary tiny final chunks.

9

Sentence Chunking Is Not Semantic Chunking

Sentence boundaries are linguistic boundaries, not semantic boundaries. Two adjacent sentences can discuss different topics, while a single topic can continue across several paragraphs.

SENTENCE CHUNKING

Uses sentence boundaries

Fast and understandable. It focuses on preserving complete sentences rather than measuring semantic change.

VS
SEMANTIC CHUNKING

Uses meaning changes

Attempts to group text around shifts in semantic similarity or topic, usually with additional computation.

Sentence chunking is therefore a useful middle step between arbitrary fixed windows and more advanced semantic strategies.

10

Sentence Chunking in RAG

1 Β· CHUNK

Split by sentences

Convert long documents into manageable groups of complete sentences.

2 Β· EMBED

Create vectors

Generate an embedding for each sentence-based chunk.

3 Β· STORE

Index chunks

Store vectors and useful metadata in a vector index or database.

4 Β· RETRIEVE

Find relevant chunks

Embed the user query and retrieve the most similar chunks.

The retrieved chunks are then passed to the LLM as context. Better chunk boundaries can help the retrieved context contain complete, relevant information instead of fragments.

11

Keep Metadata With Each Chunk

Chunk text is not the only useful information. Store metadata such as the source document, section, page, chunk position, and document ID so the application can filter and trace retrieved results.

SOURCEemployee-handbook.pdfIdentifies the original document.
SECTIONLeave PolicyHelps preserve document structure.
POSITIONChunk 8Records the chunk's location.
TEXTSentence-based contentThe actual text embedded and retrieved.
Why it matters: metadata lets you apply filters, show citations, reconstruct nearby context, and debug poor retrieval results.
12

Where Sentence Chunking Works Well

FAQSQuestions and answers

Complete sentences can keep an answer together when the source is already well structured.

POLICIESBusiness rules

Keeping complete policy sentences together can avoid arbitrary cuts through conditions.

ARTICLESNormal prose

Paragraphs made of clear sentences are a natural fit for sentence-based grouping.

SUPPORT DOCSExplanations

Several neighboring sentences can form a useful retrieval unit.

13

Where It Can Struggle

ABBREVIATIONSFalse sentence breaks

Simple punctuation rules may treat β€œDr.” or similar abbreviations as sentence endings.

TABLESNon-prose structure

Tables may not have conventional sentence boundaries at all.

CODEProgramming syntax

Periods and punctuation do not represent natural-language sentences in source code.

HEADINGSMissing context

A heading can be important context even though it is not a sentence.

MIXED CONTENTComplex documents

PDFs can contain lists, captions, columns, and footnotes that need structure-aware handling.

TOPIC SHIFTSMeaning can change

Adjacent sentences may belong to different topics even when they are grammatically complete.

14

Improve Sentence Chunking With Structure

A practical pipeline does not have to choose between β€œonly sentences” and β€œonly fixed size.” You can combine rules.

DocumentPDF, HTML, Markdown
β†’
StructureHeadings and sections
β†’
SentencesNatural boundaries
β†’
Size ruleToken or word budget
β†’
ChunksRetrieval units

This approach can preserve a section heading while still using sentences as the basic boundary. If a chunk becomes too large, the size rule can split it between sentences rather than through a sentence.

15

How to Evaluate Sentence Chunking

Do not judge chunking only by whether the chunks look nice. Test whether the right information is retrieved for real questions.

RETRIEVAL HITDid the right chunk appear?

Measure whether relevant source content is present in top-k results.

CONTEXT QUALITYIs the answer complete?

Check whether retrieved chunks contain enough surrounding information.

NOISEHow much irrelevant text?

Watch for large chunks that retrieve extra unrelated material.

BOUNDARYWas the idea preserved?

Inspect questions whose answers cross sentence or section boundaries.

COSTHow many chunks?

More overlap and smaller chunks can increase embeddings and storage.

ANSWER QUALITYDid the final answer improve?

Evaluate the complete RAG pipeline, not only vector similarity scores.

16

Common Mistakes

MISTAKE 1One sentence per chunk

This can make retrieval too narrow and remove important surrounding context.

MISTAKE 2No size limit

Grouping sentences forever defeats the purpose of creating manageable chunks.

MISTAKE 3Blind regex splitting

Simple punctuation rules can fail on real-world documents.

MISTAKE 4Ignoring headings

Sentence text may lose the section context that explains what it means.

MISTAKE 5Too much overlap

Repeated sentences can increase cost and duplicate retrieval results.

MISTAKE 6Never evaluating

A theoretically clean chunker can still perform poorly on your actual questions.

PRACTICE

Build a Sentence Chunker

Create a Python function that accepts a paragraph, splits it into sentences, and groups sentences until a maximum word count is reached.

  1. Split the input into sentences.
  2. Set a maximum chunk size such as 40 words.
  3. Add complete sentences until the next sentence would exceed the limit.
  4. Store each finished chunk in a list.
  5. Try one version with zero overlap and another with one-sentence overlap.
  6. Compare which version gives better context for five sample RAG questions.
Challenge: add document metadata such as source, section, and chunk_index to every generated chunk.

Quick Quiz

1. What is the main boundary used by sentence chunking?

Sentence endings rather than arbitrary character positions.

2. Should every sentence always become its own chunk?

No. Multiple sentences are often grouped to preserve useful context.

3. What is sentence overlap?

Repeating one or more sentences between neighboring chunks to preserve continuity.

4. Is sentence chunking the same as semantic chunking?

No. Sentence chunking uses linguistic boundaries; semantic chunking attempts to follow changes in meaning or topic.

5. What should you measure when evaluating chunking?

Retrieval relevance, context completeness, noise, cost, and final answer quality.

30-Second Recap

1 Β· SPLITFind sentence boundaries.
2 Β· GROUPCombine sentences into practical chunks.
3 Β· OVERLAPRepeat context when useful.
4 Β· EMBEDCreate vectors for each chunk.
5 Β· EVALUATETest retrieval and answer quality.

Key Takeaways

  • Sentence chunking uses natural sentence boundaries instead of arbitrary hard cuts.
  • It can preserve complete thoughts better than simple fixed-size splitting.
  • Good sentence chunking still needs a practical size limit.
  • Overlap can preserve context but increases duplication and cost.
  • Sentence chunking is not the same as semantic chunking.
  • Real documents need handling for headings, tables, code, abbreviations, and other structures.
  • The best chunking strategy is the one that improves retrieval and final answer quality on your real dataset.