arXiv:2507.20888cs.SEcs.CL2025-07被引 10

通过推断内部API提升代码补全准确率

Enhancing Project-Specific Code Completion by Inferring Internal API Information

  • 不依赖导入信息,从使用实例和语义描述构建API知识库
  • 在真实项目上实现代码精确匹配提升22.72%,标识符匹配提升18.31%
  • 适合需要高精度项目级代码补全的开发者和工具研发者

项目级代码补全需利用项目上下文生成准确代码。现有先进方法虽采用大语言模型与检索增强生成(RAG)结合项目信息,但难以融入未显式导入的内部API信息,影响准确性。为此,本文提出一种无需依赖导入即可推断内部API信息的方法。通过构建使用示例和语义描述扩展API表示,建立知识库供大语言模型生成相关补全。同时引入ProjBench基准测试集,避免导入泄露,包含大规模真实项目数据。在ProjBench与CrossCodeEval上的实验表明,该方法显著优于现有方法,代码精确匹配提升22.72%,标识符精确匹配提升18.31%。将本方法集成至现有基线后,代码匹配提升47.80%,标识符匹配提升35.55%。

原文摘要 · Abstract (English)

Project-specific code completion is a critical task that leverages context from a project to generate accurate code. State-of-the-art methods use retrieval-augmented generation (RAG) with large language models (LLMs) and project information for code completion. However, they often struggle to incorporate internal API information, which is crucial for accuracy, especially when APIs are not explicitly imported in the file. To address this, we propose a method to infer internal API information without relying on imports. Our method extends the representation of APIs by constructing usage examples and semantic descriptions, building a knowledge base for LLMs to generate relevant completions. We also introduce ProjBench, a benchmark that avoids leaked imports and consists of large-scale real-world projects. Experiments on ProjBench and CrossCodeEval show that our approach significantly outperforms existing methods, improving code exact match by 22.72% and identifier exact match by 18.31%. Additionally, integrating our method with existing baselines boosts code match by 47.80% and identifier match by 35.55%.

代码补全API推断LLM应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。