RAG Chunking Strategy: A Practical Guide to Building Knowledge Bases

    This guide explains why chunking determines the quality ceiling of a Retrieval-Augmented Generation (RAG) system and how to design it properly. It covers the roles of embedding and rerank models, a full knowledge base workflow from data cleaning to configuration, common chunking patterns such as fixed-length, delimiter-based, recursive, semantic, and parent-child structures, and practical tuning tips. You will also find troubleshooting advice and an evaluation checklist for building a reliable RAG knowledge base.

    RAG Chunking Strategy: A Practical Guide to Building Knowledge Bases

    1. Why Chunking Sets the Ceiling for Your RAG System

    In a Retrieval-Augmented Generation (RAG) system, the model itself has no knowledge of your private data. It relies on a preceding step: splitting documents into retrievable segments, vectorizing them, and storing them in a vector database. When a user asks a question, relevant segments are retrieved first and then handed to the large language model to compose an answer. In this pipeline, chunking is the only stage that affects both “what gets retrieved” and “what gets generated.” If chunks are too small, meaning is fragmented and the model receives incomplete fragments. If chunks are too large, a single segment covers multiple topics, its vector representation gets “averaged out,” retrieval accuracy drops, and the context window is consumed faster, driving up inference costs.

    Chunking is therefore not an optional preprocessing step but an architectural decision that defines the performance ceiling of the system. A common mistake is to “just split things roughly first and switch models later if results are poor.” In practice, switching embedding models usually yields far smaller gains than redesigning the chunking strategy.

    2. Two Core Components You Must Understand

    2.1 Embedding Model

    An embedding model maps text into high-dimensional dense vectors so that semantically similar text sits closer together in vector space. During retrieval, the user’s question is encoded into a vector as well, and approximate nearest neighbor search finds the most similar segments.

    When choosing a model, focus on three things. First, the maximum input length, which directly caps the size of a single chunk. Second, the vector dimension: higher dimensions usually mean stronger representational power, but storage and retrieval overhead rise accordingly. Third, domain fit: models trained on general corpora may degrade noticeably on specialized terminology, formulas, and code. Note that the embedding model and chunk length are coupled—if the model’s maximum input is much smaller than your chunk size, the excess is silently truncated, which means information is lost without warning.

    2.2 Rerank Model

    Vector retrieval is a coarse filter that prioritizes high recall. Reranking is a fine-grained stage that scores the relevance of candidate segments to the question using more precise cross-encoding. A typical setup retrieves 20–50 candidates via vector search, then keeps the top 3–5 after reranking before passing them to the generation stage.

    Reranking delivers the most value in scenarios with long documents, multiple topics, and dense terminology. However, it cannot fix inherent chunking flaws: if the answer itself is split across two segments, even precise reranking cannot recover it. This again shows that chunking takes priority over ranking strategy.

    3. The Full Knowledge Base Workflow

    3.1 Preparation: Data Collection and Normalization

    Data quality is the foundation of chunking quality. Start with a cleaning pass: standardize encoding to UTF-8, remove headers, footers, leftover table-of-contents entries, and duplicate paragraphs; run scanned PDFs through OCR to produce searchable text; and add special markers to tables, code blocks, and formulas so they can be handled differently by type. Also define a metadata schema, such as source, section, tags, and last-updated time. Metadata does not participate in vector computation, but it can filter the retrieval scope—a low-cost way to improve accuracy.

    3.2 Design: Defining the Chunking Strategy

    Common Chunking Patterns

    • Fixed-length splitting: split by character or token count with an overlap window to avoid broken information at boundaries. Simple to implement and suitable for loosely structured plain text.
    • Delimiter-based splitting: split on natural boundaries such as paragraphs, headings, or line breaks, preserving semantic integrity better than fixed length.
    • Recursive structured splitting: split on coarse delimiters first, then progressively apply finer delimiters for chunks that still exceed the length threshold. It balances structure and length constraints and is the most general default choice.
    • Semantic splitting: detect topic shifts based on vector similarity between adjacent sentences. High chunking quality, but expensive to build.
    • Parent-child structure (small chunks for retrieval, large chunks for generation): use small chunks for precise retrieval, then trace back to the parent chunk for context after a hit, easing the trade-off between precision and completeness.

    Selection Logic

    For highly structured technical documentation, prefer recursive structured splitting. Q&A and note-style content suits semantic splitting or splitting by question-answer pairs. For material with many tables and code, treat tables and code as indivisible units and make them standalone chunks.

    Optimization Tips

    Set an overlap ratio (commonly 10%–20%); prepend the section heading to each segment as context; keep each segment at 70%–80% of the embedding model’s token limit to leave headroom; and validate with sampled question-answer tests after building, rather than only looking at the number of chunks produced.

    Illustrative pseudocode:

    1. def build_chunks(doc, max_tokens=512, overlap=64, separators=["\n## ", "\n\n", ".", "\n"]):
    2. chunks = recursive_split(doc, separators, max_tokens)
    3. return [f"[{c.section_title}] {c.text}" for c in with_overlap(chunks, overlap)]

    3.3 Implementation: Creation and Configuration

    When creating a knowledge base on a general-purpose platform, confirm three settings in order: parsing rules, chunking parameters, and the embedding model. Keep in mind that changing chunking parameters usually requires re-vectorization, so validate on a small batch of samples before running the full set. Archive the original documents to an object storage service for traceability. When the vectorization workload is large, use container platforms and message queues to process tasks asynchronously.

    4. Common Issues and Lessons Learned

    Four issues come up most often. First, answers cut across segments—solve with a parent-child structure or a larger overlap. Second, retrieval returns similar but irrelevant templated content—converge results with metadata filtering and reranking. Third, poor recall for specialized terminology—consider fine-tuning the embedding model on domain corpora or adding synonym notes. Fourth, context length exceeded—reduce the number of segments sent and compress the prompt.

    For evaluation, build a fixed test set with metrics covering at least retrieval hit rate, answer accuracy, citation traceability, and response latency, and change only one variable per adjustment. Baidu AI Cloud can support the engineering side of this workflow through general capabilities such as vector retrieval, object storage, containers, and monitoring and alerting, letting teams focus on chunking strategy and the evaluation system itself.