A clinical search service has two constraints that refuse to stay separate: the retrieved evidence must be relevant enough to support an answer, and it must arrive before the request budget expires. The practical choice is to evaluate retrieval before shipping, with relevance and latency treated as paired release criteria rather than letting a polished generated answer stand in for evidence quality.
TL;DR: build a versioned set of realistic clinical questions and relevance judgments, measure the candidate retriever and reranker independently, preserve every query-to-document decision in an audit record, and release only when both the quality floor and latency ceiling hold on the same workload. Retrieval-augmented generation conditions output on retrieved material; if that material is wrong or missing, generation cannot repair the evidence boundary reliably.
Why does retrieval evaluation matter before shipping RAG?
The original RAG formulation separates a parametric model from non-parametric memory and retrieves documents that condition generation. That division is operationally important. An answer may read fluently while the retriever has omitted the decisive document, selected an outdated passage, or returned several near-duplicates that create an illusion of corroboration. Evaluating only the final prose collapses two different failure domains into one score.
Consider a hypothetical healthtech search request: “What follow-up is documented after an abnormal screening result?” A keyword match may rank a general screening overview above the patient-facing follow-up policy; a semantic retriever may find conceptually close material from the wrong clinical program; and a reranker may improve topical fit while adding enough latency to violate the service objective. None of those outcomes can be diagnosed from answer style.
This is why retrieval evaluation belongs before launch. It establishes whether the system can locate the evidence needed for the task, shows where that evidence disappears in the pipeline, and creates a reproducible basis for deciding whether a reranker earns its latency. The relevant unit is not “the demo looked right.” It is a query, a frozen corpus version, an ordered candidate list, explicit judgments, and a traceable configuration.
Start with an auditable evaluation contract
The evaluation set should represent the actual job: reranking search results for relevance. Each example needs a stable query identifier, the corpus snapshot, and graded judgments for candidate documents. Binary labels are easy to administer but lose a useful distinction between a passage that directly answers the question and one that merely shares vocabulary. Graded judgments retain that distinction, provided the rubric defines the grades clearly and adjudication is recorded.
Retries happen.
Keep sensitive clinical data out of ad hoc evaluation files. The Health Insurance Portability and Accountability Act Security Rule requires covered entities to apply administrative, physical, and technical safeguards to electronic protected health information. Evaluation data therefore needs the same access-control, retention, and audit thinking as production data; de-identification or synthetic examples may reduce exposure, but the chosen data must still represent the retrieval task. Access to judgments should be attributable, and changes should be reviewable.
I use an exactly-once mindset here as a design discipline, not as a claim that distributed execution becomes magical. One evaluation run receives an idempotency key derived from the dataset version, corpus version, retrieval configuration, reranker configuration, and code revision. A retry with the same key returns or verifies the same recorded run rather than appending a second, ambiguous result. If any input changes, the key changes.
The record can stay small:
package eval
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
)
type RunInput struct {
DatasetVersion string `json:"dataset_version"`
CorpusVersion string `json:"corpus_version"`
RetrieverConfig string `json:"retriever_config"`
RerankerConfig string `json:"reranker_config"`
CodeRevision string `json:"code_revision"`
}
func IdempotencyKey(in RunInput) (string, error) {
b, err := json.Marshal(in)
if err != nil {
return "", err
}
sum := sha256.Sum256(b)
return hex.EncodeToString(sum[:]), nil
}
The hash is not the audit trail. It is the join key for an immutable record containing timestamps, inputs, ranked document identifiers, relevance labels, metric outputs, errors, and the identity of the approved dataset revision. Store content references rather than unnecessary clinical text when the evaluation can be reproduced that way.
Measure the pipeline at both ranking boundaries
Evaluate the initial candidate set first. Recall at a chosen cutoff answers the gating question: did retrieval include relevant evidence for the reranker to work with? If the needed document never enters the candidate set, reranking cannot recover it. Then evaluate the reordered list with a rank-sensitive measure such as normalized discounted cumulative gain, which rewards placing highly relevant documents near the top while supporting graded judgments.
One number is insufficient.
Report slices that correspond to meaningful retrieval difficulty, such as short versus detailed queries, common versus rare terminology, and queries whose relevant evidence appears in one document versus several. These are analytical categories, not claims about performance. Define them before examining a candidate release so that a convenient aggregate cannot conceal a harmed cohort of queries.
Latency must be captured from the same runs. Record the initial retrieval duration, reranking duration, end-to-end duration, candidate count, and outcome status. Percentiles show the distribution more honestly than an average, but the acceptable percentile and ceiling are service decisions that the owning team must set from its request budget. Also report timeouts and errors as outcomes; excluding them makes the quality sample conditional on success and can overstate what users receive.
| Boundary | Primary question | Useful evidence | Release interpretation |
|---|---|---|---|
| Candidate retrieval | Was relevant material available? | Recall at a declared cutoff, sliced by query class | Low recall directs work toward indexing, query handling, or candidate breadth |
| Reranking | Did the order improve? | Rank-sensitive gain before and after reranking | Improvement must hold beyond the aggregate and on the frozen candidate sets |
| Request path | Did it finish within budget? | End-to-end latency distribution, timeout rate, error rate | Quality gains count only for requests the service can complete |
The comparison should be paired: run the baseline and candidate against the same corpus snapshot and evaluation queries, then retain per-query deltas. Averages hide reversals. Per-query records show which clinical intents improved, which regressed, and whether a latency increase comes from a larger candidate set or from reranker execution.
Turn trade-offs into a release rule
A defensible gate starts with separate minimum conditions. Candidate recall must not fall below its agreed floor. Reranked quality must meet its floor overall and on critical predefined slices. End-to-end latency must remain below its ceiling at the selected percentile, while timeout and error handling are counted rather than discarded. The exact thresholds are local policy; inventing universal values would disguise product and risk decisions as science.
Then make the trade explicit. If a larger candidate set raises ranking quality but consumes most of the latency budget, test smaller candidate counts and preserve the full curve. Do not select one point after seeing a favorable aggregate. Inspect the queries that move in each direction: a candidate configuration can lift documents for broad educational questions while pushing narrowly scoped policy documents down, and the aggregate may still improve. The release decision should state whether that redistribution matches the clinical search job rather than treating every unit of gain as interchangeable. Record why the chosen operating point is acceptable, who approved it, and which corpus and code revisions it covers. This turns “the reranker seems better” into an auditable decision that can be reviewed after the corpus or request mix changes.
Clinical content introduces another boundary: relevance is not the same as clinical correctness, currency, authorization, or suitability for a particular patient. Retrieval evaluation verifies ranking behavior against its judgments. It does not replace clinical review, privacy assessment, safety analysis, or monitoring of the generated response. Keep those controls distinct so a passing ranking metric cannot be misread as broad system approval.
Failure handling deserves equal specificity. A reranker timeout should follow a declared policy, such as returning the baseline order only when that behavior has itself passed evaluation and is visible in telemetry. Each response trace should say which path executed. Silent fallback corrupts both operational understanding and later reconciliation because the observed answer can no longer be tied confidently to the configuration believed to have produced it.
Roll out without losing the evidence chain
Ship slowly.
Begin with shadow evaluation on production-shaped queries under the applicable data controls, without allowing the candidate ranking to affect responses. Compare it with the released path using the same query identifier, corpus version, and candidate snapshot. Next, expose a limited cohort under a predeclared rollback rule, while monitoring the quality proxies that are valid online and the latency and error measures that are directly observable.
Rollout is compact; accountability is not. Preserve the decision record, configuration, evaluation artifact, approval, and deployment identifier so an answer can be reconciled with the retrieval path that served it. Re-run the gate when the corpus, chunking, embedding process, retrieval logic, reranker, or judgment set changes materially, because the earlier result describes the earlier system.
The shipping question is therefore precise: can this version retrieve and order the required evidence, for the intended query distribution, inside the declared request budget? If the evidence cannot answer that question reproducibly, the feature is not ready for release, regardless of how convincing its best generated response appears.
Top comments (0)