用知识图谱提升代码生成,精准检索+重排减少幻觉
Context-Augmented Code Generation Using Programming Knowledge Graphs
- 构建编程知识图谱,细粒度组织代码与文本上下文
- 在HumanEval和MBPP上提升20%通过率,MBPP超基线34%
- 适合需要复杂逻辑推理的代码生成任务
大型语言模型在代码生成方面表现优异,但在复杂问题上仍存在不足。检索增强生成(RAG)通过引入外部知识缓解此问题,但检索模型常遗漏相关上下文,生成模型则易产生无关幻觉。本文提出编程知识图谱(PKG),用于代码与文本的语义表征及细粒度检索。通过树剪枝提升检索精度,并采用融合非RAG解法的重排机制抑制幻觉。将外部数据结构化为更细粒度节点,增强了检索粒度。在HumanEval和MBPP上的评估显示,最多提升20%的pass@1准确率,于MBPP上较基线提升34%。结果表明,所提PKG结合重排器能有效应对复杂问题,同时对已有正确解法影响极小。复现代码已发布于https://github.com/iamshahd/ProgrammingKnowledgeGraph。
原文摘要 · Abstract (English)
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
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。