Choose informative retrieval distractors while auditing labels, lineage and split leakage before model training.
Hard-negative mining without training against true answers
Define the negative precisely
A hard negative is a passage that resembles a relevant answer but does not satisfy the query. For a request for pump P-47's current relief limit, an old revision or P-48's limit may be informative distractors. A second valid P-47 passage is a false negative even if the judgment file omitted it. Before mining, specify query intent, time boundary, tenant and what counts as support. Judgment labels should allow multiple positives and an uncertain state; a missing label is not proof of irrelevance.
Mine from several candidate pools
Lexical search yields near-word matches; dense retrieval yields semantic neighbors; a reranker can find subtle confusions. Sample within authorized, training-eligible corpora and record which model and index version produced each candidate. Balance easy and hard distractors so training does not only distinguish almost-identical policies. A candidate that is too hard may actually be another answer, especially when multiple documents repeat the same fact. Lineage checks help distinguish a copied positive from a real contradiction.
Audit false negatives before training
Compare each mined candidate with all known positives by document lineage, answer entity, valid interval and evidence span. Flag near-identical answers and ambiguous cases for human review. Do not automatically turn every high-scoring unlabeled passage into a negative. If the corpus has a corrected revision, the old passage may be a legitimate negative for a current-policy query but a positive for an as-of query. Temporal eligibility belongs in the label, not only the search filter.
Prevent split leakage
A test question and a training question can differ in wording while pointing to the same source paragraph. Split by source lineage or entity family when the evaluation asks for transfer to unseen material. Keep mined examples from a fixed training snapshot; a later corpus refresh must not add evaluation positives to the training pool. Log query ID, passage ID, source revision, mine score, decision and reviewer. Release gates should compare held-out supported recall, not training loss alone.
Measure the cost of hardness
Run an ablation with the same query set and candidate budget: baseline negatives, reviewed hard negatives, and mixed difficulty. Track false-negative audit rate, candidate recall, top-k judged relevance and answer support on held-out slices. If mining improves ranking for common queries but harms a rare language or recent-policy slice, do not ship the aggregate gain as universal. Keep a small manual audit of top-ranked new negatives after each mining cycle; retriever changes alter which mistakes are selected next.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class MinedPassage:
passage_id: str
tenant: str
lineage: str
entity_id: str
label: str
score: float
def reviewed_negatives(candidates: list[MinedPassage], tenant: str,
positive_lineages: set[str], entity_id: str) -> list[str]:
selected = [candidate for candidate in candidates
if candidate.tenant == tenant and candidate.label == "negative"
and candidate.lineage not in positive_lineages
and candidate.entity_id != entity_id]
return [candidate.passage_id for candidate in
sorted(selected, key=lambda item: item.score, reverse=True)]
pool = [MinedPassage("pump-48", "plant-a", "manual-48", "pump-p48", "negative", .94),
MinedPassage("copied-p47", "plant-a", "manual-47", "pump-p47", "negative", .99),
MinedPassage("unreviewed", "plant-a", "manual-52", "pump-p52", "unknown", .96),
MinedPassage("private", "plant-b", "manual-49", "pump-p49", "negative", .98)]
assert reviewed_negatives(pool, "plant-a", {"manual-47"}, "pump-p47") == ["pump-48"]Performance and operating cost
Filtering N mined candidates costs O(N log N) time because the sample sorts by score, with O(N) extra space; a bounded top-k heap can reduce sorting work when N is large. The expensive part is creating and auditing labels: retrieval calls, cross-source comparisons and human adjudication. Spend that budget on candidates likely to change a decision, not on repeated copies of the same mistake.
Common Mistakes
- Treating every unlabeled retrieved passage as a negative.
- Mining a copied positive into the negative pool because it has a new URL.
- Letting test-source lineages enter the training candidate pool.
- Judging the mining run only by training loss or one aggregate retrieval score.
Validation drill
Mine 79 candidates for 23 queries from lexical and dense pools. Review ambiguous matches, split by document lineage, and compare held-out top-five relevance and supported-answer rate before accepting the new negatives.
