arXiv:2607.17139cs.SEcs.CL2026-07

让代码搜索不仅找对的,还找好的——兼顾质量与效率。

SynH-Rank: Quality-Aware Code Search via Diverse Data Synthesis and Hierarchical Ranking Training

  • 用大模型生成多样化带质量标签的训练数据,解决标注不足问题。
  • 三层等级排序:优质相关 > 劣质相关 > 无关,提升质量区分能力。
  • 新评测指标验证:在复杂需求下,好代码优先级提升20.15%。

代码搜索通过促进代码复用提升开发效率。现有系统多采用检索-重排流水线,重排器侧重查询与代码的语义相关性,但忽视执行速度、内存占用、可维护性等非功能质量,而开发者实际更关注高质量代码。研究显示,开发者期望结果符合编码规范并满足资源优化等特定需求,凸显质量感知代码搜索的重要性。该任务面临两大挑战:高质量标注数据稀缺,以及标准对比学习无法捕捉高质量、低质量与无关代码间的序关系。尽管对比学习擅长区分相关与无关代码,其二元目标难以支持精细质量分级。为此,我们提出SynH-Rank,结合大模型驱动的多样数据合成与分层排序训练。该框架采用三级标签体系,显式建模高质相关 > 低质相关 > 无关的层级关系。此外,我们构建新基准(4,209对),引入两个新指标:质量偏好准确率(QPA)评估高质代码优先级,多条件准确率(MCA)评估复杂约束下的表现。实验表明,SynH-Rank相比基线模型在QPA上提升20.15%,优于仅关注相关性的对比学习15.80%,同时提升传统相关性指标与多条件泛化能力。

原文摘要 · Abstract (English)

Code search enhances developer productivity by enabling efficient code reuse. Current code search systems often use a retrieve-then-rerank pipeline, where rerankers focus on modeling semantic relevance between queries and code. However, these rerankers overlook critical non-functional qualities like execution speed, memory usage, and maintainability, which are essential for practical software development. Studies reveal developers expect results to maintain high coding standards and satisfy specific needs, such as resource optimization, highlighting the importance of quality-aware code search. Achieving quality-aware code search faces two major challenges: the scarcity of quality-annotated datasets for effective training and the limitations of standard contrastive learning objectives, which fail to capture the ordinal relationships among high-quality, low-quality, and irrelevant code. Although contrastive learning excels in distinguishing relevant from irrelevant code, its binary objective does not support nuanced quality distinctions.To address these challenges, we propose SynH-Rank, a quality-aware code reranking framework that combines LLM-driven diverse data synthesis with hierarchical ranking training. SynH-Rank employs a three-level labeling scheme to explicitly model the hierarchy: high-quality relevant > low-quality relevant > irrelevant. Additionally, we introduce a new benchmark with 4,209 pairs and two novel metrics: Quality Preference Accuracy (QPA) for assessing prioritization of high-quality code and Multi-Condition Accuracy (MCA) for evaluating performance under complex constraints.Experimental results show SynH-Rank improves QPA by 20.15\% over backbone models and outperforms standard relevance-only contrastive training by 15.80\%, while simultaneously enhancing traditional relevance metrics and multi-condition generalizability.

代码搜索质量感知大模型排序学习

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。