🦜️✂️ Chunk Division and Overlap: Understanding the Process

Gustavo EspĂ­ndola
3 min readSep 5, 2023

--

Diving into the world of text and document processing, “chunking” is a fundamental technique. But what does it mean? Essentially, it’s the process of dividing a text into smaller fragments (chunks), often to facilitate its processing.

🆕 UPDATE ARTICLE

Chunking is the process of breaking down content into smaller, more manageable parts, making it easier to handle from a computational perspective. The size of these fragments determines how much meaningful content each unit contains.

Overlap, on the other hand, is the option that allows adjacent fragments to share certain common information. In other words, it’s the “previously” when your favorite TV series’ new episode starts with details from the exciting scenes of the previous episode. And when it ends with “coming soon.”

So, the overlap of fragments is the specific amount of content these neighboring fragments share and is generally represented as a percentage. If your fragments are 500 characters long, your overlap could be 50, increasing the likelihood of delivering relevant data to the model.

Now, let’s illustrate this with an example

This overlap allows for some continuity and context between the fragments, which can be useful in storytelling, increasing the likelihood of delivering relevant data to the model.

Why is it important?

Creating good chunks is essential in semantic search and RAG (Retrieval-Augmented Generation). Effective content division ensures that we maintain coherence and context in the response. If we divide a story into unrelated fragments, we could lose the ability to create a coherent response.

What is the best strategy for chunks and overlap?

The best strategy for a text will largely depend on the nature of the document and the purpose of its analysis.

For unstructured text documents, I personally recommend the “Recursive Character Splitting” strategy.

This strategy excels at preserving semantic coherence in the resulting fragments, effectively adapting to various types of documents while avoiding the loss of relevant information.

LangChain

In the LangChain library, you can find various text splitters that help determine how fragment size and overlap are measured.

đź”´ Watch live on streamlit

So, I suggest planning your fragments based on the type of content you’ll feed into your AI. You can use a tool I’ve developed to make this analysis easier.

If you need assistance, don’t hesitate to ask in the comments.

Additional Resources

đź”— See the Demo & đź”— GitHub Repository

--

--

Gustavo EspĂ­ndola

Maker & Senior Product Designer — Co-founder of CodeGPT by Judini AI