This article describes something that does not exist. The retriever running today ranks chunks by counting shared terms. Its successor is fully specified, down to the constants and the rule for accepting it, and is waiting on two decisions. I am writing it up because the specification is where the engineering judgement is, and because a portfolio that only showed finished work would hide the part I am least sure about.

The problem

The current selection has two steps: chunks that verified fields cite, then chunks ranked by how many of the task’s terms they contain. It fails in a predictable way. A customer asks for an article about “sensitive skin”, and the brand’s page says “gentle enough for daily use on reactive skin”. No term matches. The chunk that answers the task is never selected.

A dense retriever fixes that case and introduces another. Embeddings are good at meaning and poor at exact strings. Brand content is full of exact strings: a model name, a certification number, an ingredient code. A dense model happily returns a passage about a similar product.

Neither kind alone is right, which is the usual argument for a hybrid. The less usual question is how to know the hybrid is better on this data before putting it in front of generators.

The running config and the specified one

Table comparing two retrieval configs. Method: rc-0 uses chunks cited by fields then term overlap; rc-1 uses sparse and dense search fused by reciprocal rank. Candidates: rc-0 all active chunks of the brand; rc-1 50 sparse and 50 dense. Fusion: rc-0 none; rc-1 reciprocal rank fusion with k equal to 60. Per source: rc-0 no limit; rc-1 at most 2 chunks from one page. Returned: rc-0 top 6 up to 6,000 characters; rc-1 top 8 up to 6,000 characters. Reranker: none in both, none to start with for rc-1. Filters: rc-0 workspace and brand; rc-1 workspace and brand required, then language, product and page type. A note explains how rc-1 will be chosen: for ten sample brands, one natural question and one keyword query are generated per chunk and a sample is checked by a person; sparse, dense and hybrid are compared on recall at 5, recall at 10 and MRR at 10; the config with the higher recall at 5 becomes rc-1 provided no single brand drops by more than 0.1; no target was set before measuring.
Figure 1. The two configs. The left column is in code and recorded in every trace. The right column is the specification.

The running config is a dictionary in the loader. The specified one would replace it in the same place. Written in the same form, it would read as follows. This block is the specification, not code from the repository.

# specified, not implemented
RETRIEVAL_CONFIG = {
    "name": "rc-1",
    "filters": ["workspace_id", "brand_id", "language", "product_key", "page_type"],
    "k_sparse": 50,
    "k_dense": 50,
    "fusion": {"method": "rrf", "k": 60},
    "per_source_max": 2,
    "top_k": 8,
    "max_chars": 6000,
    "rerank": None,
}
PartSpecificationReason
Filtersworkspace and brand are mandatory, then language, product and page type; policy pages are excluded by defaultthe filter is the tenancy boundary, so it is applied before any ranking
Sparsea BM25 index with k1 1.2 and b 0.75, over Korean stems plus syllable bigrams, with Latin and digit tokens kept wholeexact strings must match exactly, and Korean compounds need the bigrams
Densea local embedding model on the product’s own servercustomer text does not go to another vendor for embedding
Fusionreciprocal rank fusion with k = 60 over the two top-50 listsneeds no score calibration between two very different scorers
Per sourceat most two chunks from one pageone long page should not fill the context
Rerankernonestart without one, and add one only if it wins the offline comparison

The dense stage was first specified with a remote embedding API. A day later that was changed to local models, and the design lists three candidate pairings of a dense model with a sparse one to compare. Which one is not decided.

Choosing by measurement

A retrieval config is easy to argue for and hard to justify. The specification commits to how the choice will be made before any result exists.

A query set built from the corpus. For each of ten sample brands, up to 50 active chunks are sampled, spread across page types. For each chunk a model writes two queries that the chunk answers: one phrased as a natural question and one as keywords. The chunk is the gold answer for both. Twenty of these are checked by a person, and each query carries a status that says whether it was machine-made, human-checked or made stale by the chunk changing.

Content-hash chunk ids are what make this set durable. A gold label is a chunk id. If the page is re-read and that passage is unchanged, the id is unchanged and the label still holds. With positional ids every re-read would invalidate the whole set.

Three systems, three metrics. Sparse alone, dense alone and the hybrid are run on the same queries and compared on recall at 5, recall at 10 and mean reciprocal rank at 10.

A rule fixed in advance. The system with the higher recall at 5 becomes rc-1, on one condition: no single brand’s recall at 5 may drop by more than 0.1 compared with the alternative. An average that improves while one customer’s retrieval gets clearly worse is not an improvement I want to ship. The design states that no target value was set before measuring, so the result cannot be bent toward one.

The reranker waits. The paper behind this lineage reports that adding modules to a retrieval pipeline does not reliably help and that a reranker can lower quality. So the first config has none. A reranker would be evaluated the same way and added only if it wins.

Why it is not built

Two decisions are open, and both are about operations more than retrieval.

Open decisionThe tension
Which process builds the indexThe API process already runs measurement, scheduling and recovery on a server whose memory is shared. An embedding model loaded there competes with all of them. A separate process is another thing to deploy and watch
Which modelsThree pairings are specified. Choosing needs the evaluation, and the evaluation needs an index, which needs the first decision

Until those are made, the right amount of code is none. The seam is ready: select_evidence is the only function that would change, the config is already versioned, and every trace already records which config produced it. Swapping the retriever would show up in the data as a change of version string on a known date.

Failure modes the specification anticipates

RiskHow the specification handles it
A filter is forgotten and one brand’s chunks reach another’s promptworkspace and brand are required fields of the filter, not optional arguments
The dense model returns a near-duplicate productthe sparse list and the fusion keep the exact match in play
One page dominates the contextat most two chunks per source
The query set rots as pages changelabels are chunk ids, and a query whose chunk changed is marked stale
The index is behind the storethe design gives the context an index status, so a generator can tell it was served from an older index
The average hides a regressionthe per-brand floor of 0.1

Limits I know about

This is a plan, and plans are cheap. Nothing here has met real data. The constants are borrowed from the systems I read, where they were tuned on other corpora.

Generated queries are easier than real ones. A question that a model writes from a chunk can reuse the chunk’s words, which would favour the sparse index. The keyword variant and the human-checked sample reduce that bias and do not remove it.

Ten brands is a small sample chosen by me. A rule about per-brand regressions is only as good as the brands it is checked on.