Prompts Forms Resume Reports ★ Saved ★ Saved★ + Submit a tool
Techniques

Document Chunking Strategy

About 3266 characters Updated Nov 30, 2026 25 views AI wiki

Chunking cuts long text into short segments suited to retrieval and generation, deciding how much a segment holds and how much meaning it preserves. It determines whether retrieval can hit the target and whether the context a large model receives is coherent; in RAG it sits after document parsing and before embedding, and what looks like a preprocessing detail actually sets the ceiling of retrieval, because once the split is bad, no model can fix it.

Core Principles

Two limits drive it: the embedding context window (most Chinese models support around 512 tokens and truncate beyond) and semantic granularity (an overlong passage mixes topics, and the vector is averaged into a blurred center, hurting both precision and recall).

Strategies escalate in complexity: fixed length, cutting by token count with an overlap window to avoid mid-sentence breaks; recursive character splitting, LangChain's default, splitting by paragraph, sentence, comma and character to cut at natural boundaries; structural chunking, using Markdown headings, HTML tags, PDF chapters and table rows so a segment stays within a section.

Another neglected step is document-level preprocessing: denoising (headers, footers, watermarks, contents, garbled text) and layout restoration (two columns, tables, formulas) before chunking. More advanced is semantic chunking: embed sentences one by one, measure adjacent similarity and cut where it drops, aligning boundaries with topic shifts. Parent-child blocks and small-to-big retrieval compromise: index small blocks for precision, then return the enclosing large block for full context, resolving "retrieval wants small, generation wants large."

Key Points

First, there is no universal size: Chinese technical documents use 300 to 800 characters, QA content 200 to 400, long narrative 800 to 1200, and English 256 to 512 tokens. One criterion: can a segment answer a question alone. Second, 10% to 20% overlap is a safe start; more inflates index size and duplicate recall.

Third, keep metadata: source file, section title, page and timestamp on each segment, for citation, tracing and permission filtering; prepending the section title before embedding clearly improves recall at the lowest cost. Fourth, handle tables and code specially: split tables by row with repeated headers and code by function or class, since hard cuts destroy structure. Fifth, follow the retrieval method: hybrid retrieval can keep fine and coarse indexes together, and incremental updates must handle leftover segments from revised documents, replacing by document id being more stable than deleting one by one.

The industry has moved from "fixed length plus overlap" to "structure awareness plus semantic boundaries plus parent-child hierarchy," with one idea: each segment stands alone yet traces back to the source.

Common Misconceptions

Misconception one: insisting on 512 tokens and splitting mid-sentence, so referents such as "it" lose their referent. Misconception two: omitting titles or file names, leaving segments untopicable. Misconception three: smaller is more precise, when tiny segments lack information and hurt reranking and generation. Misconception four: no sampling check, so garbled PDF text is silently chopped and meaning breaks. Misconception five: one strategy for manuals, contracts and chat logs, ignoring type differences. Misconception six: chunking once and keeping old segments after updates.

Application Scenarios

Enterprise knowledge bases, technical documentation QA, contract clause retrieval, paper and patent parsing, code semantic retrieval, customer service FAQ ingestion, meeting minutes retrieval, multimodal image-text alignment, policy clause decomposition, textbook knowledge slicing, ticket conversation indexing, and separating chart descriptions from reports.