CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 3 · Lesson 16/45

    Chunking strategy for RAG: structure, chunk size and parent-child retrieval

    Select an appropriate chunking strategy given document structure, embedding model context length, and the types of queries the agent will face.

    17 min read
    2.22% of exam
    5 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Choose between fixed-size, paragraph-based, format-specific and semantic chunking based on how a corpus is structured
    • Use the embedding model's maximum input length as a hard ceiling on chunk size, with overlap counted inside it
    • Pick a chunk size for the queries the agent will get: small for precise fact lookup, larger for broad questions that need context
    • Explain how parent-child chunking and overlap keep matching precise without losing the context the LLM needs

    Key concept

    The chunk as the unit of retrieval — A chunk is the unit that gets embedded and matched against a query, and it is also the text that lands in the agent's context. Where you cut the boundaries and how big you make each piece decide what the retriever can find and what the LLM gets to read.

    1.Why chunk boundaries decide what an agent can retrieve

    Chunking is the step in an unstructured data pipeline where parsed documents are cut into smaller pieces, each embedded and indexed on its own. It runs after parsing, deduplication and filtering, and before embedding. Its job is to make sure that what the retriever returns fits in the LLM's context and carries as little distracting text as possible. The order of the whole pipeline is covered in designing a RAG pipeline over a Unity Catalog corpus. This lesson covers the one decision inside it that teams most often get wrong.

    No single setting is right for every corpus. The best method and size depend on the use case and on the data, and you find them by testing more than once. Five factors make up the choice:

    • Strategy: where the text gets cut (by sentences, paragraphs, token counts, or the document's own structure).
    • Size: small chunks focus on specific details, and large chunks carry more surrounding context.
    • Overlap: some text repeated across neighbouring chunks, so a fact that falls on a boundary isn't lost.
    • Semantic coherence: each chunk should hold related information and make sense when read alone.
    • Metadata: source document name, section heading or product names stored with the chunk to help match queries.

    The three questions an exam scenario asks map onto these factors. Document structure decides the strategy. The embedding model sets a ceiling on size. The type of query decides where under that ceiling the size should sit, and whether you need parent-child retrieval to get both precision and context.

    Checkpoint 1 of 8· Match them up

    Each chunking factor addresses a different problem. Match each factor to the problem it handles.

    Tap a term, then the definition that fits it.

    Sources1

    2.Matching the chunking strategy to document structure

    The right strategy is the one that keeps the document's meaningful units in one piece. A unit might be a paragraph, a section under a heading, a table of defaults, or a topic. Each strategy cuts at a different kind of boundary, so each one protects a different kind of unit.

    Chunking strategies, where they cut, and when each one fits
    StrategyWhere it splitsWhen it fitsWeakness
    Fixed-size (e.g. LangChain CharacterTextSplitter)After a set number of characters or tokensQuick prototypes and first experimentsCuts through sentences, tables and sections without regard for meaning; rarely works in production
    Paragraph-based (e.g. LangChain RecursiveCharacterTextSplitter)At natural paragraph boundariesProse where each paragraph holds related informationIgnores headings and tables in more structured documents
    Format-specific (e.g. MarkdownHeaderTextSplitter, HTML header/section splitters)At the format's own structure, such as markdown headersMarkdown, HTML and wiki pages with clear headings, lists and tablesOnly as good as the structure that survived parsing
    Semantic (e.g. LangChain SemanticChunker)At topic shifts found by topic modeling or embeddingsLong text without markup where topics change inside sectionsMore work to set up and run

    Fixed-size chunking is the one to move away from. A token counter can't tell when it's halfway through a table of parameter defaults, or when the next 200 tokens belong to a different H2 section. The result is a chunk with half a table and an unrelated heading attached. That chunk embeds poorly, and if it's retrieved it misleads the LLM. Making the fixed size bigger doesn't solve this. The cuts are still arbitrary, so a larger window just merges more unrelated sections and can still split the next long table.

    For a well-structured corpus, such as an engineering wiki with H2/H3 headings, bullet lists and embedded tables, split along the structure that's already there. Cut at headings and keep each table inside one chunk. The data-preparation guidance for AI Search puts it plainly: remove boilerplate such as headers, footers and page numbers, preserve headings, lists and tables, and keep semantic boundaries intact when chunking.

    Structure-aware chunking needs structure that survived parsing. If a PDF parser drops tables or breaks formatting, no splitter can bring them back. That is why Databricks recommends ai_parse_document for PDFs and complex documents. Its output can go straight into ai_prep_search (Beta), which splits content into semantic chunks and adds document-level context to each one, including the document title and section headers.

    Checkpoint 2 of 8· Check yourself

    A team indexes an engineering wiki written in markdown, with H2/H3 headings, bullet lists and tables of parameter defaults. They use a fixed-size splitter. Retrieved chunks often hold half a table with the heading of an unrelated section attached. Which change fixes the cause?

    Checkpoint 3 of 8· Exam question

    An internal engineering wiki is well-structured, with H2/H3 headings, bullet lists, and embedded tables of parameter defaults. The current ingestion pipeline uses naive fixed-token chunking that frequently cuts tables in half and merges unrelated sections into one chunk. Which change best improves chunk quality for this corpus?

    Sources123

    3.The embedding model's context length is a hard ceiling

    Every embedding model has a maximum number of input tokens, and that number caps your chunk size. bge-large-en-v1.5 stops at 512 tokens. The GTE model served through Foundation Model APIs and OpenAI's embedding model both accept up to 8192. Text past the limit is cut off. Whatever was in the cut-off part never reaches the vector, so a query about it can't match that chunk.

    Overlap counts against the ceiling too. Overlap means copying text from the end of one chunk into the start of the next, and that copied text is part of the chunk the model embeds. With a 512-token model, the full chunk, overlap included, has to stay at or below 512 tokens. 1,500-token manual sections therefore have to be split into several chunks. Matching chunk size to section length would truncate every section. Vector dimensionality is a property of the output and has nothing to do with how much input the model accepts.

    Staying under the ceiling is necessary, but it isn't the goal. The GTE notebook could make 8192-token chunks. Databricks still recommends splitting into smaller chunks so the reasoning model receives a wider variety of examples. Very long inputs also have a quality cost: recent research (DeepMind's LIMIT) shows embeddings can miss basic information in long contexts. That is why embedding an entire contract or wiki page as one vector does poorly even when the model technically accepts it.

    Token-based chunking in the GTE example: the limit comes from the model's maximum context lengthpython
    # The GTE model has been trained on a max context lenth of 8192 tokens.
    max_chunk_tokens = 8192
    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

    Checkpoint 4 of 8· Check yourself

    You're configuring chunking for bge-large-en-v1.5, which accepts at most 512 tokens. The source manuals have sections of about 1,500 tokens, and you want some overlap between neighbouring chunks. Which configuration keeps every part of every section searchable?

    Checkpoint 5 of 8· Exam question

    A team is selecting a chunk size for a manuals corpus using an embedding model whose maximum input length is 512 tokens. Manual sections average 1,500 tokens, and the team plans a 10% overlap between chunks. What must the chunk size satisfy to avoid content being silently truncated by the embedding model?

    Sources1452

    4.Sizing chunks for the queries the agent will face

    Below the embedding ceiling, the queries the agent will face should decide chunk size. A small chunk holds just a few facts, so its vector stays close to a narrow question about one of them. A large chunk mixes many facts into one vector. It matches broad questions better and gives the LLM more to work with, but the specific detail is harder to pinpoint.

    Starting points Databricks suggests for chunk size experimentspython
    # Common configurations to test
    small_chunks = 256   # Better for precise fact retrieval
    medium_chunks = 512  # Balanced approach
    large_chunks = 1024  # More context per chunk
    How chunk size trades off against query type
    Chunk sizeBest forCost
    Small (around 256 tokens)Narrow factual lookups, such as a single parameter default or a clause numberMay lose the surrounding context needed to interpret the fact
    Medium (around 512 tokens)Mixed workloads, as a balanced starting pointA compromise on both precision and context
    Large (around 1024 tokens)Broad questions that need explanation or several related pointsHarder to pinpoint relevant information; fewer chunks fit in the LLM context window

    The LLM's context window adds another limit. An agent usually retrieves several chunks per query, and together they have to fit. Ten 1024-token chunks cost four times as much context as ten 256-token chunks, so large chunks also mean fewer distinct sources per answer.

    Chunk size shouldn't take up all the tuning effort. Prepending the document title, a summary and the section name to each chunk often helps more. That gives the embedding model more semantic signal and helps with queries about document-level concepts. A bare 256-token chunk from the middle of a brake manual doesn't say it's about brakes. The same chunk with "Section: Emergency brake adjustment procedures" on top does. Using that metadata as separate columns for reranking or hybrid search is part of AI Search configuration.

    Checkpoint 6 of 8· Fill the gap

    Three chunk sizes are suggested as starting points for experiments. Which kind of retrieval does the smallest setting serve best?

    # Common configurations to test
    small_chunks = 256   # Better for  ?  fact retrieval
    medium_chunks = 512  # Balanced approach
    large_chunks = 1024  # More context per chunk

    Sources2

    5.Parent-child chunking and overlap

    Parent-child chunking removes the trade-off between small and large chunks. It's also called small-to-big retrieval. The document is cut into large parent chunks, each parent is cut into small child chunks, and every child row stores its parent's text. Similarity search runs against the small children, so matching stays precise. The index then returns the parent text, so the LLM reads the surrounding context.

    Recording children with their parent, then searching children and returning parentspython
    # Record child and parent chunks in your source table
    for parent_chunk in create_chunks(doc, size=2048):  # Large for context
        for child_chunk in create_chunks(parent_chunk, size=512):  # Small for precision
            source_table.append({"text": child_chunk, "parent_text": parent_chunk})
    
    # Search children, return parents
    results = index.similarity_search(
        query_text="Is attention all you need?",
        num_results=10,
        columns=["text", "parent_text"]
    )

    Contracts show where this helps. Users ask clause-level questions, so the match has to land on one clause, and a 512-token child does that. But a clause like "subject to the Indemnified Losses defined above" can't be interpreted without the text around it. Returning the 2048-token parent gives the agent that surrounding text. The other options each give up one of the two needs. Fixed-size chunks with no overlap cut clauses at random. Embedding each whole contract as one vector truncates or blurs it. Semantic chunking alone groups similar clauses but returns only the chunk it matched, with no parent context.

    Overlap deals with a smaller version of the same problem: a fact that falls on a chunk boundary. When neighbouring chunks share a strip of text, a sentence cut at the end of one chunk appears whole at the start of the next, so it can still be retrieved. A visual example uses RecursiveCharacterTextSplitter with chunk_size=100 and chunk_overlap=20, which repeats about a fifth of each chunk in the next. Overlap protects continuity across boundaries. It can't fix boundaries placed in the wrong spot by a fixed-size splitter, and it doesn't give a chunk more context than its own size.

    Checkpoint 7 of 8· Fill the gap

    In a parent-child setup for clause-level contract questions, the index must match the query against small pieces but hand the agent the surrounding text. Which variable belongs in the row's embedded "text" column?

    # Record child and parent chunks in your source table
    for parent_chunk in create_chunks(doc, size=2048):  # Large for context
        for child_chunk in create_chunks(parent_chunk, size=512):  # Small for precision
            source_table.append({"text":  ? , "parent_text": parent_chunk})
    
    # Search children, return parents
    results = index.similarity_search(
        query_text="Is attention all you need?",
        num_results=10,
        columns=["text", "parent_text"]
    )

    Checkpoint 8 of 8· Exam question

    A legal team's contract management RAG system indexes lengthy contracts whose clauses frequently reference definitions found in other sections. Users need precise, clause-level answers, but the agent also needs enough surrounding context to interpret cross-referenced terms correctly when generating a response. Which chunking strategy best addresses both needs?

    Sources21

    Sources

    (5)

    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”
      ↩︎ Why chunk boundaries decide what an agent can retrieve
      “Finding the proper chunking method is both iterative and context-dependent. There is no one-size-fits-all approach.”
      ↩︎ Why chunk boundaries decide what an agent can retrieve
      “Relevant metadata, such as the source document name, section heading, or product names, can improve retrieval.”
      ↩︎ Why chunk boundaries decide what an agent can retrieve
      “Formats such as Markdown or HTML have an inherent structure that can define chunk boundaries (for example, markdown headers).”
      ↩︎ Matching the chunking strategy to document structure
      “determine the most appropriate chunk boundaries based on topic shifts”
      ↩︎ Matching the chunking strategy to document structure
      “For example, bge-large-en-v1.5 has a maximum token limit of 512.”
      ↩︎ The embedding model's context length is a hard ceiling
      “Overlapping can ensure continuity and context preservation across chunks and improve the retrieval results.”
      ↩︎ Parent-child chunking and overlap
      “Fixed-size chunking example using LangChain's RecursiveCharacterTextSplitter with chunk_size=100 and chunk_overlap=20.”
      ↩︎ Parent-child chunking and overlap
      “The choices made on chunking will directly affect the retrieved data the LLM provides”
      ↩︎ Key concept
      “it will typically not result in consistent semantically coherent chunks. This approach rarely works for production-grade applications.”
      ↩︎ Exam trap 1
      “If you pass chunks that exceed this limit, they will be truncated, potentially losing important information.”
      ↩︎ Exam trap 2
      “Smaller chunks may focus on specific details but lose some surrounding contextual information.”
      ↩︎ Exam trap 3
      “Smaller chunks may focus on specific details but lose some surrounding contextual information. Larger chunks may capture more context but can include irrelevant information”
      ↩︎ Checkpoint
      “If you pass chunks that exceed this limit, they will be truncated, potentially losing important information.”
      ↩︎ Prediction
      “they will be truncated, potentially losing important information. For example, bge-large-en-v1.5 has a maximum token limit of 512.”
      ↩︎ Checkpoint
    2. 2.
      “Preserve document structure (headings, lists, tables).”
      ↩︎ Matching the chunking strategy to document structure
      “Poor parsing (missing tables, broken formatting) directly impacts retrieval quality.”
      ↩︎ Matching the chunking strategy to document structure
      “Recent work from DeepMind (LIMIT) shows embeddings can fail to capture basic information in long contexts”
      ↩︎ The embedding model's context length is a hard ceiling
      “Larger chunks: More context preserved, but harder to pinpoint relevant information.”
      ↩︎ Sizing chunks for the queries the agent will face
      “Context limits: Must fit within LLM context window when retrieving multiple chunks.”
      ↩︎ Sizing chunks for the queries the agent will face
      “Semantic metadata: Add document summaries and section headers to chunks.”
      ↩︎ Sizing chunks for the queries the agent will face
      “Parent-child chunking (small-to-big retrieval):”
      ↩︎ Parent-child chunking and overlap
    3. 3.
      “the function splits content into semantic chunks, enriches each chunk with document-level context such as the document title, section headers”
      ↩︎ Matching the chunking strategy to document structure
    4. 4.
      “The GTE model supports up to 8192 tokens. However, Databricks recommends that you split the data into smaller context chunks”
      ↩︎ The embedding model's context length is a hard ceiling
      “However, Databricks recommends that you split the data into smaller context chunks”
      ↩︎ Exam trap 4

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

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