Negative sampling is a training technique in contrastive learning where, for a given query or anchor, one or more non-relevant items are explicitly selected as negative examples to help a model learn effective representations. Instead of comparing against all possible negatives—a computationally prohibitive task—the algorithm samples a small, manageable set. This creates a training triplet (anchor, positive, negative) where the model's objective is to maximize the similarity to the positive example while minimizing similarity to the negatives. It is fundamental to training efficient bi-encoders for dense retrieval.
