一句话:用知识图谱对齐检索上下文子图来增强提示,显著提升 LLM 对 API 方法实参的补全精度。
API 方法实参的准确补全是现代软件开发中的难题,现有基于信息检索或语言模型混合程序分析的方法常受静态代码模式和领域知识不足的限制。本文提出 APICopilot:首先针对待补全的 API 调用,从其前序代码构建输入知识图谱(KG),并从相似代码文件集合中构建代表预期调用的目标知识图谱;其次量化两个 KG 之间的结构与语义对齐程度,从目标图中检索相关子图,为上下文学习提供关键的结构上下文;最后将子图融入提示,请求 LLM 推荐 API 实参。在 54,000 个 Java 文件上的评估表明,该方法的精确率、召回率和平均倒数排名(MRR)分别比最先进方法提升 38%、36% 和 23%。
Application Programming Interfaces (APIs) are fundamental to modern software development, yet accurately completing API method arguments remains a challenging task. Existing methods, such as information retrieval and hybrid program analysis with language models, often struggle with static code patterns and limited domain-specific knowledge. To this end, in this paper, we introduce APICopilot, a novel approach that enhances LLM-based API argument completion using dynamically generated, context-rich prompts. First, it creates an input knowledge graph (KG) from the preceding code for the to-be-complete API invocation, and a targeted knowledge graph from a collection of similar code files, both representing the anticipated API call. Second, it quantifies structural and semantic alignment between the two KGs and retrieves relevant subgraphs from the targeted graph. These subgraphs provide crucial structural context for in-context learning, enabling significantly more accurate and context-specific argument completions. Finally, we integrate the subgraphs into prompts and request LLMs to recommend API arguments. Our evaluation results on 54,000 Java files suggest that the proposed approach outperforms the state-of-the-art approach, improving precision, recall, and mean reciprocal rank by 38%, 36% and 23%, respectively.
@inproceedings{paperbot11748,
title = {LLM-based API Argument Completion with Knowledge-Augmented Prompts},
author = {Waseem Akram and Yanjie Jiang and Haris Ali Khan and Furqan Jalil and Hui Liu},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773158}
}