Large Language Models (LLMs) have demonstrated remarkable performance in code completion. However, due to the lack of domain-specific knowledge, they may not be optimal in completing code that requires intensive domain knowledge for example completing the library names. Although there are several works that have confirmed the effectiveness of fine-tuning techniques to adapt language models for code completion in specific domains. They are limited by the need for constant fine-tuning of the model when the project is in constant iteration. To address this limitation, in this paper, we propose $k$NM-LM, a retrieval-augmented language model (R-LM), that integrates domain knowledge into language models without fine-tuning. Different from previous techniques, our approach is able to automatically adapt to different language models and domains. Specifically, it utilizes the in-domain code to build the retrieval-based database decoupled from LM, and then combines it with LM through Bayesian inference to complete the code. The extensive experiments on the completion of intra-project and intra-scenario have confirmed that $k$NM-LM brings about appreciable enhancements when compared to CodeGPT and UnixCoder. A deep analysis of our tool including the responding speed, storage usage, specific type code completion, and API invocation completion has confirmed that $k$NM-LM provides satisfactory performance, which renders it highly appropriate for domain adaptive code completion. Furthermore, our approach operates without the requirement for direct access to the language model's parameters. As a result, it can seamlessly integrate with black-box code completion models, making it easy to integrate our approach as a plugin to further enhance the performance of these models.
翻译:大型语言模型(LLMs)在代码补全任务中展现出卓越性能。然而,由于缺乏领域特定知识,它们在需要深度领域知识的代码补全场景(例如补全库名称)中可能并非最优。尽管已有研究验证了微调技术可有效适配语言模型以完成特定领域的代码补全,但这些方法受限于项目持续迭代时需不断对模型进行微调的问题。为解决这一局限,本文提出$k$NM-LM——一种无需微调即可将领域知识融入语言模型的检索增强型语言模型(R-LM)。与现有技术不同,我们的方法能自动适配不同的语言模型与领域。具体而言,它利用领域内代码构建与语言模型解耦的检索式数据库,并通过贝叶斯推断将其与语言模型结合以完成代码补全。在项目内与场景内代码补全任务上的大量实验证实,与CodeGPT和UnixCoder相比,$k$NM-LM带来了显著性能提升。针对响应速度、存储占用、特定类型代码补全及API调用补全的深度分析表明,$k$NM-LM提供了令人满意的表现,使其高度适用于领域自适应代码补全。此外,该方法无需直接访问语言模型的参数,因此可无缝集成至黑盒代码补全模型,并作为插件轻松嵌入以进一步提升这些模型的性能。