Multi-round reasoning and feedback optimization method and system for industrial software codes

Through multiple rounds of inference and feedback optimization methods, a vector code library is established to perform code inference optimization and feedback optimization, which solves the existing technology in the insufficient code generation accuracy, low code snippet integration consistency, insufficient optimization capabilities of traditional compilers, and automated verification. The problem of imperfect mechanism has achieved efficient and accurate code optimization and verification.

CN119440539AActive Publication Date: 2025-02-14GUANGDONG UNIV OF PETROCHEMICAL TECH

Patent Information

Application Number
CN202411696615.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-02-14
Estimated Expiration
2044-11-25

AI Technical Summary

Technical Problem

Existing code generation and optimization technologies have problems such as insufficient accuracy, low consistency in code snippet integration, insufficient optimization capabilities of traditional compilers, and imperfect automation verification mechanisms in dealing with the development and optimization of complex industrial software.

Method used

A multi-round inference and feedback optimization method for industrial software code is proposed, and the accuracy and robustness of code generation are improved through the establishment of vector code bases, code inference optimization and feedback optimization. Specific steps include building feedback, building a vector database, summarizing format, control flow graph analysis, multi-query generation and reciprocating reorganization, inference generation subtasks, RAG cluster generation, combination completion code, scoring feedback optimization and log feedback optimization.

Benefits of technology

It significantly improves the accuracy and robustness of complex code generation, enhances the accuracy and integration of code retrieval, improves the efficiency and automation level of code optimization, and reduces development costs and error rates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440539A_ABST
    Figure CN119440539A_ABST
Patent Text Reader

Abstract

The invention belongs to but is not limited to the technical field of software development, and particularly relates to a multi-round reasoning and feedback optimization method and system for industrial software codes, and the method comprises the steps: S1, vector code library establishment: the establishment of a vector code library is composed of three parts of feedback establishment, vector database establishment and format summarization; s2, code reasoning optimization: the code reasoning optimization mainly comprises four aspects: control flow graph analysis, multi-query generation and reciprocal ranking fusion retrieval, reasoning generation subtask and code chain submodule generation, and code combination completion; and S3, feedback optimization: the feedback optimization is composed of score feedback optimization and log feedback optimization. According to the method, an automatic verification mechanism is introduced, logic consistency check and performance evaluation are carried out on the generated and optimized codes, and the correctness and execution efficiency of the codes are ensured. The verification mechanism can find and correct errors in real time in each stage of generation, so that the cost of manual verification is reduced, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to but is not limited to the field of software development technology, and in particular relates to a multi-round reasoning and feedback optimization method and system for industrial software codes. Background Art

[0002] As the complexity of software development increases, code generation and optimization technology is rapidly becoming an important research direction in the field of software engineering. Code generation and optimization methods based on large language models (LLMs) are gradually being applied to various complex development scenarios to improve the automation, readability, correctness, and efficiency of code generation. In recent years, LLM models such as GPT-4 and CodeLlama have been able to automatically generate complex code snippets by virtue of their advantages in natural language processing, and are gradually approaching or even exceeding traditional optimizing compilers in terms of performance and maintainability.

[0003] In terms of code generation, retrieval enhancement technology further improves the performance of language models in code completion tasks by introducing external knowledge bases and contextual information. Related research (such as retrieval enhancement methods based on GPT-2 and RETRO models) shows that retrieval enhancement technology can improve the accuracy and contextual consistency of code generation, especially in large projects and complex environments, retrieval enhancement becomes an efficient optimization method.

[0004] On the other hand, traditional compiler optimization technologies, such as CETUS, PLUTO, and ROSE, have long dominated the implementation of code optimization. These optimization tools help developers improve code execution efficiency and resource utilization through classic compilation optimization algorithms, such as loop optimization, parallelization, and data flow analysis. However, in the face of challenges such as modern parallel computing and dynamic workloads, the optimization capabilities of traditional compilers have gradually shown limitations and are unable to cope with complex programming requirements.

[0005] Existing code generation and optimization technologies mainly include three approaches: 1) direct code generation technology, which usually generates code in a single reasoning step by a large language model; 2) retrieval enhancement technology, which completes the code through context retrieval and external databases; 3) traditional compiler optimization technology, such as CETUS, PLUTO, etc., which uses predefined optimization rules to optimize the code structure.

[0006] 1. Direct code generation technology

[0007] This type of technology usually generates code directly from a large language model (LLM) in a single reasoning step. For example, the self-planning code generation method uses LLM to generate code by introducing two stages: planning and implementation. In the planning stage, the model generates steps for problem decomposition based on a small number of examples; in the implementation stage, the model generates code based on these steps. This approach significantly improves the accuracy of code generation in complex tasks and achieves up to 25.4% improvement in the Pass@1 metric [1]. However, when faced with very complex or large-scale code bases, its performance is still unstable. The lack of effective staged reasoning and feedback mechanisms leads to frequent erroneous codes when dealing with multi-level complex problems, and there is a lack of sufficient automated verification methods to ensure the correctness of the code.

[0008] 【1】Xue Jiang, Yihong Dong, Lecheng Wang, Fang Zheng, Qiwei Shang, Ge Li, Zhi Jin, and Wenpin Jiao. 2024. Self-planning Code Generation with Large Language Models. ACM Trans. Software. Eng. Methodol. Just Accepted (June 2024). https: / / doi.org / 10.1145 / 3672456

[0009] 2. Based on retrieval enhancement technology

[0010] Retrieval enhancement technology uses contextual retrieval and external databases to assist in enhancing the generated code. Retrieval enhancement-based methods, such as models such as GPT-2 and RETRO, have shown good performance in current code generation technologies. Through vector embedding and contextual retrieval technology, the model can extract relevant fragments from large code bases, thereby improving code quality [2]. Among them, methods such as ProCC, ReACC, and RepoCoder enhance the accuracy of code generation by retrieving code fragments and generating them in combination with contextual information. Despite this, the existing technology still has a lot of room for improvement in the accuracy of retrieval matching and the integration consistency of code fragments, especially when dealing with complex multi-language development projects, the retrieval efficiency and accuracy will be reduced.

[0011] 【2】Tan H, Luo Q, Jiang L, et al. Prompt-based Code Completion via Multi-Retrieval Augmented Generation[J]. arXiv preprintarXiv:2405.07530,2024.

[0012] 3. Classic compiler optimization techniques

[0013] Traditional compiler optimization technologies, such as CETUS, PLUTO and other tools, have excellent performance in loop optimization, parallel computing, etc. The core is program optimization transformations, the purpose of which is to replace the original program with a new program that consumes less resources, runs in a shorter time, but is semantically equivalent to the original program.

[0014] In view of the above analysis of related technologies, the technical problems that need to be urgently solved in the existing technologies are: although the existing code generation and optimization methods have achieved certain results, they still have the following main shortcomings and deficiencies in the process of dealing with complex industrial software development and optimization:

[0015] 1. Limitations of direct code generation technology in optimizing industrial software code tasks:

[0016] Although direct code generation can handle routine code tasks well, when dealing with complex optimization problems, the accuracy of the code generated from the original code is often not high, and there is a lack of effective mechanisms to analyze the problem and optimize each part of the code. In addition, existing methods mostly rely on a single generation process and cannot effectively verify and optimize the generation results, resulting in the regenerated code still having deficiencies in performance and maintainability.

[0017] 2. Insufficiency of existing search enhancement technologies in dealing with industrial software code optimization tasks:

