Code memory code generation method and device, equipment and medium

By combining code memory and large language model for semantic matching, the lack of correlation and accuracy of code search results in the existing technology is solved, more efficient and accurate code search is achieved, and development efficiency is optimized.

CN119201070APending Publication Date: 2024-12-27VOYAH AUTOMOBILE TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411402670.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Existing code search tools cannot understand code semantics in depth, resulting in limited relevance and accuracy of search results, and cannot consider the context information of the code, such as function call relationships and the overall structure of the code base.

Method used

By obtaining the search key information, inputting preset code memory and large language model, semantic matching, obtaining relevant code, and completing the complete code through the function relationship chain, optimizing the code search process.

Benefits of technology

Improve the accuracy and efficiency of code retrieval, enable more accurate understanding of code semantics and context, and provide more comprehensive code retrieval results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201070A_ABST
    Figure CN119201070A_ABST
Patent Text Reader

Abstract

The invention discloses a code memory code generation method and device, equipment and a medium, and relates to the technical field of code generation, and the code memory code generation method comprises the steps of obtaining retrieval key information, inputting a preset code memory according to the retrieval key information for retrieval to obtain function information, inputting a preset large language model according to the retrieval key information, and generating a code memory code according to the function information. And obtaining query key information, performing matching according to the function information and the query key information to obtain related codes, and performing query matching on the related codes to obtain complete codes. Semantic retrieval and complete code acquisition are realized by utilizing a large language model and a code memory, the code retrieval efficiency and accuracy are improved, and the development efficiency is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code generation, and in particular to a code memory code generation method, device, equipment and medium. Background Art

[0002] With the rapid development of information technology, the number of programming languages ​​and code bases has increased dramatically, and the complexity of software systems has also continued to increase. When developers write and maintain code, they often need to retrieve and refer to a large amount of existing code. Traditional code retrieval tools rely on keyword searches, which have limitations in understanding the semantics and context of code and are difficult to meet developers' needs for accurate and relevant code retrieval. At the same time, with the development of artificial intelligence technology, especially large-scale language models, new possibilities are provided for semantic understanding and intelligent retrieval of code.

[0003] Currently, code retrieval is mainly generated through multiple tools. Text search tools, such as grep, find code snippets by matching text strings in the code, but cannot understand the semantics of the code. Code search engines, such as GitHub's code search function, allow users to search for code by keywords, but are also limited by the semantic understanding of keywords. Integrated development environment (IDE), modern IDEs usually include code assistance functions, such as auto-completion, code navigation, etc., but these functions are limited to the current project or known code base. Code analysis tools, such as SonarQube, can analyze code quality, but are not focused on code retrieval.

[0004] Although the existing techniques for retrieval and code generation have made some progress, they still have obvious shortcomings. First, most tools cannot deeply understand the semantics of the code, resulting in limited relevance and accuracy of the retrieval results. In addition, existing tools usually cannot consider the contextual information of the code, such as function call relationships, the overall structure of the code base, etc. Therefore, there is an urgent need for a more efficient and accurate method to improve the quality of retrieval and code generation. Summary of the invention

[0005] The main purpose of this application is to provide a code memory code generation method, device, equipment and medium, aiming to solve the technical problem of how to improve the accuracy of code generation by retrieval keywords.

[0006] To achieve the above objectives, the present application proposes a code memory code generation method, the method comprising:

[0007] Obtain key information for retrieval;

[0008] Input the search key information into the preset code memory for searching to obtain function information;

[0009] Input a preset large language model according to the retrieval key information to obtain the query key information;

[0010] Matching the function information with the query key information to obtain a relevant code;

[0011] The relevant codes are queried and matched to obtain complete codes.

[0012] In one embodiment, before the step of inputting the retrieval key information into the preset code memory for retrieval to obtain the function information, the step includes:

[0013] Obtaining a programming code file, and generating an abstract syntax tree according to the programming code file;

[0014] Extracting the abstract syntax tree to obtain key features of the code;

[0015] Constructing and storing a data structure according to the key features of the code to obtain a preset code memory;

[0016] The step of inputting the retrieval key information into the preset code memory for retrieval to obtain the function information comprises:

[0017] By inputting the retrieval key information into a preset code memory for analysis, a code key feature is obtained;

