Knowledge-Driven Reasoning for Compatible and Interpretable API Recommendation via Teacher LLM Distillation
API recommendation is a crucial task in code intelligence, aiming to suggest suitable APIs for programming queries. Recent efforts have integrated Large Language Models (LLMs) into this task. However, these methods overlook the compatibility between recommended APIs and fail to fully utilize the factual knowledge of APIs. Moreover, these prompting-only methods are limited by the insufficient domain-specific knowledge of LLMs. In this article, we propose a novel fine-tuning method, KDRAR, designed to leverage knowledge-driven reasoning with LLMs for compatible and interpretable API recommendation. To fully utilize the factual knowledge, we introduce a dual matching strategy that leverages both function descriptions and keyword matching to retrieve candidate APIs. To handle compatibility, we translate compatibility information into descriptive knowledge, which is integrated into the recommendation process. Furthermore, we adopt a distilled fine-tuning strategy: a student LLM is trained via distillation from a teacher LLM to perform step-by-step reasoning for enhanced recommendation and explanation. By considering both function matching and compatibility information, the knowledge-driven reasoning not only improves API recommendation accuracy but also provides reasonable explanations for the recommendations. Experimental results show that our method significantly outperforms baseline methods on API recommendation tasks across multiple API domains.
Authors
- Haipeng Dai (ORCID: https://orcid.org/0000-0003-0545-8187)
- Xiaolong Xu (ORCID: https://orcid.org/0000-0003-4879-9803)
- Wanchun Dou (ORCID: https://orcid.org/0000-0003-4833-2023)
- Rong Gu (ORCID: https://orcid.org/0000-0002-1565-9997)
- Lianyong Qi (ORCID: https://orcid.org/0000-0002-6330-2845)
- Xuyun Zhang (ORCID: https://orcid.org/0000-0001-7353-4159)
- Hong-Ya Xiang
- Chunhua Hu (ORCID: https://orcid.org/0000-0003-0317-2687)
- Jinyun Xie (ORCID: https://orcid.org/0009-0001-9727-0028)
Institutions
- Nanjing University of Information Science and Technology (CN)
- Nanjing University of Science and Technology (CN)
- Beijing Institute of Big Data Research (CN)
- China University of Petroleum, East China (CN)
- Hunan University of Technology (CN)
- Nanjing University (CN)
- Macquarie University (AU)
Publication Details
- Journal
- ACM Transactions on Information Systems
- Published
- 2025-10-14
- DOI
- https://doi.org/10.1145/3771772
- Citations
- 12
- Primary Topic
- Semantic Web and Ontologies
- Type
- article
- Field-Weighted Citation Impact
- 29.77