CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking

Tarun Suresh, R. Reddy, Yifei Xu, Zach Nussbaum, Andriy Mulyar +2 more
12/1/2024

No official code found. Best implementation: gangiswag/cornstack (56 stars, Apache-2.0, last commit 2025-06-21).

Abstract

Effective code retrieval plays a crucial role in advancing code generation, bug fixing, and software maintenance, particularly as software systems increase in complexity. While current code embedding models have demonstrated promise in retrieving code snippets for small-scale, well-defined tasks, they often underperform in more demanding real-world applications such as bug localization within GitHub repositories. We hypothesize that a key issue is their reliance on noisy and inconsistent datasets for training, which impedes their ability to generalize to more complex retrieval scenarios. To address these limitations, we introduce CoRNStack, a large-scale, high-quality contrastive training dataset for code that spans multiple programming languages. This dataset is curated using consistency filtering to eliminate noisy positives and is further enriched with mined hard negatives, thereby facilitating more effective learning. We demonstrate that contrastive training of embedding models using CoRNStack leads to state-of-the-art performance across a variety of code retrieval tasks. Furthermore, the dataset can be leveraged for training code reranking models, a largely underexplored area compared to text reranking. Our finetuned code reranking model significantly improves the ranking quality over the retrieved results. Finally, by employing our code retriever and reranker together, we demonstrate significant improvements in function localization for GitHub issues, an important component of real-world software development.

View on arXivView PDF

Code Implementations(1)

gangiswag/cornstackCommunity100%
Apache-2.0
563CSS, HTMLNov 6, 20241 years agoApache-2.0

Similar Papers

Cite this paper

@article{suresh2024cornstack,
  title  = {CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking},
  author = {Tarun Suresh and R. Reddy and Yifei Xu and Zach Nussbaum and Andriy Mulyar and Brandon Duderstadt and Heng Ji},
  year   = {2024},
  eprint = {2412.01007},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2412.01007},
  journal = {ICLR 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2412.01007.svg)](https://codeofpaper.com/paper/2412.01007)

Discussion