[0018] Matching is performed according to the key features of the code to obtain corresponding function information.

[0019] In one embodiment, before the step of inputting a preset large language model according to the retrieval key information to obtain the query key information, the step includes:

[0020] Obtain key sample information for retrieval and build an initial large language model;

[0021] Training the initial large language model according to the retrieval key sample information to obtain a preset large language model;

[0022] The step of inputting a preset large language model according to the retrieval key information to obtain the query key information comprises:

[0023] Converting the key retrieval information into a new format to obtain the converted key retrieval information;

[0024] Inputting the converted search key information into a preset large language model to obtain query information;

[0025] The query information is analyzed and extracted to obtain query key information.

[0026] In one embodiment, the step of matching the function information with the query key information to obtain the relevant code further includes:

[0027] The function information and the query key information are used to obtain a corresponding first feature vector and a second feature vector;

[0028] Obtaining a similarity result by comparing the first feature vector with the second feature vector;

[0029] The related codes are obtained by screening the similarity results.

[0030] In one embodiment, the step of performing query matching on the relevant code to obtain the complete code includes:

[0031] Obtaining a function relationship chain by querying a preset function table according to the relevant code;

[0032] According to the functional relationship chain and the related code, a missing code is obtained;

[0033] The relevant code is completed according to the missing code to obtain a complete code.

[0034] In one embodiment, after the step of performing query matching on the relevant code based on the question-answer pair data to obtain the complete code, the following steps are performed:

[0035] Divide the complete code into logical levels to obtain multiple levels of information;

[0036] The multiple levels of information are sent to a control interface to allow a user to expand or collapse code details by clicking or selecting different levels, wherein the related codes are highlighted.

[0037] In one embodiment, after the step of performing query matching on the relevant code to obtain the complete code, the step further includes:

[0038] Receive user feedback;

[0039] The preset code memory is dynamically updated according to the user feedback information.

[0040] In addition, to achieve the above purpose, the present application also proposes a code memory code generation device, the code memory code generation device comprising:

[0041] The acquisition module is used to obtain key retrieval information;

[0042] A retrieval module, used to input the retrieval key information into a preset code memory for retrieval to obtain function information;

[0043] The retrieval module is further used to input a preset large language model according to the retrieval key information to obtain the query key information;

[0044] A matching module, used for matching the function information and the query key information to obtain a relevant code;

[0045] The result module is used to query and match the relevant codes to obtain the complete code.

[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a medium, which is a computer-readable medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the code memory code generation method described above are implemented.

[0047] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the code memory code generation method described above are implemented.

[0048] This application obtains key retrieval information, inputs the key retrieval information into a preset code memory for retrieval, obtains function information, inputs a preset large language model according to the key retrieval information, obtains query key information, matches the function information and the query key information, obtains relevant code, and performs query matching on the relevant code to obtain complete code. Using the large language model and code memory, semantic retrieval and complete code acquisition are achieved, code retrieval efficiency and accuracy are improved, and development efficiency is optimized. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0050] Figure 1 This is a flowchart of a first embodiment of a code memory code generation method of the present application;

[0051] Figure 2 This is a flow chart of a second embodiment of the code memory code generation method of the present application;

[0052] Figure 3 A schematic flow chart of a third embodiment of the code memory code generation method of the present application;

[0053] Figure 4 This is a schematic diagram of the module structure of the code memory code generation device according to an embodiment of the present application;

[0054] Figure 5 A schematic diagram of the device structure of the hardware operating environment involved in the code memory code generation method in the embodiment of the present application;

[0055] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0056] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0057] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0058] The main solution of the embodiment of the present application is: by acquiring text data, converting the text data into a preset text format, obtaining text information, constructing a mask template based on multiple preset template contents, obtaining mask template content, matching the text information with the mask template content, obtaining question-answer pair data, and generating instruction fine-tuning data based on the question-answer pair data.

[0059] Based on this, the embodiment of the present application provides a code memory code generation method, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the code memory code generation method of the present application.

[0060] In this embodiment, the code memory code generation method includes steps S10 to S50:

[0061] Step S10, obtaining key retrieval information.

