Abstract
Library migration is a critical yet labor-intensive task in software engineering, requiring developers to identify functionally equivalent APIs across different libraries. This paper introduces KGE4AR (Knowledge Graph Embedding for Analogical Recommendation), a framework that automates the discovery of analogical APIs by representing millions of software entities in a massive Knowledge Graph. By leveraging high-dimensional embeddings and a two-stage retrieval process, KGE4AR overcomes the limitations of keyword-based matching and scales to handle tens of millions of APIs. Experimental results demonstrate that KGE4AR improves recommendation accuracy (Mean Reciprocal Rank) by up to 143% over state-of-the-art baselines while maintaining sub-second response times.
Introduction
In the modern software ecosystem, developers frequently migrate between libraries to address security vulnerabilities, restrictive licensing, or lack of maintenance. A central challenge in this process is identifying "analogical APIs"—methods in a new library that perform the same function as those in the original library. For example, a developer moving from org.json to com.google.gson must recognize that JSONArray.length() corresponds to JsonArray.size().
Manually identifying these equivalents is increasingly difficult. As of 2020, the Java ecosystem alone contained over 35,000 libraries and 15 million APIs. Previous automated approaches have struggled with two primary hurdles:
- The Semantic Gap: Tools relying on simple keyword matching fail when different libraries use different terminology (e.g., "length" vs. "size") for the same concept.
- Scalability: Comparing a source API against millions of potential candidates using deep linguistic analysis is computationally prohibitive for real-time use.
Methodology: The KGE4AR Framework
KGE4AR addresses these challenges through a three-phase approach that combines graph theory with high-dimensional vector space modeling.
1. Unified API Knowledge Graph Construction
The researchers constructed a massive Knowledge Graph (KG) representing 35,773 Java libraries. This graph integrates three layers of information:
- Structural Data: Relationships between packages, classes, and methods derived via Abstract Syntax Tree (AST) analysis.
- Functional Data: Standardized "action-object" patterns (e.g., "return | element number | array") extracted from Javadoc descriptions using the FuncVerbNet tool.
- Conceptual Data: Links between domain-specific terms (e.g., "JSON" or "File") across disparate libraries to bridge vocabulary differences.
2. Knowledge Graph Embedding
To make the massive graph searchable, the authors utilized the ComplEx model, a tensor decomposition technique. This process translates the 72 million entities and 289 million relations into a high-dimensional vector space. In this space, APIs that share similar structural roles, functional descriptions, or conceptual neighborhoods are positioned close to one another.
3. Analogical API Inferring
When a recommendation is requested, KGE4AR employs a two-step search strategy:
- Retrieval: The system uses the Milvus vector database to identify the top 100 closest APIs in the embedding space within milliseconds.
- Re-ranking: The results are refined by calculating a weighted similarity score based on the API’s immediate neighbors, including input types, return values, and standardized functionality verbs.
Experimental Evaluation
The framework was evaluated using a KG source of 35,773 Java libraries from Libraries.io. Performance was measured against two benchmarks: a set of 245 manually validated analogical pairs and a new "open-world" benchmark involving 270 source APIs across 18 diverse libraries.
Key Results
- Accuracy: In scenarios with a known target library, KGE4AR improved Mean Reciprocal Rank (MRR) by 47.1% to 143.0% over existing baselines like RAPIM and D2APIMap. In the more difficult "open-world" scenario (no target library specified), it outperformed baselines by 11.7% to 80.6%.
- Efficiency: Despite the scale of the underlying data, the online recommendation process takes less than one second per query.
- Ablation Insights: The study found that "conceptual relations"—those linking specific terms to abstract concepts—provided the most significant boost to accuracy, confirming that bridging the semantic gap is the most critical factor in analogical recommendation.
Discussion and Future Work
KGE4AR demonstrates that treating API recommendation as a geometric problem in an embedding space is both more accurate and more scalable than traditional text-matching. However, the current implementation is specific to Java and relies on the language's strong typing and Javadoc conventions.
Future research will focus on adapting the Knowledge Graph schema for dynamic languages like Python, which lack explicit type information, and exploring attention mechanisms to better filter "noise" from unrelated neighboring nodes during the re-ranking phase.
Summary updated