Representation query and recommendation method based on third-party library with attribute multilayer graph model
By building a multi-layer graph model with attributes and using a multi-layer graph representation learning algorithm with weights, the challenge of efficiently finding and replacing libraries in a large number of third-party libraries is solved, and efficient analog library recommendations and demand description retrieval is achieved.
Patent Information
- Application Number
- CN202510004997.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-05-02
AI Technical Summary
The challenge of efficiently finding or replacing libraries in massive third-party libraries is especially due to the difficulty of existing technologies to effectively solve data sparsity and cold start problems, and it is difficult to support retrieval based on development requirements descriptions.
The representation query and recommendation method based on the attribute multi-layer graph model is adopted. By building a multiple graph model containing multiple relationship layers, the node attributes and structural relationships of the third-party library are combined, and the extended weighted multi-layer graph representation learning algorithm is used for embedded learning, thereby realizing the recommendation and retrieval of the analog library.
This method can effectively alleviate the cold start problem, support retrieval based on demand description, improve the accuracy and efficiency of recommendations, and significantly improve the efficiency of developers in finding and replacing third-party libraries.
Smart Images

Figure CN119917674A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes, and belongs to the field of computer science and technology. Background Art
[0002] With the rapid development of modern software development, the use of third-party libraries (TPL) has become an important way to improve development efficiency. Third-party libraries help developers save time and energy in implementing functions from scratch by providing pre-built functional modules. However, with the explosive growth in the number of third-party libraries, how to quickly find third-party libraries that meet your needs has become an important challenge.
[0003] Currently, many software ecosystems such as NPM (Javascript), Maven (Java), and PyPI (Python) provide a large number of third-party libraries for developers to retrieve and use. However, the number of third-party libraries is too large. For example, libraries.io has indexed more than 9 million open source packages, which makes it extremely difficult for developers to choose. In addition, when faced with problems such as library deprecation, missing functions, or license incompatibility, developers need to find alternative libraries, and existing search engines and recommendation systems are difficult to efficiently provide analogous library suggestions.
[0004] Existing research has proposed a variety of third-party library recommendation methods, including migration rule mining, information site analysis, functional semantic modeling, and knowledge graph learning. However, these methods usually rely on observed library replacement instances, are easily affected by data sparsity and cold start problems, and are difficult to directly support retrieval based on development requirement descriptions. Summary of the invention
[0005] Purpose of the invention: In view of the problems and shortcomings existing in the prior art, the present invention proposes a representation query and recommendation method for third-party libraries based on a multi-layer graph model with attributes to solve the challenge of efficiently searching or replacing libraries in massive third-party libraries, while alleviating the cold start problem and supporting retrieval based on demand description.
[0006] By building a multi-graph model containing multiple relationship layers, combining the node attributes and structural relationships of the third-party library, and embedding learning through an extended weighted multi-layer graph representation learning algorithm, the recommendation and retrieval of analogy libraries can be achieved under a unified framework. This method can effectively alleviate the cold start problem, support retrieval based on demand description, and improve the accuracy and efficiency of recommendations.
[0007] Technical solution: A representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes, comprising the following steps: Steps for constructing attribute multigraph: represent the third-party library as a node in the network, extract the node attributes from the description information of the third-party library, and build a layer of graph for each relationship according to different types of library relationships to build a multi-layer isomorphic graph to form an attribute multigraph; Node embedding learning steps: Expand the unweighted graph representation to a weighted graph representation, combine node attributes and multi-layer relationship weights, and generate the embedding representation of each TPL through weighted random walks and neighbor sampling; Analogy TPL recommendation and retrieval steps: By calculating the Euclidean distance between TPL embeddings, we can identify the candidate library that is most similar to the target TPL, or generate virtual embeddings based on the requirement description to achieve description-based TPL recommendation and retrieval.
[0008] Furthermore, a relational layer is constructed according to multiple dimensions to form an attributed multigraph; this means that different types of edges are constructed through multiple layers of relations, including substitution relations, migration candidate relations, shared dependency relations, dependent party relations, maintainer relations, and keyword relations, thereby forming a multigraph.
[0009] Each node is further associated with a vector containing semantic features, representing its descriptive characteristics.
[0010] The step of constructing a property multigraph includes: Step 1.1: Extract the descriptive information of TPL, including the name, introduction and ReadMe file content, and generate a 768-dimensional feature vector as the node attribute through the pre-trained text embedding model; Step 1.2: Construct an alternative relationship layer based on the alternative information between TPLs, extract alternative suggestions from the deprecation information, and use the frequency of alternative relationships as edge weights; Step 1.3: Analyze the changes in dependent libraries between project versions, extract candidate migration rules, and build a migration rule layer; Step 1.4: Count the number of shared dependency libraries between TPLs and build a shared dependency layer; Step 1.5: Count the number of shared dependent parties, shared maintainers, and shared keywords between TPLs, and build corresponding relationship layers respectively.
[0011] The node embedding learning step comprises: Step 2.1: Use the attribute graph established in step 1, generate training samples through weighted random walks according to the values of weighted edges in the graph, and learn the model by combining node attributes and relationship layer weights; Step 2.2: Adjust the neighbor sampling probability in each layer of relations so that the strength of the relations has a greater impact on the embedding generation; Step 2.3: Output the embedding vector of each TPL, which comprehensively represents its attributes and relational features.
[0012] The analogous TPL recommendation and retrieval steps include: Step 3.1: Calculate the Euclidean distance between the target TPL and the candidate TPL through the TPL embedding vector and identify the most similar analog TPL; Step 3.2: Generate virtual TPL embedding based on the semantic embedding of the requirement description, and implement description-based TPL retrieval by calculating the distance between embeddings; Step 3.3: Sort by similarity and recommend the top k TPLs as candidate libraries.
[0013] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the representation query and recommendation method of a third-party library based on a multi-layer graph model with attributes as described above is implemented.
[0014] A computer-readable storage medium stores a computer program for executing the above-mentioned representation query and recommendation method based on a third-party library with a multi-layer graph model with attributes.
[0015] The technical solution provided by the present invention has the following beneficial effects: By constructing a multi-graph of attributes, the description information and relational features of TPL are effectively integrated, and recommendation and retrieval are supported under a unified framework; based on an extended weighted multi-layer graph representation learning algorithm, the embedded representation of TPL is learned by weighted random walk, which can alleviate the cold start problem, and analogy recommendation can be achieved based on the attributes of TPL alone; support retrieval based on demand description, developers do not need to provide specific library names, and can achieve automatic matching from natural language requirements to TPL; can handle a variety of ecosystems, suitable for TPL recommendation and cross-language retrieval in different languages; provides an analog TPL recommendation method with high efficiency and high accuracy, significantly improving the efficiency of developers in finding and replacing third-party libraries. The method of the present invention is widely applicable to scenarios such as third-party library management, selection optimization, and cross-language project migration involved in modern software development. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a workflow diagram of the method according to an embodiment of the present invention, including three main stages: attributed multi-graph construction, node embedding learning, and TPL recommendation and retrieval. DETAILED DESCRIPTION
[0017] The present invention is further explained below in conjunction with specific embodiments. It should be understood that these embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent forms of modifications to the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
[0018] like Figure 1 As shown, a representation query and recommendation method of the present invention based on a third-party library (TPL) with an attributed multi-layer graph model includes the following main steps: construction of an attributed multi-layer graph; node embedding learning; recommendation and retrieval of TPL.
[0019] In the attribute multi-graph construction step, node attributes are extracted from the description information of the third-party library, and a multi-layer graph is constructed through various relationships (such as substitution relationships, migration rules, shared dependencies, etc.). In the node embedding learning step, the feature embedding of each TPL is generated by combining the weights and node attributes of the multi-layer graph through the extended weighted multi-layer graph representation learning algorithm. In the TPL recommendation and retrieval step, by calculating the similarity between embeddings, analog TPL recommendations are provided, and retrieval based on demand descriptions is supported.
[0020] It should be noted that the hardware environment of the present invention includes: a computer system that can normally access the wide area network, and a database server. The software environment includes: Python 3.10 and a supported deep learning framework (such as PyTorch).
[0021] Specifically, the representation query and recommendation method of a third-party library based on a multi-layer graph model with attributes provided by an embodiment of the present invention includes the following steps: Step 1: Construct attribute multigraph 1.1 Extract descriptive information from the metadata of third-party libraries (such as NPM, Maven, PyPI, etc.), including library name, introduction and ReadMe file content; 1.2 Use a pre-trained text embedding model (such as all-mpnet-base-v2) to semantically embed the descriptive information and generate a 768-dimensional feature vector as the node attribute; 1.3 Construct multiple graphs based on the following dimensions: Alternative relationship layer: extract deprecation information and alternative suggestions of third-party libraries, generate alternative relationship edges, and the edge weight is the frequency of occurrence of alternative relationships; Migration rule layer: analyze the changes in dependent libraries between project versions, extract migration rules, and construct non-directional migration rule edges. The edge weight is the migration frequency; Shared dependency layer: count the number of shared dependent libraries between TPLs, generate shared dependency relationship edges, and the edge weight is the number of shared dependencies; Shared dependency layer: count the number of shared dependent parties between TPLs, and generate shared dependency relationship edges; Shared maintainer layer: count the number of shared maintainers between TPLs, and generate shared maintainer relationship edges; Shared keyword layer: count the number of shared keywords between TPLs, and generate shared keyword relationship edges.
[0022] Step 2: Node Embedding Learning 2.1 Learning based on an extended weighted multi-graph representation learning algorithm: Expand the unweighted graph representation to a weighted graph representation, use weighted random walks to generate training samples, and combine node attributes and multi-layer relationship weights for embedding learning; adjust the neighbor sampling probability in each layer of the graph so that the relationship edges with larger weights have a greater impact on embedding generation; 2.2 Output the embedding vector of each TPL, which comprehensively represents its attribute and relational features.
[0023] Step 3: Recommendation and retrieval of TPL 3.1 Analogy TPL recommendation: For the target TPL, calculate the Euclidean distance between its embedding and all candidate TPL embeddings; According to the distance sorting, the first k TPLs are recommended as analogous TPLs; 3.2 Retrieval based on requirement description: The requirement description input by the user is converted into a 768-dimensional virtual node embedding through a semantic embedding model; the distance between the virtual node embedding and all TPL embeddings is calculated to provide matching results.
[0024] A typical application scenario of the present invention is to select or replace a third-party library for a software project. For example, for a project that needs to replace a currently used library (due to deprecation, missing functions, or incompatible licenses), the analog TPL recommendation method provided by the present invention can quickly find a suitable replacement library. In addition, for retrieval based on requirement descriptions, the present invention supports developers to input natural language requirements (such as "process JSON data") and generate a matching TPL recommendation list.
[0025] Those skilled in the art should understand that the various steps of the method for representing query and recommendation of a third-party library based on a multi-layer graph model with attributes in the above-mentioned embodiment of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a graph composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than that shown here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present invention are not limited to any specific combination of hardware and software.
[0026] It will be apparent to those skilled in the art that the invention is not limited to the details of the exemplary embodiments described above and that the invention can be implemented in other specific forms without departing from the spirit or essential features of the invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description, and it is intended that all variations falling within the meaning and scope of the equivalent elements of the claims be included in the invention. Any reference numeral in a claim should not be considered as limiting the claim to which it relates.
Claims
1. A representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes, characterized in that: The following steps are involved: Steps for constructing attribute multigraph: represent the third-party library as a node in the graph, extract the node attributes from the description information of the third-party library, and build a layer of graph for each relationship according to different types of library relationships to build a multi-layer isomorphic graph to form an attribute multigraph; Node embedding learning steps: Expand the unweighted graph representation to a weighted graph representation, combine node attributes and multi-layer relationship weights, and generate the embedding representation of each TPL through weighted random walks and neighbor sampling; Analogy TPL recommendation and retrieval steps: By calculating the Euclidean distance between TPL embeddings, we can identify the candidate library that is most similar to the target TPL, or generate virtual embeddings based on the requirement description to achieve description-based TPL recommendation and retrieval.
2. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 1, characterized in that: The steps of constructing the attribute multigraph include: Step 1: Node attribute construction: semantically embed the descriptive information of each TPL and generate an N-dimensional feature vector as the node attribute; Step 2: Relationship layer construction: Construct the following multi-layer relationships, including the alternative relationship layer, candidate migration rule layer, shared dependency relationship layer, shared dependent party relationship layer, shared maintainer relationship layer, and shared keyword relationship layer.
3. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 2, characterized in that: The descriptive information of the TPL includes name, introduction and ReadMe content.
4. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 2, characterized in that: The steps of constructing the alternative relationship layer include: Step 1: Extract the deprecation information in TPL and analyze the replacement suggestions provided by developers; Step 2: Construct alternative relationship edges between TPLs based on alternative suggestions, and use the number of occurrences of alternative relationships as the weight of the edge.
5. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 2, characterized in that: The candidate migration rule layer construction step includes: Step 1: Analyze the changes in dependent libraries between different versions of the project and extract migration rule pairs; Step 2: Count the frequencies of migration rule pairs in multiple projects, construct non-directional candidate migration rule edges, and use the frequencies as edge weights.
6. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 2, characterized in that: The steps of constructing the shared dependency relationship layer, the shared dependent party relationship layer, the shared maintainer relationship layer and the shared keyword relationship layer include: Step 1: Analyze TPL's dependencies, dependent parties, maintainers, and keyword information; Step 2: Count the number of shared dependencies, dependent parties, maintainers, and keywords respectively, build corresponding relationship edges, and use the number of shares as the weight of the corresponding edge.
7. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 1, characterized in that: The node embedding learning step includes: Step 1: Expand the unweighted graph representation to a weighted graph representation, and perform weighted random walks based on node attributes and multi-layer relationships; Step 2: Generate an embedding vector for each TPL to comprehensively represent its attributes and relational features.
8. The representation query and recommendation method for a third-party library based on a multi-layer graph model with attributes according to claim 1, characterized in that: The analogous TPL recommendation and retrieval steps include: Step 1: Calculate the Euclidean distance between TPLs based on the node embedding vector to represent the similarity between the two TPLs; Step 2: For a given TPL node, select the top k most similar TPL nodes according to the distance sorting as the recommendation result; Step 3: For the requirement description, generate the embedding vector of the virtual node through semantic embedding, and combine it with distance calculation to realize description-based TPL retrieval.
9. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the representation query and recommendation method based on a third-party library with an attributed multi-layer graph model as described in any one of claims 1 to 8 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the representation query and recommendation method based on a third-party library with an attributed multi-layer graph model as described in any one of claims 1 to 8.
Citation Information
Cited By
Third-party library recommendation method based on multi-relation fusion
CN121167047A