[0062] It should be noted that the system starts the retrieval process by inputting the key retrieval information provided by the user, such as a specific function name, constant, or description related to the code function. This key retrieval information is then entered into the system's code memory for search. The memory stores pre-processed code snippets, including data generated by steps such as standardization, syntax parsing, segmentation and tagging, and storage. In order to ensure the relevance and accuracy of the retrieval results, the system uses natural language processing techniques, such as part-of-speech tagging, named entity recognition, and dependency syntax analysis, to understand the semantic content of the user's query. In addition, the system may also use machine learning algorithms to intelligently predict and optimize the extraction of key retrieval information based on the user's historical retrieval behavior and feedback.

[0063] The retrieval process not only relies on keyword matching, but also utilizes advanced semantic retrieval technology, which includes using a pre-trained code semantic model to map query information and code snippets into the same semantic space and calculate the semantic similarity between the two, thereby returning the most relevant results.

[0064] Step S20, searching in a preset code memory according to the search key information input to obtain function information.

[0065] It should be noted that the process of searching in the preset code memory based on the search key information input starts with the query input by the user. The system receives these queries as the search key information, which may be the name of the function, constant definition, or text description of the function. These search key information are used to search in the code memory. A large amount of code data has been pre-processed and organized in the memory. These data have been standardized, comments and blank characters have been removed, and syntax parsed through the Abstract Syntax Tree (AST). AST is a tree structure used to represent the syntax structure of the source code, in which each node represents a component in the code, such as a function call, loop structure or conditional judgment. It is segmented and marked according to the granularity such as function, class or module. Each piece of code is given a unique identifier and stored in a JSON format file. The search module uses these pre-processed data to find the corresponding function information in the memory by keyword matching, which includes detailed information such as the function name, source code and its specific location in the file.

[0066] Furthermore, by inputting the search key information into the preset code memory for analysis, the key features of the code are obtained, and matching is performed according to the key features of the code to obtain the corresponding function information. When the user enters the search key information, the system enters the information into the preset code memory for analysis, and the memory contains the previously processed code data. These data have been standardized, comments and unnecessary blank characters have been removed, and syntax parsing has been performed through the abstract syntax tree to ensure the grammatical correctness of the code. The key features of the code are extracted from the search key information, which may include specific function names, variable names, algorithm patterns, programming paradigms, or specific programming language constructs. Next, the code is divided into smaller granular units, such as functions, classes, or modules, and a unique identifier is assigned to each unit. All of these processed code data are stored in a structured format, such as a JSON file, which contains the name of each function, source code, location of the file, and other important information. After receiving the search request, the system will use these pre-processed data to match based on the input search key information. During this process, the system not only considers the matching of direct keywords such as function names and constant names, but also uses semantic graph indexing to understand the logical relationship and semantic connection between codes, thereby improving the accuracy of retrieval. In this way, the system can identify the function information most relevant to the key information to be retrieved, including the specific content of the function, its location in the code base, and even the function description generated by the large language model.

[0067] Furthermore, before using the preset code memory, the programming code file is obtained, and an abstract syntax tree is generated according to the programming code file. According to the abstract syntax tree, the key features of the code are extracted, and the data structure is constructed and stored according to the key features of the code to obtain the preset code memory. The system first preprocesses it, removes comments and redundant blank characters, so as to reduce the complexity of subsequent processing and improve efficiency. Then, the system uses the lexical analyzer in the compilation principle to convert the code into a series of tags, which are the basic elements that constitute the code, such as keywords, variable names, operators, etc. Subsequently, the system generates an abstract syntax tree based on these tags through a syntax analyzer. Based on the generated abstract syntax tree, the system further extracts the key features of the code, which include function signatures, parameter types, return value types, variable declarations and usage, etc. By extracting these features, the system can understand the basic logic and structure of the code. Then, the system constructs data structures based on these key features. These data structures include database tables, index structures, or graph databases, etc., in order to effectively store code information and facilitate subsequent retrieval and query operations. Through such processing, the system creates a preset code memory, which is the core part of the code knowledge base. It not only stores the code itself, but also retains the important attributes and contextual information of the code, providing a solid foundation for subsequent function retrieval and code reuse.

[0068] Step S30, inputting a preset large language model according to the search key information to obtain the query key information.

