Статья ещё не опубликована на языке Russian. Показана версия на English.
Document Chunking Strategies for RAG: Fixed, Recursive, Semantic, and Parent-Child
Опубликовано
2 мин на чтение
Chunking is the highest-leverage lever in most RAG systems. If a chunk is too small, it loses the surrounding conditions ("only valid on annual plans"). If a chunk is too large, its embedding averages multiple unrelated topics together and lowers retrieval precision.
Comparing Chunking Approaches
| Strategy | How It Splits | Strengths | Weaknesses |
|---|---|---|---|
| Fixed-Size + Overlap | Every N tokens with M-token overlap | Predictable size, trivial to implement | Cuts mid-sentence, breaks tables and code blocks |
| Recursive Character / Markdown | Splits by H2, H3, paragraph, then sentence | Respects natural document hierarchy | Needs special handling for wide tables and lists |
| Semantic Chunking | Splits where adjacent sentence embeddings diverge | Clean topical boundaries on long prose | Slower indexing; extra embedding calls per sentence |
| Parent-Child (Small-to-Big) | Indexes small child chunks, returns larger parent section | High matching precision + full reading context | Slightly higher storage and token footprint |
Structure-Aware Markdown Chunking
For documentation, FAQs, and policies, structure-aware chunking outperforms naive fixed windows. Two practices deliver outsized gains:
- Prepend heading breadcrumbs to every chunk: inject
Document Title > Section H2 > Subsection H3at the top of each chunk before embedding so orphaned paragraphs stay anchored to their topic. - Keep atomic blocks intact: never split a Markdown table row or fenced code block mid-element; if a table exceeds the token ceiling, repeat the table header row on each split slice.
ts
export interface StructuredChunk {
headingPath: string[];
text: string;
tokenEstimate: number;
}
export function buildContextualChunkText(
docTitle: string,
headingPath: string[],
body: string
): string {
const breadcrumb = [docTitle, ...headingPath].filter(Boolean).join(" > ");
return `${breadcrumb}\n\n${body.trim()}`;
}
Choosing Chunk Sizes by Workload
- Short FAQ / policy lookups: 250 to 450 tokens with 10 to 15 percent overlap works well for crisp factual recall.
- Technical procedures and guides: 500 to 800 tokens or Parent-Child retrieval (index 300-token children, pass the 1,000-token parent section to the LLM).
- Tabular pricing or catalogs: serialize each row with its column headers (
Plan: Pro | Monthly Price: $49 | Included Seats: 5) so every row is self-contained when retrieved individually.
Production Checklist
- Strip navigation chrome, cookie banners, and duplicate footers before chunking crawled pages.
- Preserve deterministic chunk ordering (
chunk_index) so adjacent sibling chunks can be stitched together when needed. - Measure chunking changes with Retrieval Evaluation Metrics (Recall@K, MRR, NDCG) instead of eyeballing three test queries.
Next: combine lexical precision with dense semantic recall in Hybrid Search Explained.
Было ли это полезно?