Code diagnosis method, system and equipment

By adopting large language models and retrieval enhancement generation technology in code diagnostic tools, the existing tools have limited detection capabilities and insufficient repair capabilities have been solved, and more accurate code problem identification and efficient repair suggestions are achieved, which significantly improves the code Quality and system stability.

CN119473299APending Publication Date: 2025-02-18CORECHENG (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411258735.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-09
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

Existing code diagnostic tools have limited detection capabilities, making it difficult to identify implicit errors and logical vulnerabilities, lack context understanding, insufficient repair capabilities, and it is difficult to efficiently deal with code problems in complex autonomous driving systems.

Method used

The large language model is combined with search enhancement generation technology to search large-scale code bases to provide accurate context information for the model, so that the model can more accurately identify code problems and automatically generate targeted repair suggestions.

Benefits of technology

Significantly improve code quality and system stability, reduce manpower investment, enable more accurate identification of potential problems and generate effective repair suggestions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473299A_ABST
    Figure CN119473299A_ABST
Patent Text Reader

Abstract

The invention relates to a code diagnosis method, system and equipment, and the method comprises the steps: carrying out the preprocessing of code data, and generating structured data; vectorizing the structured data to construct a vector database; based on a user diagnosis request, a retrieval enhancement generation technology is adopted to retrieve related context fragments; screening out target context fragments, combining the target context fragments into context information, and outputting the context information to a large language model; the large language model identifies potential problems in the code data and generates repair suggestions. According to the method, efficient retrieval can be performed in a large-scale code library on the basis of the large language model by combining and applying a retrieval enhancement generation technology, necessary and accurate context information related to a user diagnosis request is provided for the large language model, so that the large language model can identify potential problems in codes more accurately; and a targeted repair suggestion is automatically generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a code diagnosis method, system and equipment, and belongs to the technical field of computer-aided driving. Background Art

[0002] With the rapid development of intelligent driving technology, the code complexity of autonomous driving systems is also increasing, making it more difficult to diagnose and repair code problems. Existing code diagnosis and repair tools mainly have the following technical problems:

[0003] 1. Limited detection capabilities: Static analysis tools can usually only detect explicit errors in the code, and it is difficult to identify implicit errors and logical vulnerabilities, especially when these errors involve complex deep learning algorithms.

[0004] 2. Lack of contextual understanding: Traditional code review tools have difficulty fully understanding the contextual information of the code and cannot accurately locate the root cause of the problem. This is particularly evident when dealing with large-scale code bases (such as autonomous driving software).

[0005] 3. Insufficient repair capabilities: Existing automated repair tools are mainly based on templates and rules, and it is difficult to generate targeted and effective repair suggestions. In many cases, manual debugging is still required, which is not only time-consuming and labor-intensive, but also requires a high level of experience and skills from engineers. It is difficult to efficiently handle code problems in complex autonomous driving systems. Summary of the invention

[0006] In view of the deficiencies in the prior art, the present invention provides a code diagnosis method, system and device, which are based on a large language model and use retrieval enhancement generation technology to search a large-scale code base, provide accurate context information for the model, enable the model to more accurately identify code problems, and automatically generate targeted repair suggestions.

[0007] According to a first aspect of the present invention, a code diagnosis method is provided, the method comprising:

[0008] Preprocessing the code data to generate structured data, wherein the preprocessing includes code decomposition and information extraction;

[0009] Vectorizing the structured data to construct a vector database for retrieval;

[0010] Adopting the search enhancement generation technology, based on the user's diagnosis request and the problem site data, extracting the search keywords, generating the query statement, converting the query statement into a query vector, searching in the vector database, and obtaining the relevant context fragments;

[0011] The relevant context fragments are scored using a scoring mechanism to obtain a comprehensive score for each context fragment, and based on the comprehensive score, target context fragments are screened out in combination with information diversity and semantic integrity, combined into context information, and output to the large language model;

[0012] The large language model analyzes the user diagnosis request and the context information, identifies potential problems and generates repair suggestions.

[0013] According to one embodiment, the code decomposition includes:

[0014] Acquire code data, wherein the code data includes a historical version and a current version;

[0015] Decomposing the code data according to different granularities of files, classes, functions, and logic blocks to extract code snippets;

[0016] The code snippets are formatted to unify the format and remove redundant information.

[0017] According to one embodiment, the information extraction comprises:

[0018] Extracting metadata of the code snippet, wherein the metadata includes file name, author, and version number;

[0019] Analyze the structure of code data and extract structural information associated with code snippets, wherein the structural information includes function call relationships and class inheritance relationships;

[0020] Analyze the operation log and extract the operation information and error information related to the code snippet;

[0021] Integrate the extracted code snippets, metadata, structural information, and operation logs to generate structured data.

[0022] According to one embodiment, the adopting a scoring mechanism to score the relevant context segments to obtain a comprehensive score for each context segment includes:

[0023] Based on the task type of the user's diagnosis request, assign a task relevance score to each context segment according to task relevance;

[0024] Calculate the semantic similarity between the context fragment and the user query sentence, and assign a semantic similarity score to each context fragment according to the degree of similarity;

[0025] Analyze the importance of each context fragment based on business logic and assign an importance score;

[0026] Analyze the historical change frequency of each context segment and assign a modification frequency score;

[0027] According to one or more scores of the task relevance score, the semantic similarity score, the importance score, and the modification frequency score, as well as the preset weights of the factors of task relevance, semantic similarity, importance, and modification frequency, each context fragment is weightedly scored to calculate the comprehensive score of each context fragment.

[0028] According to one embodiment, the step of filtering out target context fragments based on the comprehensive score and combining information diversity and semantic integrity to form context information includes:

[0029] Select the top N context segments with the highest comprehensive scores as the target context segments, where N is a positive integer;

[0030] Analyze the diversity of context fragments. When more than half of the top N context fragments with the highest comprehensive scores come from the same module or function, add one or more context fragments from other modules or functions with lower scores.

[0031] Analyze the semantic integrity of the context segments. When there is a segment with insufficient semantic integrity among the top N context segments with the highest comprehensive scores, introduce one or more context segments with higher scores and stronger relevance, and splice them with the segment with insufficient semantic integrity into a segment with more complete semantics.

[0032] The target context fragments are combined according to a predefined rule engine to generate context information.

[0033] According to one embodiment, identifying potential problems and generating repair suggestions includes:

[0034] Use a large language model to analyze the user's input diagnosis request and context information to identify potential problems related to the diagnosis request in the code;

[0035] Mark and categorize the identified problems, and generate a problem list and detailed description;

[0036] Generate repair suggestions using model reasoning, where the repair suggestions include one or more of code modification, optimization suggestions, and detailed explanations;

[0037] Output the problem list and the repair suggestions.

[0038] According to one embodiment, the code diagnosis method further includes: calling a multi-model dialogue, comprehensively analyzing the problem identification and repair suggestion generation results of multiple models, and providing more comprehensive and accurate repair suggestions.

[0039] According to a second aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the code diagnosis method described in the first aspect of the present invention are performed.

[0040] According to the third aspect of the present invention, there is provided a code diagnosis device, which includes a memory and a processor; the memory is used to store software applications; the processor is used to execute the software applications, and each program of the software application correspondingly executes each step of the code diagnosis method described in the first aspect of the present invention.

[0041] According to a fourth aspect of the present invention, a code diagnosis system is provided, which applies the code diagnosis method described in the first aspect of the present invention, and includes: an access layer unit, an application layer unit, and an infrastructure layer unit; the access layer unit includes a user interface module and a data interface module, and the user interface module provides an interactive interface between the user and the system; the data interface module performs code data synchronization and operation log and error report synchronization; the application layer unit includes a data preprocessing module and a large language model processing module; the data preprocessing module performs preprocessing on the collected code data, including code decomposition and information extraction, and provides formatted and integrated data for the large language model processing module; the large language model processing module uses retrieval enhancement generation technology based on the large language model to perform context information retrieval on the preprocessed code data, extracts and filters out context information related to the user diagnosis request as the input of the large language model, uses model reasoning to identify problems and generate repair suggestions, and collects user feedback for continuous optimization; the infrastructure layer unit includes a storage module and a large language model service module; the storage module stores and manages data required for system operation; the large language model service module provides a service interface for the large language model.

[0042] Technical features and beneficial effects of the present invention:

[0043] The present invention searches a large-scale code base based on a large language model in response to a user's code diagnosis request, and uses retrieval enhancement generation technology to provide the large language model with necessary and accurate context information, so that the large language model can more accurately identify potential problems in the code and automatically generate targeted repair suggestions, thereby significantly improving code quality and system stability and reducing manpower investment. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 A flowchart of the steps of a code diagnosis method provided by an embodiment of the present invention.

[0045] Figure 2 A schematic diagram of the architecture of a code diagnosis system provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods.

[0047] Embodiment 1:

[0048] like Figure 1 As shown, a code diagnosis method includes the following steps:

[0049] S101, preprocessing the code data, the preprocessing process includes code decomposition and information extraction, and generating structured data.

[0050] Among them, the code decomposition includes:

[0051] Obtain code data, including historical versions and current versions of code data;

[0052] Decompose code data into different granularities such as files, classes, functions, and logic blocks to extract code snippets;

[0053] Format code snippets, unify coding style and format, and remove redundant information, such as comments.

[0054] Among them, information extraction includes:

[0055] Extract metadata of the code snippet, including file name, class name, function name, line number, module name, author, version number, and other information associated with the code snippet;

[0056] Analyze the structure of code data and extract structural information associated with code snippets, including function call relationships, class inheritance relationships, etc.

[0057] Analyze the operation log and extract the operation information and error information related to the code snippet;

[0058] Integrate the extracted code snippets, metadata, structural information, and operation logs to generate structured data.

[0059] S102, vectorizing the structured data to construct a vector database for retrieval.

[0060] The vectorization process includes: taking each structured data as a basic unit and inputting it into the Embedding model provided by OpenAI (such as text-embedding-3-large). The model can capture the semantic features of the code snippets in the structured data and convert them into a vector representation. The feature vector will be used as the identifier of the structured data and stored in the vector database.

[0061] Among them, building a vector database also includes: creating an index structure based on feature vectors in the vector database, and using efficient retrieval algorithms such as HNSW (Hierarchical Navigable Small World). These index structures enable the system to quickly retrieve the code snippets most similar to the query vector in a huge database.

[0062] S103, using retrieval enhancement generation technology, based on the user's diagnosis request and problem site data, extracting retrieval keywords, generating query statements, converting the query statements into query vectors, searching in the vector database, and obtaining relevant context fragments.

[0063] Among them, user diagnostic requests can be divided into different task types, such as performance optimization, security check, logic error troubleshooting, etc. The problem site data can be the operation log, system diagnosis, perception results, etc. when the problem occurs. The extracted search keywords may include the module name, code file name, etc. extracted from the field data.

[0064] S104, using a scoring mechanism to score the relevant context fragments, obtaining a comprehensive score for each context fragment, and based on the comprehensive score, selecting target context fragments in combination with information diversity and semantic integrity, combining them into context information, and outputting them to the large language model.

[0065] Among them, context information can be understood as the environment information where the code is located, specifically referring to a batch of structured data including code snippets, structural information, log information, etc. retrieved by the method described in steps S103 and S104. These structured data reflect the background environment of the analyzed code problem. Each structured data is a context fragment. The target context fragments are further screened out from these retrieved context fragments, and then integrated into context information and sent to the large language model as part of the prompt to ensure that the model can fully understand the background of the current task.

[0066] The scoring mechanism is used to score the retrieved relevant context fragments to obtain a comprehensive score for each context fragment, which may include:

[0067] Based on the task type of the user's diagnosis request, assign a task relevance score to each context segment according to the task relevance. For example, when the user's diagnosis request belongs to a performance optimization task, a higher score is assigned to the context segment containing the operation log and resource usage.

[0068] Calculate the semantic similarity between the context fragment and the user query sentence, and assign a semantic similarity score to each context fragment according to the degree of similarity. The calculation method may adopt cosine similarity calculation;

[0069] Analyze the importance of each context fragment based on business logic, assign importance scores, and assign higher scores to context fragments containing code fragments of important modules such as core modules and security modules;

[0070] Analyze the historical change frequency of each context fragment, assign a modification frequency score, and assign a higher score to context fragments containing frequently modified code fragments, because frequently modified code often has more potential problems;

[0071] Then, according to the task relevance score, semantic similarity score, importance score, modification frequency score, and the preset weights of task relevance, semantic similarity, importance, and modification frequency factors, each context fragment is weightedly scored to calculate the comprehensive score of each context fragment.

[0072] Among them, based on the comprehensive score, information diversity and semantic integrity are combined to screen out target context fragments and combine them into context information, which exemplarily includes:

[0073] The top N context fragments with the highest comprehensive scores (i.e., Top-N fragments) are selected as the target context fragment output. The value of N can be adjusted according to the complexity of the task requested by the user. N can be set to 10 by default. For complex problems, the value of N can be increased. The value of N can be dynamically adjusted according to the score distribution of the context fragments. If the score difference of the Top-N fragments is very small, indicating that the relevance of these fragments is very close, the range of the value of N is expanded to ensure the integrity of the context information. If the score difference is large, the value of N is reduced and only the fragments with significantly higher scores are retained to improve the accuracy of the output information.

[0074] Analyze the diversity of context fragments. When most of the Top-N fragments come from the same module or function, introduce context fragments from other modules or functions with lower scores to increase the coverage of context information and provide more extensive background information for model analysis. For example, the system can select Top-N+M (such as N=10, M=5) fragments, where M context fragments come from different modules.

[0075] Analyze the semantic integrity of context fragments. When there are fragments with insufficient semantic integrity in the Top-N fragments, introduce one or more context fragments with higher scores and stronger relevance, and splice them into a more semantically complete fragment, thereby forming a more coherent context. For example, splice a function fragment with fragments of other related functions it calls to provide complete call chain information, and splice log information according to time series to form a complete occurrence chain of events.

[0076] The target context fragments filtered out in the above steps are combined according to the predefined rule engine to generate context information. These rules include function call order, class inheritance relationship, module dependency, etc. These rules are used to ensure that the system follows the actual logical relationship of the code during the combination process to avoid semantic conflicts.

[0077] S105, the large language model analyzes the user's diagnosis request and context information, identifies potential problems and generates repair suggestions.

[0078] Among them, the large language model can be GPT-4, LLAMA-3, Gemini, etc.

[0079] Use a large language model to analyze the input user diagnostic requests and context information to identify potential syntax errors, logic vulnerabilities, security issues, etc. related to the diagnostic requests in the code; mark and classify the identified problems, generate a problem list and detailed description; use model reasoning to generate repair suggestions, which include specific code modifications, optimization suggestions, detailed explanations, etc.; output a problem list and repair suggestions.

[0080] S106, collect user feedback and continue to optimize.

[0081] The user interface module displays a list of problems and repair suggestions to users, and collects user feedback and evaluations; based on the collected user feedback and evaluations, continuous optimization and improvement are carried out.

[0082] The code diagnosis method of the present invention preprocesses large-scale code data and combines the use of retrieval enhancement generation technology to achieve efficient retrieval of context information in a large-scale code base. It further provides necessary and accurate context information for a large language model through an effective screening algorithm, thereby improving the accuracy of problem identification and repair suggestion generation for the large language model.

[0083] Embodiment 2:

[0084] A computer-readable storage medium stores a computer program, which can execute the steps of the code diagnosis method of embodiment 1 when executed by a processor.

[0085] Embodiment 3:

[0086] A code diagnosis device includes: a memory and a processor; the memory is used to store software applications; the processor is used to execute the software applications, and each program of the software application correspondingly executes the steps in the code diagnosis method of Example 1.

[0087] Embodiment 4:

[0088] like Figure 2As shown, a code diagnosis system includes an access layer unit, an application layer unit and an infrastructure layer unit.

[0089] The access layer unit includes a user interface module and a data interface module; the user interface module provides an interactive interface between the user and the system, through which the user submits code and instructions and views system feedback; the data interface module performs code data synchronization as well as operation log and error report synchronization, and collects relevant data into the system.

[0090] The user interface module includes a Web UI page module, a command line module, a help desk management interface module and a user authentication module; the Web UI page module is used to provide a graphical user interface for users to interact with the system, so that users can access the system through a browser, submit code and view repair suggestions; the command line module is used to provide a command line interface for users to interact with the system, supports command line operations, so that users can interact with the system through command line tools, and is suitable for scripting and automation requirements; the help desk management interface module is used to provide a help desk management interface for users to interact with the system, provides technical support and user feedback management functions, and helps users solve problems during use; the user authentication module is used to perform user authentication.

[0091] The data interface module includes a code repository synchronization module and a log synchronization module; the code repository synchronization module is used to perform code repository synchronization, synchronize code data from the user's code repository, including historical versions and current versions of code, and collect the code data submitted by users into the system; the log synchronization module is used to perform log synchronization, synchronize operation logs and error reports, collect log data related to the code submitted by users into the system, and provide auxiliary information for problem identification and repair suggestion generation.

[0092] The application layer unit includes a data preprocessing module and a large language model processing module; the data preprocessing module performs preprocessing on the collected code data, including code decomposition and information extraction, and provides formatted and integrated data for the large language model processing module; the large language model processing module performs intelligent analysis on the preprocessed code data based on the large language model and retrieval enhancement generation technology, identifies problems and generates repair suggestions, collects user feedback, and continuously optimizes and enhances the analysis capabilities of the large language model.

[0093] The data preprocessing module includes a code repository decomposition module and an information extraction module.

[0094] Specifically, the code repository decomposition module is configured to perform: synchronizing code data from the data interface, the code data including historical versions and current versions of code; decomposing the code data according to different granularities such as files, classes, functions, and logic blocks, and extracting code snippets; formatting the code snippets, unifying the format, and removing redundant information.

[0095] Specifically, the information extraction module is configured to perform: extracting metadata of the code snippet, the metadata including file name, author, version number, etc.; analyzing the structure of the code data, extracting structural information associated with the code snippet, the structural information including function call relationships, class inheritance relationships, etc.; analyzing the operation log, extracting operation information and error information related to the code snippet; integrating the extracted code snippet, metadata, structural information and operation log to generate structured data; vectorizing the structured data to build a vector database for retrieval.

[0096] The large language model processing module includes a retrieval enhancement generation module, a problem identification module, a repair suggestion generation module, and a system feedback module.

[0097] Specifically, the retrieval enhancement generation module is configured to perform: using retrieval enhancement generation technology, based on user diagnostic requests and problem site data, extracting retrieval keywords, generating query statements, converting the query statements into query vectors, searching in the vector database, and obtaining relevant context fragments; using a scoring mechanism to score the relevant context fragments, obtaining a comprehensive score for each context fragment, and based on the comprehensive score, combining information diversity and semantic integrity to screen out target context fragments, combining them into context information, and outputting them to the large language model.

[0098] Specifically, the problem identification module is configured to perform the following: obtaining user diagnostic requests and related context information input; using a large language model to perform analysis to identify potential syntax errors, logic vulnerabilities, and security issues in the code that are related to the diagnostic requests; marking and classifying the identified problems, and generating a problem list and detailed description.

[0099] Specifically, the repair suggestion generation module is configured to perform the following: receiving the problem list and detailed description output by the problem identification module; using model reasoning to generate repair suggestions, which include specific steps for code modification, optimization suggestions, and detailed explanations; and outputting the problem list and repair suggestions to provide to developers for understanding and application.

[0100] Specifically, the system feedback module is configured to perform: displaying a list of problems and repair suggestions to users through the user interface module, and collecting user feedback and comments; recording user feedback and comments; and continuously optimizing and improving based on the collected user feedback and comments to improve the accuracy and effectiveness of system problem identification and repair suggestion generation.

[0101] The infrastructure layer unit includes a storage module and a large language model service module; the storage module is implemented using the Redis and Chroma storage systems, and is responsible for storing and managing the data required for system operation, including code data, context information, and repair suggestions; the large language model service module provides a multi-model service interface, which includes the GPT-4 service interface, the Gemini service interface, and the Llama3 service interface. By encapsulating different types of large models, the system can call multiple large models on demand, and support multi-model dialogues and comprehensive analysis. Multi-model dialogues include calling multi-model dialogues similar to AutoGen, integrating the analysis results of multiple models, and improving the ability and quality of problem identification and repair suggestion generation.

[0102] Specifically, the storage module includes a Redis sub-storage module and a Chroma sub-storage module; the Redis sub-storage module is used to store temporary data and cache to improve the system's response speed and data processing efficiency; the Chroma sub-storage module is used to store persistent data, including code data, context information, and repair suggestions.

[0103] Specifically, the large language model service module includes the GPT-4 service interface encapsulation module, the Gemini service interface encapsulation module and the Llama3 service interface encapsulation module; the GPT-4 service interface encapsulation module provides the GPT-4 service interface and encapsulates the GPT-4 pre-trained language model, provides large-scale pre-trained language model services, and supports the analysis and repair suggestion generation of complex code problems; the Gemini service interface encapsulation module provides the Gemini service interface and encapsulates the Gemini pre-trained language model, providing additional analysis and repair capabilities; the Llama3 service interface encapsulation module provides the Llama3 service interface and encapsulates the Llama3 pre-trained language model to further enhance the system's analysis and repair capabilities.

[0104] The code diagnosis system of the present invention is based on a large language model and combines the application of retrieval enhancement generation technology to achieve efficient retrieval of context information in a large-scale code base, providing the large language model with necessary and accurate context information, thereby improving the accuracy of problem identification and repair suggestion generation of the large language model, solving the problem that a large-scale code base cannot be input into the model at one time, and ensuring that the large language model can work effectively in a complex and dynamic code environment.

[0105] Compared with traditional static and dynamic analysis methods, large language models have stronger self-learning capabilities. The code diagnosis system of the present invention will feed back the identified problems and generated repair suggestions to the user, and collect and record the user's feedback and evaluation. Through a continuous self-learning mechanism, the system can continuously optimize and improve the ability to identify problems and generate repair suggestions, thereby improving the intelligence level of the system.

[0106] The code diagnosis system of the present invention also provides multi-model dialogue and comprehensive analysis, encapsulates different types of large language models, and supports the system's ability to call multiple large models on demand. For complex code problems, it can call multi-model dialogues similar to AutoGen, integrate the output results of multiple models, and provide more comprehensive and accurate repair suggestions, thereby improving the system's ability to solve complex problems.

[0107] It should be understood that the above is only an exemplary embodiment of the present invention, and the protection scope of the present invention is not limited thereto. Those skilled in the art can easily conceive of modifications, replacements or adaptive changes without departing from the principle and essence of the present invention, which should all be covered within the protection scope of the present invention.

Claims

1. A code diagnosis method, characterized in that: include: Preprocessing the code data to generate structured data, wherein the preprocessing includes code decomposition and information extraction; Vectorizing the structured data to construct a vector database for retrieval; Adopting the search enhancement generation technology, based on the user's diagnosis request and the problem site data, extracting the search keywords, generating the query statement, converting the query statement into a query vector, searching in the vector database, and obtaining the relevant context fragments; The relevant context fragments are scored using a scoring mechanism to obtain a comprehensive score for each context fragment, and based on the comprehensive score, target context fragments are screened out in combination with information diversity and semantic integrity, combined into context information, and output to the large language model; The large language model analyzes the user diagnosis request and the context information, identifies potential problems and generates repair suggestions.

2. The code diagnosis method according to claim 1, characterized in that: The code decomposition includes: Acquire code data, wherein the code data includes a historical version and a current version; Decomposing the code data according to different granularities of files, classes, functions, and logic blocks to extract code snippets; The code snippets are formatted to unify the format and remove redundant information.

3. The code diagnosis method according to claim 2, characterized in that: The information extraction includes: Extracting metadata of the code snippet, wherein the metadata includes file name, author, and version number; Analyze the structure of code data and extract structural information associated with code snippets, wherein the structural information includes function call relationships and class inheritance relationships; Analyze the operation log and extract the operation information and error information related to the code snippet; Integrate the extracted code snippets, metadata, structural information, and operation logs to generate structured data.

4. The code diagnosis method according to claim 1, characterized in that: The adopting of a scoring mechanism to score the relevant context fragments to obtain a comprehensive score for each context fragment includes: Based on the task type of the user's diagnosis request, assign a task relevance score to each context segment according to task relevance; Calculate the semantic similarity between the context fragment and the user query sentence, and assign a semantic similarity score to each context fragment according to the degree of similarity; Analyze the importance of each context fragment based on business logic and assign an importance score; Analyze the historical change frequency of each context segment and assign a modification frequency score; According to one or more scores of the task relevance score, the semantic similarity score, the importance score, and the modification frequency score, as well as the preset weights of the factors of task relevance, semantic similarity, importance, and modification frequency, each context fragment is weightedly scored to calculate the comprehensive score of each context fragment.

5. The code diagnosis method according to claim 1, characterized in that: The target context fragments are screened out based on the comprehensive score in combination with information diversity and semantic integrity, and combined into context information, including: Select the top N context segments with the highest comprehensive scores as the target context segments, where N is a positive integer; Analyze the diversity of context fragments. When more than half of the top N context fragments with the highest comprehensive scores come from the same module or function, add one or more context fragments from other modules or functions with lower scores. Analyze the semantic integrity of the context segments. When there is a segment with insufficient semantic integrity among the top N context segments with the highest comprehensive scores, introduce one or more context segments with higher scores and stronger relevance, and splice them with the segment with insufficient semantic integrity into a segment with more complete semantics. The target context fragments are combined according to a predefined rule engine to generate context information.

6. The code diagnosis method according to claim 1, characterized in that: Identify potential issues and generate repair suggestions, including: Use a large language model to analyze the user's input diagnosis request and context information to identify potential problems related to the diagnosis request in the code; Mark and categorize the identified problems, and generate a problem list and detailed description; Generate repair suggestions using model reasoning, where the repair suggestions include one or more of code modification, optimization suggestions, and detailed explanations; Output the problem list and the repair suggestions.

7. The code diagnosis method according to claim 1, characterized in that: Also includes: Invoke multi-model dialogue to comprehensively analyze the problem identification and repair suggestion generation results of multiple models to provide more comprehensive and accurate repair suggestions.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the code diagnosis method according to any one of claims 1 to 7 are performed.

9. A code diagnostic device, characterized in that: The device comprises a memory and a processor; The memory is used to store software applications; The processor is used to execute the software application, and each program of the software application correspondingly executes each step of the code diagnosis method described in any one of claims 1-7.

10. A code diagnosis system, characterized in that: include: An access layer unit, an application layer unit and an infrastructure layer unit; the access layer unit includes a user interface module and a data interface module, the user interface module provides an interactive interface between the user and the system; the data interface module performs code data synchronization and operation log and error report synchronization; the application layer unit includes a data preprocessing module and a large language model processing module; The data preprocessing module performs preprocessing on the collected code data, including code decomposition and information extraction, and provides formatted and integrated data for the large language model processing module; The large language model processing module is based on the large language model and adopts the retrieval enhancement generation technology to perform context information retrieval on the preprocessed code data, extract and filter out the context information related to the user's diagnosis request as the input of the large language model, use model reasoning to identify problems and generate repair suggestions, and collect user feedback for continuous optimization; the infrastructure layer unit includes a storage module and a large language model service module; the storage module stores and manages the data required for the operation of the system; the large language model service module provides a service interface for the large language model.

Citation Information

Cited By

  • Small and micro credit approver expert system and method based on large language model

    CN120088059A

  • Automatic data cleaning method and system based on large language model

    CN121455932A

  • Code task processing method and code repair method

    WO2026188951A1