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.
The five factors handle separate problems. Strategy decides where the cuts fall, size trades precision against context, overlap protects facts that sit on a boundary, coherence keeps each chunk meaningful on its own, and metadata helps match queries to chunks. In an exam scenario, document structure points to strategy and query type points to size.
“Smaller chunks may focus on specific details but lose some surrounding contextual information. Larger chunks may capture more context but can include irrelevant information”Source: docs.databricks.com
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.
| Strategy | Where it splits | When it fits | Weakness |
|---|---|---|---|
| Fixed-size (e.g. LangChain CharacterTextSplitter) | After a set number of characters or tokens | Quick prototypes and first experiments | Cuts through sentences, tables and sections without regard for meaning; rarely works in production |
| Paragraph-based (e.g. LangChain RecursiveCharacterTextSplitter) | At natural paragraph boundaries | Prose where each paragraph holds related information | Ignores 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 headers | Markdown, HTML and wiki pages with clear headings, lists and tables | Only as good as the structure that survived parsing |
| Semantic (e.g. LangChain SemanticChunker) | At topic shifts found by topic modeling or embeddings | Long text without markup where topics change inside sections | More 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?
The cause is that fixed-size cuts ignore what the content means. A bigger size or more overlap still leaves the cut points arbitrary. Paragraph splitting ignores headings and tables. A format-specific splitter cuts at the wiki's own headings, so each section and its tables stay together.
“Formats such as Markdown or HTML have an inherent structure that can define chunk boundaries (for example, markdown headers).”Source: docs.databricks.com
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?
Correct answer: B — Chunk along the document's existing structure, splitting at headings and keeping each table within one chunk
- A. Incorrect. A larger fixed size may happen to fit some tables, but it still ignores heading boundaries, so unrelated sections keep getting merged together and larger chunks still risk splitting bigger tables.
- B. Correct. When a document already has clear structure, chunking should follow that structure: split at heading boundaries and keep tables intact within a single chunk, which is the recommended data-preparation practice for preserving semantic boundaries.
- C. Incorrect. Randomly distributing table rows across overlapping chunks fragments the table further and makes it harder, not easier, to retrieve coherent parameter information.
- D. Incorrect. Removing overlap does not address the root cause, which is chunking that ignores heading and table boundaries; overlap and structure-awareness are separate concerns.
- E. Incorrect. Embedding each full page as one vector eliminates the fine-grained retrieval needed to surface a specific parameter table and dilutes the embedding with unrelated page content.
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.
# 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 chunksIt uses 1024. The model's limit is only the ceiling. Smaller chunks let the RAG application pass a wider variety of examples to the reasoning model.
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?
Text past the 512-token limit is silently truncated, and overlap is part of the chunk that gets embedded. 512 tokens plus 64 of overlap goes over the limit, and 1,500-token chunks lose most of each section. Vector dimensionality is a property of the output and does not raise the input limit.
“they will be truncated, potentially losing important information. For example, bge-large-en-v1.5 has a maximum token limit of 512.”Source: docs.databricks.com
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?
Correct answer: A — Chunk size, including any overlap, must stay at or below the embedding model's 512-token maximum input length
- A. Correct. The embedding model can only process up to its maximum input length; any chunk (plus overlap) that exceeds 512 tokens will be truncated before embedding, so the chunking strategy must keep chunk size within that limit.
- B. Incorrect. Sizing chunks to the 1,500-token average section length far exceeds the embedding model's 512-token limit, guaranteeing truncation rather than preventing it.
- C. Incorrect. Chunk size is not irrelevant; embedding models truncate input that exceeds their maximum length rather than automatically re-chunking and re-embedding it.
- D. Incorrect. Making chunks larger than the embedding model's limit does not help the reranker; it causes the embedding step itself to truncate the chunk before reranking is even possible.
- E. Incorrect. Chunk size must be sized in tokens relative to the model's maximum input length, not set equal to the embedding vector's dimensionality, which is an unrelated property of the output vector.
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.
# Common configurations to test
small_chunks = 256 # Better for precise fact retrieval
medium_chunks = 512 # Balanced approach
large_chunks = 1024 # More context per chunk| Chunk size | Best for | Cost |
|---|---|---|
| Small (around 256 tokens) | Narrow factual lookups, such as a single parameter default or a clause number | May lose the surrounding context needed to interpret the fact |
| Medium (around 512 tokens) | Mixed workloads, as a balanced starting point | A compromise on both precision and context |
| Large (around 1024 tokens) | Broad questions that need explanation or several related points | Harder 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 chunkA small chunk holds only a few facts, so its vector stays close to a narrow question about one of them. That makes 256 tokens the starting point for exact lookups such as a single parameter default. Large chunks carry more context but make the specific detail harder to pinpoint, so they suit broad questions instead.
Source: docs.databricks.comSources2
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.
# 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"]
)Similarity search runs against the small 512-token child chunks, which keeps matching precise. The 2048-token parent is stored in parent_text and returned with the result, so the LLM still gets the context it needs to interpret the match. Putting the parent or the whole document in "text" would bring back the blurred, oversized match that parent-child chunking exists to avoid.
Source: docs.databricks.comCheckpoint 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?
Correct answer: B — Parent-child chunking, indexing small child chunks for retrieval and returning their parent chunks for context
- A. Incorrect. A single fixed chunk size with no overlap does not give the agent both a precise retrieval unit and a larger surrounding context for cross-referenced terms; it forces a single size to serve two competing needs.
- B. Correct. Parent-child (small-to-big) chunking indexes small, precise child chunks for retrieval so clause-level matches stay sharp, while returning the larger parent chunk that contains surrounding sections, giving the agent the context needed to resolve cross-references.
- C. Incorrect. Random-length chunking at arbitrary character positions is likely to split clauses and definitions mid-sentence, degrading both precision and context rather than improving either.
- D. Incorrect. Embedding each entire contract as a single vector loses the precision needed to retrieve a specific clause and dilutes the embedding with unrelated sections of the contract.
- E. Incorrect. Semantic chunking can group related clauses together, but on its own it does not provide a distinct larger context unit the way parent-child chunking does, so cross-referenced definitions outside the semantic group are still missed.
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/quality-data-pipeline-ragOfficial docs
“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.
“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.
“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.https://docs.databricks.com/aws/en/ai-search/vector-search-foundation-embedding-model-gte-exampleOfficial docs
“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 - 5.https://docs.databricks.com/aws/en/ai-search/vector-search-external-embedding-model-exampleOfficial docs
“max_chunk_tokens = 1024”
↩︎ The embedding model's context length is a hard ceiling