[0018] Although the performance of existing retrieval enhancement technologies in assisting general code tasks has been improved, the accuracy of retrieval is limited by the context analysis capabilities of existing models when dealing with complex code structures and industrial software code optimization tasks in large-scale projects. In addition, the integration consistency between the retrieved code snippets and the current development environment is often low, which makes it easy for the retrieved code to be incompatible or have logical errors when it is actually incorporated into the original code process.

[0019] 3. Limitations of traditional compiler optimization tools:

[0020] Although traditional compilers such as CETUS and PLUTO have certain automation capabilities in code optimization, their optimization methods are relatively static and cannot adapt to the needs of modern complex parallel computing environments. Faced with dynamically changing workloads, the optimization effect of existing compilers is limited, and the optimization process usually requires a lot of manual configuration, which is difficult to meet the automation needs in actual development.

[0021] 4. Limitations of automated verification mechanisms:

[0022] Existing code tasks lack a complete automated verification method, which makes it difficult to ensure the accuracy and performance of the optimized code. Especially when the code size and complexity increase, manual verification is inefficient and has a high error rate. Summary of the invention

[0023] In view of the problems existing in the prior art, the present invention provides a multi-round reasoning and feedback optimization method and system for industrial software code.

[0024] The present invention is implemented as follows: a multi-round reasoning and feedback optimization method for industrial software code, comprising:

[0025] S1, vector code library establishment: the establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format;

[0026] S2, code reasoning optimization: In code reasoning optimization, there are four main components: control flow graph (CFG) analysis, multi-query generation and reciprocal ranking (RRF) fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion;

[0027] S3, feedback optimization: Feedback optimization consists of scoring feedback optimization and log feedback optimization.

[0028] Furthermore, S1 specifically includes:

[0029] S101, construct feedback: divide the function blocks in the relevant industrial software code files, use the large model to actively retrieve and analyze the blocks in the process, and generate and construct feedback information.

[0030] The feedback structure is as follows:

[0031] 1. Potential errors: Feedback code potential errors and exceptions

[0032] 2. Execution results: feedback code execution results

[0033] 3. Function description: gives the function's function, input, output and workflow

[0034] 4. Improvement suggestions: Provide some optimization suggestions for this function

[0035] Feedback can make it easier for queries to find corresponding function blocks, and can also provide assistance for subsequent code optimization and improve the performance of generated optimized code.

[0036] S102, build function block code library:

[0037] Based on previous feedback and the divided code blocks, an embedding model is used to build a vector database for improved query generation and information retrieval.

[0038] S103, summary format:

[0039] Based on the code file content of the industrial software, the relevant unified format of the software is summarized for subsequent code merging.

[0040] Furthermore, S2 specifically includes:

[0041] S201, generate a control flow graph (CFG) based on the syntax tree (AST):

[0042] First, the function analysis code is called to generate an abstract syntax tree, and then the control flow graph is generated through the abstract syntax tree. By subsequently analyzing the control flow graph of the code, the system can identify potential logic errors, redundant paths, and optimization opportunities.

[0043] S202, retrieval by multi-query generation and reciprocal ranking fusion: Multi-query generation and reciprocal ranking fusion (RRF) technology is used to ensure that more comprehensive and accurate query results can be retrieved in the subsequent RAG clustering generation process. This technology generates multiple related queries based on the initial query, and uses RRF to fuse each result to generate the final ranking result.

[0044] Multiple query generation:

[0045] Multi-query generation refers to the generation of multiple related but different queries by the large model based on the initial query.

[0046] Improve search diversity: Generate multiple related queries to avoid insufficient information from a single query and cover a wider range of information.

[0047] Enhance answer relevance: Through multi-query generation, the matching degree between the final result and the user's intent is improved.

[0048] Reciprocal Rank Fusion (RRF):

[0049] Reciprocal rank fusion works by taking search results from multiple methods, assigning a reciprocal rank score to each document in the results, and then combining those scores to create a new rank. The concept is that documents that appear in the top positions in multiple search methods are likely to be more relevant and should therefore be ranked higher in the combined results.

[0050] Result fusion: By performing inverse ranking fusion on multiple parallel query results, we ensure that the results with higher rankings have more weight in the final results.

[0051] Quality improvement: RRF can optimize the code based on high-quality search results without adjusting the parameters of the original model.

[0052] S203, reasoning to generate subtasks: Use reasoning structure to generate task modules, decompose complex tasks into multiple submodules, and optimize the code through multiple code chain generation and clustering mechanisms. The specific steps include extracting the generated submodules, clustering them, and selecting representative modules as the basis for optimization to ensure the high quality and reusability of the generated code.

[0053] S204, RAG cluster generation:

[0054] Clustering is to divide similar objects into different groups or more subsets through static classification methods, so that member objects in the same subset have similar properties, commonly including shorter spatial distances in the coordinate system.

[0055] Retrieval Augmented Generation (RAG), takes an input and retrieves a set of relevant / supporting documents from a given source (e.g. Wikipedia). These documents are concatenated with the original input prompt as context and fed into a text generator that produces the final output. This allows RAG to adapt to situations where facts may change over time. While the parameter knowledge of LLMs is static, RAG allows the language model to bypass retraining, enabling access to the latest information to generate reliable output through retrieval-based generation.

[0056] At the beginning of each round, the present invention uses RAG combined with the above-mentioned multi-query generation and reciprocal ranking fusion retrieval method, takes the subtask as the retrieval input, and retrieves the function block vector database. The retrieval results and subtask descriptions are input into the large model, and N generation is performed. Then, the generated submodules are clustered by the K-means clustering method, and the central submodule is extracted as a representative sub-code block. This is one round, and a total of M rounds are performed.

[0057] S205, combination completion code

[0058] The present invention first adds an error feedback mechanism to the sub-code blocks, and then combines the sub-modules into the final code according to the code format.

[0059] Error feedback: In each submodule, the present invention designs a detailed error detection and return mechanism to ensure that the system can provide timely feedback when problems are found. When each submodule is subsequently executed, if an error is encountered, a specific error code or error message will be returned, which will be used for logging and subsequent analysis.

[0060] Furthermore, the reasoning method in S203 specifically includes:

[0061] 1. Selection: Select the reasoning modules related to task solving from the reasoning module description set (not every reasoning module is useful for every task);

[0062] Given an original set of reasoning module descriptions, such as "critical thinking" and "decomposing problems into sub-problems", we first select useful reasoning module descriptions from the subset of reasoning modules using the model and the prompt words.

[0063] 2. Adaptation: Since each reasoning module provides a general description of how to solve the problem, the next step is to customize the description adaptively based on the input for each selected module.

[0064] 3. Implementation: Based on the adjusted reasoning module description, the reasoning module is converted into an implemented reasoning structure, which clearly states what to generate at each step.

[0065] 4. Processing tasks: Attach the reasoning structure to all instances of the task and prompt the model to follow the reasoning structure to generate subtask modules.

[0066] Furthermore, S3 specifically includes:

[0067] S301, rating feedback optimization

[0068] The present invention comprehensively evaluates the generated optimized code through multiple generation scoring and feedback mechanisms, and ensures the accuracy of the scoring results through multi-evidence calibration (MEC) and balanced position calibration (BPC) technology. And through comprehensive feedback, it ensures that the feedback and optimization corrections are more targeted.

[0069] Multiple Evidence Calibration (MEC): The system generates explanatory evidence and then scores the code based on that evidence, ensuring that the score is consistent with the evidence.

