Experimental evaluation reveals reduced code hallucinations and improved functional accuracy in large language models, indicating enhanced reliability for software engineering automation.
Large language models have achieved strong performance in code generation, but generated code may contain syntactically plausible yet semantically incorrect API calls, invalid imports, and inconsistent logic. To mitigate such code -generation hallucinations, this study proposes a retrieval-augmented generation framework integrating multi-source retrieval, generation constraints, post-verification, and feedback optimization. Code repositories, technical documents, and Q&A data are jointly modeled through semantic and structural retrieval, and retrieved fragments are represented as structured context units containing API descriptions, sample code, and constraints. During generation, token-level confidence assessment and semantic-consistency constraints are used to identify and control low-confidence fragments. After generation, abstract syntax tree analysis, type consistency checking, API constraint checking, and unittest feedback form a closed-loop generation–verification–correction process. A retrieval–generation collaborative optimization mechanism further updates retrieval weights according to confidence, consistency, and execution feedback. Experiments on code-generation benchmarks show that the method increases BLEU to 42.7, CodeBLEU to 46.3, and Pass@1 to 56.4, while reducing the hallucination rate to 9.8%. The framework provides a reliable method for semantic retrieval, software-engineering automation, and constrained intelligent code generation.
No takes yet. Share an insight, caveat, or question.
K. Wei (2026) studied this question.
Synapse has enriched 5 closely related papers on similar clinical questions. Consider them for comparative context: