更多检索反而有害:基于检索的代码审查生成
When More Retrieval Hurts: Retrieval-Augmented Code Review Generation
AI总结:
本文提出RARe框架,通过检索历史审查作为上下文示例提升代码审查生成质量,实验表明仅使用top-1检索效果最佳,过多检索反而导致性能下降。
摘要:
代码审查生成可通过生成简洁的审查反馈减少开发者工作量。然而,生成模型常产生通用或偏离主题的审查,而仅检索的方法难以适应新情境。本文将基于检索的代码审查视为检索增强的上下文学习,通过将检索到的历史审查作为输入上下文中的示例来引导模型输出。基于此观点,我们提出RARe框架,从语料库中检索相关历史审查,并将检索到的上下文示例作为条件输入大型语言模型。在两个公开基准测试中,RARe优于强基线模型,达到BLEU-4分数12.32和12.96。关键发现是更多检索反而有害:仅使用top-1检索示例效果最佳,而添加更多检索项会因上下文预算有限导致冗余和冲突提示而降低性能。人工评估和可解释性分析进一步支持检索增强生成减少了通用输出并提高了审查专注度。
英文摘要:
Code review generation can reduce developer effort by producing concise, reviewer-style feedback for a given code snippet or code change. However, generation-only models often produce generic or off-point reviews, while retrieval-only methods struggle to adapt well to new contexts. In this paper, we view retrieval augmentation for code review as retrieval-augmented in-context learning, where retrieved historical reviews are placed in the input context as examples that guide the model's output. Based on this view, we propose RARe (Retrieval-Augmented Code Reviewer), a framework that retrieves relevant historical reviews from a corpus and conditions a large language model on the retrieved in-context examples. Experiments on two public benchmarks show that RARe outperforms strong baselines and reaches BLEU-4 scores of 12.32 and 12.96. A key finding is that more retrieval can hurt: using only the top-1 retrieved example works best, while adding more retrieved items can degrade performance due to redundancy and conflicting cues under limited context budgets. Human evaluation and interpretability analysis further support that retrieval-augmented generation reduces generic outputs and improves review focus.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。