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.
Only a change of strategy places boundaries more sensibly. Size controls how much text a chunk holds, overlap keeps content that crosses a boundary together, and metadata such as a document name or section heading helps queries match chunks. Changing size or overlap moves or duplicates arbitrary boundaries, but it does not fix them.
“Chunking strategy: The method you use to divide the original text into chunks.”Source: docs.databricks.com
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.
| Strategy | Where it puts boundaries | Example tool | Best fit |
|---|---|---|---|
| Fixed-size | Every N characters or tokens, wherever that falls | LangChain CharacterTextSplitter | Quick prototypes only; it rarely works in production |
| Paragraph-based | At natural paragraph boundaries | LangChain RecursiveCharacterTextSplitter | Plain prose such as transcripts, articles and emails |
| Format-specific | At the format's own structure, such as markdown headers or HTML sections | LangChain MarkdownHeaderTextSplitter, HTML header/section-based splitters | Markdown or HTML with headed sections |
| Semantic | At topic shifts, found by topic modeling or embeddings | LangChain SemanticChunker | Long 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?
Smaller blocks, overlap and a bigger embedding model all leave the cuts at arbitrary character counts. Splitting at paragraph boundaries keeps each chunk coherent. A header-aware splitter needs headers, and these tickets have none.
“Use the natural paragraph boundaries in the text to define chunks. This method can help preserve the chunks' semantic coherence”Source: docs.databricks.com
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?
Correct answer: A — Switch to paragraph-based or format-specific chunking, so that chunk edges follow the sentence and section structure of each transcript.
- A. Paragraph-based or format-specific chunking places chunk edges at sentence and section breaks instead of at a character count. Retrieved chunks then start and end at natural points, which removes the cause of the half-cut sentences.
- B. More overlap repeats text around each split, but the splits still fall at arbitrary character positions. Retrieved chunks still begin and end mid-sentence, and the index grows with duplicated text. The context handed to the LLM stays fragmentary.
- C. A smaller fixed size still cuts at character counts that ignore sentence breaks. Transcript sentences vary in length, so many are still split, and shorter chunks carry less surrounding context, which can make retrieved results more fragmentary.
- D. The embedding model's input window controls how much text it can embed at once. It does not control where the splitter cuts. Fixed 512-character blocks would still end mid-sentence, so the retrieved chunks would be just as incomplete.
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?
Correct answer: A — Use a Markdown-aware splitter that cuts each file where a heading line starts, keeping the text under each heading together.
- A. A Markdown-aware splitter uses the heading lines as chunk boundaries, so the text under each heading stays together as one chunk. The chunks then match the document's section and subsection structure, not a size limit.
- B. A recursive character splitter prefers paragraph and line breaks, but it still ends chunks by length (about 1,000 characters). It does not look at headings, so a long section is cut partway and a short one is merged with its neighbour. Chunks would not line up with sections.
- C. Semantic splitting infers boundaries from changes in embedding similarity between sentences. Those cut points can fall inside a section or run across a heading. The files already mark their sections with headers, which give exact boundaries, so inferred topic shifts do not reliably produce one chunk per section.
- D. Splitting at blank lines gives one chunk per paragraph, which is much finer than a section, and removing the markup discards the headers that define the sections. A section would be scattered over many chunks, none of which represents the whole section.
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:
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 chunksThis 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:
| Chunk size (tokens) | Good for | Cost |
|---|---|---|
| 256 | Precise fact retrieval | May lose surrounding context |
| 512 | A balance between precision and context | Middle ground on both |
| 1024 | More context per chunk | Harder 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?
The token limit is only an upper bound. Databricks recommends smaller chunks so that more varied examples reach the LLM, and its OpenAI example uses 1,024 tokens. Characters do not reliably stand in for tokens, and large chunks use up the LLM's context, so retrieving more of them does not bring in variety.
“Databricks recommends that you split the data into smaller context chunks so that you can feed a wider variety of examples into the reasoning model”Source: docs.databricks.com
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?
Overlap repeats boundary content in the next chunk, so the instruction appears complete in chunk 8. A higher top-k still returns chunks that each hold only part of the instruction. Retrieval ranks chunks by similarity, not by where they sit in the index. A better embedding model cannot embed text that a chunk does not contain.
“To ensure that important information is not lost when splitting the data into chunks, consider including some overlap between adjacent chunks.”Source: docs.databricks.com
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?
Correct answer: A — Configure adjacent chunks to overlap by a set number of tokens so boundary content appears in more than one chunk.
- A. Adding overlap between adjacent chunks means content near a boundary is duplicated into both chunks, so an instruction that straddles the boundary will appear in full inside at least one chunk and can be retrieved intact.
- B. Returning more candidate chunks increases the chance both neighboring chunks are retrieved together, but neither chunk individually contains the complete instruction, so the response context is still fragmented across two partial chunks.
- C. A domain-tuned embedding model can improve semantic matching for retrieval, but it does not change where chunk boundaries fall, so the instruction would still be split across two chunks.
- D. Physical storage order in the vector index does not affect which chunks are returned for a similarity search, so this does not help the retriever surface the complete instruction.
Sources
(4)
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”
↩︎ 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.https://docs.databricks.com/aws/en/ai-search/vector-search-foundation-embedding-model-gte-exampleOfficial docs
“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.
“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
- https://docs.databricks.com/aws/en/ai-search/vector-search-external-embedding-model-exampleOfficial docs
“Databricks recommends that you split the data into smaller context chunks so that you can feed a wider variety of examples into the reasoning model”
↩︎ Checkpoint