[0070] Balanced Position Calibration (BPC): By swapping the response positions, this ensures that there is no bias in the comparison process, ultimately generating more accurate scoring results.

[0071] Comprehensive feedback return: By summarizing the key points of multiple feedbacks, the feedback input for re-optimizing the code is more instructive.

[0072] Correct the code: The code is corrected by the large model based on the comprehensive feedback and then re-scored

[0073] S302, log feedback optimization

[0074] The log module of the present invention is used to analyze the feedback information during the execution of industrial software. If it is correct, the optimization is completed. If it is an error, it is analyzed in combination with the log of software feedback to generate a detailed error report, guide re-optimization, and then run again.

[0075] Error classification and logging: The system classifies the errors in the logs and generates detailed error reports for error cause analysis.

[0076] Automated verification: Automatically run the optimized code to verify whether the problem is effectively solved.

[0077] Another object of the present invention is to provide a multi-round reasoning and feedback optimization system for industrial software code that implements the multi-round reasoning and feedback optimization method for industrial software code, comprising:

[0078] Vector code library establishment module: The establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format;

[0079] Code reasoning optimization module: Code reasoning optimization mainly consists of four aspects: control flow graph (CFG) analysis, multi-query generation and reciprocal ranking (RRF) fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion;

[0080] Feedback optimization module: Feedback optimization consists of rating feedback optimization and log feedback optimization.

[0081] Another object of the present invention is to provide a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the multi-round reasoning and feedback optimization method of the industrial software code.

[0082] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, enables the processor to execute the steps of the multi-round reasoning and feedback optimization method of the industrial software code.

[0083] Another object of the present invention is to provide an information data processing terminal, which includes the multi-round reasoning and feedback optimization method system of the industrial software code.

[0084] In combination with the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solutions to be protected by the present invention are as follows:

[0085] First, in view of the shortcomings of the prior art, the present invention proposes a code optimization system based on natural language reasoning and feedback, aiming to solve the following technical problems:

[0086] 1. Solve the limitations of direct code generation technology:

[0087] The present invention significantly improves the accuracy and robustness of complex code generation by introducing a phased reasoning and feedback mechanism. By performing phased reasoning and decomposing complex problems during the code generation process, the correctness of the generated code at each stage is ensured. Phased reasoning: When faced with highly nested logical structures, the prior art is prone to generate code that does not meet expectations, resulting in logical errors or performance bottlenecks when the program is running. Therefore, the present invention reasoned and analyzed the complex code generation process and correctly decomposed it into multiple stages, each of which focuses on solving logical problems at a specific level or direction. For example, when generating recursive algorithms or complex state machines, the prior art is difficult to ensure the correctness of each layer of logic, resulting in crashes or dead loops in the generated code during execution. Our method reasoned and planned out related function methods that first generated basic recursive logic and then gradually added boundary conditions and optimization strategies. Feedback mechanism: During the code generation process, the present invention calibrates errors in the generation process in real time through a feedback mechanism. For example, when generating multi-threaded code, the prior art is prone to resource competition and deadlock problems, resulting in system instability. Our generation method evaluates the generated code through two-step feedback (scoring feedback and log feedback after automated operation). If problems such as resource competition are found, the feedback content will be used to automatically adjust the thread synchronization strategy to ensure that the generated code is more stable and reliable during concurrent execution.

[0088] 2. Solve the shortcomings of retrieval enhancement technology:

[0089] The present invention enhances the accuracy of code retrieval by optimizing vector embedding and context retrieval algorithms. By introducing a more intelligent RRF+ multi-retrieval fusion mechanism, it is possible to accurately identify code snippets related to the current context and reduce incompatibility issues. When performing vector retrieval on a code database, the prior art often only compares a corresponding input content based on similarity, resulting in the corresponding related code vector being difficult to retrieve. For example, when dealing with multi-level nested code structures, a single vector retrieval method is difficult to capture the complex relationship between code snippets, resulting in the found code being incompatible with the original code.

[0090] 3. Solve the limitations of traditional compiler optimization tools:

[0091] The present invention automates the code optimization process through a feedback mechanism, and can flexibly adjust the optimization strategy according to the feedback. Under given conditions (score threshold / whether there is error feedback), the judgment is automatically made, reducing the dependence of traditional compiler optimization tools on manual work, that is, the code is optimized during compilation, and then the developer needs to manually adjust the optimization parameters according to the specific task requirements. The present invention automatically adjusts the optimization code according to the set condition threshold, thereby improving the robustness of the system.

[0092] Second, the advantages of the present invention include:

[0093] 1. Improve the accuracy and robustness of code optimization

[0094] The existing method of directly regenerating from the original code is prone to generating incomplete or erroneous code in complex tasks, and lacks a verification mechanism. The present invention decomposes complex problems by introducing a phased reasoning and feedback mechanism, and implements calibration and automated verification at each stage to ensure that the generated code remains logically consistent and correct. The reasoning results of each stage are adjusted through feedback to avoid the accumulation and amplification of errors.

[0095] For example, in a multi-step reasoning task, the system will first generate a preliminary code framework and refine each module in the subsequent stages to ensure that the execution logic of each step is verified. This mechanism significantly reduces the error rate in code generation and improves the robustness and overall performance of the code. In addition, the automated feedback mechanism reduces the need for manual intervention and significantly shortens the development cycle and cost.

[0096] 2. Optimize the integration and effectiveness of search enhancement technology

[0097] When dealing with complex code projects, the existing search enhancement technology has low matching and integration between the search results and the context, which affects the usability of the retrieved code. The present invention enhances the relevance of the search fragments to the current development environment by improving the search technology. The introduced RRF (search fusion ranking) and multiple feedback mechanisms ensure a high degree of matching and consistency between the retrieved code and the context. For example, when the system retrieves multiple related code fragments, the RRF mechanism can better sort and select these fragments, giving priority to the parts that are most compatible with the current logic.

[0098] 3. Improve code optimization efficiency

[0099] Traditional compiler optimization tools, such as CETUS and PLUTO, have functions such as loop optimization, but they are mostly static optimizations and are difficult to cope with complex dynamic workloads. The present invention combines multiple feedback optimization mechanisms to dynamically adjust the optimization strategy according to the actual task. This allows the code to be optimized not only during compilation, but also after running, it can be dynamically adjusted according to the feedback content, thereby further improving the execution efficiency of the code. For example, in a highly concurrent distributed system, the system will adjust the execution path and optimization strategy of the code in real time according to the load conditions of different tasks, ensuring that the optimal execution efficiency can be maintained under different tasks.

[0100] 4. Reduce costs and improve user convenience

[0101] Existing compiler tools often require manual tuning in complex environments, which increases development costs and debugging time. The present invention greatly reduces the reliance on manual debugging by providing automated code generation, optimization, and verification processes. For example, users can automatically adjust optimization strategies through simple configurations, such as specifying the number of iterations, enabling optimization of specific modules, etc., to meet the personalized needs of specific projects. This greatly reduces the threshold for use, and developers can obtain optimization effects without having to master complex compiler tuning techniques, effectively improving the convenience of operation.

[0102] 5. Enhance automated verification methods to ensure code reliability

