Chunking.

The process of splitting documents into smaller passages for embedding and retrieval in RAG systems, where chunk size and overlap affect retrieval quality.

Chunking is a fundamental preprocessing step in Retrieval-Augmented Generation (RAG) systems where large documents are divided into smaller, manageable passages that can be embedded and stored in vector databases. This process is critical because embedding models have token limits and retrieval systems work more effectively with focused, coherent text segments rather than entire documents. The quality of chunking directly impacts how well a RAG system can find and retrieve relevant information to answer user queries.

The chunking process involves several key decisions: chunk size (typically 100-1000 tokens), overlap between adjacent chunks (usually 10-20% to maintain context continuity), and splitting strategies (sentence boundaries, paragraph breaks, or semantic segmentation). Simple approaches split text at fixed token counts or character limits, while more sophisticated methods use semantic analysis to identify natural breakpoints. The overlap ensures that information spanning chunk boundaries isn't lost, though too much overlap can introduce noise and increase storage costs.

Effective chunking requires balancing competing factors: smaller chunks provide more precise retrieval but may lack sufficient context, while larger chunks contain more context but can dilute relevance scores. Common mistakes include ignoring document structure (splitting tables or code blocks inappropriately), using chunks that are too large for the embedding model's optimal range, or failing to preserve critical relationships between concepts. Modern RAG systems often experiment with multiple chunk sizes or use hierarchical chunking strategies to optimize retrieval performance for their specific use cases.