[0069] It should be understood that the purpose of presetting the large language model based on the input of the key retrieval information is to extract more in-depth and rich key query information from the query provided by the user. The large language model has powerful natural language processing capabilities, can understand complex query statements, and extract the core intent and relevant context from them. When the user enters the key retrieval information, the system passes it to the pre-trained large language model, which performs a deep semantic analysis of the text through its internal multi-layer neural network structure. The large language model can identify the entities, actions, and the relationships between them in the query. Even if the query is vague or there are multiple interpretations, the model can make reasonable inferences through contextual understanding. In addition, the model can also convert natural language queries into a form that is easier for machines to understand, thereby obtaining key query information. Key query information includes specific function names, class names, variable names, data types, and even functional descriptions of code snippets.

[0070] Further, the retrieval key information is converted into a format to obtain the converted retrieval key information, and the converted retrieval key information is input into a preset large language model to obtain query information, and the query information is analyzed and extracted to obtain the query key information. The retrieval key information is converted into a format to better meet the needs of subsequent processing steps. This step usually includes formatting the free text input by the user into a more structured form, such as removing special characters, unifying capitalization, word segmentation, and stemming. Through these processes, the retrieval key information can be made more standardized and consistent, which helps to improve the accuracy and efficiency of subsequent retrieval. After completing the format conversion, the system inputs the converted retrieval key information into a preset large language model, which uses its powerful natural language processing capabilities to deeply understand and parse the input information. In the large language model, the input information is embedded in a multidimensional vector space, and the model encodes and decodes this information through its internal complex neural network architecture to obtain query information. These query information contains the semantic understanding and expansion of the original retrieval key information, and can capture a wider range of related concepts and contexts. Next, the system will analyze and extract the query information, and use natural language processing technologies such as named entity recognition (NER) and dependency syntax analysis to further refine and refine the query content and extract the most core query key information.

[0071] Furthermore, before using the preset large language model, the key sample information of the retrieval is obtained, and the initial large language model is established. The initial large language model is trained according to the key sample information of the retrieval to obtain the preset large language model. Obtaining the key sample information of the retrieval is the first step in building the preset large language model. These sample information usually includes a large number of annotated programming code snippets and their corresponding natural language descriptions or annotations. These data sets cover various programming languages ​​and different application scenarios to ensure that the model can understand and generate diverse codes and texts. After collecting enough key sample information of the retrieval, the next step is to establish the initial large language model. This usually involves selecting a basic model architecture, such as the Transformer architecture. Once the initial model architecture is determined, the model is trained using the key sample information of the retrieval. During the training process, the model gradually learns how to map the natural language description to the code snippet. Through repeated iterations, the model learns the syntax and semantics of the programming language and the correspondence between the natural language and the programming language from the sample. As the training deepens, the model gradually optimizes its weight parameters to minimize the gap between the predicted output and the true label. After sufficient training, the initial model is evolved into a preset large language model that meets the requirements.

[0072] Step S40, matching is performed based on the function information and the query key information to obtain the relevant code.

[0073] It should be noted that the process of matching function information with query key information is aimed at finding the most relevant code by comparing the key elements in the user query with the known function information. This process usually starts with parsing the query key information, using natural language processing technology to extract the main concepts, entities, and actions in the query, such as function name, parameter types, return value type, and operations performed by the function. Then, the system will compare the extracted query key information with the function information stored in the code memory. The function information in the memory includes the function definition, comments, used data types, and other metadata.

[0074] The matching algorithm calculates the similarity score between the query key information and the function information, involving a variety of technical means such as string matching, semantic similarity evaluation, and comparison based on function signatures. In order to improve the accuracy of matching, the system may use methods such as TF-IDF (Term Frequency-Inverse Document Frequency) or Word2Vec to quantify the similarity between the query and the function information. In addition, the system may also use deep learning technology, such as Siamese networks, to evaluate the semantic similarity between the query and the function description.

[0075] Finally, the system will sort by matching scores and return the top candidate code snippets as query results. These results are usually the relevant codes that are most likely to meet the user's needs. In this way, the system can not only provide accurate code matches, but also recommend code snippets with similar or related functions based on contextual understanding, thus helping users find the information they need faster.

[0076] Step S50, query and match the relevant codes to obtain the complete code.

