Retrieval enhancement generation method and device
By combining knowledge graphs and large language models, this approach solves the problem that existing code analysis tools cannot accurately understand code topology and perform cross-project analysis, achieving efficient and accurate cross-project code analysis and reducing risks in modular applications.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-03-13
AI Technical Summary
Existing code analysis tools, when using large language models, cannot accurately distinguish the topological structure of the code, resulting in inaccurate search results, inability to perform cross-project analysis, and lack of complete project dependency structure and private code context, which can easily lead to erroneous code or inability to answer questions.
By constructing a knowledge graph, target nodes and related nodes are retrieved from the pre-built knowledge graph, prompt words are generated, and response information is generated using a large language model. Combined with the abstract syntax tree and semantic vector database of the code, cross-project and cross-platform code analysis can be achieved.
It improves the accuracy and efficiency of code analysis, enabling cross-project research to be completed in minutes, reducing the risk of global crashes caused by changes in modular applications, and enhancing R&D efficiency and code comprehension.
Smart Images

Figure CN121658618A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of artificial intelligence, particularly to the fields of intelligent search, code analysis, and intelligent agents, specifically to a retrieval enhancement generation method and apparatus. Background Technology
[0002] Existing code analysis tools typically use LLM (Large Language Model) to answer specific code questions within a project. However, searching through plain text or vectors loses the core topology of the code (such as inheritance trees and call networks), leading to inaccurate search results (e.g., inability to distinguish between "function A was called" and "function A was defined"). They are limited to a single local project, unable to perform cross-project analysis, and the data is difficult to export and reuse. Due to the lack of a complete project dependency structure and private code context, large language models are prone to generating incorrect code or failing to provide answers. Summary of the Invention
[0003] This disclosure provides a method, apparatus, device, storage medium, and computer program product for enhancing retrieval.
[0004] According to a first aspect of this disclosure, a retrieval enhancement generation method is provided, comprising: retrieving a target node matching demand information in a pre-constructed knowledge graph, and determining associated nodes of the target node, wherein the knowledge graph includes nodes for representing code entities and edges for representing relationships between code entities; generating prompt words based on the attribute information of the target node and associated nodes respectively; and determining response information of the demand information through a first language model based on the demand information and the prompt words.
[0005] According to a second aspect of this disclosure, a method for constructing a knowledge graph is provided, comprising: extracting an abstract syntax tree from code; determining code entity nodes based on at least one of the following entities in the abstract syntax tree: class, interface, struct, method, function; determining code entity edges based on at least one of the following relationships between code entity nodes: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, reference relationship; and constructing a knowledge graph based on the code entity nodes and code entity edges.
[0006] According to a third aspect of this disclosure, a retrieval enhancement generation apparatus is provided, comprising: a retrieval unit configured to retrieve a target node matching demand information in a pre-constructed knowledge graph and determine associated nodes of the target node, wherein the knowledge graph includes nodes for representing code entities and edges for representing relationships between code entities; a prompting unit configured to generate prompt words based on attribute information of the target node and associated nodes; and a response unit configured to determine response information of the demand information based on the demand information and the prompt words, using a first language model.
[0007] According to a fourth aspect of this disclosure, an apparatus for constructing a knowledge graph is provided, comprising: an extraction unit configured to extract an abstract syntax tree from code; a node determination unit configured to determine code entity nodes based on at least one of the following entities in the abstract syntax tree: class, interface, struct, method, function; an edge determination unit configured to determine code entity edges based on at least one of the following relationships between code entity nodes: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, reference relationship; and a construction unit configured to construct a knowledge graph based on the code entity nodes and code entity edges.
[0008] According to a fifth aspect of this disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of the first or second aspects.
[0009] According to a sixth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause the computer to perform the method of any one of the first or second aspects.
[0010] According to a seventh aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method of any one of the first or second aspects.
[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0012] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein: Figure 1 This is an exemplary system architecture diagram to which one embodiment of this disclosure can be applied; Figure 2 This is a flowchart of an embodiment of the search enhancement generation method according to the present disclosure; Figure 3a , Figure 3b This is a schematic diagram illustrating an application scenario of the search enhancement generation method based on this disclosure; Figure 4 This is a flowchart of an embodiment of a method for constructing a knowledge graph according to the present disclosure; Figure 5 This is a schematic diagram of a structure of an embodiment of the search enhancement generation apparatus according to the present disclosure; Figure 6 This is a schematic diagram of a structure of an embodiment of an apparatus for constructing a knowledge graph according to the present disclosure; Figure 7 This is a schematic diagram of the structure of a computer system suitable for implementing embodiments of the present disclosure. Detailed Implementation
[0013] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0014] Figure 1 An exemplary system architecture is shown that can be applied to embodiments of the retrieval enhancement generation method or retrieval enhancement generation apparatus of this disclosure.
[0015] like Figure 1 As shown, the system architecture may include terminal devices and servers. The server runs the server-side program of the code analysis tool, and may include an input layer, a parsing and processing layer, a storage layer, an application interaction layer, and an intelligent service layer. The specific functions implemented by each layer are as follows: 1. Input Layer: Build configuration (CocoaPods / Gradle): iOS uses CocoaPods to manage dependencies, and Android uses Gradle to manage builds / dependencies. This part is the source for subsequent parsing of project structures such as "Package / Module". iOS project (Swift / ObjC): Native code for iOS (Swift + Objective-C); Android project (Kotlin / Java): Native code for the Android platform (Kotlin + Java).
[0016] 2. Parsing and Processing Layer
[0017] On the iOS side: use SwiftSyntax to parse Swift code and Clang to parse ObjC code, and extract the AST (Abstract Syntax Tree); On the Android side: use the Kotlin Compiler API to parse Kotlin code and JavaParser to parse Java code, and extract the AST in the same way; Unified Schema (Graph Model) Transformation Engine: Converts the AST and project configuration information parsed from both ends into a "YAML / JSON intermediate format" (conforming to the node / relationship rules of the unified graph model); Code vectorization model: Embedding (vectorizing) the source code / comments of code entities (classes, methods) to prepare data for subsequent semantic retrieval.
[0018] 3. Storage Layer
[0019] Graph database (Neo4j): Stores "topology" - that is, the nodes (Class / Interface / Module, etc.) and relationships (INHERITS_FROM / CALLS, etc.) of the unified graph model, corresponding to the structure / dependency logic of the two-way code; Vector Database: Stores "semantic vectors"—vector data generated by the code vectorization model to support subsequent semantic retrieval (such as natural language queries like "how the login module handles token refresh").
[0020] 4. Application Interaction Layer (UI Layer)
[0021] IDE plugins: Embedded in development tools (such as Xcode / Android Studio), allowing developers to directly query the graph (such as querying the call chain of a method) while writing code. Web analytics platform: Provides functions such as visual graph browsing, cross-platform dependency analysis, and change impact assessment.
[0022] 5. Intelligent Service Layer (RAG Service)
[0023] Semantic Recall: The Hybrid Retriever finds the Top-K code nodes that semantically match the user's question from the vector database; Structural expansion: Starting from the recall node, perform "multi-hop queries" in the graph database (such as finding the module to which it belongs, the caller / callee); Large Language Model (LLM): Assembles the "code snippets + graph structure information" obtained by the hybrid retrieval tool into a Prompt, generating accurate answers that fit the project context (solving the "illusion" problem of large models).
[0024] Figure 1 This is just an example showcasing the iOS and Android platforms; many more platforms can actually be supported.
[0025] Users can interact with the server via a network using their terminal devices, for example, by triggering the server to perform code analysis using a code analysis tool. The server then sends the code analysis results back to the terminal device.
[0026] A server can be a server that provides various services, such as a server that provides code analysis for terminal devices.
[0027] It's important to note that a server can be either hardware or software. When a server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When a server is software, it can be implemented as multiple software programs or software modules (e.g., multiple software programs or software modules used to provide distributed services), or as a single software program or software module. No specific limitations are made here. A server can also be a server for a distributed system, or a server integrated with blockchain technology. A server can also be a cloud server, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.
[0028] It should be noted that the search enhancement generation method provided in the embodiments of this disclosure is generally executed by a server, and correspondingly, the search enhancement generation device is generally located in the server.
[0029] It should be understood that Figure 1 The number of terminal devices and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices and servers can be used.
[0030] Continue to refer to Figure 2 The diagram illustrates a flow 200 of an embodiment of the retrieval enhancement generation method according to the present disclosure. The retrieval enhancement generation method includes the following steps: Step 201: Retrieve target nodes that match the requirement information in the pre-built knowledge graph, and determine the associated nodes of the target nodes.
[0031] In this embodiment, the execution entity of the retrieval enhancement generation method (e.g., Figure 1 The server shown can receive user requests submitted via terminal devices through wired or wireless connections. For example, users can input the following in an IDE plugin or web application: "Analyze the differences in the call chain between the iOS and Android payment modules."
[0032] To ensure compatibility with different platforms, such as iOS and Android, this application designs an abstract, unified mobile graph model (i.e., knowledge graph) that masks language differences. The knowledge graph is constructed as shown in flowchart 400.
[0033] The knowledge graph consists of nodes representing code entities and edges representing the relationships between them. Each node's description, also known as attribute information, may include at least one of the following: name, developer, version, and functional description. The name can be the node's name, such as a class name or function name. The developer can be the developer who most recently modified the code corresponding to that node. The version records the time information of each modification to the code corresponding to that node. The functional description can summarize the functionality implemented by the code corresponding to the node, such as login or payment.
[0034] Target nodes matching the requirement information can be searched from the knowledge graph using string matching or semantic matching methods. For example, for the requirement information "Analyze the differences in the call chains of the payment modules on iOS and Android," semantic analysis requires the following steps: search for the payment modules in the knowledge graphs for both iOS and Android, then identify the call chains of the payment modules, and finally compare the differences between the two call chains. Nodes whose attribute information matches "payment module" can be retrieved from the knowledge graph as target nodes. Nodes that adjust the "payment module" can then be designated as related nodes.
[0035] Step 202: Generate prompt words based on the attribute information of the target node and related nodes respectively; In this embodiment, the attribute information of the target node and the attribute information of the associated nodes can be directly concatenated to generate the prompt word. Alternatively, a large language model can be used to generate the prompt word based on the attribute information of both the target node and the associated nodes. The attribute information of the target node and the associated nodes can provide the complete dependency structure and private code context of the project.
[0036] Step 203: Based on the demand information and prompt words, determine the response information of the demand information through the first major language model.
[0037] In this embodiment, during RAG (Retrieval-Augmented Generation) question answering, the prompt words obtained in step 202 can retrieve key dependency nodes (such as parent classes or protocol definitions). LLM can generate correct contextual understanding and output accurate response information. The first large language model can be a common large language model on the market, such as chatGPT or DeepSeek.
[0038] Existing technologies using pure vector RAG only vectorize code slices, failing to answer highly structured questions like "Which of the subclasses of class A's parent class overrides method B?", resulting in low accuracy. Current methods based on IDE AST plugins directly utilize IDE interfaces for analysis. However, performance is limited by local machines, preventing the creation of a shared knowledge base across the entire team and hindering global analysis (spanning hundreds of Git repositories).
[0039] The methods provided in the above embodiments of this disclosure can reduce the research time for cross-project and cross-platform code from days to minutes, thereby improving R&D efficiency. Accurate graph dependency analysis can avoid the "change one thing and crash the whole site" incident, especially in highly modular large-scale apps, thus reducing maintenance risks and costs. Through Graph-RAG (Graph-Retrieval Enhanced Generation) technology, the problem of large models "talking nonsense" on private code repositories is solved, enabling AI assistants to truly possess project-level understanding capabilities. Applicable fields include: mobile application development, static code analysis, intelligent code assistants, DevOps pipelines, etc.
[0040] In some optional implementations of this embodiment, the code for different platforms corresponds to different knowledge graphs; and the method further includes: determining the platform to which the code belongs based on the requirement information; and determining the knowledge graph corresponding to the platform.
[0041] A specific schema design was implemented for the mobile development ecosystem (iOS / Android) (such as handling specific concepts like Category, Extension, Gradle Flavor, CocoaPods, etc.), while the knowledge graph for general code is mainly for C / C++ backend code.
[0042] In some optional implementations of this embodiment, determining the knowledge graph corresponding to a platform includes: in response to identifying that the demand information involves multiple platforms, determining the knowledge graph corresponding to multiple platforms. This emphasizes unified modeling of different platforms (e.g., iOS and Android) within the same knowledge graph, supporting multi-platform comparative analysis, which is not available in existing single-platform tools.
[0043] In some optional implementations of this embodiment, retrieving target nodes that match the requirement information from a pre-built knowledge graph includes: extracting keywords from the requirement information; matching the keywords with the attribute information of nodes in the knowledge graph, wherein the attribute information includes at least one of the following: name, developer, version, and function description information; and determining nodes with a matching degree greater than a predetermined threshold as target nodes.
[0044] Keywords can be extracted from demand information through pre-trained keyword extraction models, such as named entity recognition models.
[0045] Keywords are matched with the attribute information of nodes in the knowledge graph, for example, by calculating the matching degree using methods such as Euclidean distance and cosine similarity. Nodes with high matching degrees are selected as target nodes for retrieval.
[0046] By using keyword regular expression matching to search for target nodes, the nodes can be accurately located, improving the accuracy of search results.
[0047] In some optional implementations of this embodiment, retrieving target nodes that match the demand information from a pre-constructed knowledge graph includes: extracting semantic information from the demand information; matching the semantic information with semantic vectors in a pre-created vector database, wherein the vector database stores semantic vectors corresponding to the attribute information of each node in the knowledge graph; and determining the node corresponding to the successfully matched semantic vector as the target node.
[0048] Building upon the knowledge graph, a vector database (Vector DB) is introduced for semantic enhancement: For nodes such as Method and Class in the knowledge graph, their source code and DocString annotations are extracted, embedded (vectorized), and stored in the vector database. The vector ID is then stored as an attribute on the graph node. When a user inputs a natural language question (e.g., "How does the login module handle token refresh?"), the top-K relevant code nodes are found through vector retrieval.
[0049] Combining attribute graphs (structural information) with vector retrieval (semantic information) in the RAG system solves the barrier of mastering complex query language (Cypher) required for simple graph queries, and also solves the problem of lack of logic in simple vector retrieval.
[0050] In some optional implementations of this embodiment, determining the associated nodes of the target node includes: starting from the target node, querying the parent node in the knowledge graph for nodes of the class to which the target node belongs and nodes of the module to which the target node belongs as associated nodes of the target node; starting from the target node, querying the knowledge graph for associated nodes that call the target node and associated nodes that are called by the target node; starting from the target node, querying the knowledge graph for associated nodes that inherit from or follow the target node and associated nodes that are inherited from or followed by the target node.
[0051] Graph Traversal: Starting from the recalled node, perform multi-hop queries in the graph: Searching towards the parent: retrieves the class and module information. Searching towards references: retrieves CALLS (caller) and CALLED_BY (callee). Searching towards definitions: retrieves the parent class of INHERITS_FROM or the protocol definition of CONFORMS_TO.
[0052] Traditional string matching or regular expression search cannot understand deep code relationships such as "inheritance," "implementation," and "overriding," resulting in extremely low efficiency (O(n²) complexity) when querying complex questions such as "all implementation classes of a certain interface." When directly using LLMs (such as ChatGPT) to answer specific project code questions, the lack of a complete project dependency structure and private code context can easily lead to incorrect code or an inability to answer.
[0053] This application can obtain the complete dependency structure and private code context of a project, understand deep code relationships such as "inheritance", "implementation", and "overriding", improve query efficiency, and generate correct context understanding.
[0054] In some optional implementations of this embodiment, prompt words are generated based on the attribute information of the target node and the associated nodes, including: obtaining the code snippet corresponding to the target node; determining the call chain and inheritance relationship based on the associated nodes; and generating prompt words based on the code snippet, the call chain, and the inheritance relationship.
[0055] The retrieved code snippets and graph structure information (call chains, inheritance relationships) are combined into a Prompt and submitted to the large model to generate answers. This introduces code context, preventing the large model from experiencing "illusions" that could lead to incorrect code or an inability to answer.
[0056] In some optional implementations of this embodiment, the method further includes: in response to detecting code changes on the target platform, acquiring the knowledge graph corresponding to the target platform and the knowledge graph corresponding to the associated platforms of the target platform, and generating requirement information for analyzing the impact of code changes on different platforms; and retrieving target nodes that match the requirement information in the pre-built knowledge graph, including: determining the nodes corresponding to the classes and modules involved in the changed code as target nodes.
[0057] It not only supports user-submitted requirements, but also automatically generates code analysis requirements based on code changes, thus automatically triggering the analysis. This allows for precise analysis of the impact of code changes, ensuring code quality.
[0058] In the context of natural language intelligent question answering (Chat interaction): 1. User Operation: Enter the following in the IDE plugin or web interface: "Analyze the differences in the call chain of the payment module on iOS and Android." 2. System processing: The system identifies the "payment module" and locates the PaymentManager for iOS and the PaymentRepository for Android through vector retrieval.
[0059] Using the call relationships in the graph, complete call chain graphs at both ends are generated through Breadth-First Search (BFS).
[0060] LLM compares the topologies of the two links and summarizes the differences.
[0061] 3. Front-end display: The left side displays a text summary generated by LLM, and the right side dynamically displays a comparison graph of the two-end code (visual node connections).
[0062] See also Figure 3a , Figure 3a This is a schematic diagram illustrating an application scenario of the retrieval enhancement generation method according to this embodiment. Figure 3a In this application scenario, if a developer modifies network library parameters, they can submit an API change (Commit) for a Core module, which the code repository receives. The code repository triggers a "Change Analysis Service" via a Webhook, initiating an automated analysis process. The Change Analysis Service first performs Diff Parsing to identify the affected definition node (Node A) from the code changes. The system then uses Node A as the starting point in the graph to find all modules that depend on it. The Change Analysis Service initiates a "recursive search" request to the graph database (Neo4j) that stores the graph: using the Cypher query statement (MATCH(n)-[:DEPENDS_ON | CALLS in the graph). The process iterates backwards through the DEPENDS_ON and CALLS relationships (Node A) to retrieve a set of dependency paths across iOS and Android platforms (e.g., iOS business modules and Android business modules) from the graph database. It then identifies all affected iOS Targets and Android Modules across module boundaries. The change analysis service aggregates the dependency results returned by the graph database to obtain a "list of affected modules." On the Code Review page, a bot comments: "This change will affect 3 business modules on iOS and 2 business modules on Android. Please test carefully." The change analysis service determines the impact type based on the aggregation results: if it affects both iOS and Android platforms, a warning is sent: "This change affects both iOS and Android"; if it affects only one platform, a notification is sent: "Only affects iOS." Finally, the specific number of affected modules is automatically reflected in the Code Review.
[0063] Further reference Figure 4 This illustrates a flow 400 of yet another embodiment of the retrieval enhancement generation method. The flow 400 of this retrieval enhancement generation method includes the following steps: Step 401: Extract the abstract syntax tree from the code; In this embodiment, the iOS parsing pipeline integrates SwiftSyntax (for Swift) and Clang / SourceKitten (for ObjC / C++), extracts the AST (Abstract Syntax Tree), and converts it into the YAML / JSON intermediate format of the unified schema mentioned above.
[0064] Android parsing pipeline: Integrates Kotlin Compiler API and JavaParser to parse Gradle dependency tree and source code AST, mapping them to the same schema.
[0065] Step 402: Determine the code entity nodes based on the entities in the abstract syntax tree.
[0066] In this embodiment, the entities in the abstract syntax tree include at least one of the following: class, interface, struct, method, and function.
[0067] Class: uniformly represented as Swift Class, ObjC Class, Kotlin Class, and Java Class.
[0068] Interface: uniformly represented as Swift Protocol, ObjC Protocol, and Kotlin Interface.
[0069] Struct / Data: A unified representation of Swift Structs and Kotlin Data Classes.
[0070] Method / Function: A unified representation of function methods across languages.
[0071] Step 403: Determine code entity edges based on the relationships between code entity nodes.
[0072] In this embodiment, as Figure 3b As shown, the relationships between code entity nodes include at least one of the following: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, and reference relationship.
[0073] Structural relationships: CONTAINS (containment), DEFINES (definition).
[0074] Inheritance implementation: INHERITS_FROM (inheritance), CONFORMS_TO (compliance / implementation).
[0075] Dependencies include: CALLS (method calls), DEPENDS_ON (module dependencies), and IMPORTS (references).
[0076] Cross-platform mapping (innovation): Introducing the EQUIVALENT_TO relationship, which is used to manually or automatically mark classes with aligned business logic on both platforms (such as UserViewModel in iOS and UserViewModel in Android), enabling cross-platform analysis.
[0077] Step 404: Construct a knowledge graph based on code entity nodes and code entity edges.
[0078] In this embodiment, the intermediate format files of code entity nodes and code entity edges are imported into a graph database (such as Neo4j) to form a complete mobile project knowledge graph.
[0079] By using knowledge graphs, we can address the problem that when using LLMs (such as ChatGPT) to answer specific code questions in existing technologies, the lack of a complete dependency structure and private code context can lead to incorrect codes or unanswerable questions.
[0080] In some optional implementations of this embodiment, the knowledge graph includes project structure nodes, and the construction of the knowledge graph based on the code entity nodes and the code entity edges includes: constructing project structure nodes and project structure edges based on the engineering information of the code; determining platform-specific nodes and platform-specific edges based on platform-related features in the code; and constructing the knowledge graph based on the code entity nodes, the code entity edges, the project structure nodes, the project structure edges, the platform-specific nodes, and the platform-specific edges.
[0081] The specific structure is as follows: 1. Unified Node System: 1) Project structural nodes: Workspace / Project: Map Xcode Workspace or Gradle Root Project.
[0082] Module: Maps to iOS Target / Framework or Android Gradle Module.
[0083] Package: Maps CocoaPods / SPM dependencies or Maven / Gradle dependencies.
[0084] 2) Code entity nodes (abstracted): Class: uniformly represents Swift Class, ObjC Class, Kotlin Class, and Java Class.
[0085] Interface: A unified representation of Swift Protocol, ObjC Protocol, and Kotlin Interface.
[0086] Struct / Data: A unified representation of Swift Struct and Kotlin Data Class.
[0087] Method / Function: A unified representation of function methods across languages.
[0088] 3) Platform-specific nodes (distinguished by tags): iOS-specific: Actor, Extension, Category.
[0089] Android-specific features: Coroutines and Annotations.
[0090] 2. Unified Relationship System: Structural relationships: CONTAINS (containment), DEFINES (definition).
[0091] Inheritance implementation: INHERITS_FROM (inheritance), CONFORMS_TO (compliance / implementation).
[0092] Dependencies include: CALLS (method calls), DEPENDS_ON (module dependencies), and IMPORTS (references).
[0093] Cross-platform mapping: The EQUIVALENT_TO relationship is introduced to manually or automatically mark classes with aligned business logic on both platforms (such as UserViewModel in iOS and UserViewModel in Android) to achieve cross-platform analysis.
[0094] Adding project structure nodes connects code syntax entities with project organizational structure, enabling unified management of global project assets across both platforms and precise analysis of cross-module dependencies and change impacts. Adding platform-specific nodes preserves the unique syntax features of each iOS / Android platform without disrupting the unified graph model, accurately reproducing the actual code logic on both platforms and improving the accuracy of cross-platform dependency analysis and change impact assessment.
[0095] In some optional implementations of this embodiment, the method further includes: obtaining the source code and / or annotation documents corresponding to the nodes in the knowledge graph; and generating exemplary code as attribute information of the nodes based on the source code and / or the annotation documents through a second language model.
[0096] The second language model can be the same as or different from the first language model.
[0097] This feature supplements knowledge graph nodes with exemplary code attributes, enriching the dimensions of graph information and extending nodes from merely containing structural relationships to possessing "usage reference" capabilities, thereby enhancing the practical value of the graph. At the same time, developers can directly obtain code usage examples through node attributes without having to interpret source code or comments line by line, significantly reducing the cost of code understanding and reuse. Furthermore, when intelligent services such as RAG call node information, they can combine the example code to generate solutions that are more in line with project coding habits, further improving the accuracy of large model output.
[0098] Further reference Figure 5 As an implementation of the methods shown in the above figures, this disclosure provides an embodiment of a retrieval enhancement generation apparatus, which is similar to... Figure 2Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0099] like Figure 5 As shown, the retrieval enhancement generation device 500 of this embodiment includes: a retrieval unit 501, a prompting unit 502, and a response unit 503. The retrieval unit 501 is configured to retrieve target nodes matching the demand information in a pre-constructed knowledge graph and determine the associated nodes of the target nodes. The knowledge graph includes nodes representing code entities and edges representing relationships between code entities. The prompting unit 502 is configured to generate prompt words based on the attribute information of the target nodes and the associated nodes. The response unit 503 is configured to determine the response information of the demand information based on the demand information and the prompt words, using a first large language model.
[0100] In this embodiment, the specific processing of the retrieval unit 501, prompting unit 502, and response unit 503 of the retrieval enhancement generation device 500 can be referred to Figure 2 Steps 201, 202, and 203 in the corresponding embodiment.
[0101] In some optional implementations of this embodiment, the code for different platforms corresponds to different knowledge graphs; and the device 500 further includes a determining unit (not shown in the figures): determining the platform to which the code belongs based on the requirement information; and determining the knowledge graph corresponding to the platform.
[0102] In some optional implementations of this embodiment, the determining unit is further configured to: in response to identifying that the demand information involves multiple platforms, determine the knowledge graphs corresponding to the multiple platforms.
[0103] In some optional implementations of this embodiment, the retrieval unit 501 is further configured to: extract keywords from the demand information; match the keywords with the attribute information of nodes in the knowledge graph, wherein the attribute information includes at least one of the following: name, developer, version, and function description information; and determine the nodes with a matching degree greater than a predetermined threshold as target nodes.
[0104] In some optional implementations of this embodiment, the retrieval unit 501 is further configured to: extract semantic information from the demand information; match the semantic information with semantic vectors in a pre-created vector database, wherein the vector database stores semantic vectors corresponding to the attribute information of each node in the knowledge graph; and determine the node corresponding to the successfully matched semantic vector as the target node.
[0105] In some optional implementations of this embodiment, the retrieval unit 501 is further configured to: starting from the target node, query the parent node in the knowledge graph for nodes of the class to which the target node belongs and nodes of the module to which the target node belongs as associated nodes of the target node; starting from the target node, query the knowledge graph for associated nodes that call the target node and associated nodes that are called by the target node; starting from the target node, query the knowledge graph for associated nodes that inherit from or follow the target node and associated nodes that are inherited from or followed by the target node.
[0106] In some optional implementations of this embodiment, the prompting unit 502 is further configured to: obtain the code snippet corresponding to the target node; determine the call chain and inheritance relationship based on the associated nodes; and generate a prompt word based on the code snippet, call chain, and inheritance relationship.
[0107] In some optional implementations of this embodiment, the apparatus 500 further includes a generation unit (not shown in the figures), configured to: in response to detecting code changes on the target platform, acquire the knowledge graph corresponding to the target platform and the knowledge graph corresponding to the associated platforms of the target platform, and generate requirement information for analyzing the impact of code changes on different platforms; and the retrieval unit 501 is further configured to: determine the nodes corresponding to the classes and modules involved in the changed code as target nodes.
[0108] Further reference Figure 6 As an implementation of the methods shown in the above figures, this disclosure provides an embodiment of an apparatus for constructing a knowledge graph, which is similar to... Figure 4 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0109] like Figure 6 As shown, the knowledge graph construction apparatus 600 of this embodiment includes: an extraction unit 601, a node determination unit 602, an edge determination unit 603, and a construction unit 604. The extraction unit 601 is configured to extract an abstract syntax tree from code; the node determination unit 602 is configured to determine code entity nodes based on at least one of the following entities in the abstract syntax tree: class, interface, struct, method, function; the edge determination unit 603 is configured to determine code entity edges based on at least one of the following relationships between code entity nodes: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, reference relationship; and the construction unit 604 is configured to construct a knowledge graph based on the code entity nodes and the code entity edges.
[0110] In this embodiment, the specific processing of the extraction unit 601, node determination unit 602, edge determination unit 603, and construction unit 604 of the knowledge graph construction apparatus 600 can be referred to Figure 4 The corresponding steps are 401, 402, 403 and 404 in the embodiment.
[0111] In some optional implementations of this embodiment, the knowledge graph includes project structure nodes, and the construction unit 604 is further configured to: construct project structure nodes and project structure edges based on the engineering information of the code; determine platform-specific nodes and platform-specific edges based on platform-related features in the code; and construct a knowledge graph based on code entity nodes, code entity edges, project structure nodes, project structure edges, platform-specific nodes, and platform-specific edges.
[0112] In some optional implementations of this embodiment, the apparatus 600 further includes a generation unit (not shown in the figures), configured to: obtain the source code and / or annotation documents corresponding to the nodes in the knowledge graph; and generate exemplary code as attribute information of the nodes based on the source code and / or annotation documents through a second language model.
[0113] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0114] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0115] An electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method described in process 200 or 400.
[0116] A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to perform the method described in process 200 or 400.
[0117] A computer program product includes a computer program that, when executed by a processor, implements the method described in process 200 or 400.
[0118] Figure 7A schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0119] like Figure 7 As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 702 or a computer program loaded into random access memory (RAM) 703 from storage unit 708. The RAM 703 may also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. Input / output (I / O) interface 705 is also connected to bus 704.
[0120] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 708, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0121] The computing unit 701 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as the retrieval enhancement generation method. For example, in some embodiments, the retrieval enhancement generation method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the retrieval enhancement generation method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the retrieval enhancement generation method by any other suitable means (e.g., by means of firmware).
[0122] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0123] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0124] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0125] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0126] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0127] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0128] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0129] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A retrieval enhancement generation method, comprising: Retrieve target nodes that match the requirement information in a pre-constructed knowledge graph, and determine the associated nodes of the target nodes, wherein the knowledge graph includes nodes for representing code entities and edges for representing the relationships between code entities; Prompt words are generated based on the attribute information of the target node and the associated node, respectively. Based on the demand information and the prompt words, the response information for the demand information is determined using the first major language model.
2. The method according to claim 1, wherein, Different platforms correspond to different knowledge graphs; as well as The method further includes: The platform to which the code belongs is determined based on the aforementioned requirements information; Determine the knowledge graph corresponding to the platform.
3. The method according to claim 2, wherein determining the knowledge graph corresponding to the platform includes: In response to the identification that the demand information involves multiple platforms, the knowledge graphs corresponding to the multiple platforms are determined.
4. The method according to claim 1, wherein, The step of retrieving target nodes that match the required information from a pre-constructed knowledge graph includes: Extract keywords from the aforementioned demand information; The keywords are matched with the attribute information of the nodes in the knowledge graph, wherein the attribute information includes at least one of the following: name, developer, version, and function description information; Nodes with a matching degree greater than a predetermined threshold are identified as target nodes.
5. The method according to claim 1, wherein, The step of retrieving target nodes that match the required information from a pre-constructed knowledge graph includes: Extract semantic information from the demand information; The semantic information is matched with semantic vectors in a pre-created vector database, wherein the vector database stores semantic vectors corresponding to the attribute information of each node in the knowledge graph. The node corresponding to the successfully matched semantic vector is identified as the target node.
6. The method according to claim 1, wherein, Determining the associated nodes of the target node includes: Starting from the target node, query the parent node in the knowledge graph for the nodes of the class to which the target node belongs and the nodes of the module to which the target node belongs, as the associated nodes of the target node; Starting from the target node, query the knowledge graph for associated nodes that call the target node and associated nodes that are called by the target node; Starting from the target node, query the knowledge graph for related nodes that inherit from or follow the target node and related nodes that are inherited from or followed by the target node.
7. The method according to claim 1, wherein, The generation of prompt words based on the attribute information of the target node and the associated node includes: Obtain the code snippet corresponding to the target node; The call chain and inheritance relationship are determined based on the associated nodes; Prompt words are generated based on the code snippet, the call chain, and the inheritance relationship.
8. The method according to claim 1, further comprising: In response to the detection of code changes on the target platform, the knowledge graph corresponding to the target platform and the knowledge graph corresponding to the associated platforms of the target platform are obtained respectively, and requirement information for analyzing the impact of code changes on different platforms is generated. as well as The step of retrieving target nodes that match the required information from a pre-constructed knowledge graph includes: The nodes corresponding to the classes and modules involved in the changed code are identified as the target nodes.
9. A method for constructing a knowledge graph, comprising: Extracting an abstract syntax tree from the code; Code entity nodes are determined based on at least one of the following entities in the abstract syntax tree: class, interface, struct, method, function; Code entity edges are determined based on at least one of the following relationships between code entity nodes: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, and reference relationship; A knowledge graph is constructed based on the code entity nodes and the code entity edges.
10. The method according to claim 9, wherein, The knowledge graph includes project structure nodes, and the knowledge graph constructed based on the code entity nodes and code entity edges includes: Construct project structure nodes and project structure edges based on the project information in the code; Identify platform-specific nodes and edges based on platform-related features in the code; A knowledge graph is constructed based on the code entity nodes, code entity edges, project structure nodes, project structure edges, platform-specific nodes, and platform-specific edges.
11. The method according to claim 9 or 10, wherein, The method further includes: Obtain the source code and / or annotation documents corresponding to the nodes in the knowledge graph; Based on the source code and / or the commented documentation, exemplary code is generated as attribute information of the node using a second major language model.
12. A retrieval enhancement generation apparatus, comprising: The retrieval unit is configured to retrieve target nodes that match the demand information in a pre-built knowledge graph and determine the associated nodes of the target nodes, wherein the knowledge graph includes nodes for representing code entities and edges for representing the relationships between code entities; The prompting unit is configured to generate prompt words based on the attribute information of the target node and the associated node, respectively; The response unit is configured to determine the response information for the demand information based on the demand information and the prompt words, using a first language model.
13. An apparatus for constructing a knowledge graph, comprising: The extraction unit is configured to extract the abstract syntax tree from the code; The node determination unit is configured to determine code entity nodes based on at least one of the following entities in the abstract syntax tree: class, interface, struct, method, function; The edge determination unit is configured to determine code entity edges based on at least one of the following relationships between code entity nodes: containment relationship, definition relationship, inheritance relationship, implementation relationship, conformity relationship, call relationship, dependency relationship, and reference relationship; The building unit is configured to construct a knowledge graph based on the code entity nodes and the code entity edges.
14. An electronic device comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-11.
15. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-11.
16. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-11.