SemanticForge:基于语义知识图谱和约束满足的仓库级代码生成
SemanticForge: Repository-Level Code Generation through Semantic Knowledge Graphs and Constraint Satisfaction
AI总结:
针对大型语言模型代码生成中的逻辑与模式幻觉问题,提出SemanticForge框架,通过双知识图谱协调、神经图查询生成、集成SMT的束搜索及增量维护算法,实现仓库级语义感知代码生成,提升生成准确性。
摘要:
大型语言模型(LLMs)通过自动化代码生成改变了软件开发,但它们常因系统性错误限制实际部署。我们发现两个关键失效模式:逻辑幻觉(错误的控制/数据流推理)和模式幻觉(类型不匹配、签名违规及架构不一致)。这些错误源于缺乏仓库范围语义的显式可查询表示。本文提出SemanticForge,为语义感知代码生成引入四项基础算法改进:(1)双静态-动态知识图谱的自动协调算法,统一编译时和运行时程序语义;(2)从自然语言生成结构化图查询的神经方法,精度达73%,高于传统检索的51%;(3)集成SMT求解的束搜索算法,在生成中实时验证约束而非事后验证;(4)增量维护算法,以O(|ΔR|·log n)时间更新知识图谱并保持语义等价。
英文摘要:
Large language models (LLMs) have transformed software development by enabling automated code generation, yet they frequently suffer from systematic errors that limit practical deployment. We identify two critical failure modes: \textit{logical hallucination} (incorrect control/data-flow reasoning) and \textit{schematic hallucination} (type mismatches, signature violations, and architectural inconsistencies). These errors stem from the absence of explicit, queryable representations of repository-wide semantics. This paper presents \textbf{SemanticForge}, which introduces four fundamental algorithmic advances for semantically-aware code generation: (1) a novel automatic reconciliation algorithm for dual static-dynamic knowledge graphs, unifying compile-time and runtime program semantics; (2) a neural approach that learns to generate structured graph queries from natural language, achieving 73\% precision versus 51\% for traditional retrieval; (3) a novel beam search algorithm with integrated SMT solving, enabling real-time constraint verification during generation rather than post-hoc validation; and (4) an incremental maintenance algorithm that updates knowledge graphs in $O(|ΔR| \cdot \log n)$ time while maintaining semantic equivalence.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。