SelfRACG: Enabling LLMs to Self-Express and Retrieve for Code Generation
Qian Dong, Jia Chen, Qingyao Ai, Hongning Wang, Haitao Li, Yiwu, Yao Hu, Yiqun Liu, Shaoping Ma
Abstract
Existing retrieval-augmented code generation (RACG) methods typically use an external retrieval module to fetch semantically similar code snippets used for generating subsequent fragments. However, even for consecutive code fragments, the content often diverges due to logical progression, resulting in a content gap. This gap undermines the performance of current RACG methods, as external retrieval modules based on content matching fail to infer the specific information need of LLMs to generate the next code fragment. Therefore, we propose SelfRACG, a novel paradigm that enables large language models (LLMs) to Self-express their information needs to enhance RACG. Specifically, SelfRACG includes an information need expression module and a two-stage information need-guided training strategy, which encourages LLMs to express their information need. Extensive experiments demonstrate that SelfRACG can retrieve external knowledge that better aligns with the LLM’s own information needs, resulting in superior generation performance compared to vanilla RACG. Moreover, both the training and deployment costs for retrieval in our framework are much lower than those of the strongest retrieval model.- Anthology ID:
- 2025.emnlp-main.541
- Volume:
- Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing
- Month:
- November
- Year:
- 2025
- Address:
- Suzhou, China
- Editors:
- Christos Christodoulopoulos, Tanmoy Chakraborty, Carolyn Rose, Violet Peng
- Venue:
- EMNLP
- SIG:
- Publisher:
- Association for Computational Linguistics
- Note:
- Pages:
- 10705–10716
- Language:
- URL:
- https://preview.aclanthology.org/ingest-emnlp/2025.emnlp-main.541/
- DOI:
- Cite (ACL):
- Qian Dong, Jia Chen, Qingyao Ai, Hongning Wang, Haitao Li, Yiwu, Yao Hu, Yiqun Liu, and Shaoping Ma. 2025. SelfRACG: Enabling LLMs to Self-Express and Retrieve for Code Generation. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, pages 10705–10716, Suzhou, China. Association for Computational Linguistics.
- Cite (Informal):
- SelfRACG: Enabling LLMs to Self-Express and Retrieve for Code Generation (Dong et al., EMNLP 2025)
- PDF:
- https://preview.aclanthology.org/ingest-emnlp/2025.emnlp-main.541.pdf