A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat

Zezhou Yang, Ting Peng, Cuiyun Gao, Chaozheng Wang, Hailiang Huang, Yuetang Deng

Introduction

Large Language Models (LLMs) have revolutionized general software development, yet they frequently encounter significant "distribution shifts" when applied to proprietary industrial codebases like WeChat's. These environments are characterized by unique internal APIs, custom frameworks, and specific naming conventions absent from public training data. Due to security and privacy constraints, fine-tuning on sensitive source code is often unfeasible. Retrieval-Augmented Generation (RAG) offers a compelling alternative by dynamically providing local context. This study explores optimizing RAG for a massive, closed-source C++ ecosystem, evaluating 26 LLMs ranging from 0.5B to 671B parameters.

Methodology: Identifier vs. Similarity-Based RAG

The researchers investigated two primary RAG paradigms to bridge the industrial knowledge gap:

  1. Identifier-based RAG: Functions as an intelligent lookup, identifying variables or functions in the current context and retrieving their definitions from the codebase.
  2. Similarity-based RAG: Retrieves code snippets based on their resemblance to the current task. This includes Lexical Retrieval (BM25) for keyword matching and Semantic Retrieval (e.g., GTE-Qwen, CodeBERT) for logic-based matching.

A critical component of their approach is a Fine-grained Data Preprocessing algorithm designed for C++. By navigating complex header dependencies and macros, the algorithm extracts semantically intact class and function definitions, ensuring the retrieved context is coherent and useful for the LLM.

Evaluation Benchmark

To rigorously test these methods, the study utilized a massive internal corpus from 1,669 WeChat repositories. The evaluation was conducted on a newly developed, manually annotated benchmark consisting of 100 high-quality examples.

Distribution of the 100-example evaluation benchmark across domains and difficulty levels.

As shown in the figure above, the benchmark covers seven distinct domains—including network connections, data storage (kv), and utility functions—with each example categorized by senior developers as "easy" or "hard" to ensure a comprehensive assessment of model capabilities.

Key Insights: The Hybrid Advantage

The study revealed several critical insights into industrial code completion:

  • The Incomplete Query Paradox: Standard semantic models often struggle because code completion queries are, by definition, incomplete. However, models like GTE-Qwen demonstrated remarkable robustness in handling these partial snippets.
  • Lexical Resilience: Despite the rise of deep learning, BM25 remains highly effective. Proprietary code often relies on unique, specific function names that lexical matching captures more reliably than semantic models, which may "smooth over" such details.
  • The Hybrid Sweet Spot: The most effective approach combined BM25 (for exact API names) with GTE-Qwen (for logical context). This hybrid strategy proved particularly potent for larger models (7B+ parameters), which possess the reasoning capacity to synthesize diverse retrieved contexts.

Results and Performance Gains

Quantitative analysis across the model fleet demonstrated that similarity-based RAG consistently outperforms identifier-based approaches.

Performance comparison (CodeBLEU/Exact Match) of various LLMs across different RAG configurations.

The performance gains are most striking at the highest scales. For the DeepSeek-V3 (671B) model, implementing GTE-Qwen-based RAG boosted the CodeBLEU score from 35.23 to 60.28—a 71% relative improvement. These quantitative results were mirrored by qualitative developer surveys, where the hybrid BM25 + GTE-Qwen approach received the highest marks for code quality.

Conclusion and Future Directions

While RAG significantly enhances a model's ability to utilize the correct internal tools, "Logic Errors" still account for approximately 52% of failures. This suggests that while retrieval provides the "what," it does not fully solve the "how" of complex business logic. Future work will focus on developing retrieval models specifically trained on incomplete-to-complete code pairs and extending these preprocessing techniques to dynamic languages like Python and JavaScript.

Summary updated

BibTeX
@inproceedings{yang2025deep,
  author = {Zezhou Yang and Ting Peng and Cuiyun Gao and Chaozheng Wang and Hailiang Huang and Yuetang Deng},
  title = {{A Deep Dive into Retrieval-Augmented Generation for Code Completion: Experience on WeChat}},
  booktitle = {ICSME},
  year = {2025},
  doi = {10.1109/icsme64153.2025.00062},
}
Figure