arXiv:2608.29604cs.IRAug 2026

Manuscript Offprint

arXiv:2608.29604

RePair: Turning Retrieval Failures into Counterfactual Hard Pairs

Siyi Liu, Xiaorong Zhu, Enjun Du, Xinyu Zuo, Lisheng Duan, Haijin Liang, Jin Ma, Junfu Pu, Yongqi Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Vision-language retrieval with CLIP-style dual encoders achieves strong cross-modal performance, yet practical accuracy often hinges on localized semantic distinctions where top-ranked near misses differ from the true match by a single critical detail. Hard-sample mining can select confusable candidates but cannot construct corrected counterparts; synthetic augmentation can generate novel samples but, without conditioning on actual model failures, targets irrelevant dimensions of hardness. We observe that a top-ranked false positive is a counterfactual scaffold—sharing most of the query’s semantics while differing in a localized failure-causing residual. Minimally correcting this residual yields a hard positive of the ground truth in the same modality; the corrected and unedited versions form a hard negative pair that straddles the decision boundary, producing complementary pull-push supervision. We introduce RePair, guided by three principles—Validity, Minimality, and Locality—which mines false positives bidirectionally, applies LLM-guided counterfactual editing, and trains with a local hard-pair contrastive objective. On Flickr30K and COCO30K, RePair outperforms controlled augmentation baselines with only 107K synthetic samples—26%–75% fewer than comparable methods—confirming failure-conditioned repair is more data-efficient than error-agnostic augmentation.

1 Introduction

Vision-language retrieval has become a standard interface for cross-modal search, with CLIP-style dual encoders serving as the dominant architecture (Radford et al., 2021; Jia et al., 2021). While these models are effective at matching high-level visual and textual concepts, practical retrieval often hinges on localized semantic distinctions—attribute binding, relations, and word order—on

Query: A girl in a red shirt is on a tire swing.

Figure

Figure 1: The RePair operator. Top: For a text query q, the retrieval system returns a near-miss false positive pfpp^{fp} that shares the query's scaffold (green: “a girl in a red shirt”) but differs on the failure-causing residual (red: wrong swing type). RePair minimally edits only the residual to produce peditp^{edit}, which carries the same semantics as the ground truth pgtp^{gt}. Bottom: Before repair, pfpp^{fp} falls in the FP zone between the ideal boundary and the model's learned boundary. The repair signal pulls peditp^{edit} toward pgtp^{gt} and pushes pfpp^{fp} away, shifting the model boundary to eliminate the FP zone.

which diagnostic benchmarks document persistent failures (Thrush et al., 2022; Yuksekgonul et al., 2023). The critical details can be subtle: whether a person is alone or in a group, whether an object is a projector or a skateboard, or who is performing versus receiving an action. Under such demands, the most consequential errors are not obviously unrelated candidates, but top-ranked near misses that satisfy most of the query while missing the detail that makes the match correct (see Fig. 1, top, for an example). These near misses are especially informative because they reveal precisely where the retriever's semantic understanding breaks down.

Near misses therefore provide a natural handle for refining retrieval models. Standard contrastive fine-tuning relies largely on random in-batch negatives, many of which are too easy to sharpen

†^{\dagger}Equal contribution.

∗^{*}Corresponding author.

such fine-grained boundaries (Robinson et al., 2021). Hard-sample mining moves closer to the boundary by retrieving confusable candidates from the training corpus, and has become a common way to strengthen contrastive supervision (Karpukhin et al., 2020; Xiong et al., 2021). However, mining—like reweighting (Robinson et al., 2021; Chuang et al., 2020)—remains a selection-only mechanism: both families select or reweight existing items rather than altering pair content. Mining can identify what the model should push away, but it cannot construct the corrected neighbor in the same semantic region. As a result, the model receives repulsive supervision from hard negatives, but lacks a matched attractive signal that specifies how the boundary should be repaired.

