Probe retrieval and answer support with controlled evidence edits, plausible distractors and first-loss diagnosis.
Counterfactual retrieval tests: change one fact and trace the failure
Change one controlled variable
A counterfactual retrieval test alters an evidence fact while keeping the rest of the query and corpus stable. Replace a pump limit of 83 kPa with 67 kPa in a synthetic revision, or swap the relevant entity ID, then check whether retrieval and the answer respond to that change. The point is to expose reliance on memorized or distracting text. Use synthetic, clearly isolated fixtures; never mutate a production source or present a test revision as a real policy. Release evaluation can run these cases as a separate judged slice.
Keep labels and access coherent
When a fact changes, update the gold passage, expected answer, revision metadata and all copied evidence that derives from it. Leave unrelated passages unchanged. A distractor can be highly similar yet invalid because its entity, date, tenant or negation differs. If the counterfactual version conflicts with a legitimate original left in the same eligible corpus, the expected behavior may be conflict reporting, not a forced new number. Lineage controls help distinguish an accidental duplicate from independent contradictory evidence.
Locate the first loss
Trace whether the edited passage enters the lexical or vector candidate pool, survives filters and reranking, reaches the context window, and supports the final claim. A wrong answer with the correct passage in context is an answer-use failure; a correct answer after the passage was excluded may indicate memorization or leakage. Do not call both failures 'retrieval quality'. Retrieval traces should carry candidate IDs and score stages so the first bad decision is visible.
Probe distractors without gaming them
Vary one failure mode at a time: wrong part number, old revision, copied note, negated sentence, unit mismatch or unauthorized source. Include a genuinely unanswerable case. A model might pass a simple value swap but fail when the old value appears in a top-ranked stale document. Keep distractor language natural and the target question unchanged. Avoid test cases whose answer is visible in the file name or test label. Hard-negative audits keep distractors from accidentally becoming valid answers.
Report stability and sensitivity
The system should remain stable when irrelevant text changes and change when the supporting fact changes. Measure candidate recall, supported top-one answer, contradiction detection and abstention for each perturbation type. Compare against the same corpus snapshot and model versions. A pass rate that averages easy no-op edits with hard entity swaps obscures the actual weakness; keep per-perturbation slices. Review a sample of failures manually to confirm that the synthetic edit did not create an unintended second answer.
Worked contract
from dataclasses import dataclass, replace
@dataclass(frozen=True)
class EvidenceRecord:
passage_id: str
entity_id: str
revision: str
value_kpa: int
def answer_limit(records: list[EvidenceRecord], entity_id: str,
revision: str) -> int | None:
matches = [record.value_kpa for record in records
if record.entity_id == entity_id and record.revision == revision]
if len(matches) > 1:
raise ValueError("conflicting eligible evidence")
return matches[0] if matches else None
original = EvidenceRecord("manual-p47-r4", "pump-p47", "r4", 83)
distractor = EvidenceRecord("manual-p48-r4", "pump-p48", "r4", 83)
edited = replace(original, value_kpa=67)
assert answer_limit([original, distractor], "pump-p47", "r4") == 83
assert answer_limit([edited, distractor], "pump-p47", "r4") == 67
assert answer_limit([distractor], "pump-p47", "r4") is NonePerformance and operating cost
Creating a synthetic variant costs O(C) for C copied records and running the baseline scan costs O(C) time with O(K) match space. The real expense is repeated retrieval and answer generation across perturbation suites. Keep fixtures small and deterministic for every commit, then run a wider judged sample before a release. Store only synthetic values in test logs so a reviewer cannot confuse them with production facts.
Common Mistakes
- Changing a value without changing its expected answer and revision label.
- Leaving an eligible original passage that makes the edited answer ambiguous.
- Calling a memorized correct answer a retrieval success when evidence never entered context.
- Averaging all perturbation types into one score that hides a severe slice failure.
Validation drill
Construct 47 synthetic question variants across value, entity, negation, date and permission edits. Record the first pipeline stage that loses the required evidence and whether the final answer changes only when it should.