[0077] It should be noted that in the process of query matching of relevant codes, the system will search for the most relevant code snippets based on the key information of the user's query through the previously constructed code memory. This memory stores code data after preprocessing and feature extraction, including key features such as function name, function body, and location information. The system will first search for matching function information in the memory based on the key query information entered by the user, such as function name, function description, etc. In order to ensure the accuracy of the match, the system uses a variety of technologies, such as keyword matching, semantic similarity calculation, etc., to determine which code snippets best meet the user's query requirements. Once the relevant code snippets are found, the system will further confirm whether these code snippets contain the complete code required by the user. If the initially matched code snippets are not sufficient to meet the user's needs, the system will continue to search for relevant code snippets based on the function relationship chain, that is, the calling relationship between functions, until the complete code is obtained. This process may involve tracing the function call stack, obtaining the definition of the called function, and recursively searching for related code. Finally, the system will integrate all relevant code snippets to form a complete code implementation and display this complete code to the user.

[0078] Furthermore, logical levels are divided according to the complete code to obtain multiple levels of information. Specifically, after obtaining the complete code, the system will divide the code into logical levels, that is, decompose the code into multiple meaningful levels of information. This process may include identifying structures such as functions, classes, modules, and the hierarchical relationships between them. For example, a class may contain multiple methods, and a method may call other auxiliary functions. The system generates a hierarchical code view by analyzing the code structure, and each layer represents a component of the code, such as the top-level class or module, the next layer of function or method, and the next layer of specific code lines.

[0079] Furthermore, multiple levels of information are sent to the control interface to allow users to expand or collapse code details by clicking or selecting different levels, where relevant code is highlighted. Subsequently, these level information are sent to the control interface, and users can expand or collapse code details by clicking or selecting different levels. This hierarchical display method not only helps users quickly browse the overall structure of the code, but also facilitates them to look into the specific implementation when needed. To further enhance the user experience, the system will highlight the relevant code, which means that those code snippets that are most relevant to the user's query will be specially marked so that users can notice the important parts at a glance. This method not only ensures the readability of the code, but also improves the efficiency of users finding specific information. Through such interactive design, users can manage and understand complex code structures more easily.

[0080] Furthermore, after displaying the complete code, the user is allowed to provide feedback on the search results to optimize future search results. The system receives user feedback information and dynamically updates the preset code memory based on the user feedback information. Specifically, after receiving user feedback information, the system dynamically updates the preset code memory to continuously optimize the code storage and retrieval effect. User feedback information includes satisfaction evaluation of the search results, correction suggestions for specific code snippets, or new code requirements. The system first analyzes these feedback information to identify the code parts that need to be adjusted or supplemented. Next, the system monitors the changes in the code base in real time, including newly added, modified, and deleted code files, and incrementally updates the index in the memory, processing only those parts that have changed, thereby improving the update efficiency. For newly added or modified code, the system will re-execute the code preprocessing process, including standardization, syntax parsing, segmentation and marking, and storage steps to ensure that the new code can be correctly included in the memory. For deleted code, it is removed from the memory accordingly to maintain the timeliness and accuracy of the memory content. In addition, the system also maintains version history, supports users to retrieve the code status at a specific point in time, and ensures that the dynamic update of the code memory does not affect the accessibility of historical data. In this way, the system can continuously learn and adapt to changes in user needs, and continuously improve the quality of code retrieval and services.

[0081] This embodiment provides a code memory code generation method, by obtaining retrieval key information, inputting the retrieval key information into a preset code memory for retrieval, obtaining function information, inputting a preset large language model according to the retrieval key information, obtaining query key information, matching the function information and the query key information, obtaining related codes, querying and matching the related codes, and obtaining complete codes. Using the large language model and code memory, semantic retrieval and complete code acquisition are realized, code retrieval efficiency and accuracy are improved, and development efficiency is optimized.

[0082] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 2 The code memory code generation method step S40 also includes steps S401 to S403:

[0083] Step S401: combine function information and query key information to obtain corresponding first eigenvector and second eigenvector.

[0084] It should be noted that the system uses preprocessed function information, including function name, parameter type, return value type, function description, etc., to generate the first feature vector through feature extraction technology. This process may involve using AST to capture the structural characteristics of the code and combining static analysis tools to extract the semantic information of the code. For query key information, the system also uses natural language processing technology, such as word embedding or pre-trained models such as BERT, to convert it into a second feature vector that can capture semantic meaning.

