Code knowledge graph generation method and device, code generation method and device, equipment and medium

By generating code knowledge graphs and retrieving them based on them, the problem of multimodal large model code generation quality and performance evaluation is solved, and more efficient code intelligent understanding and generation is achieved.

CN119721222AActive Publication Date: 2025-03-28BEIJING BAIDU NETCOM SCI & TECH CO LTD

Patent Information

Application Number
CN202411775261.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-28
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

In the field of intelligent code understanding and generation, it is difficult for the prior art to efficiently and automatically evaluate the generation quality and performance of multimodal large models, especially in code generation, where there are problems of hallucination and insufficient context information.

Method used

By obtaining the code tree, a code knowledge graph is generated, and searching in the graph, the target code knowledge is obtained to assist in generating reply information. The code tree is generated by parsing the content of the source code, and the graph nodes and edge information are built based on code elements and structural relationships.

Benefits of technology

It improves the integrity and construction efficiency of the code knowledge graph, reduces the storage amount and data processing amount of the knowledge graph, and enhances the accuracy and reliability of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119721222A_ABST
    Figure CN119721222A_ABST
Patent Text Reader

Abstract

The invention provides a code knowledge graph generation method and device, a code generation method and device, equipment and a medium, and relates to the field of data processing, in particular to the technical field of intelligent search, man-machine interaction, artificial intelligence and large models. According to the specific implementation scheme, the method comprises the steps that a code tree is obtained, wherein the code tree comprises first code elements and the structural relation between the first code elements; wherein the code tree is generated by performing content analysis on a source code; generating first map node information according to the first code element; according to the structural relationship, generating first map edge information between the corresponding map nodes; and generating a code knowledge graph according to the first graph node information and the first graph edge information. According to the embodiment of the invention, the integrity of the knowledge graph can be improved, the storage capacity and the data processing capacity of the knowledge graph are reduced, and the knowledge graph construction efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing, specifically to the fields of intelligent search, human-computer interaction, artificial intelligence and large model technology, and in particular to a code knowledge graph generation, code generation method, device, equipment and medium. Background Art

[0002] Large Language Model (LLM) can generate code.

[0003] With the rapid development of large multimodal models, efficiently and automatically evaluating the generation quality and performance of these models in practical applications is currently a key issue.

[0004] In the field of intelligent code understanding and generation, strengthening the Large Language Model (LLM) based on Retrieval-Augmented Generation (RAG) can enrich the context depth by using vector semantic retrieval and keyword full-text retrieval, while ensuring the timeliness and accuracy of relevant knowledge, which can alleviate problems such as hallucinations and insufficient context information to a certain extent. Summary of the invention

[0005] The present invention provides a code knowledge graph generation, a code generation method, an apparatus, a device and a medium.

[0006] According to one aspect of the present disclosure, a method for generating a code knowledge graph is provided, comprising:

[0007] Acquire a code tree, the code tree including a first code element and a structural relationship between the first code elements; wherein the code tree is generated by performing content parsing on a source code;

[0008] Generate first graph node information according to the first code element;

[0009] According to the structural relationship, first graph edge information between corresponding graph nodes is generated;

[0010] Generate a code knowledge graph based on the first graph node information and the first graph edge information.

[0011] According to one aspect of the present disclosure, there is provided a code generation method, comprising:

[0012] Get the input question information;

[0013] According to the question information, searching is performed in the code knowledge graph to obtain target code knowledge; the code knowledge graph is generated by the code knowledge graph generation method provided by any embodiment of the present disclosure;

[0014] Generate response information based on the target code knowledge and the question information.

[0015] According to one aspect of the present disclosure, a device for generating a code knowledge graph is provided, comprising:

[0016] A code tree acquisition module, used to acquire a code tree, wherein the code tree includes a first code element and a structural relationship between the first code elements; wherein the code tree is generated by performing content parsing on a source code;

[0017] A graph node generation module, used to generate first graph node information according to the first code element;

[0018] A graph edge generation module, used for generating first graph edge information between corresponding graph nodes according to the structural relationship;

[0019] The knowledge graph construction module is used to generate a code knowledge graph based on the first graph node information and the first graph edge information.

[0020] According to one aspect of the present disclosure, there is provided a code generation device, comprising:

[0021] A question acquisition module is used to obtain input question information;

[0022] A knowledge retrieval module, used to search in a code knowledge graph according to the question information to obtain target code knowledge; the code knowledge graph is generated by the code knowledge graph generation method provided by any embodiment of the present disclosure;

[0023] The reply generation module is used to generate reply information according to the target code knowledge and the question information.

[0024] According to another aspect of the present disclosure, there is provided an electronic device, comprising:

[0025] at least one processor; and

[0026] a memory communicatively connected to the at least one processor; wherein,

[0027] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code knowledge graph generation method or code generation method described in any embodiment of the present disclosure.

[0028] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the code knowledge graph generation method or the code generation method described in any embodiment of the present disclosure.

[0029] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, which, when executed by a processor, implements the code knowledge graph generation method or the code generation method described in any embodiment of the present disclosure.

[0030] The disclosed embodiments can increase the integrity of the knowledge graph, reduce the storage volume and data processing volume of the knowledge graph, and improve the efficiency of knowledge graph construction.

[0031] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0033] Figure 1 It is a flowchart of a method for generating a code knowledge graph according to an embodiment of the present disclosure;

[0034] Figure 2 It is a schematic diagram of a code knowledge graph construction scenario disclosed in an embodiment of the present disclosure;

[0035] Figure 3 It is a schematic diagram of a code knowledge graph disclosed according to an embodiment of the present disclosure;

[0036] Figure 4 is a flowchart of a code generation method disclosed in an embodiment of the present disclosure;

[0037] Figure 5 is a flowchart of another code generation method disclosed in an embodiment of the present disclosure;

[0038] Figure 6 It is a scene diagram of a code knowledge search method disclosed in an embodiment of the present disclosure;

[0039] Figure 7 is a scene graph of a code generation method disclosed in an embodiment of the present disclosure;

[0040] Figure 8 It is a structural schematic diagram of a code knowledge graph generating device disclosed in an embodiment of the present disclosure;

[0041] Fig. 9is a schematic diagram of the structure of a code generating device disclosed in an embodiment of the present disclosure;

[0042] Fig.10 It is a block diagram of an electronic device according to the code knowledge graph generation method disclosed in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0043] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0044] Figure 1 This is a flowchart of a method for generating a code knowledge graph according to an embodiment of the present disclosure. This embodiment can be applied to the case of constructing a knowledge graph. The method of this embodiment can be executed by a code knowledge graph generating device, which can be implemented in software and / or hardware and is specifically configured in an electronic device with certain data computing capabilities, which can be a server device.

[0045] S101. Obtain a code tree, where the code tree includes first code elements and structural relationships between first code elements; wherein the code tree is generated by performing content parsing on source code.

