RAG Chunking Strategies: A Practical Guide to Selection and Tuning

    This article explains why chunking sets the upper limit on RAG quality and how to choose a strategy deliberately. It covers the division of labor between embedding models for coarse retrieval and rerank models for fine ranking, the full knowledge base pipeline from data cleanup and metadata tagging to chunk design, a comparison of fixed-length and structure-aware recursive chunking, and an evaluation loop for iteration. You will find practical starting parameters, selection guidance, and code illustrating recursive splitting.

    1. Why Chunking Sets the Ceiling on RAG Quality

    In a retrieval-augmented generation (RAG) pipeline, the large language model does not inherently “know” private enterprise knowledge. It relies on the retrieval stage to place relevant fragments into the context. Chunking is the step that decides the granularity at which documents are split, and it affects three things at once: the hit rate of vector recall, the difficulty of reranking, and the completeness of the context finally passed to the model.

    A common mistake is treating chunking as a purely pre-processing detail. In reality, there is a natural tension between chunk granularity and semantic completeness. Finer chunks concentrate the meaning of each segment, so vector matching is more precise, but context is badly fragmented and the model tends to take statements out of context. Larger chunks preserve context, but the vector is diluted across multiple topics, similarity becomes less discriminative, and the token cost per call rises.

    Chunking strategy should therefore make an explicit tradeoff between retrieval precision and context sufficiency, rather than applying a fixed number.

    2. Prerequisites: The Roles of Embedding and Rerank Models

    2.1 Embedding Models: Coarse Filtering

    An embedding model maps text into fixed-length vectors so that semantically similar content sits closer together in vector space. Three points matter when selecting one:

    • Maximum input length: it must exceed your chunk length, otherwise input is silently truncated, which is the most hidden source of failures;
    • Language fit: Chinese corpora require a model sufficiently trained on Chinese semantics;
    • Vector dimension: higher dimensions bring expressiveness but also amplify storage and retrieval overhead.

    Note that embedding uses a “dual-tower” structure: passages and queries are encoded independently. It is good at quickly narrowing the candidate set, but not at fine-grained comparison.

    2.2 Rerank Models: Fine Ranking

    Rerank uses an interactive structure that jointly encodes the query and the passage, capturing word-level correspondences. Its discriminative power is significantly stronger than vector similarity, at the cost of computing each candidate one by one, so results cannot be precomputed.

    The two are stages in a pipeline, not substitutes. A typical flow:

    1. Document -> Chunking -> Embedding -> Vector store
    2. Query -> Embedding -> TopK coarse recall (e.g., 20~50)
    3. -> Rerank -> TopN (e.g., 3~5) -> Assemble context -> Generation

    A practical rule: K for coarse recall should be clearly larger than the final N, leaving room for the reranker to correct mistakes. If K and N are close, reranking yields almost no benefit.

    3. The Full Knowledge Base Pipeline

    3.1 Preparation: Collecting and Cleaning Material

    Material quality is the ceiling. This stage should cover:

    1. Deduplication and denoising: remove repeated boilerplate such as headers, footers, navigation, and copyright notices; they generate many near-identical vectors that crowd out recall slots;
    2. Format normalization: convert tables, PDFs, and scans into parseable structured text; scans need OCR first;
    3. Metadata tagging: attach fields such as source, section, effective date, and permission labels to each chunk, laying the groundwork for filtered retrieval;
    4. Freshness governance: define document versions and invalidation rules so expired content is not recalled.

    Metadata deserves particular investment. Filtering by metadata before computing similarity is often more effective than tuning parameters alone.

    3.2 Design: Defining the Chunking Strategy

    Before setting a strategy, answer three questions: Is the document structure regular? Are users “looking up facts” or “asking for a process”? Does the answer require cross-chunk reasoning? Regular structure and factual lookup favor small chunks; complete processes or cross-chunk reasoning favor larger chunks with overlap.

    A general starting point: chunk length of 300~800 characters with 10%~20% overlap. Overlap prevents an answer that happens to straddle a split boundary from being cut apart.

    3.3 Two Mainstream Chunking Modes

    The first is generic fixed-length chunking. Text is split by character or token count. It is simple and predictable, and suits loosely structured text without heading hierarchy, such as meeting notes and ticket records. The drawback is that it may cut sentences and tables.

    The second is structure-aware recursive chunking. It splits level by level using high-priority separators (section headings, paragraphs, periods) until the length constraint is met, breaking at natural semantic boundaries where possible. It fits hierarchical material such as technical documentation and policy manuals, at the cost of more complex configuration and greater variance in chunk length.

    Illustrative configuration logic:

    1. separators = ["\n## ", "\n### ", "\n\n", ".", "\n", " "]
    2. def split(text, max_len=500, overlap=80):
    3. for sep in separators:
    4. parts = text.split(sep)
    5. if all(len(p) <= max_len for p in parts):
    6. return merge_with_overlap(parts, max_len, overlap)
    7. return hard_cut(text, max_len, overlap)

    3.4 Comparison and Selection

    Dimension Fixed-length chunking Structure-aware recursive chunking
    Implementation complexity Low Medium
    Semantic boundary preservation Weak Strong
    Chunk length consistency High Lower
    Suitable material Unstructured text Hierarchical documents
    Main risk Truncated tables/sentences Overly long chunks dilute semantics

    Recommendation: use a hybrid. Route hierarchical documents through structure-aware chunking, fall back to fixed length for unstructured text, and handle table content with a separate branch that keeps each table intact and prepends a summary.

    4. Evaluation and Iteration

    Do not tune by feel. Build a small evaluation set (50~200 real questions with annotated answer passages) and track three metrics: recall hit rate, TopN hit rate after reranking, and answer accuracy. Change one variable at a time: first fix chunking and tune K, then fix K and tune chunk length, then evaluate whether to introduce reranking.

    If you use general-purpose cloud capabilities, vector retrieval can run on a managed retrieval service or a containerized self-hosted setup, with original documents in object storage, change events driving incremental rebuilds through a message queue, and logging plus monitoring with alerts to observe fluctuations in recall quality. General cloud product categories from vendors such as Baidu AI Cloud can serve as the underlying platform, but the specific selection should still depend on your own data scale and compliance requirements.

    5. Conclusion

    Chunking is not a one-time configuration but an engineering decision that evolves with your data. Govern material and metadata first, then choose a chunking mode based on document structure, compensate for granularity loss with “coarse recall + reranking,” and drive iteration with an evaluation set. That is how you consistently obtain high-quality retrieval.