Tuning Chunking, Thresholds and Retrieval
This lesson explains how chunk size, overlap and structure affect retrieval, how top-k and thresholds control context, and how filters and query strategies improve results.
Learning outcomes
After completing this lesson, you will be able to:
- Explain the trade-off of chunk size and overlap.
- Describe structure-aware chunking.
- Explain how top-k and thresholds are calibrated.
- Choose a filter or query strategy for a problem.
Chunk size and overlap
Chunk size is a trade-off. Small chunks, such as 200 tokens, produce precise embeddings and return only what is relevant, but may cut an explanation in half or lose the heading that gives it meaning. Large chunks, such as 1,500 tokens, keep context together, but their embeddings average many topics, so they match queries less precisely, and each retrieved chunk adds many tokens to the prompt.
Overlap repeats the end of one chunk at the start of the next, so a sentence that spans a boundary appears whole in at least one chunk. A common starting point is around 512 tokens with 10 to 25 percent overlap, which is then tuned with evaluation. In Azure AI Search, the Text Split skill sets the split mode, the maximum page length and the overlap length.
Structure-aware chunking
Fixed-length splitting ignores document structure, so it can separate a table from its header or a step from its procedure. Structure-aware chunking splits on headings, sections and paragraphs, keeps tables and lists intact, and adds context such as the document title and section heading to each chunk. In Azure AI Search, the Document Layout skill extracts sections and tables as Markdown, which a split by section then turns into coherent chunks.
- Prefix each chunk with its document title and section path, such as "Policy handbook > Claims > Water damage".
- Keep tables in one chunk with their header row, or convert rows into sentences that repeat the column names.
- Store metadata such as product, version, date and access group with each chunk for filtering.
Top-k and similarity thresholds
Top-k is the number of chunks returned and passed to the model. Too few, and the relevant chunk may be just outside the results; too many, and irrelevant chunks dilute the context, increase cost and latency, and can lead the model astray. A similarity threshold discards results whose score is below a minimum, so that a question with no good match receives little or no context and the model can say it does not know, rather than answering from weak matches.
A useful pattern is to retrieve generously and filter strictly: retrieve, for example, 50 candidates with hybrid search, rerank them with the semantic ranker, and keep only those above a reranker score threshold, up to a small maximum such as five. Thresholds must be calibrated on evaluation data, because score scales differ between similarity metrics, search modes and rankers.
Calibrate thresholds on both sides
Watch the unanswerable questions in the evaluation set when tuning thresholds. A threshold that is too low makes the assistant answer them from irrelevant passages; one that is too high makes it decline questions it could answer.
Filters and query strategies
Metadata filters restrict retrieval to documents that can apply: the customer's product, the current policy version, the user's region or the documents the user is allowed to see. Filters improve precision cheaply and enforce security trimming, and in Azure AI Search they can apply before the vector search (pre-filtering), so that the top results all satisfy them.
| Strategy | What it does | Helps when |
|---|---|---|
| Query rewriting | A model rewrites the user's message into a clearer search query, adding context from the conversation | Follow-up questions such as "what about the premium plan?" |
| Multi-query | Generates several variants of the query and merges results | Questions can be phrased in different ways |
| Query decomposition and agentic retrieval | Splits a complex question into sub-queries, runs them and combines results | Questions that need several pieces of information |
| Hybrid search and reranking | Combines keyword and vector results, then reranks | Exact terms matter, or ranking quality is low |
Tuning for precise answers
A product support assistant uses 1,500-token chunks and top-k of 10. Evaluation shows good recall: the relevant passage is retrieved 93 percent of the time. But groundedness is only 3.4, answers often mix details from different product models, and prompts average 16,000 tokens. Every chunk carries a product model field.
Retrieval finds the right content, but too much other content arrives with it. Add a metadata filter on the product model, reduce chunk size to around 500 tokens with overlap and structure-aware splitting, and reduce top-k, possibly after semantic reranking with a threshold. Re-measure recall, groundedness and tokens after each change.
Increasing top-k would add more mixed content. A larger context window model would accept the 16,000 tokens but not stop it mixing products. Re-embedding with a larger embedding model addresses recall, which is already good.
What is the purpose of overlap between chunks?
Show answer
Overlap repeats the end of one chunk at the start of the next, so that a sentence or idea that spans a chunk boundary appears whole in at least one chunk.
Exam Tips
Remember for the exam
- Small chunks are precise; large chunks keep context; start near 512 tokens with 10 to 25 percent overlap.
- Structure-aware chunking keeps sections and tables intact and adds titles and headings.
- Retrieve generously, rerank, then keep a few results above a calibrated threshold.
- Metadata filters improve precision and enforce security trimming.