[0085] After generating feature vectors, the system can use these vectors to represent the query and function information in a multidimensional space, so that even seemingly different expressions can be mapped to close positions in the vector space as long as they are semantically similar. In this way, by calculating the distance or similarity between the first feature vector and the second feature vector, the system can identify the function information most relevant to the query.

[0086] Step S402: Compare the first feature vector and the second feature vector to obtain a similarity result.

[0087] It should be understood that the process of comparing the first feature vector and the second feature vector is to measure the degree of match between the query and the code snippet by calculating the similarity between the two vectors. Usually, the system uses cosine similarity as the comparison standard because it can well reflect the angular difference between the two vectors in the multidimensional space without being affected by their lengths. When calculating, the system puts the first feature vector (representing function information) and the second feature vector (representing query key information) in the same semantic space, and calculates the dot product of the two and divides it by the module length product of each vector to obtain the cosine similarity. The similarity result reflects the semantic proximity between the query and the code snippet. The higher the value, the greater the similarity between the two. The system can sort multiple candidate code snippets according to this similarity result, so as to return the most relevant code to the user. In addition, the system may also use other similarity measurement methods, such as Euclidean distance, Manhattan distance or Jaccard similarity coefficient, to further verify and optimize the matching results.

[0088] Step S403, obtaining relevant codes by screening the similarity results.

[0089] It should be noted that by screening the similarity results, the system can select the code that is most relevant to the user's query from a large number of candidate code snippets. This process usually includes setting a threshold, and only those codes with similarity scores higher than this threshold will be considered relevant. The system will sort the candidate codes according to the similarity score and select the top-ranked group of codes as the final relevant codes. The purpose of this is to ensure that only those codes that are semantically closest to the user's query can be presented to the user, thereby improving the accuracy and effectiveness of the retrieval. The screening process may also be combined with other factors, such as the frequency of use of the code, the latest modification date, or the quality score of the code, to further improve the relevance and practicality of the results.

[0090] This embodiment obtains the corresponding first feature vector and second feature vector by combining function information and query key information, obtains similarity results by comparing the first feature vector and the second feature vector, and obtains relevant codes by screening the similarity results. Accurately matching code requirements improves retrieval efficiency, enhances semantic understanding, and optimizes development experience.

[0091] Based on the first embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the first embodiment can be referred to the above description, and will not be described in detail later. Figure 3 The code memory code generation method step S50 further includes steps S501 to S503:

[0092] Step S501, obtaining a function relationship chain by querying a preset function table according to relevant codes.

[0093] It should be noted that, based on the relevant code, the system queries the preset function table to obtain the function relationship chain. This step is to reveal the mutual calling relationship between the functions in the code snippet. By accessing the function relationship table, the system can identify which other functions a function calls, and which functions call the current function, and establish a network of function calls. This function relationship chain provides important contextual information to help understand the role and location of the relevant code in the entire program. Using this relationship chain, the system can track all other functions that are directly or indirectly related to the target function, thereby building a complete code execution flow chart.

[0094] Step S502, obtaining missing codes according to the function relationship chain and related codes.

[0095] It should be noted that the process of obtaining missing code based on the function relationship chain combined with the related code is intended to identify any necessary code snippets that are not included in the current search results by analyzing the existing code snippets and their calling relationships. This process usually starts with obtaining the function relationship chain. The system identifies other functions that are directly or indirectly related to the retrieved related code by querying the preset function table. These functions form a call network that helps the system understand the context and overall logic of the code. The system checks whether these related code snippets contain all the necessary function definitions and calls. If it is found that some called functions do not appear in the search results, the system will treat these missing functions as targets to be supplemented.

[0096] Step S503, completing the relevant code according to the missing code to obtain a complete code.

[0097] It should be noted that the process of completing the relevant code based on the missing code is aimed at building a complete code implementation by identifying and supplementing those code snippets that are not included in the retrieved relevant code but are critical to its functional implementation. This process first identifies those functions or modules that are referenced by the current code snippet but have not been retrieved based on the function relationship chain. The system will query the code memory again based on the identifiers of these missing parts to find and obtain the missing code. These missing codes may include function definitions, class declarations, import statements, etc., which are crucial to ensure that the code snippet can run independently. Once the missing code is found, the system will integrate it into the existing relevant code and ensure that the code structure is reasonable and logically clear through proper organization and arrangement. This completion process is not limited to adding missing function definitions, but also includes ensuring that all necessary import statements are correctly added and checking whether there are any unmet dependencies. In this way, the system can generate a functionally complete and logically coherent code snippet that users can use or further develop directly without having to find missing parts or manually add missing definitions.

