Search

Search IconIcon to open search

Sliding-window (Fixed-sized) Chunking

Last updatedUpdated: by Jakub Žovák · 1 min read

Properties
created 07.02.2025, 16:04
modified 02.08.2026, 10:12
published Empty
topics Chunking
authors Jakub
ai-assisted No

This is the most common and straightforward approach to chunking: we simply decide the number of tokens in our chunk and, optionally, whether there should be any overlap between them. In general, we will want to keep some overlap between chunks to make sure that the semantic context doesn’t get lost between chunks.

1
2
3
4
5
6
7
8
text = "..." # your text
from langchain.text_splitter import CharacterTextSplitter
text_splitter = CharacterTextSplitter(
    separator = "\n\n",
    chunk_size = 256,
    chunk_overlap  = 20
)
docs = text_splitter.create_documents([text])