[0046] Among them, the code tree may refer to a tree describing the structural relationship between the first code element and the first code element. The first code element may refer to the basic unit that constitutes the code structure and behavior in the source code. The structural relationship between the first code elements may refer to the relationship of interaction and connection between the first code elements. The nodes in the tree are the first code elements, and the relationship between the nodes is the structural relationship of the first code elements. In some embodiments, the first code element includes at least one of the following: file, class, parent class, interface, method, field, parameter passing, return type, call and type, etc. The structural relationship may include: dependency relationship, inclusion relationship and description relationship, etc. The code tree can perform content parsing on the source code to obtain the code elements included in the source code and the structural relationship between the code elements, and use them as the first code element and the structural relationship between the first code elements.

[0047] It should be noted that the code tree is used to form a code knowledge graph. The source code is parsed at a coarse granularity to construct a code tree, and then a code knowledge graph is generated based on the constructed code tree. In this way, the code tree serves as intermediate data for forming a code knowledge graph, which can reduce the amount of data calculation on the current end.

[0048] In addition, the source code can be uploaded by the user to the current end, or the current end obtains the authorized open source source code, and the current end builds a code tree based on the obtained source code. Alternatively, the source code can be the client's local code, and the client can process the source code to generate a code tree, send the code tree to the current end, and generate a code knowledge graph by the current end, which can avoid the current end directly obtaining the user's local code and improve the security of the local code.

[0049] S102. Generate first graph node information according to the first code element.

[0050] The first graph node information may include the first graph node and the associated information of the first graph node. A first code element is taken as a first graph node, and the information that can be extracted from the first code element in the source code is taken as the associated information of the first graph node. The first graph node and the associated information are combined to generate the first graph node information. In some embodiments, the associated information may include the attribute information of the first code element and the position in the source code.

[0051] S103. Generate first graph edge information between corresponding graph nodes according to the structural relationship.

[0052] Among them, the first graph edge information may include the first graph node connected by the first graph edge, the direction of the first graph edge, and the relationship represented by the first graph edge. A first graph edge is created for the first graph node corresponding to the first code element with a structural relationship to connect the corresponding first graph node. The first graph edge indicates that there is a structural relationship between the first code elements represented by the first graph node connected by the first graph edge. The first graph edge can be a directed line. Exemplarily, the first graph edge between the first graph nodes corresponding to the two first code elements with a dependency relationship has a direction from the dependent first graph node to another first graph node. For another example, the first graph edge between the first graph nodes corresponding to the two first code elements with an inclusion relationship has a direction from the first graph node with a large range to the first graph node with a small range (included). For another example, the first graph edge between the first graph nodes corresponding to the two first code elements with a hierarchical relationship has a direction from the upper first graph node to the lower first graph node.

[0053] S104: Generate a code knowledge graph based on the first graph node information and the first graph edge information.

[0054] The code knowledge graph includes a first graph node and a first graph edge representing a relationship between two first graph nodes. According to the first graph node information, a first graph node is created, and according to the first graph edge information, two connected first graph nodes are queried, a first graph edge is created between the two connected first graph nodes, and the direction of the first graph edge is determined according to the first graph node information and / or the first graph edge information. By directly extracting the first code elements and structural relationships from the source code, the unprocessed code information can be obtained, and continuous relationship information can be obtained at the same time, so as to avoid the loss of data due to processing of the code information, thereby avoiding information loss in the code knowledge graph. In addition, by extracting the first code elements and structural relationships from the source code and deleting redundant comments and other information, it is possible to compress the code content and reduce redundant data.

[0055] In addition, the source code also includes the first code elements of other coding scopes outside the current coding scope and the structural relationship between the first code elements of the current coding scope. For example, a method in a source code file calls a method in another source code, and the code tree corresponding to the former source code includes the method in the latter source code and the relationship between the two methods. Therefore, the code tree constructed based on the source code includes the first code elements of other coding scopes, so that the global information can be completed in the constructed code knowledge graph, so that the code tree has complete and rich code information, thereby enriching the information in the code knowledge graph.

[0056] In the disclosed embodiment, the code knowledge graph is used to retrieve based on question information when the large language model performs human-computer interaction to obtain code knowledge, so as to assist the large language model in understanding the question information and generating the response information required by the user.

[0057] According to the technical solution disclosed in the present invention, by performing content parsing on the source code, extracting the code elements and structural relationships in the source code, generating a code tree based on the extracted content, and generating a code knowledge graph based on the code tree, the processing of code elements and structural relationships can be reduced, and the loss of valid data in the code knowledge graph can be reduced. At the same time, redundant information in the source code can be deleted, and the code knowledge graph can be streamlined. The storage amount and data processing amount of the knowledge graph can be reduced, and the efficiency of knowledge graph construction can be improved. Code elements of other scopes involved in the source code can also be obtained to increase global information, thereby increasing the integrity of the knowledge graph.

[0058] In an optional embodiment, the code knowledge graph generation method further includes: obtaining description information associated with the code tree; and adding the description information to the code knowledge graph.

[0059] The description information may refer to the functional or business description information of the source code. Adding the description information to the code knowledge graph can increase the natural language content in the code knowledge graph. Exemplarily, the description information may include at least one of the following: submission information, merge information, and tag information of the source code. The description information may be text information and comments related to the source code. As a representation of the natural language content of the source code, the description information can assist in understanding the first graph node and the first graph edge in the code knowledge graph.

[0060] The description information of the source code used to generate the code tree can be obtained. The description information may include sub-information of at least one first code element and / or at least one structural relationship. According to the first code element and / or structural relationship associated with the sub-information in the description information, the sub-information is added to the corresponding position in the corresponding code knowledge graph. In some embodiments, the description information of the source code can also be obtained, and a code tree is generated based on the description information and the source code, and the sub-information in the description information is used as a code element of the code tree. In this way, the description information exists in the code knowledge graph generated based on the code tree.

[0061] By adding the description information associated with the code tree to the code knowledge graph, the business service information in the code knowledge graph can be increased, which is closer to the user's natural language and improves the convenience of retrieval.

[0062] In an optional embodiment, adding the description information to the code knowledge graph includes: generating second graph node information based on the description information; adding the second graph node information to the code knowledge graph; obtaining a second code element corresponding to the description information; generating second graph edge information between the second graph node information and the corresponding first graph node in the code knowledge graph; and adding the second graph edge information to the code knowledge graph.

[0063] Among them, the second graph node information may include the second graph node, and the association information of the second graph node. The second graph edge information may include the second graph node and the first graph node connected by the second graph edge, the direction of the second graph edge and the relationship represented by the second graph edge, etc. The second graph edge is in the form of a connected first graph node pointing to a connected second graph node. The relationship represented by the second graph edge is a relationship describing business information. The description information is taken as a second graph node, and a second graph edge is established between the first graph nodes corresponding to the described object. The description information includes at least one sub-information. A second graph node is generated for one sub-information, the first code element described by the sub-information is obtained, and a second graph edge is created between the second graph node generated by the sub-information and the first graph node generated by the described first code element, and the direction of the second graph edge is from the first graph node to the second graph node.