[0098] This embodiment obtains a function relationship chain by querying a preset function table according to relevant codes, obtains missing codes according to the function relationship chain and relevant codes, and completes relevant codes according to the missing codes to obtain complete codes, thereby improving the practicality of the code and improving the efficiency and experience of developers.

[0099] This application also provides a code memory code generation device, please refer to Figure 4 , the device comprises:

[0100] The acquisition module 10 is used to acquire key retrieval information.

[0101] The search module 20 is used to search in a preset code memory according to the search key information input to obtain function information.

[0102] The retrieval module 20 is also used to input a preset large language model according to the retrieval key information to obtain the query key information.

[0103] The matching module 30 is used to perform matching according to the function information and the query key information to obtain the relevant code.

[0104] The result module 40 is used to query and match the relevant codes to obtain the complete code.

[0105] The code memory code generation device provided by the present application adopts the code memory code generation method in the above embodiment, which can solve the technical problem of how to improve the accuracy of the code generation of the search keyword. Compared with the prior art, the beneficial effects of the code memory code generation device provided by the present application are the same as the beneficial effects of the code memory code generation method provided by the above embodiment, and the other technical features in the code memory code generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0106] In one embodiment, the retrieval module 20 is further used to obtain key features of the code by inputting the retrieval key information into a preset code memory for analysis; and to obtain corresponding function information by matching according to the key features of the code.

[0107] In one embodiment, the retrieval module 20 is further used to convert the retrieval key information into a format to obtain the converted retrieval key information; input the converted retrieval key information into a preset large language model to obtain query information; and analyze and extract the query information to obtain the query key information.

[0108] In one embodiment, the matching module 30 is further used to obtain the corresponding first feature vector and second feature vector based on the function information and the query key information; obtain the similarity result by comparing the first feature vector and the second feature vector; and obtain the relevant code by screening the similarity result.

[0109] In one embodiment, the result module 40 is further used to obtain a function relationship chain by querying a preset function table according to the relevant code; obtain the missing code according to the function relationship chain combined with the relevant code; and complete the relevant code according to the missing code to obtain a complete code.

[0110] In one embodiment, the result module 40 is also used to divide the logical levels according to the complete code to obtain multiple levels of information; the multiple levels of information are sent to the control interface to allow the user to expand or collapse the code details by clicking or selecting different levels, wherein the relevant code is highlighted.

[0111] In one embodiment, the result module 40 is further used to receive user feedback information; and dynamically update the preset code memory according to the user feedback information.

[0112] The present application provides a code memory code generation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the code memory code generation method in the above-mentioned embodiment one.

[0113] Reference below Figure 5 , which shows a schematic diagram of the structure of a code memory code generation device suitable for implementing the embodiment of the present application. The code memory code generation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The code memory code generation device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0114] like Figure 5As shown, the code memory code generation device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. Various programs and data required for the operation of the code memory code generation device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 may allow the code memory code generation device to communicate wirelessly or wired with other devices to exchange data. Although the code memory code generation device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.

[0115] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0116] The code memory code generation device provided by the present application adopts the code memory code generation method in the above embodiment, which can solve the technical problem of how to improve the accuracy of the code generation of the search keyword. Compared with the prior art, the beneficial effects of the code memory code generation device provided by the present application are the same as the beneficial effects of the code memory code generation method provided by the above embodiment, and the other technical features in the code memory code generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0117] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0118] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0119] The present application provides a computer-readable medium having computer-readable program instructions (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the code memory code generation method in the above-mentioned embodiment.

[0120] The computer-readable medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, 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 above. In this embodiment, the computer-readable medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0121] The computer readable medium may be included in the code memory code generating device; or may exist independently without being assembled into the code memory code generating device.

[0122] The computer-readable medium carries one or more programs, and when the one or more programs are executed by the code memory code generating device, the code memory code generating device can write a computer program code for performing the operation of the present application in one or more programming languages ​​or a combination thereof, and the programming language includes an object-oriented programming language, such as Java, Smalltalk, C++, and a conventional procedural programming language, such as "C" language or a similar programming language. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).