[0103] Current code generation and optimization tools lack an automated verification mechanism, resulting in uncertainty in code performance and correctness. The present invention introduces an automated verification mechanism to conduct a comprehensive inspection of the quality, functionality, structure and readability of the optimized code to ensure that it meets the goals of the optimization task. The verification mechanism combined with CFG and error feedback can quickly locate the potential errors of each function, and make corrections based on the feedback content, thereby ensuring the reliability and efficiency of the code in actual operation, reducing the burden of manual testing and improving production quality. For example, when generating a large-scale data processing algorithm, the automated verification mechanism will evaluate the processing speed and resource utilization of the code feedback under the corresponding set data volume, and change the corresponding processing function when necessary to ensure that the optimized code is efficient and stable in actual operation.

[0104] 6.Flexibility to adapt to different project needs

[0105] The present invention provides a variety of flexible configurable modules, which can not only adapt to code generation tasks of different scales and complexities, but also be customized and optimized according to specific project requirements. Whether it is the code generation method, reasoning strategy, or verification mechanism, it can be adjusted through simplified configuration. This flexibility enables the present invention to perform well when dealing with projects in different languages ​​and different architectures, and is suitable for a variety of software development scenarios, thereby improving production efficiency and code maintainability. For example, when dealing with large-scale data processing tasks, developers can change the corresponding scoring feedback mechanism to ensure its ability to handle actual large-scale data; when dealing with highly concurrent tasks, developers can adjust the customized tasks of the reasoning module to focus more on optimizing stability and efficiency during concurrent execution.

[0106] Third, as auxiliary evidence of the inventiveness of the claims of the present invention, it is also reflected in the following important aspects:

[0107] (1) The expected benefits and commercial value of the technical solution of the present invention after transformation are:

[0108] Improve development efficiency: Traditional code development and optimization processes usually require developers to spend a lot of time on code review, error troubleshooting, and performance tuning. This invention greatly shortens the development cycle and reduces labor costs by automating code generation, reasoning, and optimization. Developers can focus more on the implementation of core business functions, thereby improving overall productivity.

[0109] Reduce error rate: This invention effectively reduces code errors and potential risks in the development process through multiple feedback optimization mechanisms. Since errors are discovered and fixed in the generation stage, the number of bugs and operational anomalies encountered by the product after it goes online will be greatly reduced, thereby improving the stability and reliability of the software.

[0110] Save maintenance costs: Maintenance costs often account for a large proportion of the software life cycle. Through the feedback optimization mechanism of the present invention, the code can be continuously improved and optimized, reducing the subsequent maintenance workload. Functions such as error reporting and automatic log analysis further simplify the process of problem location and repair, reducing the difficulty and cost of maintenance.

[0111] Market competitive advantage: Since the present invention improves the efficiency of code generation and optimization, enterprises can launch high-quality software products faster and seize market opportunities. In addition, the optimized code has better performance and stability, which helps to improve user satisfaction and market competitiveness, thereby bringing more business opportunities and benefits to enterprises.

[0112] (2) The technical solution of the present invention fills the technical gap in the industry at home and abroad:

[0113] Difficulty in large-scale code retrieval and optimization: Facing a huge code base, traditional retrieval methods are often inefficient and difficult to accurately find the function blocks that need to be optimized. The present invention uses active retrieval technology to build a vector code library, which can quickly and accurately retrieve and analyze large-scale codes, significantly improving retrieval efficiency and optimization accuracy.

[0114] Innovative multi-query fusion technology: The reciprocal ranking fusion technology (RRF) used in this invention ensures that the results in code retrieval are more comprehensive and accurate. This multi-query generation and fusion technology is applied for the first time in the field of industrial software optimization, solving the problems of single traditional query method and insufficient information coverage.

[0115] (3) The technical solution of the present invention solves the technical problems that people have been eager to solve but have never been able to solve successfully:

[0116] Complex code error troubleshooting: In large-scale code bases, error location, debugging, and repair are often time-consuming and complex processes. In particular, potential errors hidden in complex code logic are usually difficult to find in the early stages. The present invention can find potential logic errors and optimization opportunities at the code generation stage through automated control flow graph (CFG) generation and analysis, solving this technical problem that has long plagued developers.

[0117] Lack of effective code optimization methods: Existing code optimization often relies on the experience and manual judgment of developers, which is inefficient and difficult to guarantee the optimization effect. The present invention decomposes complex tasks into multiple subtask modules by generating subtasks through reasoning, and selects representative modules through clustering method, thus realizing the automation and systematization of code optimization.

[0118] Imperfect feedback mechanism: In the traditional development process, error feedback is often passive and delayed, and developers are usually required to analyze the error logs themselves after the code is executed. This approach is not only inefficient, but may also cause potential errors to be ignored. The present invention can actively detect and feedback error information through a multi-round feedback mechanism, solving the long-standing problem that the feedback mechanism is not smart and timely enough.

[0119] Difficulty in handling complex code logic and large-scale code generation: In industrial software development, complex code logic and large-scale code generation have always been difficult technical challenges to overcome. This invention introduces inference modules, code chain generation and other technologies to achieve automatic decomposition and code generation of complex logic, effectively overcoming this bottleneck.

[0120] (4) The technical solution of the present invention overcomes technical prejudice:

[0121] Subjectivity and bias of the scoring system: In the process of code optimization, scoring and evaluation are often affected by subjective factors, making it difficult to maintain objectivity and consistency. This invention ensures the fairness and accuracy of the scoring process through multi-evidence calibration (MEC) and balanced position calibration (BPC) technology, overcoming the bias problem in subjective scoring.

[0122] Insufficient information coverage during the query process: Traditional single query methods are often not comprehensive in terms of information coverage, which can easily lead to inaccurate or incomplete search results. The present invention uses multi-query generation technology to generate multiple related queries from different query angles and merge multiple results, thus avoiding the technical bias of insufficient information coverage.

[0123] Fixed template thinking in code generation: Many code generation tools use fixed templates, which leads to a lack of flexibility in the generated code and the inability to meet the needs of different scenarios. This invention generates subtasks and code chain submodules by reasoning, combined with multiple rounds of generation and cluster analysis, to ensure the diversity and flexibility of the generated code, effectively overcoming the limitations of template thinking.

[0124] The singleness of feedback optimization: Traditional code feedback optimization is often limited to static analysis, ignoring potential problems in dynamic execution. This invention combines scoring feedback optimization with log feedback optimization to achieve multi-dimensional optimization of the code, ensuring the adaptability and stability of the code in different execution environments and avoiding technical bias. BRIEF DESCRIPTION OF THE DRAWINGS

[0125] Figure 1 It is a flow chart of a multi-round reasoning and feedback optimization method for industrial software code provided by an embodiment of the present invention;

[0126] Figure 2 It is a detailed flow chart of the multi-round reasoning and feedback optimization method for industrial software code provided by an embodiment of the present invention;

[0127] Figure 3 It is a structural diagram of a multi-round reasoning and feedback optimization system for industrial software codes provided by an embodiment of the present invention;

[0128] Figure 4 This is a physical picture of aluminum block identification provided by an embodiment of the present invention;

[0129] Figure 5 This is an aluminum block shape recognition data diagram provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0130] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0131] like Figure 1 As shown, a multi-round reasoning and feedback optimization method for industrial software code provided by an embodiment of the present invention includes:

[0132] S1, vector code library establishment: the establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format;

[0133] S2, code reasoning optimization: In code reasoning optimization, there are four main aspects: control flow graph analysis, multi-query generation and inverse ranking fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion;

[0134] S3, feedback optimization: Feedback optimization consists of scoring feedback optimization and log feedback optimization.

[0135] The S1 provided in the embodiment of the present invention specifically includes:

