通过程序逻辑相似性提升代码生成准确率
ProjAgent: Procedural Similarity Retrieval for Repository-Level Code Generation

- 按推理步骤分解目标函数,检索相似执行流程的代码
- 在REPOCOD数据集上达到41.14% Pass@1,优于现有方法
- 适合需要理解跨文件逻辑的大型项目代码生成
仓库级代码生成需在考虑复杂跨文件依赖和项目特定规范的前提下实现目标函数。现有检索方法多依赖词汇、结构或语义相似性,常忽略在标识符或应用领域不同但具有相似程序逻辑的仓库函数。我们提出ProjAgent,一种引入程序相似性作为显式检索信号的仓库级代码生成系统。ProjAgent将目标函数分解为中间推理步骤,并采用智能体工作流,在每一步检索具有类似程序行为的仓库函数。检索到的程序上下文与传统语义检索结合,构建更丰富的仓库上下文以支持代码生成。ProjAgent还引入保守的静态分析反馈环,通过编译器和静态分析反馈迭代修复生成代码。在REPOCOD数据集上的评估显示,ProjAgent达到41.14% Pass@1,优于现有基于检索的基线。结果表明,程序相似性是仓库级代码生成中一个有效且此前未被探索的检索维度。
原文摘要 · Abstract (English)
Repository-level code generation requires implementing target functions while accounting for complex cross-file dependencies and project-specific conventions. Existing retrieval methods predominantly rely on lexical, structural, or semantic similarity, often overlooking repository functions that implement similar procedural logic despite differing in identifiers or application domains. We propose ProjAgent, a repository-level code generation system that introduces procedural similarity as an explicit retrieval signal. ProjAgent decomposes the target function into intermediate reasoning steps and employs an agentic workflow to retrieve repository functions that exhibit similar procedural behavior at each step. The retrieved procedural context is integrated with conventional semantic retrieval to construct a richer repository context for code generation. ProjAgent further incorporates a conservative static-analysis feedback loop that iteratively repairs generated code using compiler and static-analysis feedback. Evaluated on REPOCOD, ProjAgent achieves 41.14% Pass@1, outperforming existing retrieval-based baselines. These results demonstrate that procedural similarity is an effective and previously unexplored retrieval dimension for repository-level code generation.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。