Beginner8 min read3 of 40

Semantic Chunking

Same as Simple RAG but with smarter scissors — splits where the topic actually changes instead of every 1000 characters.

Read first:Simple RAG

Overview

PropertyDetail
PatternSemantic Chunking — Smarter Splitting
Level2 (Better chunks)
Key ImprovementSplits at meaning boundaries, not character counts
ResultFewer chunks (63 vs 97) but each is a complete thought
Notebook02_Semantic_Chunking.ipynb

Architecture

flowchart TD
    A[PDF Document] --> B[Read Full Text]
    B --> C["Embed Every Sentence (Bedrock Titan, 1024 dims)"]
    C --> D["Compare Adjacent Sentence Embeddings"]
    D --> E{"Similarity Drop Below Threshold?"}
    E -->|Yes| F["BREAKPOINT — Topic Changed"]
    E -->|No| D
    F --> G["Split at Breakpoints"]
    G --> H["Chunk 1: Topic A"]
    G --> I["Chunk 2: Topic B"]
    G --> J["Chunk 3: Topic C"]
    H --> K[(Store in Qdrant)]
    I --> K
    J --> K
    K --> L[Query as Usual]

Simple RAG vs Semantic Chunking

AspectSimple RAGSemantic Chunking
Split methodEvery 1000 charactersWhere meaning shifts
Chunks produced9763 (fewer but better)
RiskCuts mid-sentenceNever splits a coherent idea
Chunk qualityVariable — may mix topicsHigh — each chunk = one topic
SpeedFastSlightly slower (embeds every sentence first)

Test Output

Same PDF, same query: Simple RAG: 97 chunks (some cut mid-thought) Semantic: 63 chunks (each is a complete topic) Result: Better retrieval quality with fewer, more coherent chunks.

How the Breakpoints Work

Sentence PairCosine SimilarityAction
"Greenhouse gases trap heat" → "CO2 is the most common"0.85Same chunk (related)
"CO2 levels rose 40%" → "Policy changes in 2015 included"0.28SPLIT (topic changed)
"Paris Agreement set targets" → "Nations committed to reduce"0.81Same chunk (related)

When to Use

ScenarioUse Semantic Chunking?
Long documents with multiple topicsYes
Reports, research papers, manualsYes
Short single-topic documentsNo — simple chunking is fine
Need fastest possible indexingNo — extra embedding step

Tech Stack

ComponentTechnology
EmbeddingsAWS Bedrock — Amazon Titan Embed Text v2 (1024 dims)
LLMAWS Bedrock — Claude Sonnet
Vector DBQdrant Cloud (cosine similarity)
PDF ReaderPyMuPDF (fitz)
FrameworkLangChain

Source