Synthetic augmentation offers a complementary route (Liu et al., 2024, 2025): instead of only selecting existing candidates, it can generate hard positives or hard negatives (Cioni et al., 2023; Yoon et al., 2024; Alimisis et al., 2025). Yet most existing pipelines are not conditioned on the retriever's own failures. They perturb captions, rewrite texts, synthesize images, or compose counterfactuals according to predefined templates or external generators, without asking which semantic factor actually caused the current model to fail (Yuksekgonul et al., 2023; Fan et al., 2023; Patel et al., 2024; Tian et al., 2023). Consequently, the generated samples may be plausible hard cases in general, but not necessarily hard for the model being trained. They may alter irrelevant details while missing the true confusion factor, leading to low hit rates and large synthesis volumes (Chuang et al., 2020).

Our key observation is that a top-ranked false positive is a useful counterfactual scaffold, not merely a negative. It preserves much of the query’s semantic structure, explaining why the model retrieved it, while containing a localized failure-causing residual, explaining why it is wrong. This scaffold–residual view suggests a simple operator over a retrieval error: given a query q and its retrieved false positive pfpp^{fp}, minimally correct only the failure-causing residual of pfpp^{fp} while preserving its shared scaffold. As illustrated in Fig. 1, because the corrected result peditp^{edit} now carries the same semantic content as the ground truth pgtp^{gt}, it forms a hard positive of pgtp^{gt} in the same modality; meanwhile, peditp^{edit} and the unedited pfpp^{fp} form a hard negative pair that straddles the decision boundary with minimal perceptual difference. Training can therefore pull peditp^{edit} toward the query alongside pgtp^{gt} and push pfpp^{fp} away, shifting the model boundary to eliminate the FP zone where the failure occurred (Fig. 1, bottom).

We instantiate this idea as RePair. The name reflects two coupled operations: RePair re-pairs each retrieval error with a minimal counterfactual counterpart, and training on the resulting contrast repairs the local retrieval boundary by pulling the corrected counterpart toward the query alongside the ground truth while pushing the original error away. To make this operation reliable, RePair follows three design principles. Validity ensures that a mined near miss is a genuine retrieval failure rather than annotation noise or a benign alternative match. Minimality ensures that counterfactual editing changes only the failure-causing residual while preserving the shared semantic scaffold. Locality ensures that the original failure and its corrected counterpart are contrasted within the same boundary neighborhood. Operationally, RePair mines top-ranked false positives in both retrieval directions and verifies each with an LLM-based semantic auditor (Validity). It then generates minimal edit instructions and selects the least-disruptive valid edit (Minimality). Finally, it trains the resulting hard pairs with a local contrastive objective that couples pull and push signals within the same boundary neighborhood (Locality).

We evaluate RePair on Flickr30K and COCO30K under a unified CLIP fine-tuning setting. RePair achieves the strongest top-rank (R@1) retrieval performance among controlled augmentation baselines while using substantially fewer synthetic samples. Ablations confirm that failure conditioning, quality control, and paired pull-push supervision drive the gains rather than synthesis volume alone. These results support the central premise of RePair: retrieval failures are not just mistakes to be discarded or negatives to be mined, but compact opportunities for counterfactual boundary repair. In summary, we make the following contributions:

• We introduce RePair, a failure-conditioned counterfactual training framework that re-pairs a retriever’s own false positives with minimal counterfactual counterparts, converting each retrieval error into a hard positive of the ground truth and a grounded hard negative pair for local boundary repair.

• We instantiate RePair through three design principles—Validity, Minimality, and Locality—using LLM-based semantic auditing, minimal counterfactual editing with post-edit selection, bidirectional hard-pair construction, and local hard-pair contrastive training.

• We show that RePair improves vision-language retrieval more data-efficiently than error-agnostic augmentation under a unified CLIP fine-tuning setting, with ablations isolating the roles of failure conditioning, quality control, and paired pull-push supervision.