[0064] By treating the description information as a code element and a node in the code knowledge graph, the importance of the description information in the code knowledge graph is increased and the convenience of description information retrieval is improved.

[0065] In an optional embodiment, the code tree is generated by performing content parsing on source code of a specified target range, where the target range includes source files, code libraries, or directories.

[0066] The source code may be provided by a user, may be source code in a source file, may be source code in a code library, or may be source code stored in a directory.

[0067] In some embodiments, a code development application is installed locally on the client, and a target plug-in is configured in the code development application. The user specifies the target range through the target plug-in of the client, and the target plug-in of the client processes the source code of the target range, generates a code tree, and sends the code tree to the server. The server generates a code knowledge graph based on the code tree. The target range can be a local source file, a local code library, or a local directory.

[0068] In some embodiments, the user specifies the target range through the network end (web end), and the network end processes the source code of the target range, generates a code tree, and sends the code tree to the server end. The server end generates a code knowledge graph based on the code tree. The target range can be a network source file, a network code library, or a network uniform resource location address (directory), etc.

[0069] In addition, the client can generate a corresponding code tree for each source file. When the user specifies multiple source files, the code trees corresponding to the multiple source files can be sent to the current electronic device. The code tree is a tree with file granularity. Among them, a code library can include multiple source files, or multiple source files can be stored in a directory. The current electronic device generates a code knowledge graph based on multiple code trees.

[0070] By configuring the code tree to generate source code based on a user-specified target range, the flexibility and diversity of the code knowledge graph can be improved.

[0071] In some embodiments, Figure 2 This paper provides a scenario diagram of a code knowledge graph generation method. By analyzing tens of thousands of real user request scenarios and abstracting the structure of the source code, the generated code knowledge graph Scheme is as follows: Figure 3As shown. In the construction phase of the code knowledge graph, the code tree is constructed with the help of the syntax analysis capability of the client IDE (Integrated Development Environment). In this phase, it is necessary to first clarify the Scheme of the knowledge graph (the points and edges in the graph). Based on the construction of the traditional vector index, the knowledge graph at the code base level (CodeBase) can be constructed.

[0072] Different from the traditional process of chunk fragmentation and local analysis, the code base is naturally one or more "graphs", but it is not limited to a certain file, class or method. This requires the ability to parse the entire library in order to build a knowledge graph at the entire CodeBase level.

[0073] The IDE, i.e. the client, has complete syntax parsing capabilities, but it is heavily dependent on the performance and version of the user terminal. High-load parsing affects the user experience. Therefore, the IDE performs preliminary parsing, and each source file gets a GraphTree as an intermediate representation, focusing on parsing dependencies such as symbol references that the server cannot handle well. Figure 2 As shown, the graph tree is a code tree. In the graph tree, the next level of the file is the class. The next level of the class includes the parent class, interface, method and field. The next level of the method is parameter passing, return type and call. The next level of the field is type, etc.

[0074] The server converts GraphTree into a vertex and edge form acceptable to the graph, and further processes more complex deep relationships, such as generic dependencies, internal classes, and Git diff (differences between different versions). The resulting code knowledge graph is as follows: Figure 2 In the code tree, the solid arrows represent the entity hierarchy, and the dotted arrows represent the attribute pointing relationship.

[0075] In an example of a code knowledge graph, Figure 3As shown, a code repository (repo) points to a module (module), which points to a file (file), which points to class A (class A). In addition, there are other files in the code tree that point to class A, for example, class J (class J) points to a file, which points to class A. Class A points to a file different from the above, which points to class B. In fact, the code tree is generated based on a source file, but the classes included in the source file can have a structural relationship with the classes in other files, so that it can also be reflected in the code tree, so that the structural relationship of more other files can be completed in the code tree of a source file. Class A points to class E (class E), class F (class F) and method A (method A). Class F points to method B (method B). Method A points to method B, method C (method C), method D (method D), class C (class C), class D (class D) and local variables (Local variable). Method C points to method E (method E), and class I points to method E. Class G (class G) points to method C. Class D points to method D, method D points to description information (git message). Local variables point to class H (class H).

[0076] In the disclosed embodiment, most of the graph nodes in the code knowledge graph constructed based on the code tree correspond to entities in the source code, and such an intuitive conversion facilitates the conversion of code-related natural language queries to graph queries. The git message in the source file is obtained and a graph node is generated, which retains the relationship between the document and the code, and this part of the document is closer to the user's natural language. The code tree retains the direct dependencies and deep dependencies in the source code as much as possible. The code tree can be calculated through the OLTP (On-Line Transaction Processing) and OLAP (On-Line Analytical Processing) of the graph database, the code tree can be generated locally, and the code knowledge graph can be generated on the server side, reducing the server directly obtaining the source code to generate the graph, realizing the online generation of the code knowledge graph, and reducing the load pressure of the server-side graph construction and graph update.

[0077] Figure 4 This is a flowchart of a code generation method disclosed in an embodiment of the present disclosure. This embodiment can be applied to the case of human-computer interaction based on the knowledge graph constructed in the above embodiment. The method of this embodiment can be executed by a code generation device, which can be implemented in software and / or hardware and is specifically configured in an electronic device with certain data computing capabilities, which can be a server device.

[0078] S401: Obtain input question information.

[0079] In the human-computer interaction scenario, the user provides question information, and the current electronic device processes the question information to obtain reply information. The question information is natural language content, and the language and media type of the question information are not restricted.

[0080] S402. According to the problem information, search in the code knowledge graph to obtain target code knowledge; the code knowledge graph is generated by the code knowledge graph generation method of any embodiment of the present disclosure.

[0081] The code knowledge graph is used to provide target code knowledge. According to the problem information, relevant knowledge is retrieved in the code knowledge graph to obtain code knowledge. Code knowledge is used to assist the current electronic device in processing problem information. The target code knowledge may include graph nodes, graph edges, and structural relationships between the aforementioned elements in the code knowledge graph. The graph nodes may include the first graph node and the second graph node in the aforementioned embodiment, and the graph edges may include the first graph edge and the second graph edge in the aforementioned embodiment.

[0082] S403: Generate reply information according to the target code knowledge and the question information.

[0083] In some embodiments, the target code knowledge and question information are integrated, input into a large language model for processing, and the reply information is output. Specifically, the target code knowledge and question information can be added to a prompt template, and the added prompt template is input into a large language model for processing, and the reply information is output.

[0084] In some embodiments, the application scenario of human-computer interaction is to generate a code based on question information. The reply information is a code.

[0085] According to the technical solution disclosed in the present invention, by retrieving target code knowledge related to question information in the constructed code knowledge graph, and processing the question information in combination with the target code knowledge to obtain reply information, code knowledge can be retrieved in the code knowledge graph that retains the original code elements and removes redundant information, so that the limited code knowledge includes richer key information, which helps to understand the overall code architecture and improve the reliability of reply information.

