arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.07530cs.SE
收藏

通过多检索增强生成实现基于提示的代码补全

Prompt-based Code Completion via Multi-Retrieval Augmented Generation

Hanzhuo Tan, Qi Luo, Ling Jiang, Zizheng Zhan, Jing Li, Haotian Zhang, Yuqun Zhang

AI总结:

本文提出 ProCC 框架,通过基于提示的多检索器和上下文多臂老虎机自适应选择检索视角,提升 LLM 代码补全的准确性与可插拔增强能力。

摘要:

自动化代码补全旨在从未完成的代码生成后续 token,近期预训练大型语言模型(LLM)的进展使其显著受益。然而,这些模型在处理复杂代码逻辑或推断超出其训练数据的内容时,经常出现连贯性问题和幻觉。现有的检索增强生成(RAG)技术通过使用独立的编码模型检索相关代码,部分解决了这些问题,其中检索到的代码片段作为代码补全的上下文参考。但是,它们的检索范围受制于编码模型定义的单一视角,这在很大程度上忽视了代码语义固有的复杂性和多样性。为解决这一局限,我们提出 ProCC,这是一个利用提示工程和上下文多臂老虎机算法来灵活整合并适应代码多种视角的代码补全框架。ProCC 首先采用基于提示的多检索器系统,该系统构建提示模板以激发 LLM 的知识,从而从多个检索视角理解代码语义。随后,它采用自适应检索选择算法,将代码相似性纳入决策过程,以确定最适合 LLM 补全代码的检索视角。实验结果表明,就 Exact Match 而言,ProCC 在我们收集的开源基准套件上比最先进的代码补全技术高出 8.6%,在从一家拥有十亿用户的电子商务公司收集的私有领域基准套件上高出 10.1%。ProCC 还允许以即插即用的方式增强微调技术,相比我们研究的微调模型带来 5.6% 的提升。

英文摘要:

Automated code completion, aiming at generating subsequent tokens from unfinished code, has been significantly benefited from recent progress in pre-trained Large Language Models (LLMs). However, these models often suffer from coherence issues and hallucinations when dealing with complex code logic or extrapolating beyond their training data. Existing Retrieval Augmented Generation (RAG) techniques partially address these issues by retrieving relevant code with a separate encoding model where the retrieved snippet serves as contextual reference for code completion. However, their retrieval scope is subject to a singular perspective defined by the encoding model, which largely overlooks the complexity and diversity inherent in code semantics. To address this limitation, we propose ProCC, a code completion framework leveraging prompt engineering and the contextual multi-armed bandits algorithm to flexibly incorporate and adapt to multiple perspectives of code. ProCC first employs a prompt-based multi-retriever system which crafts prompt templates to elicit LLM knowledge to understand code semantics with multiple retrieval perspectives. Then, it adopts the adaptive retrieval selection algorithm to incorporate code similarity into the decision-making process to determine the most suitable retrieval perspective for the LLM to complete the code. Experimental results demonstrate that ProCC outperforms state-of-the-art code completion technique by 8.6% on our collected open-source benchmark suite and 10.1% on the private-domain benchmark suite collected from a billion-user e-commerce company in terms of Exact Match. ProCC also allows augmenting fine-tuned techniques in a plug-and-play manner, yielding 5.6% improvement over our studied fine-tuned model.

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

↑