[0123] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0124] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0125] The readable medium provided by the present application is a computer-readable medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned code memory code generation method, and can solve the technical problem of how to improve the accuracy of the code generation of the search keyword. Compared with the prior art, the beneficial effects of the computer-readable medium provided by the present application are the same as the beneficial effects of the code memory code generation method provided by the above-mentioned embodiment, and will not be repeated here.

[0126] The present application also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the steps of the code memory code generation method as described above are implemented.

[0127] The computer program product provided by the present application can solve the technical problem of how to improve the accuracy of the code generated by the search keyword. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the code memory code generation method provided by the above embodiment, which will not be repeated here.

[0128] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A code memory code generation method, characterized in that: The method comprises: Obtain key information for retrieval; Input the search key information into the preset code memory for searching to obtain function information; Input a preset large language model according to the retrieval key information to obtain the query key information; Matching the function information with the query key information to obtain a relevant code; The relevant codes are queried and matched to obtain complete codes.

2. The method according to claim 1, characterized in that Before the step of inputting the retrieval key information into the preset code memory for retrieval to obtain the function information, the step includes: Obtaining a programming code file, and generating an abstract syntax tree according to the programming code file; Extracting the abstract syntax tree to obtain key features of the code; Constructing and storing a data structure according to the key features of the code to obtain a preset code memory; The step of inputting the retrieval key information into the preset code memory for retrieval to obtain the function information comprises: By inputting the retrieval key information into a preset code memory for analysis, a code key feature is obtained; Matching is performed according to the key features of the code to obtain corresponding function information.

3. The method according to claim 1, characterized in that Before the step of inputting a preset large language model according to the retrieval key information to obtain the query key information, the method includes: Obtain key sample information for retrieval and build an initial large language model; Training the initial large language model according to the retrieval key sample information to obtain a preset large language model; The step of inputting a preset large language model according to the retrieval key information to obtain the query key information comprises: Converting the key retrieval information into a new format to obtain the converted key retrieval information; Inputting the converted search key information into a preset large language model to obtain query information; The query information is analyzed and extracted to obtain query key information.

4. The method according to claim 1, characterized in that The step of matching the function information with the query key information to obtain the relevant code also includes: The function information and the query key information are used to obtain a corresponding first feature vector and a second feature vector; Obtaining a similarity result by comparing the first feature vector with the second feature vector; The related codes are obtained by screening the similarity results.

5. The method according to claim 1, characterized in that The step of querying and matching the relevant codes to obtain the complete code includes: Obtaining a function relationship chain by querying a preset function table according to the relevant code; According to the functional relationship chain and the related code, a missing code is obtained; The relevant code is completed according to the missing code to obtain a complete code.

6. The method according to claim 1, characterized in that After the step of performing query matching on the relevant code to obtain the complete code, the method further comprises: Divide the complete code into logical levels to obtain multiple levels of information; The multiple levels of information are sent to a control interface to allow a user to expand or collapse code details by clicking or selecting different levels, wherein the related codes are highlighted.

7. The method according to claim 1, characterized in that After the step of performing query matching on the relevant code to obtain the complete code, the method further includes: Receive user feedback; The preset code memory is dynamically updated according to the user feedback information.

8. A code memory code generating device, characterized in that: The device comprises: The acquisition module is used to obtain key retrieval information; A retrieval module, used to input the retrieval key information into a preset code memory for retrieval to obtain function information; The retrieval module is further used to input a preset large language model according to the retrieval key information to obtain the query key information; A matching module, used for matching the function information and the query key information to obtain a relevant code; The result module is used to query and match the relevant codes to obtain the complete code.

9. A code memory code generating device, characterized in that: The device comprises: a memory, a processor, and a code memory code generation program stored in the memory and executable on the processor, wherein the code memory code generation program is configured to implement the steps of the code memory code generation method according to any one of claims 1 to 7.

10. A medium, characterized in that A code memory code generation program is stored on the medium, and when the code memory code generation program is executed by the processor, the steps of the code memory code generation method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Virtual reality software performance defect detection method, system, equipment and medium

    CN120011240A