[0086] In an optional embodiment, generating reply information based on the target code knowledge and the question information includes: sorting the search results included in the target code knowledge according to the question information to obtain a sorting result; and generating the reply information based on the sorting result and the question information.

[0087] Among them, the target code knowledge includes at least one search result, and each search result can be sorted according to the correlation between the search result and the question information to obtain a sorted result. In the target code knowledge directly retrieved, each search result is arranged in random order, and the sorted result can refer to the code knowledge after the search results are sorted. In fact, the arrangement order of each search result in the code knowledge before sorting can be the expected sorting order, that is, the arrangement order of each search result in the re-sorted code knowledge can be the same as the arrangement order of each search result in the code knowledge before sorting. The sorting result actually includes the correlation between each search result and the question information. Generating reply information based on the sorting result and the question information is equivalent to generating reply information based on the target code knowledge, the correlation between each search result in the target code knowledge and the question information, and the question information.

[0088] In some examples, the correlation between the search result and the question information can be determined based on the search method of the search result and the confidence of the search result under the search method. For another example, the similarity between the search result and the question information can be directly calculated as the correlation between the search result and the question information.

[0089] In some embodiments, the prompt template includes a question slot and a code knowledge slot, the question information is added to the question slot, the sorting result is added to the code knowledge slot, the prompt template after adding the question information and the sorting result is input into the large language model, and the reply information is output. The search results in the prompt template are added in the order of arrangement.

[0090] By sorting the search results in the code knowledge according to the question information, sorted code knowledge is obtained, so that the code knowledge contains the relationship sequence between the code knowledge and the question information, and based on the sorted code knowledge and the question information, reply information is generated, which can assist the device to use more relevant code knowledge to reply to the question information and obtain reply information.

[0091] In an optional embodiment, the code generation method further includes: obtaining a code tree generated based on a specified local source code; and obtaining the code knowledge graph based on the code tree.

[0092] Among them, the code tree generated based on the specified local source code can be obtained while obtaining the input question information, that is, the user can input the question information and the source code of the specified target range at the same time. In some embodiments, the client or network generates a code tree based on the source code of the target range, and sends the question information and the code tree to the current electronic device. The current electronic device receives the question information and the code tree generated by the source code of the target range. The current electronic device generates a code knowledge graph based on the code tree, and retrieves code knowledge in the generated code knowledge graph based on the question information. Reply information is generated based on the question information and the code knowledge.

[0093] By configuring the code knowledge graph to generate source code based on the target range specified by the user, the adaptability of the code knowledge graph to the problem information can be improved, the representativeness of the code knowledge can be increased, and the correlation with the problem information can be increased, thereby improving the accuracy of the response.

[0094] Figure 5 It is a flowchart of another code generation method disclosed in accordance with the embodiment of the present disclosure, which is further optimized and expanded based on the above technical solution and can be combined with the above optional implementation methods. The code knowledge map is searched according to the question information to obtain code knowledge, which is specifically as follows: the question information is intentionally identified to obtain the question intention; according to the question intention, the search type is determined; the search input information corresponding to the search type is obtained; according to the search input information, the code knowledge map is searched to obtain code knowledge.

[0095] S501: Obtain input question information.

[0096] S502: Perform intent recognition on the question information to obtain the question intent.

[0097] The question information may be semantically understood to obtain the question intent. In some embodiments, a large language model may be used to identify the intent of the question information. A prompt template of the intent identification function is used to merge the question information with the prompt template of the intent identification function, and input into the large language model to obtain the question intent.

[0098] S503: Determine the search type according to the question intention.

[0099] Among them, the search type is used to determine the search method, and the search type can also include the data source to be searched. In fact, the question intent contains the knowledge required to answer the question information, including the data source where the required knowledge is located and the search method to obtain the required knowledge. According to the question intent, the data source and search method to be searched can be obtained, and the search type can be determined based on the searched data source and search method. Through intent recognition, it can be determined how the question information needs to be searched in order to obtain sufficient context.

[0100] In some embodiments, the search type may include: query statement search, extended search or other search. For example, when the question information or question intention is a precise search such as query graph node search, complex relationship search, subgraph search or visualization search, the search type can be determined to be a query statement search. For another example, when the question information or question intention is a descriptive content search for business services or functions, which has more natural language content than programming language, the search type can be determined to be an extended search. Other types may be types that supplement the search type of the code knowledge graph. Other types may include vector search, which can encode the graph nodes and graph edges in the code knowledge graph to form vectors, and perform vector similarity calculations in the code knowledge graph based on the vector representation corresponding to the question information and / or question intention, and query related graph nodes and / or graph edges. In addition, other types may also include: search types in data sources other than the code knowledge graph.

[0101] S504: Acquire search input information corresponding to the search type.

[0102] The search input information is information used to search in the code knowledge graph. The search input information is generated according to the method corresponding to the search type.

[0103] S505. According to the search input information, search is performed in the code knowledge graph to obtain the target code knowledge; the code knowledge graph is generated by the code knowledge graph generation method of any embodiment of the present disclosure.

[0104] In some embodiments, the search type is query statement search, and the corresponding search input information is at least one query statement. Each query statement is executed to obtain at least one search result in the code knowledge graph to generate target code knowledge. For another example, the search type is extended search, and the corresponding search input information is a keyword. The graph nodes and / or graph edges corresponding to the keyword are queried in the code knowledge graph. For another example, the search type is other search, and the corresponding search input information is a vector. The graph nodes and / or graph edges corresponding to the vector are queried in the code knowledge graph; or the search input information is a vector, and similar vectors are queried in the vector library of code elements to obtain code elements and associated information corresponding to the similar vectors.

[0105] S506: Generate reply information according to the target code knowledge and the question information.

[0106] According to the technical solution disclosed in the present invention, by identifying the question intent of the question information, and determining the retrieval type and the corresponding retrieval input information according to the question intent, searching the code knowledge graph based on the retrieval input information to obtain the target code knowledge, the retrieval type required to reply to the question information can be parsed, the knowledge missing from the reply question information can be judged, and the retrieval method for obtaining the knowledge missing from the reply question information can be planned, and finally the target code knowledge can be obtained, and autonomous retrieval judgment of the code knowledge reply task can be realized. Based on the tool of the code knowledge graph, code knowledge retrieval can be performed, the retrieval feasibility judgment can be increased, and the retrieval accuracy can be improved, thereby improving the accuracy of the reply information.

[0107] In an optional embodiment, the search type includes: query statement search; the obtaining of search input information corresponding to the search type includes: generating a query statement according to the question information; wherein the search input information includes the query statement.

[0108] The code knowledge graph is actually a graph database, which can be queried using a query statement of the graph database. The query statement is used to query in the code knowledge graph. The query statement can be a query statement of the graph database. The number of query statements is at least one.

[0109] In some embodiments, Text2Gremlin may be used to convert the question information into a query statement of the graph query language gremlin. For another example, the graph query language may be Cypher. In some embodiments, the question information may be added to a prompt template for generating a query statement, and the added prompt template for generating a query statement may be input into a large language model for processing, and a query statement may be output.

