arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2605.08299cs.SEcs.AI
收藏

不要复制粘贴!代码检索的重写策略

Do not copy and paste! Rewriting strategies for code retrieval

DISI University of Bologna(博洛尼亚大学DISI学院)

Andrea Gurioli, Federico Pennino, Maurizio Gabbrielli

AI总结:

本文研究了三种重写策略在不同检索场景下的效果,发现全自然语言重写在在线检索中表现最佳,但离线检索效果下降明显,提出Delta H作为评估重写收益的指标。

摘要:

基于嵌入的代码检索常因编码器过度拟合表层语法而失效。先前工作通过使用LLM重写查询和语料库以规范化风格来缓解这一问题,但未解决两个核心问题:表征迁移程度如何影响效果,以及何时进行每查询的LLM调用是合理的。本文研究了三种重写策略:风格重写、自然语言增强的伪代码和全自然语言转录,在联合查询-语料库(QC,在线)和语料库-only(C,离线)增强下,跨六个CoIR基准、五个编码器和三个覆盖独立模型家族(Qwen、DeepSeek、Mistral)的重写器。我们首次评估了自然语言增强的伪代码和片段级自然语言作为直接检索表示,而非临时中间步骤。全自然语言重写在QC环境下获得最大收益(在MoSE-18 CT-Contest 上NDCG@10绝对提升0.51),而语料库-only重写在90种配置中导致检索性能下降56%,约62%。我们引入了两个诊断指标Delta H、token熵和Delta s(嵌入余弦),并证明Delta H在所有三种重写器家族中预测QC环境下检索增益:在DeepSeek+Codestral上Spearman rho = +0.436,p < 0.001;在Codestral单独使用时rho = +0.593;在Qwen上rho = +0.356。这确立了Delta H作为廉价、重写器无关的代理,用于在运行检索前决定何时重写值得。我们的分析将LLM重写重新定义为成本效益决策:它在轻量级编码器上对代码主导的查询最有效,但对于强编码器或自然语言密集查询,效果递减。

英文摘要:

Embedding-based code retrieval often suffers when encoders overfit to surface syntax. Prior work mitigates this by using LLMs to rephrase queries and corpora into a normalized style, but leaves two questions open: how much representational shift helps, and when is the per-query LLM call justified? We study a hierarchy of three rewriting strategies: stylistic rephrasing, NL-enriched PseudoCode, and full Natural-Language transcription, under joint query-corpus (QC, online) and corpus-only (C, offline) augmentation, across six CoIR benchmarks, five encoders, and three rewriters spanning independent model families (Qwen, DeepSeek, Mistral). We are the first to evaluate NL-enriched PseudoCode and snippet-level Natural Language as direct retrieval representations, rather than as transient intermediates. Full NL rewriting with QC yields the largest gains (+0.51 absolute NDCG@10 on CT-Contest for MoSE-18), while corpus-only rewriting degrades retrieval in 56 of 90 configurations, about 62%. We introduce two diagnostics, Delta H, token entropy, and Delta s, embedding cosine, and show that Delta H predicts retrieval gain under QC across all three rewriter families: pooled Spearman rho = +0.436, p < 0.001 on DeepSeek+Codestral; rho = +0.593 on Codestral alone; rho = +0.356 on Qwen. This establishes Delta H as a cheap, rewriter-agnostic proxy for deciding when rewriting pays off before running retrieval. Our analysis reframes LLM rewriting as a cost-benefit decision: it is most effective as a remediation layer for lightweight encoders on code-dominant queries, with diminishing returns for strong encoders or NL-heavy queries.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