[0136] S101, construct feedback: divide the function blocks in the relevant industrial software code files, use the big model to actively retrieve the analysis blocks in the process, generate and construct feedback information;

[0137] Feedback composition:

[0138] Potential errors: Feedback code potential errors and exceptions;

[0139] Execution result: feedback the execution result of the code;

[0140] Function description: gives the function's function, input, output and workflow;

[0141] Improvement suggestions: Provide some optimization suggestions for this function;

[0142] S102, build function block code library:

[0143] Based on previous feedback and the partitioned code blocks, we use the embedding model to build a vector database for improved query generation and information retrieval.

[0144] S103, summary format:

[0145] Based on the code file content of the industrial software, the relevant unified format of the software is summarized for subsequent code merging.

[0146] S2 provided in the embodiment of the present invention specifically includes:

[0147] S201, generating a control flow graph according to the syntax tree: first calling a function to analyze the code to generate an abstract syntax tree, and then generating a control flow graph through the abstract syntax tree; subsequently, by analyzing the control flow graph of the code, the system can identify potential logic errors, redundant paths and optimization opportunities;

[0148] S202, multi-query generation and inverse ranking fusion retrieval: Multi-query generation and inverse ranking fusion technology are used to ensure that more comprehensive and accurate query results can be generated during the retrieval process. This technology generates multiple related queries based on the initial query, and uses RRF to fuse each result to generate the final ranking result;

[0149] S203, reasoning to generate subtasks: using reasoning structures to generate task modules, decomposing complex tasks into multiple submodules, and optimizing the code through multiple code chain generation and clustering mechanisms. The specific steps include extracting the generated submodules, clustering them, and selecting representative modules as the basis for optimization to ensure the high quality and reusability of the generated code;

[0150] S204, RAG cluster generation:

[0151] Clustering is to divide similar objects into different groups or more subsets through static classification methods, so that the member objects in the same subset have similar properties, commonly including shorter spatial distances in the coordinate system;

[0152] Retrieval-augmented generation, accepts input and retrieves a set of relevant / supporting documents from a given source. These documents are connected to the original input prompt as context and input to a text generator that produces the final output. This allows RAG to adapt to situations where facts may change over time; RAG allows the language model to bypass retraining, allowing access to the latest information, thereby generating reliable output through retrieval-based generation; in each round, RAG is used to use a fusion retrieval method, taking the subtask as the retrieval input and retrieving the function block vector database. The retrieval results and subtask descriptions are input into the large model for N generation, and then the generated submodules are clustered through the K-means clustering method, and the central submodule is extracted as a representative sub-code block. This is one round, and a total of M rounds are performed;

[0153] S205, combining the completed code: firstly, adding an error feedback mechanism to the sub-code block, and then combining the sub-modules into the final code according to the code format;

[0154] Error feedback: In each submodule, a detailed error detection and return mechanism is designed to ensure that the system can provide timely feedback when problems are found. When each submodule is subsequently executed, if an error is encountered, a specific error code or error message will be returned, which will be used for logging and subsequent analysis.

[0155] The reasoning method in S203 provided in the embodiment of the present invention specifically includes:

[0156] 1. Selection: Select the reasoning module related to task solving from the reasoning module description set;

[0157] Given an original set D of reasoning module descriptions, including “critical thinking” and “decomposing problems into sub-problems”, and some unlabeled task examples ti∈T, we first select useful reasoning modules DS from the subset of reasoning modules using the model M and meta-hint pS;

[0158] 2. Adaptive: Since each reasoning module provides a general description of how to solve the problem, the next step is to customize each selected module adaptively based on the input;

[0159] 3. Implementation: Based on the adjusted reasoning module description DA, the reasoning module is converted into an implemented reasoning structure DI, which clearly describes what to generate at each step. In addition to the meta-prompt pI, IMPLEMENT also provides a demonstration of the reasoning structure Shuman written by humans on another task to better convert natural language descriptions into reasoning structures;

[0160] 4. Processing tasks: Attach the reasoning structure to all instances of the task and prompt the model to follow the reasoning structure to generate subtask modules.

[0161] S3 specifically includes:

[0162] S301, rating feedback optimization:

[0163] The generated optimized code is comprehensively evaluated through multiple generation scoring and feedback mechanisms, and the accuracy of the scoring results is ensured through multi-evidence calibration and balanced position calibration technology; comprehensive feedback is then used to ensure that the feedback and optimization corrections are more targeted;

[0164] Multiple evidence calibration: The system generates explanatory evidence and then scores the code based on this evidence, ensuring that the score is consistent with the evidence;

[0165] Balanced position calibration: By exchanging the response positions, it ensures that there is no bias in the comparison process, and ultimately generates more accurate scoring results;

[0166] Comprehensive feedback: By summarizing the key points of multiple feedbacks, the feedback input for re-optimizing the code is more instructive;

[0167] Correcting the code: The code is corrected by the big model based on the comprehensive feedback and then re-scored;

[0168] S302, log feedback optimization: the log module is used to analyze the feedback information during the execution of the industrial software. If it is correct, the optimization is completed. If it is wrong, it is analyzed in combination with the log of the software feedback, and a detailed error report is generated to guide re-optimization before running;

[0169] Error classification and logging: The system classifies the errors in the log and generates a detailed error report for error analysis;

[0170] Automated verification: Automatically run the optimized code to verify whether the problem is effectively solved;

[0171] like Figure 3As shown, a multi-round reasoning and feedback optimization system for industrial software code provided by an embodiment of the present invention includes:

[0172] Vector code library establishment module: The establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format;

[0173] Code reasoning optimization module: Code reasoning optimization mainly consists of four aspects: control flow graph analysis, multi-query generation and inverse ranking fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion;

[0174] Feedback optimization module: Feedback optimization consists of rating feedback optimization and log feedback optimization.

[0175] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the multi-round reasoning and feedback optimization method of the industrial software code.

[0176] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor executes the steps of the multi-round reasoning and feedback optimization method of the industrial software code.

[0177] An information data processing terminal includes the multi-round reasoning and feedback optimization method system of industrial software code.

[0178] The present invention is specifically implemented:

[0179] like Figure 2 As shown, 1. Method

[0180] The main processes in the method of the present invention are divided into four processes: vector code library establishment, code reasoning optimization and feedback optimization.

[0181] 1.1. Establishment of vector code library

[0182] The establishment of the vector code library consists of three parts: building feedback, building a vector database, and summarizing the format.

[0183] 1.1.1 Build Feedback

[0184] The present invention divides function blocks from relevant industrial software code files, uses a large model to actively retrieve and analyze blocks during the process, and generates and constructs feedback information.

[0185] Feedback composition:

[0186] Potential errors: Feedback code that may have potential errors and exceptions

[0187] Execution result: feedback code execution result

[0188] Function description: gives the function's function, input, output, and workflow

[0189] Improvement suggestions: Provide some optimization suggestions for this function

[0190] Feedback can make it easier for queries to find corresponding function blocks, and can also provide assistance for subsequent code optimization and improve the performance of generated optimized code.

[0191] 1.1.2 Build function block code library:

[0192] The present invention constructs a vector database based on previous feedback and divided code blocks using an embedding model to improve query generation and information retrieval.

[0193] 1.1.3 Summary format:

[0194] The present invention summarizes the relevant unified format of the software according to the code file content of the industrial software for use in subsequent merged codes.

[0195] 1.2 Code Reasoning Optimization

