CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 2 · Lesson 7/56

    Chunking strategies for RAG: structure, size and overlap

    Apply a chunking strategy for a given document structure and model constraints

    15 min read
    1.75% of exam
    4 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Pick fixed-size, paragraph/recursive, format-specific or semantic chunking from the structure of a document
    • Size chunks so they fit under the embedding model's token limit without being silently truncated
    • Set chunk overlap so content that crosses a boundary can still be retrieved whole
    • Check that top-k retrieved chunks plus the prompt fit within the LLM's context window

    Key concept

    Chunk boundary — The point where a splitter ends one chunk and starts the next. The chunking strategy decides where boundaries fall, the chunk size decides how far apart they are, and overlap decides how much text the chunks on either side of a boundary share.

    1.What a chunking decision controls

    Chunking splits parsed documents into the units that a RAG application embeds, indexes and retrieves. Each chunk is the smallest thing the retriever can return. If a chunk holds half an answer, the LLM gets half an answer. Chunking comes after parsing, deduplication and filtering in the data pipeline. Its job is to keep retrieved text small enough to fit in the LLM's context while leaving out distracting material. That makes it one of the first layers of optimization in a RAG application.

    A chunking configuration has three settings, and each one fixes a different failure:

    • Strategy decides where boundaries fall: by character or token count, at paragraphs or sentences, at headers, or at topic shifts. If boundaries cut through sentences or sections, change the strategy.
    • Size decides how much text goes into each chunk. Small chunks focus on specific details but lose surrounding context. Large chunks keep context but bring in irrelevant text and cost more to compute.
    • Overlap repeats some text from the end of one chunk at the start of the next. It protects content that sits across a boundary.

    Keeping these three apart matters when you diagnose a problem. Changing size or overlap moves or duplicates boundaries, but it does not place them any more sensibly. Only a change of strategy does that.

    The best configuration depends on the data. Choosing a chunking method is iterative and context-dependent, so treat any setting as a starting point and measure it against retrieval results. That measurement is the subject of choosing a chunking strategy from evaluation. Metadata is a fourth lever: a source document name or section heading attached to a chunk helps match queries to it.

    Checkpoint 1 of 7· Match them up

    A RAG team sees each of these retrieval problems. Match each problem to the chunking setting that addresses it.

    Tap a term, then the definition that fits it.

    Sources1

    2.Matching the strategy to the document's structure

    There are four families of chunking strategy, and the right one depends on how much structure the document already has. Start by asking what in the text marks where one idea ends and the next begins. Then choose the strategy that splits at that marker.

    Chunking strategy families and the document structure each one uses
    StrategyWhere it puts boundariesExample toolBest fit
    Fixed-sizeEvery N characters or tokens, wherever that fallsLangChain CharacterTextSplitterQuick prototypes only; it rarely works in production
    Paragraph-basedAt natural paragraph boundariesLangChain RecursiveCharacterTextSplitterPlain prose such as transcripts, articles and emails
    Format-specificAt the format's own structure, such as markdown headers or HTML sectionsLangChain MarkdownHeaderTextSplitter, HTML header/section-based splittersMarkdown or HTML with headed sections
    SemanticAt topic shifts, found by topic modeling or embeddingsLangChain SemanticChunkerLong text whose topic changes are not marked by headers

    Fixed-size chunking is easy to set up and ignores meaning. A splitter that cuts plain-text support tickets into 512-character blocks will regularly end a chunk mid-sentence. The retriever then hands the LLM a fragment. These chunks are typically not semantically coherent, so the approach rarely works for production-grade applications. Tuning its numbers does not fix this. A 128-character block still cuts wherever the count runs out, and more sentences now cross a boundary. Overlap copies the fragment into the next chunk, but the boundary is still in the wrong place. A larger embedding model only changes how long a chunk can be before it is truncated. It has no effect on where the splitter cuts.

    Paragraph-based chunking solves the mid-sentence problem for prose. Paragraphs usually hold related information, so splitting between them keeps each chunk coherent. Format-specific chunking goes a step further when the file has markup. A header-aware splitter turns each Markdown or HTML section into its own chunk, so chunks follow the document's logical outline rather than a character count. Semantic chunking looks at the content itself to find topic shifts. It produces chunks closest to the natural divisions of the text, but it is more involved than the other approaches. Use it when the structure that would mark those divisions is missing, not when headers already do the job. Tables and figures also need their structure preserved, which starts at parsing; see choosing an extraction package.

    Checkpoint 2 of 7· Check yourself

    Your support-ticket corpus is plain-text prose with paragraphs but no headers. It is split into 512-character blocks, and retrieved chunks often stop mid-sentence. Which change fixes where the chunks are cut?

    Checkpoint 3 of 7· Exam question

    A data engineering team ingests thousands of unstructured plain-text support-ticket transcripts and applies a chunking strategy that splits every document into fixed 512-character blocks with no attention to sentence or paragraph boundaries. During evaluation, retrieved chunks frequently cut sentences in half, and the RAG application returns incomplete or confusing context to the LLM. What should the team do to address this?

    Checkpoint 4 of 7· Exam question

    A team is preparing a corpus of Markdown product documentation, where each file uses #, ##, and ### headers to organize content into sections and subsections. They want chunks that align with the document's logical structure rather than arbitrary character counts, so that each chunk corresponds to a coherent section. Which chunking approach best fits this requirement?

    Sources1

    3.Sizing chunks against the embedding model's token limit

    The embedding model's maximum token count is a hard upper limit on chunk size, and going over it fails silently. bge-large-en-v1.5 accepts 512 tokens. Any chunk longer than that is cut to fit before it is embedded, and nothing alerts you. A sentence in the dropped part can never match a query, even though it still appears in the chunk text. Measure chunk length in the same unit the model uses, which is tokens. Characters are not a reliable proxy. Choosing the model itself is covered in selecting an embedding model's context length.

    A large limit does not mean you should use it all. The GTE model and OpenAI's embedding model both accept up to 8,192 tokens. Even so, Databricks recommends splitting into smaller chunks, so that a wider variety of examples can reach the LLM. The OpenAI example chunks at 1,024 tokens, an eighth of what the model allows. It counts tokens with the cl100k_base encoding so that the limit is enforced in tokens:

    Token-based chunking at 1,024 tokens, below the model's 8,192-token limitpython
    import tiktoken
    import pandas as pd
    
    
    max_chunk_tokens = 1024
    encoding = tiktoken.get_encoding("cl100k_base")
    
    
    def chunk_text(text):
        # Encode and then decode within the UDF
        tokens = encoding.encode(text)
        chunks = []
        while tokens:
            chunk_tokens = tokens[:max_chunk_tokens]
            chunk_text = encoding.decode(chunk_tokens)
            chunks.append(chunk_text)
            tokens = tokens[max_chunk_tokens:]
        return chunks

    This splitter is fixed-size by token count, with no overlap and no attention to sentences. It shows how to respect a limit. It does not show how to choose boundaries. Below the limit, choose a size from what users ask. Three sizes are common starting points for experiments:

    Starting chunk sizes and their trade-offs
    Chunk size (tokens)Good forCost
    256Precise fact retrievalMay lose surrounding context
    512A balance between precision and contextMiddle ground on both
    1024More context per chunkHarder to pinpoint the relevant passage; uses more of the LLM context per chunk

    Chunk size is still being researched, and embeddings can fail to capture basic information in long contexts. A bigger chunk is not automatically a better-represented chunk. When you need both precise matching and broad context, index small chunks and return their larger parents. That pattern is covered in advanced chunking strategies.

    Checkpoint 5 of 7· Check yourself

    An engineer indexes a wiki with OpenAI's embedding model, which accepts up to 8,192 tokens. They plan to set the chunk size to 8,192 tokens to get as much context as possible into each vector. What does Databricks recommend instead?

    Sources123

    4.Overlap and the LLM context budget

    Overlap protects content that crosses a chunk boundary. Picture an onboarding guide where one instruction starts at the end of chunk 7 and finishes at the start of chunk 8. Neither chunk contains the whole instruction. Without overlap, any query about it retrieves a chunk with only half the steps. If the last N tokens of each chunk are repeated at the start of the next, the instruction appears complete in chunk 8. That copy can now be matched and returned. The LangChain example in the Databricks pipeline guide uses chunk_size=100 with chunk_overlap=20, which repeats a fifth of each chunk in its neighbour.

    Some fixes look plausible but leave the split in place. Raising the number of chunks retrieved per query returns more candidates, but every candidate still holds only part of the instruction. Sorting chunks into document order before indexing makes no difference either. Retrieval ranks chunks by semantic similarity to the query, not by where they sit in the index. A domain-tuned embedding model represents vocabulary better, but it cannot embed text that a chunk does not contain.

    Every retrieved chunk uses up the LLM's context window. The retrieved chunks have to fit alongside the system prompt, the user's question and any instructions. The rough budget is top-k × chunk size + prompt, and it must stay under the LLM's context window. With top-k of 5 and 1,024-token chunks, retrieval alone uses 5,120 tokens before the prompt is counted. Doubling the chunk size or the top-k doubles that figure. Overlap adds to the total too, because the repeated tokens are in every chunk. This is why the 256/512/1024 starting points matter even with an 8,192-token embedding model. The embedding model limits how big one chunk can be. The LLM's window limits how much text in total can be retrieved.

    Checkpoint 6 of 7· Check yourself

    In an onboarding guide, a setup instruction begins at the end of chunk 7 and finishes at the start of chunk 8. Queries about that instruction keep returning only half the steps. Which change lets one retrieved chunk hold the whole instruction?

    Checkpoint 7 of 7· Exam question

    An engineer builds a RAG pipeline over long onboarding guides. During testing, they notice that a key instruction spanning the end of one chunk and the beginning of the next is never retrieved in full: the retriever returns one chunk or the other, but neither chunk alone contains the complete instruction. Which adjustment to the chunking configuration most directly addresses this failure?

    Sources13

    Sources

    (4)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “ensures that retrieved data fits in the LLM's context while minimizing the inclusion of distracting or irrelevant information”
      ↩︎ What a chunking decision controls
      “Finding the proper chunking method is both iterative and context-dependent.”
      ↩︎ What a chunking decision controls
      “This approach rarely works for production-grade applications.”
      ↩︎ Matching the strategy to the document's structure
      “Use the natural paragraph boundaries in the text to define chunks.”
      ↩︎ Matching the strategy to the document's structure
      “For example, bge-large-en-v1.5 has a maximum token limit of 512.”
      ↩︎ Sizing chunks against the embedding model's token limit
      “Overlapping can ensure continuity and context preservation across chunks and improve the retrieval results.”
      ↩︎ Overlap and the LLM context budget
      “allow fast and accurate retrieval of the most relevant chunks based on their semantic similarity to a retrieval query”
      ↩︎ Overlap and the LLM context budget
      “it will typically not result in consistent semantically coherent chunks”
      ↩︎ Exam trap 1
      “Although more involved than basic approaches”
      ↩︎ Exam trap 2
      “If you pass chunks that exceed this limit, they will be truncated, potentially losing important information.”
      ↩︎ Exam trap 3
      “Overlapping can ensure continuity and context preservation across chunks and improve the retrieval results.”
      ↩︎ Exam trap 5
      “Chunking strategy: The method you use to divide the original text into chunks.”
      ↩︎ Checkpoint
      “Formats such as Markdown or HTML have an inherent structure that can define chunk boundaries (for example, markdown headers).”
      ↩︎ Prediction
      “Use the natural paragraph boundaries in the text to define chunks. This method can help preserve the chunks' semantic coherence”
      ↩︎ Checkpoint
      “If you pass chunks that exceed this limit, they will be truncated, potentially losing important information.”
      ↩︎ Prediction
      “To ensure that important information is not lost when splitting the data into chunks, consider including some overlap between adjacent chunks.”
      ↩︎ Checkpoint
    2. 2.
      “The GTE model supports up to 8192 tokens.”
      ↩︎ Sizing chunks against the embedding model's token limit
      “so that you can feed a wider variety of examples into the reasoning model for your RAG application”
      ↩︎ Exam trap 4
    3. 3.
      “Smaller chunks: Better localization of specific information, but may lose context.”
      ↩︎ Sizing chunks against the embedding model's token limit
      “Context limits: Must fit within LLM context window when retrieving multiple chunks.”
      ↩︎ Overlap and the LLM context budget
      “Maintain semantic boundaries when chunking.”
      ↩︎ Key concept

    Also cited

    Spotted a mistake, or was something unclear? Tell us.