CoQuIR: A Comprehensive Benchmark for Code Quality-Aware Information Retrieval

Jiahui Geng, Fengyu Cai, Shaobo Cui, Qing Li, Liangwei Chen, Chenyang Lyu, Haonan Li, Derui Zhu, Alexander Pretschner, Heinz Koeppl, Fakhri Karray

TL;DR

CoQuIR is a new large-scale benchmark that shifts the focus of code retrieval from simple functional relevance to code quality. By evaluating models across correctness, efficiency, security, and maintainability, the researchers found that most current retrievers—including top-tier LLMs—struggle to distinguish robust code from buggy or insecure snippets. To fix this, they introduced a contrastive training method that boosts quality-aware performance by up to 30% without sacrificing the model's ability to find relevant code.

What Problem Does This Paper Address?

In the era of Retrieval-Augmented Generation (RAG), code retrieval is the backbone of automated programming. When a developer (or an AI agent) asks for a specific function, the retriever searches a massive database for a matching snippet. Historically, these systems have been evaluated on "semantic relevance": Does this code do what the user asked for?

However, the authors argue that relevance is not enough. A retriever might find a snippet that technically performs the requested task but is riddled with security vulnerabilities, uses deprecated APIs, or is incredibly inefficient. If a RAG system feeds this "low-quality" code to an LLM, the LLM will likely propagate those flaws into the final product, creating technical debt or security risks. CoQuIR addresses this gap by providing a framework to measure and improve a retriever's "quality-awareness."

Methods

The researchers developed CoQuIR (Code Quality-aware Information Retrieval), which annotates code snippets across four dimensions:

  1. Correctness: Is the code bug-free?
  2. Efficiency: Does it avoid unnecessary performance overhead?
  3. Security: Is it free of known vulnerabilities (CWEs)?
  4. Maintainability: Does it use modern, supported APIs?

To measure performance, they introduced two new metrics:

  • Pairwise Preference Accuracy (PPA): The percentage of times a model ranks a high-quality snippet above a functionally identical low-quality one.
  • Margin-based Ranking Score (MRS): A stricter metric that quantifies the "gap" in rank between good and bad code, rewarding models that push bad code to the very bottom of the list.

Finally, they proposed a contrastive fine-tuning approach. By training models on pairs of "good" and "bad" code for the same task, they "taught" the retrievers to recognize the subtle features that signal high quality.

Datasets

The CoQuIR benchmark is a massive multilingual effort covering 11 programming languages, 42,725 queries, and over 134,000 code snippets. It is built by curating and annotating several existing specialized datasets:

  • CodeNet-B & Defects4J: For correctness (buggy vs. fixed code).
  • CodeNet-E & SQLR2: For efficiency (optimized vs. slow implementations).
  • CVEFixes & SafeCoder: For security (vulnerable vs. secure patterns).
  • DepreAPI: For maintainability (modern vs. deprecated API usage).

Key Insights and Ideas

  • Relevance $\neq$ Quality: The most striking finding is that high scores in traditional metrics (like nDCG) do not correlate with quality-awareness. A model can be excellent at finding "relevant" code while being totally blind to whether that code is actually good.
  • The "Instruction" Failure: Current instruction-following retrievers are surprisingly insensitive to quality prompts. Even when explicitly told to "retrieve the correct code" vs. "retrieve the buggy code," most models produced nearly identical rankings. They aren't yet "listening" to the quality requirements in the query.
  • Scale Helps, But Isn't a Cure: While larger, LLM-based retrievers generally performed better than smaller, unsupervised models, even the 8B-parameter models frequently failed to prioritize secure or efficient code without specific fine-tuning.
  • Voyage-code-3 Leads the Pack: Among proprietary models, Voyage-code-3 showed significantly higher quality-awareness, suggesting that specialized training for code search pays off.

Key Results

  • Benchmarking: The authors tested 23 models. Most performed near or even below the random baseline (0.5 PPA) on several quality tasks, particularly in security and maintainability.
  • Fine-Tuning Gains: By applying their contrastive training method to the RepLLaMA model, the researchers saw 20–30% improvements in PPA across all quality dimensions.
  • Downstream Impact: In RAG experiments, using a quality-aware retriever significantly reduced the number of vulnerabilities in the code generated by the LLM. This proves that "cleaning" the retrieval step is a viable way to make AI-assisted coding safer.

Limitations and Future Work

The authors acknowledge several limitations:

  • Language Coverage: While 11 languages are included, many others remain unexplored.
  • Quality Dimensions: The benchmark focuses on four key areas but doesn't yet account for more subjective traits like readability or documentation quality.
  • Static vs. Dynamic: The current evaluation is based on static snippets; future work could involve dynamic execution to verify code behavior more rigorously.

By establishing CoQuIR, the researchers have provided a much-needed "quality compass" for the next generation of AI development tools.

Summary updated

BibTeX
@inproceedings{geng2026coquir,
  author = {Jiahui Geng and Fengyu Cai and Shaobo Cui and Qing Li and Liangwei Chen and Chenyang Lyu and Haonan Li and Derui Zhu and Alexander Pretschner and Heinz Koeppl and Fakhri Karray},
  title = {{CoQuIR: A Comprehensive Benchmark for Code Quality-Aware Information Retrieval}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.512},
}
Figure