[0196] There are four main aspects in code reasoning optimization: control flow graph (CFG) analysis, multi-query generation and reciprocal ranking (RRF) fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion.

[0197] 1.2.1 Generate Control Flow Graph (CFG) from Syntax Tree (AST)

[0198] Abstract Syntax Tree (AST) is an abstract representation of the syntax structure of source code. It represents the syntax structure of a programming language in a tree-like form, and each node in the tree represents a structure in the source code.

[0199] Control-flow graph (CFG) is the core technology for systematic analysis of code execution paths. It uses the mathematical representation of graphs to mark all the paths taken during the execution of a computer program.

[0200] First, the function analysis code is called to generate an abstract syntax tree, and then the control flow graph is generated through the abstract syntax tree. By subsequently analyzing the control flow graph of the code, the system can identify potential logic errors, redundant paths, and optimization opportunities.

[0201] 1.2.2 Multi-query generation and inverse ranking fusion retrieval

[0202] The present invention adopts multi-query generation and reciprocal ranking fusion (RRF) technology to ensure that more comprehensive and accurate query results can be generated during the retrieval process. The technology generates multiple related queries based on the initial query, and uses RRF to fuse the results to generate the final ranking result.

[0203] Multiple query generation:

[0204] Multi-query generation refers to the generation of multiple related but different queries by the large model based on the initial query.

[0205] Improve search diversity: Generate multiple related queries to avoid insufficient information from a single query and cover a wider range of information.

[0206] Enhance answer relevance: Through multi-query generation, the matching degree between the final result and the user's intent is improved.

[0207] Reciprocal Rank Fusion (RRF):

[0208] Reciprocal rank fusion works by taking search results from multiple methods, assigning a reciprocal rank score to each document in the results, and then combining those scores to create a new rank. The concept is that documents that appear in the top positions in multiple search methods are likely to be more relevant and should therefore be ranked higher in the combined results.

[0209] Result fusion: By performing inverse ranking fusion on multiple parallel query results, we ensure that the results with higher rankings have more weight in the final results.

[0210] Quality improvement: RRF can generate high-quality retrieval results without excessive parameter tuning.

[0211] 1.2.3 Reasoning Generation Subtask

[0212] The present invention uses the reasoning structure to generate task modules, decomposes complex tasks into multiple submodules, and optimizes the code through multiple code chain generation and clustering mechanisms. The specific steps include extracting the generated submodules, clustering them, and selecting representative modules as the basis for optimization to ensure the high quality and reusability of the generated code.

[0213] Reasoning method:

[0214] 1. Selection: Select the reasoning modules related to task solving from the reasoning module description set (not every reasoning module is useful for every task);

[0215] Given an original set of reasoning module descriptions, such as "critical thinking" and "decomposing problems into sub-problems", we first select useful reasoning module descriptions from the subset of reasoning modules using the model and the prompt words.

[0216] 2. Adaptation: Since each reasoning module provides a general description of how to solve the problem, the next step is to customize the description adaptively based on the input for each selected module.

[0217] 3. Implementation: Based on the adjusted reasoning module description, the reasoning module is converted into an implemented reasoning structure, which clearly states what to generate at each step.

[0218] 4. Processing tasks: Attach the reasoning structure to all instances of the task and prompt the model to follow the reasoning structure to generate subtask modules.

[0219] 1.2.4RAG cluster generation:

[0220] Clustering is to divide similar objects into different groups or more subsets through static classification methods, so that member objects in the same subset have similar properties, commonly including shorter spatial distances in the coordinate system.

[0221] Retrieval Augmented Generation (RAG), takes an input and retrieves a set of relevant / supporting documents from a given source (e.g. Wikipedia). These documents are concatenated with the original input prompt as context and fed into a text generator that produces the final output. This allows RAG to adapt to situations where facts may change over time. This is very useful because the parameter knowledge of LLMs is static. RAG allows the language model to bypass retraining, thus being able to access the latest information and thus generate reliable output through retrieval-based generation.

[0222] The present invention uses RAG in each round, uses a fusion retrieval method, takes subtasks as retrieval input, and retrieves the function block vector database. The retrieval results and subtask descriptions are input into the large model, and N generation is performed. Then, the generated submodules are clustered by the K-means clustering method, and the central submodule is extracted as a representative sub-code block. This is one round, and a total of M rounds are performed.

[0223] 1.2.5 Combination completion code

[0224] The present invention first adds an error feedback mechanism to the sub-code blocks, and then combines the sub-modules into the final code according to the code format.

[0225] Error feedback: In each submodule, the present invention designs a detailed error detection and return mechanism to ensure that the system can provide timely feedback when problems are found. When each submodule is subsequently executed, if an error is encountered, a specific error code or error message will be returned, which will be used for logging and subsequent analysis.

[0226] 1.3 Feedback Optimization

[0227] Feedback optimization consists of score feedback optimization and log feedback optimization.

[0228] 1.3.1 Rating feedback optimization

[0229] The present invention comprehensively evaluates the generated optimized code through multiple generation scoring and feedback mechanisms, and ensures the accuracy of the scoring results through multi-evidence calibration (MEC) and balanced position calibration (BPC) technology. And through comprehensive feedback, it ensures that the feedback and optimization corrections are more targeted.

[0230] Multiple Evidence Calibration (MEC): The system generates explanatory evidence and then scores the code based on that evidence, ensuring that the score is consistent with the evidence.

[0231] Balanced Position Calibration (BPC): By swapping the response positions, this ensures that there is no bias in the comparison process, ultimately generating more accurate scoring results.

[0232] Comprehensive feedback return: By summarizing the key points of multiple feedbacks, the feedback input for re-optimizing the code is more instructive.

[0233] Correct the code: The code is corrected by the large model based on the comprehensive feedback and then re-scored

[0234] 1.3.2 Log feedback optimization

[0235] The log module of the present invention is used to analyze the feedback information during the execution of industrial software. If it is correct, the optimization is completed. If it is an error, it is analyzed in combination with the log of software feedback to generate a detailed error report, guide re-optimization, and then run again.

[0236] Error classification and logging: The system classifies the errors in the logs and generates detailed error reports for error cause analysis.

[0237] Automated verification: Automatically run the optimized code to verify whether the problem is effectively solved.

[0238] Code optimization step flow (including reasoning and feedback):

[0239] 1. Input original code and natural language optimization requirements.

[0240] 2. Control flow graph CFG analysis code structure

[0241] 3. The reasoning module combines CFG to analyze the code structure and decompose the code into subtasks

[0242] 4. Combine the function block vector database content and improve the subtask into a subcode module

[0243] 5. After multiple rounds of generation, cluster the submodules and select representative code blocks.

[0244] 6. Add error feedback for sub-code blocks and complete the code according to code format

[0245] 7. Use multiple generation feedback and scoring mechanisms to evaluate code quality.

[0246] 8. If the rating is not satisfactory, regenerate based on the feedback

[0247] 9. Execute the code and capture the log messages.

[0248] 10. If it is not a successful message, regenerate it according to the error message feedback

[0249] 11. Output the final optimized code

[0250] The steps to create a vector code library are as follows:

[0251] 1. Enter a certain number of reference code documents

[0252] 2. Decompose into function blocks and record

[0253] 3. The large model actively searches for content to supplement the function block

[0254] 4. Convert blocks into vectors and store them in the database for backup

[0255] Analyze the code documentation and summarize the overall format followed

