RAG or Fine-tuning? A Comparative Study on LCMs-based Code Completion in Industry

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Wang, Chaozheng, Yang, Zezhou, Gao, Shuzheng, Gao, Cuiyun, Peng, Ting, Huang, Hailiang, Deng, Yuetang, Lyu, Michael
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909618013208576
author Wang, Chaozheng
Yang, Zezhou
Gao, Shuzheng
Gao, Cuiyun
Peng, Ting
Huang, Hailiang
Deng, Yuetang
Lyu, Michael
author_facet Wang, Chaozheng
Yang, Zezhou
Gao, Shuzheng
Gao, Cuiyun
Peng, Ting
Huang, Hailiang
Deng, Yuetang
Lyu, Michael
contents Code completion, a crucial practice in industrial settings, helps developers improve programming efficiency by automatically suggesting code snippets during development. With the emergence of Large Code Models (LCMs), this field has witnessed significant advancements. Due to the natural differences between open-source and industrial codebases, such as coding patterns and unique internal dependencies, it is a common practice for developers to conduct domain adaptation when adopting LCMs in industry. There exist multiple adaptation approaches, among which retrieval-augmented generation (RAG) and fine-tuning are the two most popular paradigms. However, no prior research has explored the trade-off of the two approaches in industrial scenarios. To mitigate the gap, we comprehensively compare the two paradigms including Retrieval-Augmented Generation (RAG) and Fine-tuning (FT), for industrial code completion in this paper. In collaboration with Tencent's WXG department, we collect over 160,000 internal C++ files as our codebase. We then compare the two types of adaptation approaches from three dimensions that are concerned by industrial practitioners, including effectiveness, efficiency, and parameter sensitivity, using six LCMs. Our findings reveal that RAG, when implemented with appropriate embedding models that map code snippets into dense vector representations, can achieve higher accuracy than fine-tuning alone. Specifically, BM25 presents superior retrieval effectiveness and efficiency among studied RAG methods. Moreover, RAG and fine-tuning are orthogonal and their combination leads to further improvement. We also observe that RAG demonstrates better scalability than FT, showing more sustained performance gains with larger scales of codebase.
format Preprint
id arxiv_https___arxiv_org_abs_2505_15179
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle RAG or Fine-tuning? A Comparative Study on LCMs-based Code Completion in Industry
Wang, Chaozheng
Yang, Zezhou
Gao, Shuzheng
Gao, Cuiyun
Peng, Ting
Huang, Hailiang
Deng, Yuetang
Lyu, Michael
Software Engineering
Code completion, a crucial practice in industrial settings, helps developers improve programming efficiency by automatically suggesting code snippets during development. With the emergence of Large Code Models (LCMs), this field has witnessed significant advancements. Due to the natural differences between open-source and industrial codebases, such as coding patterns and unique internal dependencies, it is a common practice for developers to conduct domain adaptation when adopting LCMs in industry. There exist multiple adaptation approaches, among which retrieval-augmented generation (RAG) and fine-tuning are the two most popular paradigms. However, no prior research has explored the trade-off of the two approaches in industrial scenarios. To mitigate the gap, we comprehensively compare the two paradigms including Retrieval-Augmented Generation (RAG) and Fine-tuning (FT), for industrial code completion in this paper. In collaboration with Tencent's WXG department, we collect over 160,000 internal C++ files as our codebase. We then compare the two types of adaptation approaches from three dimensions that are concerned by industrial practitioners, including effectiveness, efficiency, and parameter sensitivity, using six LCMs. Our findings reveal that RAG, when implemented with appropriate embedding models that map code snippets into dense vector representations, can achieve higher accuracy than fine-tuning alone. Specifically, BM25 presents superior retrieval effectiveness and efficiency among studied RAG methods. Moreover, RAG and fine-tuning are orthogonal and their combination leads to further improvement. We also observe that RAG demonstrates better scalability than FT, showing more sustained performance gains with larger scales of codebase.
title RAG or Fine-tuning? A Comparative Study on LCMs-based Code Completion in Industry
topic Software Engineering
url https://arxiv.org/abs/2505.15179