Chunking, Hybrid Search, and Reranking
Make documents retrievable without losing meaning
Chunking divides a source into passages that fit retrieval and context constraints. Tiny chunks can lose conditions; large chunks can dilute relevance. Preserve headings, document IDs, version dates, and meaningful boundaries where possible.
Consider “Refunds are available within 14 days, except custom orders.” Splitting before the exception can retrieve an incomplete rule. Keep related conditions together, or attach neighboring context when constructing evidence.
Overlap is useful but not free
An overlap retains some text across adjacent chunks. It can preserve boundary information but increases index size and duplicates in retrieved context. Choose chunk size and overlap by evaluating representative questions, not by adopting a universal token count.
For an example 900-token document, 400-token chunks with 100-token overlap could cover ranges 0–399, 300–699, and 600–899. That is 1,100 indexed tokens with duplication, not 900 unique tokens.
Hybrid retrieval
Lexical methods such as BM25 emphasize term matches and document statistics. Dense retrieval emphasizes relationships learned by an embedding model. Hybrid search combines them, useful when queries include both semantic requests and exact identifiers.
Avoid directly adding raw scores from incomparable scales. Rank fusion, such as reciprocal rank fusion, combines rank positions: score(doc)=Σ 1/(k+rank(doc)). The constant k controls how sharply top ranks dominate; it is not the number of retrieved documents.
flowchart LR A[Authorized query] --> B[Lexical retrieval] A --> C[Dense retrieval] B --> D[Merge and deduplicate] C --> D D --> E[Rerank candidates] E --> F[Select evidence under budget]
A reranker scores a query-document pair more carefully after initial retrieval. Cross-encoders can jointly process the pair, improving ranking at additional cost. Retrieving 100 candidates then reranking does not help if the needed source never enters those 100.
Access and freshness
Apply document permissions during retrieval and recheck before constructing the prompt. Do not fetch cross-tenant evidence, let a model inspect it, and then hope to redact the answer. Track document deletion and superseded policies in both source storage and search indexes.
Checkpoint with answers
What should you measure separately? Candidate recall, final ranking quality, evidence completeness, latency, and authorized-access correctness.
Exercise: Search retrieves a refund clause but loses its custom-order exception. What fixes might help? Answer: semantic chunk boundaries, parent-section expansion, or explicit condition-preserving evidence assembly, followed by an exception-focused evaluation case.