[0110] By generating query statements corresponding to the question information and using them as search input information for the query statement search type, we can increase the statement query scenarios of the graph and achieve rapid and accurate positioning of code knowledge in the code knowledge graph.

[0111] In an optional embodiment, the search type includes: extended search; the obtaining of search input information corresponding to the search type includes: determining key information based on the question information and the question intent; wherein the search input information includes the key information.

[0112] Among them, extended retrieval may refer to the type of retrieval of the attributes of the graph nodes in the code knowledge graph. In some embodiments, the key information is matched with the attribute information of the graph nodes in the code knowledge graph. In some embodiments, keywords are extracted from the question information and the question intent respectively, and fused to obtain key information. For example, the question information can be rewritten according to the question information and the question intent, and a series of related questions can be generated, and keywords can be extracted from each question. Extracting keywords from the question can be segmenting the question, and supplementing, expanding and transforming the segmentation according to the question intent, etc., to obtain a large number of keywords. The large number of generated keywords can also be screened according to the question information and the question intent to obtain key information. Extended retrieval provides the functions of key information and full-text retrieval.

[0113] By obtaining the key information of the problem information as the search input information corresponding to the extended search type, the search scope can be expanded and the content of the search results can be enriched. In addition, searching based on the attributes of the precise graph nodes in the code knowledge graph can reduce redundant search results and improve search accuracy.

[0114] In an optional embodiment, searching in the code knowledge graph according to the retrieval input information to obtain the target code knowledge includes: searching in the code knowledge graph according to the retrieval input information to obtain at least two target nodes; generating a subgraph according to the target nodes and the association relationship between the target nodes; wherein the target code knowledge includes: the target node and the subgraph.

[0115] The target node is a graph node retrieved based on the search input information. The association relationship may refer to the connection relationship between the target nodes, and the connection relationship may be the structural relationship of the code elements represented by the target nodes. The subgraph may be composed of the retrieved target nodes and the connection relationship between the retrieved target nodes. The subgraph and the target node are regarded as the target code knowledge.

[0116] In some embodiments, a subgraph is generated based on at least two target nodes and the edges between these target nodes. In some embodiments, the target nodes can be expanded in the code knowledge graph to obtain more graph nodes, and the expanded graph nodes and these target nodes are used together to generate a subgraph.

[0117] In some embodiments, among at least two target nodes, if there is a path that can be connected between the two target nodes, the graph nodes through which the connection path of the two target nodes passes are obtained. The target nodes and all the graph nodes through which the obtained connection path passes are used to generate a subgraph. In addition, the direction of the connection path can also be limited, and according to the direction of the directed edge of the target node, the graph nodes passing in the direction of the path that satisfies the specified connection are obtained.

[0118] In one example, target node A and target node D are retrieved, and target node A can reach target node D by sequentially passing through graph node B and graph node C. Target node A, graph node B, graph node C, and target node D can be combined to generate a subgraph.

[0119] In one example, the target node A can reach the target node D by passing through the graph node B and graph node C in turn on the outgoing edge connectivity path. The target node A's incoming edge connectivity path passes through the graph node E, and the outgoing edge connectivity path of the graph node E passes through the target node F. Only the target node A, graph node B, graph node C, and target node D can be used to generate a subgraph, while the graph node E on the incoming edge path is not used as a node for generating the subgraph. Among them, the incoming edge is the graph edge pointing to the graph node, and the outgoing edge is the graph edge of other graph nodes pointed to by the graph node.

[0120] In some embodiments, for each target node, a preset number of graph nodes passed through on a connection path in a specified direction of the target node may be obtained and added to the subgraph.

[0121] By generating a subgraph through the target nodes retrieved from the code knowledge graph and the existing associations, we can enrich the deeper relationships between code elements in the search results and increase the code structure relationships in the target code knowledge. This can complete the missing paths in the search results and provide replies based on the target code knowledge. In scenarios where a large language model is used for human-computer interaction, richer context and structural relationships are provided for the large language model, which can enhance the large language model's understanding of code structure relationships and improve the accuracy of reply information.

[0122] In an optional embodiment, the code generation method further includes: outputting the question intention, the target code knowledge and the response information.

[0123] When generating a subgraph, the target code knowledge includes the subgraph, thereby outputting the target code knowledge, that is, outputting the target node and the subgraph. By providing the user with the question intent, the target code knowledge and the reply information, the intermediate processing process of the question information is provided to the user, which can help the user understand the reply processing process, increase the understanding of the code structure relationship, improve the reliability of the reply information and improve the user experience.

[0124] In an optional embodiment, searching in the code knowledge graph based on the retrieval input information to obtain target code knowledge includes: matching the retrieval input information with a graph node identifier of the code knowledge graph to obtain the target code knowledge, wherein the graph node identifier is identification information of a code element in the source code used to construct the code knowledge graph.

[0125] Among them, the node identifier can uniquely identify the graph node in the code knowledge graph. The node identifier can be the identification information of the code element that generates the identified graph node. The identification information can be a name. By matching the search input information with the node identifier, the graph node of the node identifier corresponding to the search input information can be retrieved. In some embodiments, the search input information is a query statement search, and the node identifiers that meet the conditions can be queried based on the query statement. For example, the search input information is an extended search, and the node identifier corresponding to the key information can be queried based on the key information.

[0126] Existing keyword searches are usually based on text matching, which can easily retrieve results from scripts or text files that are irrelevant to source code.

[0127] By setting the node identification of the graph node to be consistent with the identification information of the code element, searching based on the code identification information can avoid retrieving some script fragments, and accurately retrieve code elements from the source code, thereby improving the accuracy of the search and reducing redundant search results.

[0128] In some embodiments, Figure 6 Schematic diagram of the retrieval scenario shown.

[0129] In the retrieval stage, the disclosed embodiment integrates graph retrieval and traditional RAG retrieval components, and also makes up for the shortcomings of vector retrieval in processing more complex and context-related query capabilities. For different user question-answering and code generation scenarios, the intent recognition model determines the user's request and how to search in order to obtain sufficient context. The intent recognition model outputs the question intent, and the corresponding retrieval type can be determined based on the question intent.

[0130] 1. For query statement retrieval, Text2Gremlin (large language model) can be used to convert natural language question information into query statements in specific graph query languages ​​(such as Gremlin and Cypher).

[0131] 2. For extended search, a large language model can be used to identify the entity of the question information, rewrite, expand and translate the question information, and obtain the key information corresponding to the question information. The functions of keyword and full-text search can be realized based on the attributes of the graph nodes and the key information.

[0132] 3. For the search type of other search, for example, other search types may include server-side search, client-side search, and hybrid search between client and server. Specifically, the search of other search types on the server may include: based on traditional RAG search, specifically vector search or keyword search, etc. The search of other search types on the client may include local file query. The search of other search types of hybrid search may include: the server provides a search range or search conditions, and the client performs a local search based on the provided search range or search conditions.

