Model and Inference EngineeringTraining data and objectivesPrincipal
How can in-batch negatives train a retriever to reject other valid answers?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A retriever uses one labeled positive per query and treats other batch documents as negatives. Increasing batch size lowers recall on questions with several valid policy passages. Explain the loss assumption and gradient mechanism, design a judged diagnostic, and compare batch construction, masking and multi-positive objectives without removing useful hard negatives.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
A contrastive retriever learns to score useful passages above competing candidates. In one multiple-negatives ranking objective, each query has one labeled positive document. The other documents in the batch become negatives for that query. Bigger batches give more comparisons and often harder ones. They also increase the chance that an “other” document actually answers the query.
Think of two support tickets asking the same thing in different words. One has the policy page as its labeled positive. The other's positive is a newer FAQ with the same correct answer. If they land in one batch, the first query is trained to push down the FAQ, and the second may push down the policy. This is a false negative. Sentence Transformers' loss documentation describes the in-batch-negative assumption and false-negative filtering options. Its duplicate-batch sampler guidance helps with exact duplicates, but equivalent answers with different text need more than string deduplication.
For a hypothetical query, let the scores for its labeled passage P, another valid passage Q and an irrelevant passage R be 2, 2 and 0. Treat those scores as logits after any temperature scaling. In a softmax ranking loss with only P positive, the probability of P is exp(2)/(2×exp(2)+1), about 0.468. The gradient with respect to Q’s score is positive, so gradient descent pushes that valid alternative down. The supervision is wrong even if the model’s scores correctly recognize both useful passages.
One multi-positive formulation instead rewards the combined probability mass of P and Q. Its numerator includes both exp(2) terms, giving accepted-answer mass about 0.937 in this example. This formulation asks for some valid answer, while objectives that require ranking every relevant document can differ. Specify which behavior the product needs. Masking a known false negative avoids pushing it down, but does not automatically teach it as a positive.
I would inspect the highest-scoring “negatives” for a sample of queries and have someone judge whether they are truly irrelevant. Measure the rate by topic, customer and document family. Compare recall against a judged set with multiple acceptable passages per query, not an evaluation set that marks only one document correct. Otherwise retrieval can improve for users while the metric punishes it, or the model can genuinely learn to reject useful alternatives and the metric can hide the harm.
Possible fixes depend on what labels we have. Group equivalent queries or documents away from one another during batch construction, mark all known relevant documents as positives in a multi-positive objective, or mask known false negatives from the denominator. Hard-negative mining needs a check for relevance before treating high similarity as proof of a mistake. Sampling only easy negatives avoids this conflict but can weaken learning.
If the interviewer says, “More negatives should always help,” ask whether those items satisfy the loss's negative assumption. The same large batch that gives a stronger signal can also make the wrong supervision more frequent.
Related questions
Keep practising model and inference engineering
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux