code-retrieval-eval
CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking — Tarun Suresh et al. (2024) (arXiv:2412.01007, 2024)
What this evaluates
Evaluates the ability of code embedding models and LLM-based rerankers to retrieve relevant code snippets or functions given natural language queries. It probes semantic matching between text descriptions (e.g., GitHub issues, function comments) and code across multiple programming languages, as well as function localization in real-world software repositories.
Datasets
- CodeSearchNet — total ?; splits: test (-1)
- AdvTest — total ?; splits: test (-1)
- CoIR — total ?; splits: test (-1)
- SWE-Bench-Lite — total 274; splits: test (274)
Metrics
MRR@1000 (primary) — range: percent
- Mean Reciprocal Rank at cutoff 1000. For each query, compute 1/rank of the first relevant document, then average across all queries.
nDCG@10 — range: [0, 1]
- Normalized Discounted Cumulative Gain at cutoff 10. Measures ranking quality by discounting gains logarithmically based on position, normalized by the ideal DCG.
MRR@100 — range: percent
- Mean Reciprocal Rank at cutoff 100, used for evaluating the listwise reranker on top-100 retrieved results.
Top-K Accuracy — range: percent
- Percentage of queries where the ground-truth function/file appears within the top K retrieved results (K=1,2,3,5,10).
Input / output format
Input: Natural language query (e.g., function description or GitHub issue) for retrieval; for reranking, the query plus the top-100 retrieved code snippets.
Output: A ranked list of code snippets or functions ordered by relevance to the query.
Scoring recipe
def compute_mrr_at_k(ranks, k):
relevant_ranks = [r for r in ranks if r <= k]
if not relevant_ranks:
return 0.0
return 1.0 / min(relevant_ranks)
def compute_ndcg_at_k(scores, labels, k):
ranked = sorted(zip(scores, labels), reverse=True)[:k]
dcg = sum((2**l - 1) / math.log2(i + 2) for i, (_, l) in enumerate(ranked))
ideal = sorted(labels, reverse=True)[:k]
idcg = sum((2**l - 1) / math.log2(i + 2) for i, l in enumerate(ideal))
return dcg / idcg if idcg > 0 else 0.0
Common pitfalls
- Zero-shot evaluation: models are not fine-tuned on the test benchmarks, so performance reflects generalization rather than dataset-specific adaptation.
- SWE-Bench-Lite localization only considers examples where patches modify existing functions/classes; examples introducing new functions or imports are excluded.
- CoIR aggregates results across multiple task types (code-to-text, code-to-code, hybrid), which may require careful averaging to match reported numbers.
Evidence (verbatim from paper)
We report the official metrics for each dataset: MRR@1000 for CodeSearchNet and Advtest, and nDCG@10 for COIR. During inference, the top 100 results from our code retriever are passed to the reranker, with evaluation conducted using MRR@100.
Citation
@misc{suresh2024cornstack,
title={CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking},
author={Tarun Suresh et al. (2024)},
year={2024},
note={arXiv:2412.01007}
}
1---2name: code-retrieval-eval3description: Evaluates the ability of code embedding models and LLM-based rerankers to retrieve relevant code snippets or functions given natural language queries. It probes semantic matching between text descriptions (e.g., GitHub issues, function comments) and code across multiple programming languages, as well as function localization in real-world software repositories. Use when the user wants to benchmark on CodeSearchNet, AdvTest, CoIR, SWE-Bench-Lite, or asks about evaluating this task. Reports MRR@1000.4metadata:5 source: https://skillmd.com/skills/qhjqhj00/code-retrieval-eval6 skill_kind: dataset_eval7 source_arxiv: 2412.010078 bibtex_key: suresh2024cornstack9 confidence: high10---1112# code-retrieval-eval1314> CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking — Tarun Suresh et al. (2024) (arXiv:2412.01007, 2024)1516## What this evaluates1718Evaluates the ability of code embedding models and LLM-based rerankers to retrieve relevant code snippets or functions given natural language queries. It probes semantic matching between text descriptions (e.g., GitHub issues, function comments) and code across multiple programming languages, as well as function localization in real-world software repositories.1920## Datasets2122- **CodeSearchNet** — total ?; splits: test (-1)23- **AdvTest** — total ?; splits: test (-1)24- **CoIR** — total ?; splits: test (-1)25- **SWE-Bench-Lite** — total 274; splits: test (274)2627## Metrics2829- `MRR@1000` **(primary)** — range: percent30 - Mean Reciprocal Rank at cutoff 1000. For each query, compute 1/rank of the first relevant document, then average across all queries.31- `nDCG@10` — range: [0, 1]32 - Normalized Discounted Cumulative Gain at cutoff 10. Measures ranking quality by discounting gains logarithmically based on position, normalized by the ideal DCG.33- `MRR@100` — range: percent34 - Mean Reciprocal Rank at cutoff 100, used for evaluating the listwise reranker on top-100 retrieved results.35- `Top-K Accuracy` — range: percent36 - Percentage of queries where the ground-truth function/file appears within the top K retrieved results (K=1,2,3,5,10).3738## Input / output format3940**Input**: Natural language query (e.g., function description or GitHub issue) for retrieval; for reranking, the query plus the top-100 retrieved code snippets.4142**Output**: A ranked list of code snippets or functions ordered by relevance to the query.4344## Scoring recipe4546```python47def compute_mrr_at_k(ranks, k):48 relevant_ranks = [r for r in ranks if r <= k]49 if not relevant_ranks:50 return 0.051 return 1.0 / min(relevant_ranks)5253def compute_ndcg_at_k(scores, labels, k):54 ranked = sorted(zip(scores, labels), reverse=True)[:k]55 dcg = sum((2**l - 1) / math.log2(i + 2) for i, (_, l) in enumerate(ranked))56 ideal = sorted(labels, reverse=True)[:k]57 idcg = sum((2**l - 1) / math.log2(i + 2) for i, l in enumerate(ideal))58 return dcg / idcg if idcg > 0 else 0.059```6061## Common pitfalls6263- Zero-shot evaluation: models are not fine-tuned on the test benchmarks, so performance reflects generalization rather than dataset-specific adaptation.64- SWE-Bench-Lite localization only considers examples where patches modify existing functions/classes; examples introducing new functions or imports are excluded.65- CoIR aggregates results across multiple task types (code-to-text, code-to-code, hybrid), which may require careful averaging to match reported numbers.6667## Evidence (verbatim from paper)6869> We report the official metrics for each dataset: MRR@1000 for CodeSearchNet and Advtest, and nDCG@10 for COIR. During inference, the top 100 results from our code retriever are passed to the reranker, with evaluation conducted using MRR@100.7071## Citation7273```bibtex74@misc{suresh2024cornstack,75 title={CoRNStack: High-Quality Contrastive Data for Better Code Retrieval and Reranking},76 author={Tarun Suresh et al. (2024)},77 year={2024},78 note={arXiv:2412.01007}79}80```8182- arXiv: 2412.01007