Home / Articles / A RAG System Can “Work” and Still Retrieve the Wrong Evidence First

This article is published in English.

A RAG System Can “Work” and Still Retrieve the Wrong Evidence First

Operable walkthrough of A RAG System Can “Work” and Still Retrieve the Wrong Evidence First: contracts, checks, and drop-in code slots for teams shipping this pattern.

1229 words

The following notes reconstruct a practical path around “”. Emphasis stays on contracts, checks, and drop-in code placeholders rather than motivational framing.

A RAG System Can “Work” and Still Retrieve the Wrong Evidence First

When working through the A RAG System Can stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Measure recall on a fixed question set before tuning prompts. Prompt churn rarely fixes a weak retrieval surface.

Quick glance

When working through the Quick glance stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Write a short runbook: how to rotate keys, how to drain the queue, how to roll back the last ingest.

def recall_at_k(gold_id: str, ranked_ids: list[str], k: int = 5) -> int:
    """1 if the gold chunk appears anywhere in the top k, else 0."""
    return int(gold_id in ranked_ids[:k])

def reciprocal_rank(gold_id: str, ranked_ids: list[str]) -> float:
    """1/rank of the gold chunk's first appearance, 0 if absent."""
    for rank, doc_id in enumerate(ranked_ids, start=1):
        if doc_id == gold_id:
            return 1.0 / rank
    return 0.0
def reciprocal_rank_fusion(
    rankings: dict[str, list[str]], k: int = 60
) -> list[str]:
    """Fuse multiple ranked lists using rank position only."""
    scores: dict[str, float] = {}
    for ranking in rankings.values():
        for rank, doc_id in enumerate(ranking, start=1):
            scores[doc_id] = scores.get(doc_id, 0.0) + 1.0 / (k + rank)
    return sorted(scores, key=scores.get, reverse=True)

Could you tune the problem away?

When working through the Could you tune the stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Write a short runbook: how to rotate keys, how to drain the queue, how to roll back the last ingest.

Closing thought

When working through the Closing thought stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Write a short runbook: how to rotate keys, how to drain the queue, how to roll back the last ingest.

Code and reading

When working through the Code and reading stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Write a short runbook: how to rotate keys, how to drain the queue, how to roll back the last ingest. When working through the Code and reading stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Operational checklist

For the Operational checklist stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state.

Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph.

Add a smoke test that exercises the critical path in CI with fixtures, not live paid APIs, whenever budgets allow.

Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.

Pin dependency versions and record the image digest that ran the demo. Reproducibility beats tribal knowledge.

Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.

Before promoting the stack, freeze versions, capture a golden transcript for the critical path, and confirm rollback steps. Shared environments need rate limits, tenancy checks, and a clear owner for secret rotation. Prefer boring reliability over clever one-off demos.

Batch note for e21201356c55: keep provider keys out of the repo, set a per-session token ceiling, and store transcripts next to the eval fixtures so later model swaps stay comparable.

The hardening note 0 stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph.

Hardening detail 0/710: measure wall time, error class, and token spend for this note, then decide whether to keep the change based on a fixed question set rather than anecdote.

For the hardening note 1 stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.

Hardening detail 1/710: measure wall time, error class, and token spend for this note, then decide whether to keep the change based on a fixed question set rather than anecdote.

When working through the hardening note 2 stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments.

Hardening detail 2/710: measure wall time, error class, and token spend for this note, then decide whether to keep the change based on a fixed question set rather than anecdote.

The hardening note 3 stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish.

Hardening detail 3/710: measure wall time, error class, and token spend for this note, then decide whether to keep the change based on a fixed question set rather than anecdote.