Abstract
Traditional code search benchmarks often rely on a one-to-one matching paradigm, which fails to capture the diversity of valid implementations for a single query. We present CoSQA+, a large-scale dataset featuring over 400,000 query-code pairs annotated via a novel test-driven agent pipeline. By prioritizing functional correctness over surface-level similarity, CoSQA+ achieves 93.9% annotation accuracy, providing a more realistic and robust foundation for evaluating modern code search models.
Introduction
When developers search for code, they rarely seek a single "gold" snippet. Instead, multiple implementations—varying in performance, library usage, or edge-case handling—may all be correct. However, existing benchmarks like CodeSearchNet or the original CoSQA are limited by three primary challenges: scalability (human annotation is expensive), accuracy (humans often miss functional bugs), and evaluation mismatch (metrics like MRR ignore multiple valid results).
CoSQA+ addresses these issues by shifting the paradigm from one-to-one matching to a "multi-choice" scenario, utilizing automated LLM agents to verify code functionality at scale.
Methodology: Test-Driven Agent Annotation
The core of CoSQA+ is an automated pipeline designed to judge code based on behavior rather than appearance. The process involves four key stages:
- Candidate Selection: An ensemble of embedding models (CodeBERT, UniXcoder, and CodeT5+) identifies the top 20 candidate snippets for a given query.
- Preliminary Screening: An LLM filters obvious matches and non-matches.
- Test-Driven Verification: For ambiguous cases, a specialized agent generates a Python test suite. A "Bug Fixer" agent resolves environment or dependency issues, and a "Test Executor" runs the code in an isolated Docker container.
- Final Arbitration: An arbiter agent reviews the code, generated tests, and execution results to assign a final label.
The CoSQA+ Dataset
The resulting dataset consists of two versions: CoSQA+_all (412,080 pairs) and CoSQA+_verified (1,000 human-verified pairs). These were constructed by pairing web queries from CoSQA with code from CodeSearchNet.
A key finding during construction was the "multi-choice" reality of code search. A survey of developers showed that over 60% of queries correspond to multiple valid snippets. CoSQA+ reflects this distribution, moving away from the artificial constraint of a single correct answer.
Key Results and Insights
- Superior Accuracy: The test-driven agents achieved 93.9% accuracy, surpassing human experts (89.1%) who relied solely on code inspection. This underscores the difficulty of identifying functional bugs without execution.
- Model Performance: Models fine-tuned on CoSQA+ consistently outperform those trained on legacy datasets. Furthermore, the use of Mean Average Precision (MAP) as a metric provides a better evaluation of a model's ability to retrieve all relevant snippets.
- Cost Efficiency: The automated pipeline reduced annotation costs to approximately $0.00062 per sample, enabling the creation of massive datasets that would be prohibitively expensive for human teams.
Conclusion
CoSQA+ represents a significant step toward more realistic code search evaluation. By leveraging test-driven agents, the dataset ensures functional correctness and embraces the inherent diversity of code implementations. Future work will focus on resolving query ambiguity and expanding the verified gold standard to additional programming languages.
Summary updated