Semantic and Lexical Retrieval-Augmented Large Language Models for Code Summarization
Year: 2026
Type: article
Abstract: As software systems grow, automatic code summarization is vital for program comprehension and maintenance. While Large Language Models (LLMs) excel at this task, they often generate verbose, incomplete, or hallucinated summaries when relying solely on source code. Retrieval-augmented generation (RAG) addresses this by incorporating external code-summary examples. However, existing single-strategy retrievers struggle to capture both deep semantic similarity and precise keyword matching. To overcome these limitations, we propose HyRALLM, a hybrid retrieval-augmented LLM framework. First, a dense retriever is constructed via cross-modal contrastive learning for semantic alignment, which is then integrated with a keyword-based sparse retriever. During the generation stage, the retrieved context is utilized to guide the LLM in generating summaries, and the quality of the generated summaries is further enhanced through a multi-candidate strategy and a post-processing discrimination mechanism. Experiments on the JCSD and PCSD benchmark datasets demonstrate that HyRALLM achieves highly competitive performance across BLEU, ROUGE-L, METEOR, and CIDEr metrics. Additional analyses confirm our framework effectively improves summary quality, reduces semantic deviation, and enhances generation robustness.
Authors: Jiawei Wang, Chunli Xie, Wei Zhu, Chunpeng Kang
Language: English
Subfield: Information Systems
Field: Computer Science
Domain: Physical Sciences
Open Access status: green
OpenAlex ID: W7160024503
