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

TL;DR

While Retrieval-Augmented Generation (RAG) has supercharged code completion on open-source benchmarks, its efficacy inside massive, proprietary enterprise codebases has remained a black box. This paper provides a comprehensive evaluation of RAG methods across 26 large language models (LLMs) using WeChat’s industrial-scale codebase. The authors discover that while similarity-based RAG consistently outperforms identifier-based lookups, a hybrid approach combining lexical (BM25) and semantic (GTE-Qwen) retrieval yields the highest performance gains.

What Problem Does This Paper Address?

Most code completion models are evaluated on public repositories (like GitHub) and standard open-source benchmarks. However, production-grade, closed-source codebases—such as the one powering WeChat, which serves over a billion users—look entirely different. They are filled with proprietary frameworks, unique coding patterns, complex business logic, heavy C++ macro usage, and auto-generated code (like Protocol Buffers).

This creates a significant "distribution shift." Standard RAG techniques might struggle to find relevant context when the query is an incomplete snippet of highly specialized internal code. This paper bridges the gap by systematically analyzing how different RAG paradigms and retrieval techniques perform across various model scales (from 0.5B to 671B parameters) in a real-world corporate environment.

Methods

The authors explore two primary RAG paradigms for code completion:

  1. Identifier-based RAG: Uses an LLM to extract key identifiers (classes, functions, or protobuf messages) from the current code context, looks up their exact definitions or declarations in an indexed codebase, and appends them to the prompt.
  2. Similarity-based RAG: Uses the code snippet itself as a query to retrieve similar code implementations from the codebase. The authors test both lexical retrieval (BM25, which matches exact text tokens) and semantic retrieval (dense vector embeddings from models like CodeBERT, UniXcoder, CoCoSoDa, and GTE-Qwen).

To make this work on a massive C++ codebase, they developed a fine-grained data preprocessing algorithm. Instead of chunking files using a naive sliding window (which breaks code structure), their pipeline parses out clean class and function definitions, recursively resolves header file dependencies, extracts concise message definitions directly from .proto files, and normalizes C++ macros into function-like structures.

Datasets

  • Retrieval Corpus: 1,669 internal proprietary repositories from WeChat's development ecosystem.
  • Evaluation Benchmark: A newly curated, hand-annotated benchmark consisting of 100 function-level code completion examples. These span 7 core enterprise domains (e.g., remote procedure calls, data storage, message queues) and are categorized by difficulty.
Fig. 1. Statistics of our benchmark.

Key Insights and Ideas

  • Similarity Beats Structure: Intuitively, providing an LLM with exact definitions of the functions it's calling (identifier-based) sounds ideal. However, similarity-based RAG consistently won. Seeing how similar logic is implemented provides richer contextual patterns for the LLM to mimic.
  • Lexical and Semantic Search are Orthogonal: When comparing the candidates retrieved by BM25 (lexical) and dense retrievers (semantic), the authors found shockingly little overlap (64% to 76% of the retrieved snippets were completely distinct). BM25 excels at matching exact variable names and internal API keywords, while semantic models capture structural intent.
  • The Incomplete Query Dilemma: Most semantic code retrievers are trained on complete code blocks. In real-world code completion, however, the query is inherently incomplete. While models like UniXcoder suffer from this misalignment, GTE-Qwen proved remarkably robust at handling partial code queries out of the box.

Key Results

The authors evaluated performance using CodeBLEU (CB) and Edit Similarity (ES) across 26 models.

A snippet of the massive evaluation across 26 LLMs, highlighting the superiority of similarity-based RAG (specifically GTE-Qwen and BM25).
  • Massive Boosts for State-of-the-Art Models: For DeepSeek-V3 (671B), adding GTE-Qwen-based RAG pushed CodeBLEU/Edit Similarity from a base of 35.23/54.85 up to 60.28/73.11.
  • The Power of Hybrid Retrieval: Combining BM25 and GTE-Qwen yielded the absolute best results for larger models (7B+ parameters). For instance, DeepSeek-V3 reached an optimal score of 63.62 / 75.26 under this hybrid configuration.
  • Developer Validation: A survey of internal WeChat developers confirmed that the hybrid RAG approach generated the highest-quality completions. However, the survey also highlighted that "Missing or Incorrect Logic" still accounts for ~52% of all generation failures, showing that retrieval alone cannot entirely compensate for an LLM's reasoning limitations.

Limitations and Future Work

The primary limitation is external validity: the evaluation was conducted entirely within Tencent's WeChat ecosystem, which is heavily C++ centric. The challenges and preprocessing solutions might differ for proprietary codebases dominated by dynamically typed languages like Python or JavaScript.

For future work, the authors point out a clear research gap: the community needs to develop specialized semantic retrieval models optimized specifically for incomplete code queries, rather than relying on models trained purely on complete functions.

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