Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/LangChain Mastery/Part 4 · 3. Data Ingestion & Preparation
Lesson 25 of 68

RecursiveCharacterTextSplitter

The gold standard for general text. Respecting the hierarchy of language.

Derpx0610 Jan · 1 min read
LangChain Mastery
The Document Object & MetadataLoaders: PDF, HTML, Text, WebCleaning & NormalizationChunking: Why It ExistsRecursiveCharacterTextSplitterToken-Aware & Syntax-Aware SplittingMarkdown & Code SplittingMetadata Enrichment StrategiesDeduplication via Content HashingLazy Loading & Generators
Contents
1. The Strategy2. The Hierarchy of Separation3. Implementation4. Why Overlap Matters5. Summary
0% read · 1 min leftBack to top ↑
Course outline & contents0%
LangChain Mastery
The Document Object & MetadataLoaders: PDF, HTML, Text, WebCleaning & NormalizationChunking: Why It ExistsRecursiveCharacterTextSplitterToken-Aware & Syntax-Aware SplittingMarkdown & Code SplittingMetadata Enrichment StrategiesDeduplication via Content HashingLazy Loading & Generators
Contents
1. The Strategy2. The Hierarchy of Separation3. Implementation4. Why Overlap Matters5. Summary

1. The Strategy

The RecursiveCharacterTextSplitter is the default choice for a reason. It doesn't just cut; it attempts to keep related text together by using a list of Separators.

2. The Hierarchy of Separation

It tries to split by the first separator. If the chunk is still too big, it moves to the next separator.

Format: ["\n\n", "\n", " ", ""] (Paragraphs -> Lines -> Words -> Characters)

  1. Paragraphs (\n\n): Try to keep paragraphs intact. Ideally, a chunk is just 3-4 paragraphs.
  2. Lines (\n): If a paragraph is too long (bigger than chunk_size), split it by sentences/lines.
  3. Words ( ): If a sentence is too enormous, split by words.
  4. Chars (""): If a word is too long (like a URL), force split it characters.

3. Implementation

recursive_split.py
from langchain_text_splitters import RecursiveCharacterTextSplitter

splitter = RecursiveCharacterTextSplitter(
  chunk_size=1000,
  chunk_overlap=200,
  separators=["\n\n", "\n", " ", ""]
)

docs = splitter.create_documents([long_text])

4. Why Overlap Matters

Notice chunk_overlap=200. This creates a "sliding window." Chunk 1: [Paragraph A, Paragraph B] Chunk 2: [Paragraph B, Paragraph C]

Paragraph B appears in both. Why? Because if a query matches the end of A and the start of B, we need a vector that contains both to capture the relationship. Overlap prevents "boundary semantic loss."

5. Summary

Recursive splitting mimics how humans read: Paragraph by paragraph. It only degrades to word-splitting when absolutely forced.

Key Intuition: "Split at the strongest pause possible."

Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonChunking: Why It ExistsNext lesson →Token-Aware & Syntax-Aware Splitting