Improve retrieval with evidence from traces
Find the binding performance constraint, expose missing telemetry, and compare retrieval designs.
An engineering reference service answers questions about changing parts manuals. Its product owner wants correct citations within a fixed response time during peak traffic.
3.3 · Relieve the binding quality or latency constraint
Separate retrieval recall, answer grounding, and end-to-end latency. Suppose relevant evidence is retrieved in 98% of cases but the generator misreads a units table. More candidates will add tokens and time with little effect on the defect. Improve table representation or evidence interpretation. If the right evidence is absent, measure retrieval before changing model tier.
Use an experiment table with one row per configuration, including retrieval depth, reranking, quality by query class, p95, and cost. Select the least expensive feasible change against the binding constraint.
Read the denominator before upgrading the model
In 100 held-out questions, the retriever returns the required passage for 78. The generator gives 74 grounded answers among those 78 and abstains when evidence is absent. The target is 90 grounded answers with p95 below 1.8 seconds. A better generator leaves retrieval unchanged. A hybrid retriever returns the passage for 95, yields 91 grounded answers, and measures 1.6 seconds p95.
Locate the binding constraint
Baseline retrieval recall is 78%. Generation succeeds on about 95% of the cases where it has evidence. Under the stated grounding rule even a perfect generator could reach only 78 grounded answers with the baseline retriever. The hybrid replay meets both observed limits. Examine cases lost by the hybrid retriever as well as newly recovered ones, and check the results by manual family and query type.
If the latency figure were 2.1 seconds, the same change would fail a hard constraint. Time candidate generation and reranking separately. Try reranking only ambiguous matches and run the same suite again before selecting it.
Video background · freeCodeCamp at 0:39:21 · seeing why a whole document gives an imprecise match
3.4 · Instrument a failure at scale
Give each request a trace ID and each retrieval, model, tool, and queue operation a span. Capture tenant-safe cohort tags, model and index revisions, document IDs, durations, token counts, retry outcomes, and whether the required source was available. Use metrics for fleet trends, traces for critical paths, and sampled redacted logs for individual decisions. Keep failures and slow traces represented when sampling.
A global success rate can mask one locale serving an obsolete index. Break down grounded answer rate and index freshness by locale, alert an owner, and link the alert to a representative trace.
Find an incident hidden by a green dashboard
In a 1,000-request sample, all requests return HTTP 200. Nine hundred English queries use index r18. One hundred French queries still use r14, and 24 of their citations fail the revision check. The dashboard shows 100% availability. Specify the signal, its denominator, and the trace fields that would let an operator act.
Build an alert the on-call team can use
Keep request availability as one metric. Add revision-correct citation rate for evaluated answers by locale and index revision. Here the French sample has 76 valid citations out of 100. A global figure of 97.6% would conceal that local failure if the other 900 citations all passed. Report sample size and evaluation coverage with each rate.
Record the expected and served index revisions, source reference, tenant-safe cohort and parent trace ID. Page the index owner when stale revisions persist beyond the agreed refresh interval. A recovery replay should show r18 serving the French cases and the formerly failing citations resolving.
Video background · freeCodeCamp at 3:07:31 · identifying gaps in a coordinator’s trace
3.5 · Choose retrieval architecture and index design
For a small stable handbook that fits the budget, supplying the complete text can beat maintaining an index. For a large corpus of manuals with frequent similar queries, pre-index meaningful sections, retain headings, revisions, access metadata, and table headers, and refresh changed entries. Combine lexical retrieval for part IDs with semantic retrieval for paraphrases. Contextual prefixes can disambiguate otherwise similar chunks. Rerank a bounded candidate set if its measured benefit fits the latency budget.
Agentic search fits data that must be explored live through tools when variable latency is acceptable. For low-confidence retrieval, try an authorized alternate query or ask for a part number. If evidence is still absent, surface the gap. An index or cache must preserve deletions and current entitlements.
Rebuild a chunk that lost its exception
Revision 8 of a gauge manual says “Inspect after 300 cycles” in a table row. Its header specifies indoor units, and the next row changes the interval to 120 cycles for outdoor units. An older manual uses the same part ID. A vector query retrieves the 300-cycle row for an outdoor unit. Design the indexed record and a fallback when the unit type is missing.
Compare the evidence a reader would receive
Index the table with its header, indoor and outdoor qualifiers, model, revision, source location and access metadata. Use lexical matching for the exact part ID and semantic matching for descriptions such as “exposed to weather.” Filter by current revision and access before evidence enters context. Rerank a bounded candidate set using a labeled mix of exact-ID and paraphrased queries.
A wide overlap can recover a nearby header but can also surface duplicate rows or an obsolete edition. Inspect the actual returned passage. With a known outdoor unit, an acceptable answer cites the 120-cycle row from revision 8. With no unit type, request the missing fact or give both explicitly conditional intervals with citations.
Video background · freeCodeCamp at 0:41:40 · testing chunk boundaries and overlap
Diagnose a retrieval regression after an encoder change
A team changes the query encoder from E1 to E2 and leaves the corpus vectors on E1. Both return 384 numbers. Exact part-number searches still pass, but paraphrases start returning unrelated parts. The identical vector length satisfies a storage constraint. It provides no evidence that two encoders assign the same meaning to each coordinate.
Replay a labeled slice with the matching E1 query encoder and E1 index. Build a separate E2 index with its matching query configuration and compare recall, access filters, revision freshness and latency before switching traffic. Keep the index and query encoder as one versioned deployment pair. A bounded lexical fallback can preserve exact-ID lookups while semantic retrieval is degraded.
Further study · freeCodeCamp at 0:35:53 · indexing and querying a vector collection
Replay three retrieval failures
Use this Python 3 fixture to inspect the stage between retrieval and generation. Each row is an already-ranked candidate with its tenant, revision, unit type and inspection interval in cycles. The authorized customer is Pine, its current manual is revision 8 and its unit is outdoors. Predict what a first-hit policy would return, then run the fixture locally.
# Synthetic candidate list, highest retrieval score first.
rows = [
("Oak", 8, "outdoor", 80),
("Pine", 7, "outdoor", 150),
("Pine", 8, "indoor", 300),
("Pine", 8, "outdoor", 120),
]
def intervals(tenant, revision, unit):
return [cycles for owner, rev, kind, cycles in rows
if (owner, rev, kind) == (tenant, revision, unit)]
print(rows[0][-1])
print(intervals("Pine", 8, "outdoor"))
print(intervals("Pine", 8, "unknown"))
Check the output and interpret it
80
[120]
[]The first hit belongs to Oak and must not enter Pine’s model context. Filtering only by tenant still admits the obsolete 150-cycle interval. Filtering tenant and revision still leaves the indoor exception. With the unit unknown, the empty result should trigger clarification. Delete the final row and repeat to see the difference between an absent authorized passage and an unsupported guess. In a deployed index apply access filtering at retrieval and verify it before exposing results. This fixture isolates candidate selection and uses no model or external service.
Design exercise
A test set has two classes, exact part IDs and descriptions of symptoms. Score recall for each before and after hybrid retrieval. Add duplicate section titles from different manuals and check that the returned chunk carries its parent and revision. Record the latency added by reranking before enabling it for every query.
Further reading · Contextual retrieval · Evaluation design for agents
Improve retrieval with evidence from traces quiz
Answer 10 questions. Check each answer for an explanation.