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.
翻译:大型语言模型在代码补全中展现了卓越的性能。然而,由于缺乏领域特定知识,它们在需要深度领域知识(例如补全库名称)的代码补全中可能并非最优。尽管已有研究证实了微调技术可有效适应特定领域的语言模型进行代码补全,但这些方法面临项目持续迭代时需要不断微调模型的局限。为解决此问题,本文提出$k$NM-LM,一种检索增强型语言模型,无需微调即可将领域知识整合到语言模型中。与现有技术不同,本方法能够自动适应不同的语言模型和领域。具体而言,它利用领域内代码构建与语言模型解耦的检索式数据库,随后通过贝叶斯推理将其与语言模型结合以完成代码补全。在项目内和场景内代码补全上的大量实验证实,与CodeGPT和UnixCoder相比,$k$NM-LM带来了显著提升。对工具的深入分析(包括响应速度、存储占用、特定类型代码补全及API调用补全)证实$k$NM-LM具有令人满意的性能,使其高度适用于领域自适应代码补全。此外,本方法无需直接访问语言模型参数,因此可无缝集成至黑盒代码补全模型中,作为插件轻松增强这些模型的性能。