arXiv:2601.19697cs.SEcs.AI2026-01被引 9

让代码补全更懂项目上下文,提升跨文件匹配准确率。

AlignCoder: Aligning Retrieval with Target Intent for Repository-Level Code Completion

  • 用多候选生成增强查询,缩小初始查询与目标代码的语义差距。
  • 引入强化学习训练检索器,在跨文件匹配中提升18.1%准确率。
  • 适用于多种主流代码模型和编程语言,通用性强。

现有代码大模型在仓库级代码补全任务中表现受限,主要因其对项目特定上下文和领域知识理解不足。尽管检索增强生成(RAG)方法通过检索相关代码片段作为跨文件上下文展现潜力,但仍存在两大问题:检索过程中查询与目标代码语义不匹配,且现有检索方法无法有效利用推理信息。为此,我们提出AlignCoder框架,引入查询增强机制与基于强化学习的检索器训练方法。该方法生成多个候选补全以构建增强查询,弥合初始查询与目标代码间的语义鸿沟;同时,采用强化学习训练一个AlignRetriever,使其能利用增强查询中的推理信息实现更精准检索。我们在CrossCodeEval和RepoEval两个主流基准上,针对五种骨干代码大模型进行评估,结果显示在CrossCodeEval上相比基线模型提升18.1%的精确匹配(EM)分数。结果表明,该框架性能优越且在不同代码大模型与编程语言间具有高度泛化能力。

原文摘要 · Abstract (English)

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.

代码补全检索增强强化学习大模型

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