arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.20810cs.SEcs.LG
收藏

基于编程知识图谱的上下文增强代码生成

Context-Augmented Code Generation Using Programming Knowledge Graphs

University of British Columbia(不列颠哥伦比亚大学);University of Melbourne(墨尔本大学)

Shahd Seddik, Fahd Seddik, Iman Saberi, Fatemeh Fard, Minh Hieu Huynh, Patanamon Thongtanunam

AI总结:

本文提出编程知识图谱(PKG)和重排序机制,通过细粒度检索和减少幻觉,提升代码生成在复杂问题上的表现。

摘要:

大型语言模型(LLMs)在代码生成方面表现出色,但在处理复杂问题时却存在困难。检索增强生成(RAG)通过整合外部知识来缓解这一问题,但检索模型常常遗漏相关上下文,而生成模型则容易产生幻觉。我们提出了编程知识图谱(PKG)用于代码和文本的语义表示和细粒度检索。我们的方法通过树修剪来提高检索精度,并通过整合非RAG解决方案的重排序机制来缓解幻觉。将外部数据结构化为更细粒度的节点可以提高检索的粒度。在HumanEval和MBPP上的评估显示,精度达到最高20%的pass@1提升,并在MBPP上比基线提高了34%。我们的发现表明,所提出的PKG方法以及重排序器能够有效解决复杂问题,同时在不使用RAG的情况下对已正确解决方案的负面影响保持最小。复制包发布在https://github.com/iamshahd/ProgrammingKnowledgeGraph。

英文摘要:

Large Language Models (LLMs) excel at code generation but struggle with complex problems. Retrieval-Augmented Generation (RAG) mitigates this issue by integrating external knowledge, yet retrieval models often miss relevant context, and generation models hallucinate with irrelevant data. We propose Programming Knowledge Graph (PKG) for semantic representation and fine-grained retrieval of code and text. Our approach enhances retrieval precision through tree pruning and mitigates hallucinations via a re-ranking mechanism that integrates non-RAG solutions. Structuring external data into finer-grained nodes improves retrieval granularity. Evaluations on HumanEval and MBPP show up to 20% pass@1 accuracy gains and a 34% improvement over baselines on MBPP. Our findings demonstrate that our proposed PKG approach along with re-ranker effectively address complex problems while maintaining minimal negative impact on solutions that are already correct without RAG. The replication package is published at https://github.com/iamshahd/ProgrammingKnowledgeGraph

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