Chunking splits source documents into retrievable units and attaches metadata. Each chunk has to be self-contained enough to answer a question and specific enough to rank well.

Chunking & Indexing StrategiesDiagram with these labels, in reading order: Source Document; Chunking Strategy; (Structure-aware,; Semantic); Metadata Attachment; (Headings, Context); Retrievable Chunks; Indexing; (Granularity,; Normalization).Source DocumentChunking Strategy(Structure-aware,Semantic)Metadata Attachment(Headings, Context)Retrievable ChunksIndexing(Granularity,Normalization)
Chunking & Indexing Process

Fixed windows versus structure-aware splits

A fixed-size window divides text into segments of a set number of tokens. It is simple, and it can slice through the middle of a table, a paragraph or a code block and strip the heading that gives the text its meaning. The retriever then returns fragments the model cannot use.

Structure-aware splitting follows headings, paragraphs and code blocks, so each chunk carries a complete thought. It needs more parsing up front. It targets a common RAG complaint: retrieved passages that are fragments.

  • Parent-child: small chunks are retrieved together with their enclosing section, which gives precise matches plus broader context.
  • Contextual retrieval: a short description of the chunk's place in the document (often generated by a model) is prepended to each chunk before embedding, so an ambiguous chunk still signals its topic.

Example scenario: a technical document explains an algorithm. Fixed windows cut an explanation or code listing in half. Structure-aware chunks keep each explanation and listing whole, and retrieval improves.

Matching chunking to document type

DocumentStrategy
Uniform proseFixed-size chunks
Code, tables, mixed formattingStructure-aware chunks
Precision matters and chunks must be smallParent-child retrieval
Chunks unclear on their ownContextual prefixes

Both approaches trade effort for quality. Fixed windows cost almost nothing to build and work when the text is uniform. Structure-aware splitting costs parsing effort and pays it back in coherent chunks, which is why it is the better choice once documents contain code, tables or mixed formatting.

Metadata is what makes chunks findable. A parent link lets the system return the surrounding section when a small chunk matches, and a prepended description tells the model what the chunk is about. Without either, a chunk may lack the context to produce a meaningful answer.

Chunking as index granularity

Chunking is like choosing index granularity in a database, except that the rows are prose. A badly drawn chunk raises no error. It lowers relevance quietly, which makes the fault hard to find.

Naive splits Fixed-size splits can cut away context and make retrieval ineffective.

Low retrieval accuracy from chunk size

Example scenario: only 60% of queries retrieve a relevant document (illustrative). Chunks that are too large or too small lose context or fragment it. If chunks hold 500 words but the answer spans 600, retrieval can miss it.

Chunking & Indexing StrategiesDiagram with these labels, in reading order: Initial Chunk Size; Metadata Completeness; Check; Relevance Scoring; Algorithm; Chunk Overlap Assessment; Adjust Chunk Size; Enhance Metadata Quality; Refine Relevance Scoring.Initial Chunk SizeMetadata CompletenessCheckRelevance ScoringAlgorithmChunk Overlap AssessmentAdjust Chunk SizeEnhance Metadata QualityRefine Relevance Scoring
Chunking & Indexing Debugging Flow
  1. Measure average chunk size and where relevant context falls across chunks.
  2. Read retrieval logs for common queries that return irrelevant results.
  3. A/B test chunk sizes, for example 250 words against 500 words.

Adjust sizes to the context distribution, accepting more processing time. Retrieval quality sets the ceiling for the whole RAG system, so track retrieval accuracy and user satisfaction after each change.

Back to the knowledge baseRequest an assessment