[0133] The first two graph searches can be used as secondary filtering or supplements to traditional embedding (vector search) and keyword searches. The graph search provided by the disclosed embodiment can implement dependency searches at the file, class and method levels, graphical search results (subgraphs) and Symbol (node ​​identifier) ​​searches.

[0134] The server can integrate all the search results and sort the search results according to the correlation between the question information and each search result to obtain the target code knowledge. The target code knowledge is provided to the large language model, and the large language model generates the reply information.

[0135] In addition, the graph retrieval capability can be used independently as a supplement to the agent capability of the large language model. Specifically, the graph retrieval implementation code can be encapsulated to a certain extent, and the large language model can use it autonomously through tools or function calls. The main encapsulations are:

[0136] 1.search_method_in_class(method_name:str,class_name:str)

[0137] 2.search_method_in_file(method_name:str,file_path:str)

[0138] 3.Search_method(method_name:str)

[0139] 4.Search_class_in_file(self,class_name,file_name:str)

[0140] In an application scenario, such as Figure 7In the scenario diagram of the code generation method based on the code knowledge graph shown, the question-answering process may refer to the process in which the user inputs question information, the current electronic device processes it, and outputs reply information. The retrieval process may refer to the process in which the retrieval model learns retrieval capabilities and the process in which the code knowledge graph is retrieved. The graph construction process may refer to the process in which the code knowledge graph is constructed. It should be noted that the question-answering process, the graph construction process, and the retrieval process are not completely unrelated processes, and there is a connection between the three processes.

[0141] In the graph construction process, the IDE obtains the local source code of the target range specified by the user, generates a code tree, and sends the code tree to the server. The server builds a code knowledge graph based on the code tree to implement graph updates.

[0142] In the question-answering process, the user inputs the question information (query), and the server inputs the question information into the intent recognition model for processing to obtain the question intent. The intent recognition model adapts the graph retrieval capability according to the question intent and determines the retrieval type. The retrieval process is executed according to the retrieval type. Among them, the retrieval type can include other retrieval, which includes local retrieval and hybrid retrieval.

[0143] In the search process, according to the search input information corresponding to the search type, the search model searches the constructed code knowledge graph to obtain the search results of the graph. The question-answering process is executed according to the search results.

[0144] In the question-answering process, the IDE performs local search based on the search type to obtain local code, or performs hybrid search based on the cooperation between the server and the IDE. The search results of hybrid search and local search are sent to the server. The server integrates the search results. Specifically, the server integrates the search results of local search, hybrid search and graph to form target code knowledge. The target code knowledge and question information are input into the response model to generate the code corresponding to the question information.

[0145] Among them, the intent recognition model, the reply model and the retrieval model can all be large language models, and the prompt templates of the corresponding functions are input into the large language model to realize functions such as intent recognition, question and answer, and retrieval. In addition, the retrieval model and the intent recognition model can be independent deep learning models. The retrieval model can continuously enrich the graph retrieval capability based on the question information. Exemplarily, the retrieval model can realize query statement retrieval, node-level retrieval, or graph relationship retrieval. For example, query statement retrieval may include retrieval of search rules. Node-level retrieval may include: current file, code repository (repo), folder (rodler), source file (file), and document (doc), etc. Graph relationship retrieval may include: graph dependency (graph dependcy) and graph caller (graph caller), etc.

[0146] The reply model can visualize the results. Specifically, in the model generation stage, the disclosed embodiment improves the quality of code generation by compressing and visualizing the search results based on the richer context and related information of the model. Among them, the visualized search results specifically connect the search results of the graph into a subgraph (SubGraph). On the one hand, the subgraph can be used to complete the missing paths in the search results and enrich the dependency information; on the other hand, the subgraph is visualized to the model and the user to improve the understanding of the code dependency relationship and the user experience.

[0147] In addition, the graph-based retrieval results in the disclosed embodiments achieve information compression. In terms of generalized questions and answers and deep dependencies, the graph retains the original files, classes, method signatures and call information, removes redundant comments and source codes, etc., so that the same window model receives more information, the overall code architecture is more fully understood, and the executableness of the model-generated code is further improved.

[0148] In the field of code intelligence, traditional RAG ignores the structural relationship and deep dependency information between source code elements, cannot effectively handle the structural redundancy of source code, and the plain text expression cannot fully display the structure and dependency relationship of files in the code base. In actual applications, the code generated by the model needs a lot of manual repair and adjustment before it can be correctly applied to the source file.

[0149] Based on this, the disclosed embodiment provides a method for improving the quality of LLM generated code based on code knowledge graph. Based on the fact that the code base is naturally a "graph" of associations between code elements, this method parses the source code to build a knowledge graph of the entire code base, and then identifies Router LLM and knowledge graph based on intent, providing more structured, precise, and scenario-based dependency and structure definition retrieval capabilities, integrating them into the traditional RAG Pipeline (automated process), making up for the shortcomings of vector retrieval and keyword retrieval, and solving the limitations of existing technologies in handling complex programming tasks.

[0150] According to an embodiment of the present disclosure, Figure 8 : is a structural diagram of a code knowledge graph generation device in an embodiment of the present disclosure, and the present disclosure embodiment is applicable to the case of constructing a knowledge graph. The device is implemented by software and / or hardware, and is specifically configured in an electronic device with certain data computing capabilities.

[0151] like Figure 8 The device 800 for generating a code knowledge graph shown in the figure comprises: a code tree acquisition module 801, a graph node generation module 802, a graph edge generation module 803 and a knowledge graph construction module 804.

[0152] A code tree acquisition module 801 is used to acquire a code tree, wherein the code tree includes code elements and structural relationships between code elements; wherein the code tree is generated by parsing the content of the source code;

[0153] A graph node generating module 802, configured to generate at least one graph node according to the code elements in the code tree;

[0154] A graph edge generation module 803, used to generate edges between corresponding graph nodes according to the structural relationship between the code elements in the code tree;

[0155] The knowledge graph construction module 804 is used to generate a code knowledge graph based on each of the graph nodes and the edges between the graph nodes.

[0156] According to the technical solution disclosed in the present invention, by performing content parsing on the source code, extracting the code elements and structural relationships in the source code, generating a code tree based on the extracted content, and generating a code knowledge graph based on the code tree, the processing of code elements and structural relationships can be reduced, and the loss of valid data in the code knowledge graph can be reduced. At the same time, redundant information in the source code can be deleted, and the code knowledge graph can be streamlined. The storage amount and data processing amount of the knowledge graph can be reduced, and the efficiency of knowledge graph construction can be improved. Code elements of other scopes involved in the source code can also be obtained to increase global information, thereby increasing the integrity of the knowledge graph.

[0157] Optionally, the code knowledge graph generating device further includes:

[0158] A description information acquisition module, used to acquire description information associated with the code tree;

