The retrieval step of a system that answers from documents picks the
sections the model will read. Whether it picked the right ones has an exact
answer, written down per case, so the check needs no judge, and a change to
the index is caught before any model reads the wrong sections. Every file on
this page is written, and every command run, by
tests/test_retrieval_gate_page.py in this repository, which checks every
line below against what the command printed. The run keys and times are
those of one run, and differ on yours. A run's key is the one line run
writes on standard output, and it is shown first, above what it writes on
standard error, which is the order the test reads them in; a terminal may
interleave the two.
The retriever¶
A stand-in for yours: an index of a refund policy's sections, each with the words that retrieve it, and a function that returns the ids of the sections sharing a word with the question, sorted.
# retrieval.py
#: Each section of the policy, by id, with the words that retrieve it.
INDEX = {
"refunds-1": {"refund", "refunds", "long", "days"},
"refunds-2": {"card", "paid"},
"shipping-1": {"ship", "shipping"},
}
def retrieve(question: str) -> list[str]:
"""The ids of the sections that share a word with the question, by id."""
words = set(question.lower().rstrip("?").split())
return sorted(key for key, keys in INDEX.items() if words & keys)
The suite¶
The target calls the retriever and returns the ids in Response.output, one
a line. A string, not a list, because Contains reads text only, and
Equals compares the output with Case.expected on the same branch of
Output: a string with a string. The retriever sorts the ids, so the order
the exact check compares is fixed.
# suite.py
from digline.core import Contains, Equals
from digline.run import Case, Response, Suite
from retrieval import retrieve
suite = Suite(
tenant="acme",
environment="dev",
name="refunds",
assertions=[Equals(), Contains(needle="refunds-1")],
cases=[
Case(
id="how-long",
vars={"question": "How long does a refund take?"},
expected="refunds-1",
),
Case(
id="which-card",
vars={"question": "Which card gets the refund?"},
expected="refunds-1\nrefunds-2",
),
],
)
def target(case: Case) -> Response:
sections = retrieve(str(case.vars["question"]))
return Response(output="\n".join(sections), cost_usd=0.0)
Two checks, each a question with one answer:
Equals(): the case retrieved exactly the sections it expects, no more and no fewer. It readsCase.expected, and a case without one is anerror, not a pass (Equals).Contains(needle="refunds-1"): every case of this suite is a question about refunds, so each must retrieve the policy's first section, whatever else it retrieves (Contains). It is a substring test:refunds-1is also found inrefunds-10, so keep ids that are not the start of one another, or letEqualshold the exact set.
cost_usd=0.0 is the target saying what it spent: no model was called, so
nothing is priced, and the cost is zero. A target that leaves cost_usd
out says nothing, and the run prints cost: not known, as the first block of
the README shows.
Run, and keep the reference¶
$ digline run --suite suite.py
2026-11-30T14-26-08-347106-00-00-68e2008df9b9b821
digline: tenant 'acme' · 2 cases × 1 sample = 2 calls to the target
digline: no cost estimate: this suite has no stored run to read one from, and nothing before the first call can say what a run will cost
digline: target: 2 calls · counts: none · cost: 0.000000 USD
digline: recorded .digline/acme/runs/refunds/2026-11-30T14-26-08-347106-00-00-68e2008df9b9b821.json
digline: next: digline report --suite suite.py --run latest --locale en --out report.html # read it before you promote
digline: next: digline promote --suite suite.py --run latest --replacing none # keeps this run as the reference
$ digline promote --suite suite.py --run latest --replacing none
tenant 'acme' · refunds baseline set to 2026-11-30T14-26-08-347106-00-00-68e2008df9b9b821
compared: the run's checks and judge with the suite's in force, by their configuration hash, and they match; the target's configuration is the one the run recorded, not read again
The reference is a file under .digline/acme/baselines/, committed and
reviewed like any other change.
A change to the index, caught¶
Somebody tidies the index, and the second section is now retrieved by
payment instead of card:
# retrieval.py
#: Each section of the policy, by id, with the words that retrieve it.
INDEX = {
"refunds-1": {"refund", "refunds", "long", "days"},
"refunds-2": {"payment", "paid"},
"shipping-1": {"ship", "shipping"},
}
def retrieve(question: str) -> list[str]:
"""The ids of the sections that share a word with the question, by id."""
words = set(question.lower().rstrip("?").split())
return sorted(key for key, keys in INDEX.items() if words & keys)
$ digline run --suite suite.py
2026-11-30T14-26-08-702235-00-00-68e2008df9b9b821
digline: tenant 'acme' · 2 cases × 1 sample = 2 calls to the target
digline: estimated from run 2026-11-30T14-26-08-347106-00-00-68e2008df9b9b821: 0.0000 USD, its 0.0000 USD over 2 cases scaled to 2; an estimate, not a ceiling
digline: target: 2 calls · counts: none · cost: 0.000000 USD
digline: recorded .digline/acme/runs/refunds/2026-11-30T14-26-08-702235-00-00-68e2008df9b9b821.json
digline: next: digline compare --suite suite.py --run latest # says whether anything got worse
$ digline compare --suite suite.py --run latest
1 check got worse compared with the reference. Every case could be judged. No case is suspended. The suite's checks are unchanged from the reference.
tenant 'acme', against baseline 2026-11-30T14-26-08-347106-00-00-68e2008df9b9b821
which-card · equals · Went from passing to failing (1.000000 → 0.000000).
compare exits 1, the answer a CI job reads. It names the case and the
check: which-card lost a section, so its exact set failed, and contains
did not move, because refunds-1 is still retrieved. The minimum held, and
the exact check is the one that saw the section go. how-long never
retrieved the second section and did not move either.
Where this stops¶
- The ids are compared, not what the sections say. A section whose text changed under the same id passes both checks.
Equalsis all or nothing per case. One section missing out of ten fails the case as one missing out of two does. To check that what was chosen came from what was offered, and that what was required was chosen, Testing a selection has the recipes.- Whether the sections make a good answer is a question about the
model's side, for a judge (
LlmRubric), in a suite whose target calls the model.
The target is documented in the API reference.