一句话:提出 AlignCoder,通过查询增强与强化学习检索器对齐检索与目标意图,显著提升仓库级代码补全。
仓库级代码补全要求模型理解仓库特有上下文与领域知识,现有 code LLM 能力有限;基于检索增强生成(RAG)的方法虽能引入跨文件代码片段,却面临检索查询与目标代码不对齐、且无法有效利用推理信息两大问题。为此,本文提出 AlignCoder:一方面设计查询增强机制,通过生成多个候选补全来构造增强查询,弥合初始查询与目标代码之间的语义鸿沟;另一方面采用强化学习训练 AlignRetriever,使其学会利用增强查询中的推理信息进行更准确的检索。作者在 CrossCodeEval 与 RepoEval 两个基准、五种骨干 code LLM 上进行评估,在 CrossCodeEval 上 EM 分数较基线提升 18.1%,并展现出跨模型、跨编程语言的良好泛化性。
Repository-level code completion remains a challenging task for existing code large language models (code LLMs) due to their limited understanding of repository-specific context and domain knowledge. While retrieval-augmented generation (RAG) approaches have shown promise by retrieving relevant code snippets as cross-file context, they suffer from two fundamental problems: misalignment between the query and the target code in the retrieval process, and the inability of existing retrieval methods to effectively utilize the inference information. To address these challenges, we propose AlignCoder, a repository-level code completion framework that introduces a query enhancement mechanism and a reinforcement learning based retriever training method. Our approach generates multiple candidate completions to construct an enhanced query that bridges the semantic gap between the initial query and the target code. Additionally, we employ reinforcement learning to train an AlignRetriever that learns to leverage inference information in the enhanced query for more accurate retrieval. We evaluate AlignCoder on two widely-used benchmarks (CrossCodeEval and RepoEval) across five backbone code LLMs, demonstrating an 18.1% improvement in EM score compared to baselines on the CrossCodeEval benchmark. The results show that our framework achieves superior performance and exhibits high generalizability across various code LLMs and programming languages.
DOI 原文 ·
@inproceedings{paperbot9448,
title = {AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion},
author = {Tianyue Jiang and Yanli Wang and Yanlin Wang and Daya Guo and Ensheng Shi and Yuchi Ma and Jiachi Chen and Zibin Zheng},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00085}
}