Dual Multi-RAG: Multi-View Contrastive Learning for Code Completion
Recent advances in pre-trained Large Language Models (LLMs) have greatly improved automated code completion, but challenges such as logical errors, semantic misunderstandings, and hallucinated outputs persist, especially for complex or unseen code. Retrieval-Augmented Generation (RAG) alleviates these issues by retrieving external snippets as supplementary context, yet its single-view encoder often fails to capture the full range of code semantics. We propose Dual Multi-RAG, a novel framework that combines prompt-driven multi-retrieval with multi-view contrastive learning. In the retrieval stage, carefully designed prompts guide LLMs to elicit diverse semantic perspectives. In the selection stage, a contrastive learning mechanism identifies the most contextually relevant snippet for completion. This dual design enriches semantic coverage and improves reliability. Experiments demonstrate that Dual Multi-RAG consistently outperforms existing approaches, achieving 3.91% higher accuracy on the CCEval benchmark and 2.8% improvement on HumanEval-Infilling, confirming its effectiveness for robust and accurate code completion.
Authors
- Shaoying Liu
- Yuxiang Shang (ORCID: https://orcid.org/0009-0000-7593-7269)
Institutions
- Twitter (United States) (US)
Publication Details
- Journal
- International Journal of Software Engineering and Knowledge Engineering
- Published
- 2026-04-22
- DOI
- https://doi.org/10.1142/s0218194026500348
- Primary Topic
- Software Engineering Research
- Type
- article
- Field-Weighted Citation Impact
- 0.00