[0256] An application embodiment of the present invention provides a computer device, which includes a memory and a processor. The memory stores a computer program. When the computer program is executed by the processor, the processor executes the steps of a multi-round reasoning and feedback optimization method for industrial software codes.

[0257] An application embodiment of the present invention provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor executes the steps of a multi-round reasoning and feedback optimization method for industrial software codes.

[0258] An application embodiment of the present invention provides an information data processing terminal, which includes a multi-round reasoning and feedback optimization system for industrial software codes.

[0259] The present invention provides a set of efficient code optimization methods, which are suitable for the development and optimization process of industrial software. Through the automated vector code library, control flow graph analysis and multi-round feedback optimization mechanism, the present invention can help enterprises quickly develop high-performance and stable industrial software products. An application example is as follows:

[0260] 1. Input original code and natural language optimization requirements

[0261] Original Code: Provides a Python code containing several functions for image processing and object detection.

[0262] Improvement needs: Improve exception handling, enable validation checks, refactor code to use local variables, remove unnecessary code, simplify complex logic, follow style guidelines, avoid hard-coded values, enhance error messages, and reimplement input sanitization.

[0263] 2. Control Flow Graph (CFG) Analysis of Code Structure

[0264] CFG Analysis: Use control flow graphs to analyze the structure of the original code and identify key blocks and their functions, such as initial import and setup, image download, coordinate conversion, image reasoning, image acquisition, and detection functions.

[0265] 3. The reasoning module combines CFG to analyze the code structure and decompose the code into subtasks

[0266] Subtask decomposition example: According to the CFG analysis results, the code is decomposed into multiple subtasks, including downloading BMP images, converting pixel coordinates to robot coordinates, single image reasoning, getting images from the directory, and detection functions.

[0267] 4. Combine the function block vector database content and improve the subtask into a subcode module

[0268] A multi-query fusion search is as follows:

[0269] 1. "Develop a program to download a BMP image and convert the pixel coordinates to robot coordinates."

[0270] 2. "Design an algorithm that can take images from a directory and perform single image reasoning."

[0271] 3. "Implement a detection function that can perform inference on the downloaded BMP image."

[0272] 4. "Create a tool that can process images obtained from the catalog and convert pixel coordinates to robot coordinates."

[0273] 5. "Optimize a program that can quickly download BMP images and perform image reasoning and coordinate conversion."

[0274] The following is a function block retrieved by the example:

[0275] Function:

[0276] download_bmp_image function (a function used to download a BMP image from a specified URL and save it to a local specified file name)

[0277] Execution Feedback:

[0278] Code function explanation

[0279] The function accepts a remote BMP image URL and a local file name as parameters. If the local file name does not end with .bmp, the function automatically adds the extension. Use urllib.request.urlopen to send an HTTP request to get the remote file. Write the obtained file content to the local file. Capture and handle HTTP errors and URL errors.

[0280] Potential Errors

[0281] The function does not verify that the URL points to a valid BMP image. The function does not verify that the local file path is writable, which may result in a PermissionError.

[0282] Execution Results

[0283] If the function successfully downloads the image, it prints a message indicating that the image was downloaded to the specified local file name. If an error occurs, the function prints an appropriate error message detailing the problem.

[0284] Improvement Suggestions

[0285] Before downloading, add a check to ensure that the URL points to a valid BMP image. Before writing the file, verify that the local file path is writable and accessible.

[0286] 5. Cluster the submodules after multiple rounds of generation and select representative code blocks

[0287] The representative code blocks that were regenerated multiple times and selected by clustering are as follows:

[0288] 1. `get_images_from_dir`

[0289] 2. `inference_single_image`

[0290] 3. `download_bmp_image`

[0291] 4. `robotcamchange`

[0292] 5. `detect`

[0293] 6. Add error feedback for sub-code blocks and complete the code according to code format

[0294] Add structured error messages to each sub-code block and complete code formatting according to the code style guide to ensure code readability and maintainability.

[0295] Here is an example:

[0296]

[0297]

[0298] 7. Use multiple generation feedback and scoring mechanisms to evaluate code quality

[0299] Examples of ratings and feedback are as follows:

[0300] Final rating: 8.67

[0301] Optimized:

[0302] 1. Function realization:

[0303] The code correctly implements all required functionality, including downloading the image, converting pixel coordinates to robot coordinates, performing inference on the image, and retrieving the image from the directory.

[0304] Each function returns a dictionary containing the message and the data, which is a good practice for API interaction.

[0305] 2. Parameter processing:

[0306] Parameters are handled and used accurately. Each function has well-defined parameters and type annotations, which improves the readability and maintainability of the code. Parameters are used correctly inside functions, ensuring that the expected operations are performed.

[0307] 3. Output format:

[0308] The code outputs the results in the correct format, consistently returning a dictionary with the keys "msg" and "data". This format is suitable for API responses and ensures that the results are easy to interpret.

[0309] 4. Optimization:

[0310] By refactoring to use local variables and define constants to simplify complex logic, the code effectively optimizes the task. The use of type annotations and structured error messages enhances the overall quality and maintainability of the code.

[0311] 5. Error handling:

[0312] The code provides structured error messages for each sub-functional module, indicating the specific sub-module that failed.

[0313] Improvement feedback:

[0314] `inference_single_image` function: Add error handling for `cv2.imread` failure to read images to prevent errors.

[0315] `detect` function: Enhance error messages to provide more details, especially when dealing with nested function calls. Also, avoid calling `robotcamchange` repeatedly by storing the result of the first call to reuse it.

[0316] 9. Execute code and capture log messages

[0317] Execute and log the optimized code and capture log messages to ensure that the code performs well in actual operation.

[0318] Log example:

[0319]

[0320]

[0321] 10. Output the final optimized code

[0322] Final output: Output the final optimized code

[0323] The present invention designs an aluminum block shape recognition task for an industrial software platform, with 10 aluminum block samples of different shapes. Based on the original code of the same aluminum block shape classification component, the present invention is used to perform ten code optimizations, focusing on the denoising of the image and the processing under different ambient light. The code before and after optimization is used to control the platform to process the image taken by the camera, and then the mechanical arm absorbs the aluminum block to the corresponding classification position. The success rate refers to the probability that the platform successfully recognizes and absorbs the corresponding aluminum block shape to the corresponding position after the code component is run. The following is the corresponding absorption experiment picture, as well as a summary table of the code differences before and after some optimizations.

[0324] Experimental design:

[0325] Number of samples: 10

[0326] Before optimization: only 3 copies can be identified

[0327] After optimization: 7, 8, 9, 10, 6, 7, 8, 6, 8, 9 copies can be recognized each time

[0328] Data Analysis:

[0329] Pass rate before optimization: 30%

[0330] Optimized pass rate: 78%

[0331] Improvement multiple: 0.78 / 0.3≈2.6 times.

[0332] Figure 4 Identify the physical image for the aluminum block.

[0333] Figure 5 Shape recognition data graph for aluminum block.

[0334]

[0335] It should be noted that the embodiments of the present invention can be implemented by hardware, software, or a combination of software and hardware. The hardware part can be implemented using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. It can be understood by a person of ordinary skill in the art that the above-mentioned devices and methods can be implemented using computer executable instructions and / or contained in a processor control code, such as a carrier medium such as a disk, CD or DVD-ROM, a programmable memory such as a read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. Such code is provided on the carrier medium. The device and its modules of the present invention can be implemented by hardware circuits such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., can also be implemented by software executed by various types of processors, and can also be implemented by a combination of the above-mentioned hardware circuits and software, such as firmware.