[0159] The knowledge graph generation module is used to add the description information to the code knowledge graph.

[0160] Optionally, the description information acquisition module includes:

[0161] A description node adding unit, used to generate a graph node according to the description information, and add the graph node to the code knowledge graph;

[0162] A description element corresponding unit, used to obtain a code element corresponding to the description information;

[0163] A description edge generation unit is used to generate edges between graph nodes generated by the description information and graph nodes generated by corresponding code elements in the code knowledge graph.

[0164] Optionally, the code tree is generated by performing content parsing on source code of a target range specified by a user, where the target range includes a source file, a code library or a directory.

[0165] The above-mentioned code knowledge graph generation device can execute the code knowledge graph generation method provided by any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects for executing the code knowledge graph generation method.

[0166] According to an embodiment of the present disclosure, Fig. 9 is a structural diagram of a code generation device in an embodiment of the present disclosure, and the present disclosure embodiment is applicable to the case of human-computer interaction based on the knowledge graph constructed in the above embodiment. The device is implemented by software and / or hardware, and is specifically configured in an electronic device with certain data computing capabilities.

[0167] like Fig. 9 The code generation device 900 shown in the figure includes: a question acquisition module 901, a knowledge retrieval module 902 and a response generation module 903.

[0168] The question acquisition module 901 is used to acquire question information;

[0169] A knowledge retrieval module 902, configured to search the code knowledge graph according to the question information to obtain code knowledge; the code knowledge graph is generated by the code knowledge graph generation method according to any one of claims 1 to 4;

[0170] The reply generation module 903 is used to generate reply information according to the target code knowledge and the question information.

[0171] According to the technical solution disclosed in the present invention, by retrieving code knowledge related to question information in the constructed code knowledge graph, and processing the question information in combination with the code knowledge to obtain reply information, code knowledge can be retrieved in the code knowledge graph that retains the original code elements and removes redundant information, so that the limited code knowledge includes richer key information, which helps to understand the overall code architecture and improve the reliability of reply information.

[0172] Optionally, the knowledge retrieval module 902 includes:

[0173] A question intention acquisition unit, used to identify the intention of the question information and obtain the question intention;

[0174] A search type determination unit, used to determine the search type according to the question intention;

[0175] A search information determination unit, used to obtain search input information corresponding to the search type;

[0176] The code knowledge retrieval unit is used to search the code knowledge graph according to the retrieval input information to obtain code knowledge.

[0177] Optionally, the search type includes: query statement search;

[0178] The retrieval information determining unit comprises:

[0179] A query statement generating subunit, used to generate a query statement according to the question information;

[0180] The first input determination subunit is used to determine the query statement as the search input information corresponding to the search type.

[0181] Optionally, the search type includes: extended search;

[0182] The retrieval information determining unit comprises:

[0183] A key information determination subunit, used to obtain the key information corresponding to the question information and the question intention;

[0184] The second input determination subunit is used to determine the key information as the search input information corresponding to the search type.

[0185] Optionally, the code knowledge retrieval unit includes:

[0186] A target node query subunit, used to search the code knowledge graph according to the search input information to obtain multiple target nodes;

[0187] A node subgraph generation subunit, used for generating a subgraph according to the target node and the association relationship between the target nodes;

[0188] The subgraph adding subunit is used to determine each of the target nodes and the subgraph as code knowledge.

[0189] Optionally, the code generating device further includes:

[0190] The question feedback module is used to provide the question intention, code knowledge and the reply information to the user.

[0191] Optionally, the code knowledge retrieval unit includes:

[0192] An identification matching subunit is used to match the search input information with the graph node identification of the code knowledge graph to obtain the target code knowledge, and the graph node identification is the identification information of the code element in the source code used to construct the code knowledge graph.

[0193] Optionally, the reply generation module 903 includes:

[0194] A search result sorting unit, used to sort the search results included in the target code knowledge according to the question information to obtain a sorting result;

[0195] A reply information generating unit is used to generate reply information according to the sorting result and the question information.

[0196] Optionally, the code generating device further includes:

[0197] A specified code tree acquisition module is used to acquire a code tree generated based on a specified local source code while acquiring the problem information input by the user;

[0198] A knowledge graph generation module is used to obtain the code knowledge graph according to the code tree.

[0199] The above-mentioned code generation device can execute the code generation method provided by any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of executing the code generation method.

[0200] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0201] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0202] Fig.10A schematic area diagram of an example electronic device 1000 that can be used to implement an embodiment 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 can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0203] like Fig.10 As shown, the device 1000 includes a computing unit 1001, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1002 or a computer program loaded from a storage unit 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for the device 1000 instructions can also be stored. The computing unit 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.

[0204] A number of components in the device 1000 are connected to the I / O interface 1005, including: an input unit 1006, such as a keyboard, a mouse, etc.; an output unit 1007, such as various types of displays, speakers, etc.; a storage unit 1008, such as a disk, an optical disk, etc.; and a communication unit 1009, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1009 allows the device 1000 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0205] The computing unit 1001 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1001 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1001 performs the various methods and processes described above, such as a code knowledge graph generation method or a code generation method. For example, in some embodiments, the code knowledge graph generation method or the code generation method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 1008. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1000 via the ROM 1002 and / or the communication unit 1009. When the computer program is loaded into the RAM 1003 and executed by the computing unit 1001, one or more steps of the code knowledge graph generation method or the code generation method described above may be performed. Alternatively, in other embodiments, the computing unit 1001 may be configured to execute the code knowledge graph generation method or the code generation method in any other appropriate manner (for example, by means of firmware).

[0206] Various implementations 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 objects (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0207] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, implements the functions / instructions specified in the flow chart and / or the area diagram. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0208] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0209] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the 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 acoustic input, voice input, or tactile input).

[0210] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0211] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services. The server may also be a server of a distributed system, or a server combined with a blockchain.

[0212] Artificial intelligence is a discipline that studies how to use computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.). It includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, machine learning / deep learning technology, big data processing technology, knowledge graph technology, and other major directions.

[0213] Cloud computing refers to a technology system that uses network access to elastically scalable shared physical or virtual resource pools. Resources can include servers, instruction systems, networks, software, applications, and storage devices, and can be deployed and managed on demand and in a self-service manner. Cloud computing technology can provide efficient and powerful data processing capabilities for the application of technologies such as artificial intelligence and blockchain, as well as model training.

[0214] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution provided by this disclosure can be achieved, and this document does not limit this.

[0215] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A method for generating a code knowledge graph, comprising: Acquire a code tree, the code tree including a first code element and a structural relationship between the first code elements; wherein the code tree is generated by performing content parsing on a source code; Generate first graph node information according to the first code element; According to the structural relationship, first graph edge information between corresponding graph nodes is generated; Generate a code knowledge graph based on the first graph node information and the first graph edge information.

2. The method according to claim 1, further comprising: Obtaining description information associated with the code tree; Add the description information to the code knowledge graph.