[0336] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with the technical field within the technical scope disclosed by the present invention and within the spirit and principle of the present invention should be covered by the protection scope of the present invention.

Claims

1. A multi-round reasoning and feedback optimization method for industrial software code, characterized in that: include: S1, vector code library establishment: The establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format; S2, code reasoning optimization: In code reasoning optimization, there are four aspects: control flow graph analysis, multi-query generation and inverse ranking fusion retrieval, reasoning generation subtasks and code chain submodule generation, combined to complete the code; S3, feedback optimization: Feedback optimization consists of score feedback optimization and log feedback optimization.

2. The multi-round reasoning and feedback optimization method for industrial software code according to claim 1, characterized in that: S1 specifically includes: S101, construct feedback: divide the function blocks, use the large model to actively retrieve the analysis blocks, generate and construct feedback information; Feedback composition: Potential errors: Feedback code that may have potential errors and exceptions; Execution result: feedback the execution result of the code; Function description: gives the function's function, input, output and workflow; S102, build function block code library: Based on previous feedback and the partitioned code blocks, we use the embedding model to build a vector database for improved query generation and information retrieval. S103, summary format: Based on the code file content of the industrial software, the format of the software is summarized for subsequent code merging.

3. The multi-round reasoning and feedback optimization method for industrial software code according to claim 1, characterized in that: S2 specifically includes: S201, generating a control flow graph according to the syntax tree: first calling a function to analyze the code to generate an abstract syntax tree, and then generating a control flow graph through the abstract syntax tree; subsequently, by analyzing the control flow graph of the code, the system can identify potential logic errors, redundant paths and optimization opportunities; S202, multi-query generation and inverse ranking fusion retrieval: Multi-query generation and inverse ranking fusion technology are used to ensure that more comprehensive and accurate query results can be generated during the retrieval process; this technology generates multiple related queries based on the initial query, and uses RRF to fuse each result to generate the final ranking result; S203, reasoning generation subtask: using reasoning structure to generate task modules, decomposing complex tasks into multiple submodules, and optimizing the code through multiple code chain generation and clustering mechanism; the specific steps include extracting the generated submodules, clustering them, and selecting representative modules as the basis for optimization to ensure the high quality and reusability of the generated code; S204, RAG cluster generation: Clustering is to divide similar objects into different groups or more subsets through static classification methods, so that the member objects in the same subset have similar properties, commonly including shorter spatial distances in the coordinate system; Retrieval-augmented generation, which accepts input and retrieves a set of supporting documents from a given source; these documents are connected to the original input prompt as context and input to a text generator that produces the final output; this enables RAG to adapt to situations where facts may change over time; and RAG allows the language model to bypass retraining, thereby being able to access the latest information, thereby generating reliable output through retrieval-based generation; in each round, RAG is used to use a fusion retrieval method, taking the subtask as the retrieval input and retrieving the function block vector database; the retrieval results and subtask descriptions are input into the large model, and N generations are performed, and then the generated submodules are clustered through the K-means clustering method, and the central submodule is extracted as a representative sub-code block, which is one round, and a total of M rounds are performed; S205, combining the completed code: firstly, adding an error feedback mechanism to the sub-code block, and then combining the sub-modules into the final code according to the code format; Error feedback: In each sub-module, a detailed error detection and return mechanism is designed to ensure that the system can provide timely feedback when a problem is found; when each sub-module is subsequently executed, if an error is encountered, a specific error code or error message will be returned, which will be used for logging and subsequent analysis.

4. The multi-round reasoning and feedback optimization method for industrial software code according to claim 3, characterized in that: The reasoning method in S203 specifically includes: (1) Selection: Select the reasoning module related to task solving from the reasoning module description set; Given an original set D of reasoning module descriptions, including "critical thinking" and "decomposing problems into sub-problems", and some unlabeled task examples ti∈T; first use the model M and meta-hint pS to select useful reasoning modules DS from the subset of reasoning modules; (2) Adaptive: Since each reasoning module provides a general description of how to solve the problem, the next step is to customize each selected module adaptively based on the input; (3) Implementation: Based on the adjusted reasoning module description DA, the reasoning module is converted into an implemented reasoning structure DI, which clearly describes the content to be generated in each step; in addition to the meta-hint pI, IMPLEMENT also provides a demonstration of the reasoning structure Shuman written by humans on another task to better convert natural language descriptions into reasoning structures; (4) Processing tasks: attaching the reasoning structure to all instances of the task and prompting the model to follow the reasoning structure to generate subtask modules.

5. The multi-round reasoning and feedback optimization method for industrial software code according to claim 1, characterized in that: S3 specifically includes: S301, rating feedback optimization: The generated optimized code is comprehensively evaluated through multiple generation scoring and feedback mechanisms, and the accuracy of the scoring results is ensured through multi-evidence calibration and balanced position calibration technology; comprehensive feedback is then used to ensure that the feedback and optimization corrections are more targeted; Multiple evidence calibration: The system generates explanatory evidence and then scores the code based on this evidence, ensuring that the score is consistent with the evidence; Balanced position calibration: By exchanging the response positions, it ensures that there is no bias in the comparison process, and ultimately generates more accurate scoring results; Comprehensive feedback: By summarizing the key points of multiple feedbacks, the feedback input for re-optimizing the code is more instructive; Correcting the code: The code is corrected by the big model based on the comprehensive feedback and then re-scored; S302, log feedback optimization: the log module is used to analyze the feedback information during the execution of the industrial software. If it is correct, the optimization is completed. If it is wrong, it is analyzed in combination with the log of the software feedback, and a detailed error report is generated to guide re-optimization before running; Error classification and logging: The system classifies the errors in the log and generates a detailed error report for error analysis; Automated verification: Automatically run the optimized code to verify whether the problem is effectively solved.

6. A multi-round reasoning and feedback optimization system for industrial software code that implements the multi-round reasoning and feedback optimization method for industrial software code as described in any one of claims 1 to 5, characterized in that include: Vector code library establishment module: The establishment of the vector code library consists of three parts: building feedback, building vector database, and summarizing the format; Code reasoning optimization module: Code reasoning optimization consists of four aspects: control flow graph analysis, multi-query generation and inverse ranking fusion retrieval, reasoning generation subtasks and code chain submodule generation, and combined code completion; Feedback optimization module: Feedback optimization consists of rating feedback optimization and log feedback optimization.

7. A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the multi-round reasoning and feedback optimization method for industrial software code as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to execute the steps of the multi-round reasoning and feedback optimization method for industrial software code as described in any one of claims 1 to 5.

9. An information data processing terminal, comprising the multi-round reasoning and feedback optimization system for industrial software codes as claimed in claim 6.

Citation Information

Patent Citations

  • Dynamic adaptation question answering system and method based on hierarchical structure and retrieval enhancement

    CN118193714A

  • Class case retrieval system and method based on retrieval enhancement generation technology

    CN118260391A

  • Composite symbolic and non-symbolic artificial intelligence system for advanced reasoning and semantic search

    US20240386015A1

Cited By

  • Code generation method and system based on RAG and framework type COT

    CN119987743A

  • A code generation method and system based on RAG and framework-based COT

    CN119987743B

  • Code error repairing method and system based on large model

    CN120492319A

  • Code error repair method and system based on large model

    CN120492319B

  • Large model feedback optimization system and method based on process identification and tool calling

    CN121350642A