3. The method according to claim 2, wherein: The adding the description information to the code knowledge graph includes: Generate second graph node information according to the description information; Adding the second graph node information to the code knowledge graph; Obtaining a second code element corresponding to the description information; In the code knowledge graph, generating second graph edge information between the second graph node information and the corresponding first graph node; The second graph edge information is added to the code knowledge graph.

4. The method according to claim 1, wherein: The code tree is generated by performing content parsing on source code of a specified target range, where the target range includes source files, code libraries or directories.

5. A code generation method, comprising: Get the input question information; According to the problem information, search in the code knowledge graph to obtain target code knowledge; The code knowledge graph is generated by the code knowledge graph generation method according to any one of claims 1 to 4; Generate response information based on the target code knowledge and the question information.

6. The method according to claim 5, wherein: According to the problem information, searching in the code knowledge graph to obtain target code knowledge includes: Performing intent recognition on the question information to obtain the question intent; Determine the search type based on the question intent; Obtaining search input information corresponding to the search type; According to the search input information, a search is performed in the code knowledge graph to obtain the target code knowledge.

7. The method according to claim 6, wherein: The search types include: query statement search; The obtaining of search input information corresponding to the search type includes: A query statement is generated according to the question information; wherein the search input information includes the query statement.

8. The method according to claim 6, wherein: The search types include: extended search; The obtaining of search input information corresponding to the search type includes: According to the question information and the question intention, key information is determined; wherein the search input information includes the key information.

9. The method according to claim 8, wherein: The searching in the code knowledge graph according to the search input information to obtain the target code knowledge includes: According to the search input information, a search is performed in the code knowledge graph to obtain at least two target nodes; Generate a subgraph according to the target node and the association relationship between the target nodes; Wherein, the target code knowledge includes: the target node and the subgraph.

10. The method according to claim 8, further comprising: The question intention, the target code knowledge and the response information are output.

11. The method according to claim 6, wherein searching in the code knowledge graph according to the search input information to obtain the target code knowledge comprises: The search input information is matched with the graph node identifier of the code knowledge graph to obtain the target code knowledge, wherein the graph node identifier is the identification information of the code element in the source code used to construct the code knowledge graph.

12. The method according to claim 5, wherein: The step of generating reply information according to the target code knowledge and the question information includes: According to the question information, sorting the search results included in the target code knowledge to obtain a sorting result; The reply information is generated according to the sorting result and the question information.

13. The method according to claim 5, further comprising: Get the code tree generated based on the specified local source code; According to the code tree, the code knowledge graph is obtained.

14. A device for generating a code knowledge graph, comprising: A code tree acquisition module, used to acquire a code tree, wherein the code tree includes a first code element and a structural relationship between the first code elements; wherein the code tree is generated by performing content parsing on a source code; A graph node generation module, used to generate first graph node information according to the first code element; A graph edge generation module, used for generating first graph edge information between corresponding graph nodes according to the structural relationship; The knowledge graph construction module is used to generate a code knowledge graph based on the first graph node information and the first graph edge information.

15. The device according to claim 14, further comprising: A description information acquisition module, used to acquire description information associated with the code tree; The knowledge graph generation module is used to add the description information to the code knowledge graph.

16. The device according to claim 15, wherein: The description information acquisition module includes: A description node generation unit, used to generate second graph node information according to the description information; A description node adding unit is used to add the second graph node information to the code knowledge graph; A description element corresponding unit, used to obtain a second code element corresponding to the description information; A description edge generation unit is used to generate second graph edge information between the second graph node information and the corresponding first graph node in the code knowledge graph; Describe an edge adding unit, used to add the second graph edge information to the code knowledge graph.

17. The device according to claim 14, wherein: The code tree is generated by performing content parsing on source code of a specified target range, where the target range includes source files, code libraries or directories.

18. A code generating device, comprising: A question acquisition module is used to obtain input question information; A knowledge retrieval module is used to search the code knowledge graph according to the problem information to obtain target code knowledge; The code knowledge graph is generated by the code knowledge graph generation method according to any one of claims 1 to 4; The reply generation module is used to generate reply information according to the target code knowledge and the question information.

19. The device according to claim 18, wherein: The knowledge retrieval module comprises: A question intention acquisition unit, used to identify the intention of the question information and obtain the question intention; A search type determination unit, used to determine the search type according to the question intention; A search information determination unit, used to obtain search input information corresponding to the search type; A code knowledge retrieval unit is used to search in the code knowledge graph according to the retrieval input information to obtain the target code knowledge.

20. The device according to claim 19, wherein The search types include: query statement search; The retrieval information determining unit comprises: The query statement generating subunit is used to generate a query statement according to the question information; wherein the search input information includes the query statement.

21. The device according to claim 19, wherein The search types include: extended search; The retrieval information determining unit comprises: The key information determination subunit is used to determine the key information according to the question information and the question intention; wherein the search input information includes the key information.

22. The device according to claim 21, wherein The code knowledge retrieval unit comprises: A target node query subunit, used to search the code knowledge graph according to the search input information to obtain at least two target nodes; The node subgraph generation subunit is used to generate a subgraph according to the target node and the association relationship between the target nodes; wherein the target code knowledge includes: the target node and the subgraph.

23. The apparatus according to claim 21, further comprising: The question feedback module is used to output the question intention, the target code knowledge and the reply information.

24. The device according to claim 19, wherein The code knowledge retrieval unit comprises: An identification matching subunit is used to match the search input information with the graph node identification of the code knowledge graph to obtain the target code knowledge, and the graph node identification is the identification information of the code element in the source code used to construct the code knowledge graph.

25. The apparatus of claim 18, wherein: The reply generation module comprises: A search result sorting unit, used to sort the search results included in the target code knowledge according to the question information to obtain a sorting result; A reply information generating unit is used to generate the reply information according to the sorting result and the question information.

26. The apparatus according to claim 18, further comprising: Specify a code tree acquisition module, used to obtain a code tree generated based on a specified local source code; A knowledge graph generation module is used to obtain the code knowledge graph according to the code tree.

27. 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 executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code knowledge graph generation method according to any one of claims 1-4, or the code generation method according to any one of claims 5-13.

28. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the code knowledge graph generation method according to any one of claims 1-4, or the code generation method according to any one of claims 5-13.

29. A computer program product, comprising a computer program, which, when executed by a processor, implements a code knowledge graph generation method according to any one of claims 1 to 4, or a code generation method according to any one of claims 5 to 13.

Citation Information

Patent Citations

  • Code analysis method and device based on knowledge graph

    CN114491536A

  • Structural chart generation method, model training method, atlas generation method and device

    CN114756691A

  • Software knowledge graph incremental updating method based on code submission

    CN115543402A

  • Defect positioning method and system based on code knowledge graph

    CN115629760A

  • Knowledge graph construction and query method and device, equipment, storage medium and product

    CN115827487A

Cited By

  • Code management system and method based on software demand design

    CN120162034A

  • Code query method and device, electronic equipment and storage medium

    CN121524211A