Semantic exploration-based large language model code defect repair method and device
By combining heuristic search trees and large language models, the problems of global search and deep semantic modeling in complex logical defects are solved, achieving efficient and logically coherent code defect repair and improving the accuracy and stability of the repair.
Patent Information
- Application Number
- CN202610762602.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-29
- Publication Date
- 2026-06-26
AI Technical Summary
Existing technologies lack global search capabilities, have inaccurate deep semantic modeling, and poor logical coherence in repair paths when dealing with complex logical defects, making it difficult to meet the accuracy and stability requirements of highly reliable software.
By constructing a heuristic search tree, a large language model is invoked to parse the semantic features of the code context to generate candidate patches. Through semantic space representation and adaptive clustering, multi-dimensional semantic consistency evaluation, the repair decision trajectory and dynamic reward information are integrated to generate context-enhanced prompts, guiding the large language model to generate candidate patches.
It achieves efficient global search, accurately captures deep code intent, improves the logical consistency and intelligent decision-making level of the repair path, and significantly improves the accuracy and system stability of complex software repair tasks.
Smart Images

Figure CN122285053A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software engineering technology, and in particular to a method and apparatus for repairing code defects in a large language model based on semantic exploration. Background Technology
[0002] In the field of software engineering, with the continuous growth of system scale and logical complexity, automated program repair has become a key technology for ensuring software reliability and security. In recent years, advancements in code generation and understanding using large language models have provided new technical pathways for automated program repair. However, existing technologies still face many challenges in handling complex logical defects, deep semantic alignment, and repair path decision-making.
[0003] Specifically, search-based or template-driven automated program repair methods often rely on predefined transformation rules or random mutation operators. Since these methods primarily target specific syntax errors, they often lack global search capabilities when faced with complex logical defects. This results in low search efficiency among a vast number of candidate paths, making it difficult to balance repair quality with computational resource consumption, and easily leading to local optima or ineffective loops.
[0004] Next, direct patching methods based on deep learning or large language models leverage the generative capabilities of pre-trained knowledge, improving code generation speed to some extent. However, because these methods are often limited to the textual features or shallow syntactic structures of the code, lacking the ability to model and capture the deep, hierarchical semantics of the program, the generated patch solutions are prone to overfitting. That is, although the generated patches may pass some surface tests, they still have hidden dangers in the deeper logic, making it difficult to meet the stringent requirements of high-reliability software for repair accuracy.
[0005] Furthermore, while repair methods combining multi-agent collaboration or simple iterative feedback reduce human intervention through process automation, they lack a heuristic exploration mechanism with a global perspective, making it impossible to quantify semantic novelty to guide the exploration of diverse solutions. Therefore, the repair process often exhibits significant disorder, inconsistency, and insufficient controllability, making it difficult to achieve efficient intelligent decision-making in complex patch spaces.
[0006] Furthermore, while methods that rely entirely on large language models for unconstrained iterative repair possess strong semantic understanding capabilities, they often exhibit inconsistent path decisions and significant waste of computational resources when dealing with complex defects requiring multi-step continuous logical evolution due to a lack of effective integration of repair path context and semantic clustering information.
[0007] In summary, existing technologies still have limitations in terms of the globality of search decisions, the accuracy of deep semantic modeling, and the coherence of repair paths. They are difficult to meet the stringent requirements of high-reliability software for repair accuracy and stability. There is an urgent need for an automated repair system that can achieve deep semantic alignment, logical stability, and efficient search. Summary of the Invention
[0008] (a) Technical problems to be solved
[0009] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides a method and apparatus for repairing code defects in a large language model based on semantic exploration, which solves the technical problems of lack of globality in search decision-making, inaccuracy of deep semantic modeling, and poor logical coherence of repair path in the repair of complex logical defects in the prior art.
[0010] (II) Technical Solution
[0011] To achieve the above objectives, the main technical solutions adopted by the present invention include:
[0012] In a first aspect, embodiments of the present invention provide a method for repairing code defects in a large language model based on semantic exploration, including:
[0013] The obtained defect code is used as the initial node to build a heuristic search tree, and a large language model is called to parse the contextual semantic features of the defect code to generate candidate patches. The heuristic search tree is then updated based on the candidate patches.
[0014] Candidate patches are tested and verified. If the verification fails, the candidate patches that fail the verification are represented in semantic space and adaptively clustered to obtain the corresponding structured semantic clusters.
[0015] Based on structured semantic clusters, multi-dimensional semantic consistency evaluation is performed on candidate patches that fail verification in order to obtain dynamic reward information that represents the semantic gain of the current repair action.
[0016] In the updated heuristic search tree, the repair decision trajectory from the initial node to the node corresponding to the currently generated candidate patch is extracted, and the repair decision trajectory is integrated with dynamic reward information to generate context-enhanced prompt information;
[0017] The contextual enhancement prompts are fed back to the large language model to guide it in generating the next round of candidate patches based on the logical relationship between the repair decision trajectory and the dynamic reward information, until the test verification is passed or the preset termination condition is met.
[0018] Optionally, a heuristic search tree is constructed using the obtained defect code as the initial node, and a large language model is invoked to parse the contextual semantic features of the defect code to generate candidate patches. The heuristic search tree is then updated based on the candidate patches, including:
[0019] The obtained defect code is used as the root node to construct the initial heuristic search tree;
[0020] Starting from the root node, child nodes are recursively filtered in the search tree based on the improved upper bound principle of confidence intervals until a leaf node in a non-terminating state is reached; wherein, the improved upper bound principle of confidence intervals is configured to determine the filtering priority of each child node by weighting the cumulative semantic value and exploration gain of each child node.
[0021] When a leaf node in a non-terminating state is reached, the large language model is called to parse the contextual semantic features of the code corresponding to the current leaf node at a preset level, so as to generate multiple candidate patches with corresponding semantic confidence, and the candidate patches are dynamically integrated into the search tree as new child nodes.
[0022] For candidate patches, perform patch effect prediction. During the prediction process, recursively generate patches or execute preset test cases to verify along the target search path with the highest semantic confidence, and obtain preliminary value feedback of the target search path.
[0023] The initial value feedback is propagated back along the target search path to the root node. The search evaluation index of each child node on the target search path is calculated and updated simultaneously. Based on the search evaluation index, the statistical weight of each child node in the search tree is adjusted to complete the update of the search tree.
[0024] Optionally, if the verification fails, the candidate patches that fail the verification are then subjected to semantic space representation and adaptive clustering to obtain the corresponding structured semantic clusters, including:
[0025] Determine the scope of impact of the fixes implemented by candidate patches that failed verification;
[0026] If the scope of the repair action is a local repair at the single function level, then extract the text difference terms constructed by adding and deleting lines of code, call the large language model to generate natural language semantic summary, and use the pre-trained encoder to jointly map the text difference terms and natural language semantic summary to obtain semantic embedding vectors.
[0027] If the scope of the repair action is a multi-function level project-level repair, then static analysis is performed on the preset code repository to construct a global program dependency graph. Based on the topological association features of the global program dependency graph, convergence iteration is performed to quantify the structural weight of each function change, and hierarchical semantic aggregation is performed based on the structural weight to obtain a semantic embedding vector.
[0028] Based on the spatial density distribution features, dynamic hierarchical clustering is performed on the semantic embedding vectors to obtain the initial patch clusters, and the silhouette coefficients of the initial patch clusters are calculated:
[0029] When the contour coefficient is lower than the preset merging threshold, a spatial merging operation is performed on the initial patch cluster to compress redundant search paths;
[0030] When an outlier is detected outside the initial patch cluster, and the semantic space distance between the outlier and the initial patch cluster is greater than a preset splitting threshold, a cluster splitting operation is triggered.
[0031] The initial patch clusters after spatial merging or cluster splitting operations are identified as structured semantic clusters.
[0032] Optionally, based on structured semantic clusters, multi-dimensional semantic consistency evaluation is performed on candidate patches that fail verification to obtain dynamic reward information representing the semantic gain of the current repair action, including:
[0033] Build and dynamically maintain a collection of historical reference patches;
[0034] Determine if the historical reference patch set is empty, or if the currently generated candidate patch belongs to a new repair attempt type;
[0035] If the historical reference patch set is not empty, the average semantic space distance between the current semantic representation of the candidate patch and the historical semantic representation in the historical reference patch set is calculated, and the average semantic space distance is mapped to a normalized interval to obtain the semantic novelty score.
[0036] If the historical reference patch set is empty or the candidate patch belongs to a new repair attempt type, the candidate patch is directly assigned the highest semantic novelty score;
[0037] The large language model is invoked to insert candidate patches into the sorted list of the corresponding structured semantic cluster based on the relative preference mechanism. The sorting position of the candidate patch in the sorted list is obtained, and the quality score of the candidate patch is calculated based on the sorting position and the failure statistical features of the structured semantic cluster.
[0038] By dynamically adjusting the weighting ratio of semantic novelty score and quality score through an online reinforcement learning mechanism, the weighted fusion score is determined as dynamic reward information.
[0039] Optionally, the large language model is invoked to insert candidate patches into the sorted list of the corresponding structured semantic cluster based on a relative preference mechanism. The sorting position of the candidate patch in the sorted list is obtained, and the quality score of the candidate patch is calculated based on the sorting position and the failure statistical features of the structured semantic cluster, including:
[0040] Once a candidate patch enters the corresponding structured semantic cluster, a relative evaluation mechanism based on preference order is triggered. The large language model is invoked to perform a pairwise relative preference comparison between the candidate patch and the historical patches within the structured semantic cluster, and the relative comparison results are obtained.
[0041] Based on the relative comparison results, candidate patches are inserted into the sorted list maintained within the structured semantic cluster according to the principle of decreasing quality, so as to update the dynamic preference sequence reflecting logical correctness and extract the sorting position of candidate patches from the dynamic preference sequence.
[0042] The basic quality score is obtained by quantizing the sorting position using the exponential decay function, and the historical failure frequency of the structured semantic cluster corresponding to the candidate patch is extracted as the failure statistical feature.
[0043] Determine whether the frequency of historical failures is greater than a preset frequency threshold. If the frequency of historical failures is greater than the frequency threshold, dynamically calculate the semantic cluster penalty coefficient based on the frequency of historical failures and the preset normalized reference value.
[0044] By using the semantic cluster penalty coefficient as a penalty term, the basic quality score is compressed and attenuated to obtain a quality score.
[0045] Optionally, in the updated heuristic search tree, the repair decision trajectory from the initial node to the node corresponding to the currently generated candidate patch is extracted. The repair decision trajectory is integrated with dynamic reward information to generate context-enhanced cue information, including:
[0046] In the updated heuristic search tree, extract the repair decision trajectory from the initial node to the corresponding child node of the currently generated candidate patch;
[0047] Each sub-node on the repair decision trajectory is identified as a decision point, and multi-dimensional feature units are extracted for each decision point. Each multi-dimensional feature unit includes the natural language intent summary, novelty score, and quality score of the candidate patch of the corresponding sub-node.
[0048] Arrange the multidimensional feature units according to the time series to construct the repair evolution chain;
[0049] Based on the repair evolution chain, semantic falsification of failure paths is performed to identify positive gain repair directions and falsified trial repair actions;
[0050] For project-level repairs involving multiple functions, extract global logical constraints across files from the repair evolution chain;
[0051] The repair evolution chain, positive gain repair direction and falsified trial repair actions are integrated, and the extracted global logical constraints are integrated in the same way when project-level repairs involving multiple functions are involved, so as to build enhanced background information.
[0052] The enhanced background information is combined with the dynamic reward information to generate context-enhanced prompts.
[0053] Optionally, context-enhanced hints are fed back to the large language model to guide it in generating the next round of candidate patches based on the logical relationship between the repair decision trajectory and dynamic reward information, until the test verification is passed or a preset termination condition is met, including:
[0054] The large language model is invoked to parse the contextual enhancement prompts of the input, and the enhanced background information is mapped with dynamic reward information to determine the generation constraints.
[0055] Based on the generative constraints, the large language model is guided to combine the repair evolution chain, avoid the falsified trial repair actions and follow the positive gain repair direction, and follow the global logical constraints when the enhanced background information contains global logical constraints to generate the next round of candidate patches.
[0056] The next round of candidate patches are dynamically integrated into the heuristic search tree as new child nodes, and the next round of candidate patches are fed back to the step of testing and verifying the candidate patches to trigger a new round of automated repair loop;
[0057] During the execution of the automated repair loop, the feedback results of the test verification and the iteration status of the heuristic search tree are monitored in real time.
[0058] If the feedback result of the current test verification indicates that the candidate patch has passed the test verification, then the automated repair loop ends and the candidate patch that has passed the test verification is output as the repair solution.
[0059] If the number of iterations in the automated repair loop reaches the preset iteration threshold, the preset termination condition is determined to have been met, the automated repair loop ends, and the candidate patch with the best search evaluation index is output as the repair solution based on the search evaluation index of each child node in the heuristic search tree.
[0060] Secondly, embodiments of the present invention provide a large language model code defect repair system based on semantic exploration, comprising: a heuristic path search decision module, used to construct a heuristic search tree using the acquired defective code as the initial node, and call the large language model to parse the contextual semantic features of the defective code to generate candidate patches, and update the heuristic search tree based on the candidate patches; a patch verification module, used to test and verify the candidate patches; a semantic space representation and clustering module, used to perform semantic space representation and adaptive clustering on the candidate patches that fail verification if the verification fails, to obtain the corresponding structured semantic clusters; and a multi-dimensional semantic evaluation module, used to evaluate the defective code based on the structured semantic clusters. The validated candidate patches undergo multi-dimensional semantic consistency evaluation to obtain dynamic reward information representing the semantic gain of the current repair action. The cross-domain context enhancement and integration module is used to extract the repair decision trajectory from the initial node to the corresponding node of the currently generated candidate patch in the updated heuristic search tree, and integrate the repair decision trajectory with the dynamic reward information to generate context enhancement prompts. The feedback and iteration module is used to feed the context enhancement prompts back to the large language model to guide the large language model to generate the next round of candidate patches based on the logical relationship between the repair decision trajectory and the dynamic reward information, until the test verification is passed or the preset termination condition is reached.
[0061] Thirdly, embodiments of the present invention provide a large language model code defect repair device based on semantic exploration, comprising: at least one controller; and a memory communicatively connected to the at least one controller; wherein the memory stores instructions executable by the at least one controller, the instructions being executed by the at least one controller to enable the at least one controller to perform the large language model code defect repair method based on semantic exploration as described above.
[0062] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a controller, implement the semantic exploration-based large language model code defect repair method described above.
[0063] (III) Beneficial Effects
[0064] The beneficial effects of this invention are:
[0065] First, this invention constructs a heuristic search tree using the acquired defective code as initial nodes and updates the search tree based on candidate patches, thus achieving systematic modeling of a high-dimensional, discrete patch space. This invention achieves efficient global search and targeted exploration among a large number of candidate solutions, effectively overcoming the technical bottleneck of traditional random search or simple heuristic algorithms easily getting trapped in local optima or invalid loops in complex code logic, and significantly improving the globality of search decisions.
[0066] Secondly, this invention achieves a fundamental leap from "text matching" to "semantic alignment" by performing semantic space representation and adaptive clustering on candidate patches that have failed verification. This technology can transform discrete code changes into geometric features in a high-dimensional continuous vector space, identify semantic neighbors and compress redundant paths through adaptive clustering, thereby accurately capturing the deep intent of the code. This effectively solves the overfitting problem caused by existing technologies being limited to shallow syntactic structures, and improves the semantic correctness of patch generation.
[0067] Furthermore, this invention provides precise quantitative feedback for the repair process by conducting multi-dimensional semantic consistency evaluation based on structured semantic clusters. This technology transforms the semantic features of patches into dynamic reward information that guides the search, enabling it to autonomously identify high-potential repair branches, avoiding the disorderliness of the repair process, and significantly improving the intelligent decision-making level and search efficiency of automated repair.
[0068] Furthermore, this invention effectively solves the problem of logical discontinuity in multi-step continuous repair actions by extracting the repair decision trajectory and integrating it with dynamic reward information to construct context-enhanced prompts. By constructing a semantic panoramic view based on the decision trajectory, it ensures the coherence of repair actions across file logic and historical decision-making context, eliminating information silos and significantly improving the logical consistency of the repair path. Finally, the context-enhanced prompts are fed back to a large language model for iterative generation.
[0069] Therefore, this invention constructs an exploration scheme from defect perception to logical closed loop. This scheme can be dynamically optimized based on real-time feedback from testing and verification, which significantly improves the accuracy, engineering feasibility and system stability in complex software repair tasks, and provides robust technical support for the automated maintenance of highly reliable software. Attached Figure Description
[0070] Figure 1 This is a schematic diagram of the overall process of the method provided in the embodiments of the present invention;
[0071] Figure 2 This is a schematic diagram illustrating the specific process of step S1 of the method provided in this embodiment of the invention;
[0072] Figure 3 This is a detailed flowchart illustrating step S2 of the method provided in this embodiment of the invention;
[0073] Figure 4 This is a detailed flowchart illustrating step S3 of the method provided in this embodiment of the invention;
[0074] Figure 5 This is a detailed flowchart illustrating step S51 of the method provided in this embodiment of the invention;
[0075] Figure 6 This is a detailed flowchart illustrating step S4 of the method provided in this embodiment of the invention;
[0076] Figure 7 This is a detailed flowchart illustrating step S5 of the method provided in this embodiment of the invention;
[0077] Figure 8 This is a schematic diagram of the logical architecture of the system provided in an embodiment of the present invention. Detailed Implementation
[0078] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0079] like Figure 1 As shown in the embodiment of the present invention, a method for repairing code defects in a large language model based on semantic exploration is proposed, which includes: constructing a heuristic search tree using the acquired defective code as the initial node, and calling the large language model to parse the contextual semantic features of the defective code to generate candidate patches, and updating the heuristic search tree based on the candidate patches; testing and verifying the candidate patches, and if the verification fails, performing semantic space representation and adaptive clustering on the candidate patches that fail the verification to obtain the corresponding structured semantic clusters; performing multi-dimensional semantic consistency evaluation on the candidate patches that fail the verification based on the structured semantic clusters to obtain dynamic reward information representing the semantic gain of the current repair action; extracting the repair decision trajectory from the initial node to the corresponding node of the currently generated candidate patch in the updated heuristic search tree, integrating the repair decision trajectory with the dynamic reward information to generate context enhancement prompt information; feeding back the context enhancement prompt information to the large language model to guide the large language model to generate the next round of candidate patches based on the logical association between the repair decision trajectory and the dynamic reward information, until the test verification is passed or a preset termination condition is reached.
[0080] First, this invention constructs a heuristic search tree using the acquired defective code as initial nodes and updates the search tree based on candidate patches, thus achieving systematic modeling of a high-dimensional, discrete patch space. This invention achieves efficient global search and targeted exploration among a large number of candidate solutions, effectively overcoming the technical bottleneck of traditional random search or simple heuristic algorithms easily getting trapped in local optima or invalid loops in complex code logic, and significantly improving the globality of search decisions.
[0081] Secondly, this invention achieves a fundamental leap from "text matching" to "semantic alignment" by performing semantic space representation and adaptive clustering on candidate patches that have failed verification. This technology can transform discrete code changes into geometric features in a high-dimensional continuous vector space, identify semantic neighbors and compress redundant paths through adaptive clustering, thereby accurately capturing the deep intent of the code. This effectively solves the overfitting problem caused by existing technologies being limited to shallow syntactic structures, and improves the semantic correctness of patch generation.
[0082] Furthermore, this invention provides precise quantitative feedback for the repair process by conducting multi-dimensional semantic consistency evaluation based on structured semantic clusters. This technology transforms the semantic features of patches into dynamic reward information that guides the search, enabling it to autonomously identify high-potential repair branches, avoiding the disorderliness of the repair process, and significantly improving the intelligent decision-making level and search efficiency of automated repair.
[0083] Furthermore, this invention effectively solves the problem of logical discontinuity in multi-step continuous repair actions by extracting the repair decision trajectory and integrating it with dynamic reward information to construct context-enhanced prompts. By constructing a semantic panoramic view based on the decision trajectory, it ensures the coherence of repair actions across file logic and historical decision-making context, eliminating information silos and significantly improving the logical consistency of the repair path. Finally, the context-enhanced prompts are fed back to a large language model for iterative generation.
[0084] Therefore, this invention constructs an exploration scheme from defect perception to logical closed loop. This scheme can be dynamically optimized based on real-time feedback from testing and verification, which significantly improves the accuracy, engineering feasibility and system stability in complex software repair tasks, and provides robust technical support for the automated maintenance of highly reliable software.
[0085] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.
[0086] Specifically, embodiments of the present invention provide a method for repairing code defects in a large language model based on semantic exploration, comprising:
[0087] S1. Use the obtained defect code as the initial node to build a heuristic search tree, and call the large language model to parse the contextual semantic features of the defect code to generate candidate patches, and update the heuristic search tree based on the candidate patches.
[0088] This step aims to address the technical challenges of high-dimensional, discrete search spaces that are prone to getting trapped in local optima during software defect repair by establishing a patch space exploration mechanism based on sequential decision-making. It uses the defective code to be repaired as the root node and employs an improved Monte Carlo Tree Search (MCTS) strategy to incrementally construct a tree structure in a complex patch variant space. By balancing the development depth and exploration breadth of the repair path, it achieves rapid convergence of high-confidence repair solutions.
[0089] Furthermore, such as Figure 1 and Figure 2 As shown, step S1 includes:
[0090] S11. Construct an initial heuristic search tree using the obtained defect code as the root node. During implementation, the defective program to be fixed is defined as the root node of the search tree. The root node represents the initial state of the obtained defect code, including the abstract syntax tree structure, function call relationships, and logical semantics.
[0091] S12. Starting from the root node, recursively filter child nodes in the search tree based on the improved upper bound principle of the confidence interval until a leaf node in a non-terminating state is reached. The improved upper bound principle of the confidence interval is configured to determine the filtering priority of each child node by weighting the cumulative semantic value and exploration gain of each child node. This ensures that search resources are preferentially allocated to branches with potential logical correctness, thereby guiding the search towards a preset high-value region. The cumulative semantic value is the sum of verification values obtained during the search process according to the preset semantic logic standard, and the exploration gain refers to the ratio of the access frequency of the current node to its parent node.
[0092] S13. When a leaf node in a non-terminating state is reached, the large language model is called to parse the contextual semantic features of the code corresponding to the current leaf node at a preset level, so as to generate multiple candidate patches with corresponding semantic confidence, and the candidate patches are dynamically integrated into the search tree as new child nodes.
[0093] Here, a leaf node refers to a branch node in the search tree that is currently at the end and has not yet been further expanded, representing the current boundary of the repair attempt. When the search reaches a leaf node that is not in a terminated state, it enters the expansion phase. The large language model is used to capture the preset hierarchical context features of the current code, generate multiple semantically feasible patch variants as new child nodes, and dynamically integrate them into the search tree structure to complete the real-time expansion of the search space.
[0094] S14. Perform patch effect prediction for candidate patches. During the prediction process, recursively generate patches or execute preset test cases to verify the target search path with the highest semantic confidence, and obtain preliminary value feedback of the target search path.
[0095] Next, in the simulation prediction stage, a lightweight patch effect prediction is performed starting from the newly expanded candidate nodes. Unlike traditional random path simulation, it tends to recursively generate patches or directly execute test cases for verification along the path with the highest semantic confidence. Instead of performing full regression testing, it observes indicators such as compilation status, execution time, and test pass rate to quickly obtain the initial value feedback of the path with lower computational cost.
[0096] S15. Propagate the initial value feedback back along the target search path to the root node, simultaneously calculate and update the search evaluation index of each child node on the target search path, adjust the statistical weight of each child node in the search tree based on the search evaluation index, and complete the update of the search tree.
[0097] During the backpropagation process, the value signal obtained from the simulation is updated backward to the root node along the search path, and the search evaluation indicators of each node on the path, including access frequency and average quality score, are updated synchronously. The average quality score refers to the statistical mean of the performance indicators (such as test pass rate, compilation status, etc.) obtained by the node in multiple iterations of simulation prediction.
[0098] Based on the updated search evaluation metrics, the statistical weights of each child node in the search tree are dynamically adjusted. Nodes with higher access frequency and better average quality scores have increased statistical weights, thus gaining higher priority in subsequent iterations. Through this weight adjustment mechanism based on evaluation metrics, the statistical significance of high-potential repair branches is continuously strengthened. After meeting preset iteration thresholds or passing all functional tests, the patch scheme with the highest access frequency and best average quality score is automatically locked and output, thereby constructing a theoretically complete and dynamically adaptive defect repair decision-making closed loop.
[0099] S2. Test and verify the candidate patches. If the verification fails, perform semantic space representation and adaptive clustering on the candidate patches that fail the verification to obtain the corresponding structured semantic clusters.
[0100] Furthermore, in step S2, the candidate patches are tested and verified. As a crucial physical feedback loop from the generation of spatial vectors to actual execution, testing and verification bear the heavy responsibility of rigorously reviewing the functionality and dynamically evaluating the quality of the candidate patches. The specific testing and verification process includes: dynamically injecting the generated patch fragments into the original software project by constructing an isolated automated testing sandbox environment, and triggering a preset regression test suite. By capturing real-time feedback signals during test execution (including but not limited to compilation status, runtime, exception stack traces, and the pass / fail ratio of test cases), it is possible to accurately determine whether the patch truly fixes the defective logic or introduces new regression faults.
[0101] In the specific execution process, the code changes of candidate patches are first automatically patched to ensure they conform to the project's build specifications. Then, the underlying test execution engine is concurrently invoked to perform full or targeted stress tests on the affected functional modules while maintaining execution environment consistency. If a candidate patch successfully passes all known fault test cases without causing degradation of the original functionality, it is considered a successful fix and marked as a valid solution output. If verification fails, detailed failure context (such as assertion errors or timeout information) is extracted and converted into quantifiable penalty signals to be fed back to subsequent semantic evaluation and path decision-making stages. This rigid constraint based on actual operating results not only provides a real-world reward function for the search algorithm but also ensures that the final delivered fix has extremely high production environment reliability.
[0102] Furthermore, such as Figure 1 and Figure 3 As shown, in step S2, if the verification fails, the candidate patch that fails the verification is represented in semantic space and adaptively clustered to obtain the corresponding structured semantic cluster.
[0103] This step aims to fundamentally address the technical bottleneck of traditional patching methods, which struggle to capture the deep intent of code when performing "patchwork" at the grammatical level, by constructing a multi-scale, granular adaptive semantic mapping mechanism. Its core logic lies in transforming discrete, unstructured code change information into geometric features in a multi-dimensional continuous vector space, thereby achieving a leap from "text matching" to "semantic alignment" in patching solutions. Specifically, it includes the following steps:
[0104] S21. Determine the scope of impact of the repair actions of candidate patches that have not passed verification.
[0105] S22. If the scope of the repair action is a local repair at the single function level, then extract the text difference terms constructed by adding and deleting lines of code, call the large language model to generate a natural language semantic summary, and use a pre-trained encoder to jointly map the text difference terms and the natural language semantic summary to obtain a semantic embedding vector.
[0106] For local repair at the single-function level, a composite semantic difference term is used as the basic representation unit. This unit not only includes text difference terms constructed by adding and deleting lines of code, but also innovatively introduces natural language semantic summaries generated synchronously using a large language model. Then, by jointly mapping the two through a pre-trained encoder, semantic intents such as "boundary condition correction" or "concurrency lock optimization" can be captured, forming a semantic embedding vector with strong discriminative power.
[0107] S23. If the scope of the repair action is a multi-function level project-level repair, then perform static analysis on the preset code repository to construct a global program dependency graph. Based on the topological association features of the global program dependency graph, perform convergence iteration to quantify the structural weight of each function change, and perform hierarchical semantic aggregation based on the structural weight to obtain a semantic embedding vector.
[0108] For complex project-level fixes involving collaborative modifications of multiple functions, to quantify the contribution of different function changes to the overall system stability, a static analysis of the code repository is first performed to construct a global program dependency graph. After constructing the global program dependency graph, the PageRank algorithm is introduced for convergence iteration. The physical meaning of this algorithm is that if a frequently called core function undergoes a semantic change, its structural weight in PageRank will significantly increase. This weight allocation mechanism based on topological importance ensures that the fix process prioritizes aligning with the most critical logical nodes in the system, effectively preventing patch failures due to ignoring core dependencies.
[0109] S24. Based on the spatial density distribution features, dynamic hierarchical clustering is performed on the semantic embedding vectors to obtain initial patch clusters, and the silhouette coefficient of the initial patch clusters is calculated. In the clustering and spatial optimization stage, a dynamic clustering algorithm based on the HDBSCAN (density-based hierarchical spatial clustering) framework is used to perform structured pruning on the generated patch vector space. This algorithm does not require a preset number of clusters and can adaptively identify semantic neighbors based on the density of the patch distribution. To ensure the scientific nature of the clustering evolution, the silhouette coefficient is introduced as a real-time monitoring indicator to ensure the scientific validity of the clustering evolution.
[0110] S25. When the contour coefficient is lower than the preset merging threshold, a spatial merging operation is performed on the initial patch cluster to compress redundant search paths. When a large number of patches are concentrated in a certain semantic region and the contour coefficient is lower than the preset merging threshold, it indicates that there is serious semantic duplication in the current repair attempt. The spatial merging operation is then triggered to merge these semantically similar patch clusters to compress redundant search paths and optimize search resources.
[0111] S26. When an outlier is detected outside the initial patch cluster, and the semantic space distance between the outlier and the initial patch cluster is greater than a preset splitting threshold, a cluster splitting operation is triggered. In the semantic space, the semantic space distance characterizes the degree to which the outlier deviates geometrically from the existing patch cluster. If a new outlier is found and the distance exceeds the preset splitting threshold, it indicates that the outlier represents a repair direction with independent semantic features, rather than noise points in the existing cluster. Triggering the cluster splitting operation at this time can divide the outlier and its neighborhood into a new semantic cluster, thereby achieving a refined division of the search space and guiding subsequent search decisions towards this emerging repair direction.
[0112] S27. The initial patch clusters after spatial merging or cluster splitting operations are identified as structured semantic clusters. Through this dynamic structured partitioning mechanism, the width of the search tree is continuously reduced and high-quality semantic branches are mined, greatly improving the execution efficiency and logical closure capability of large-scale software repair tasks.
[0113] It's important to understand that if the verification passes, the solution will be directly output as the final patch.
[0114] S3. Based on structured semantic clusters, perform multi-dimensional semantic consistency evaluation on candidate patches that have not passed verification to obtain dynamic reward information that represents the semantic gain of the current repair action.
[0115] This step transforms the semantic features of patches into quantifiable metrics that guide the search by constructing a complementary evaluation system, thereby providing precise reward signals for heuristic path selection. The mechanism consists of two core dimensions: semantic novelty evaluation and semantic ranking quality scoring. By dynamically balancing the benefits of exploring new paths with the potential to develop high-quality regions, it ensures that the repair process efficiently avoids local optima and quickly converges to the global optimum.
[0116] Furthermore, such as Figure 1 and Figure 4 As shown, step S3 includes:
[0117] S31. Construct and dynamically maintain a historical reference patch set. Specifically, this involves retrieving historical data to construct and maintain a historical reference patch set.
[0118] S32. Determine whether the historical reference patch set is empty, or whether the currently generated candidate patch belongs to a new repair attempt type.
[0119] S33. If the historical reference patch set is not empty, calculate the average semantic space distance between the current semantic representation of the candidate patch and the historical semantic representation in the historical reference patch set, and map the average semantic space distance to a normalized interval to obtain a semantic novelty score. In this process, the semantic difference between the currently generated patch and the historical exploration path is mainly measured. Specifically, the uniqueness of the patch is characterized by the average cosine distance in a continuous vector space containing multi-dimensional features, where the dimension of the vector space is determined by the feature dimension output by the pre-trained encoder. For patches highly similar to historical schemes, the score is mapped by calculating the mean semantic distance between the patch and the embedding subset of the historical reference patch set.
[0120] S34. If the historical reference patch set is empty or the candidate patch belongs to a new repair attempt type, the candidate patch is directly assigned the highest semantic novelty score to encourage the search algorithm to explore unnoticed areas.
[0121] It is important to understand that, at the semantic novelty evaluation level, in order to ensure the robustness and real-time performance of the evaluation, an embedded caching optimization mechanism and explicit boundary condition processing logic are integrated. This avoids the waste of redundant computational resources and ensures the consistency and stability of the evaluation results at different repair stages.
[0122] S35. The large language model is invoked to insert candidate patches into the sorted list of the corresponding structured semantic clusters based on a relative preference mechanism. The ranking position of the candidate patch in the sorted list is obtained, and the quality score of the candidate patch is calculated based on the ranking position and the failure statistical features of the structured semantic clusters. In the semantic ranking scoring dimension, unlike the approach of relying on the large language model to directly give an absolute score, this embodiment of the invention focuses on evaluating the relative competitive advantage of the patch in high-quality semantic clusters, and adopts a relative evaluation mechanism based on preference order relationship, which can effectively shield annotation noise caused by subjective scale differences.
[0123] Furthermore, such as Figure 4 and Figure 5 As shown, step S35 includes:
[0124] S351. When a candidate patch enters the corresponding structured semantic cluster, a relative evaluation mechanism based on preference order is triggered. The large language model is invoked to perform a pairwise relative preference comparison between the candidate patch and historical patches within the structured semantic cluster, yielding the relative comparison result. This step is designed based on the Bradley-Terry model, which posits that individuals exhibit higher consistency and robustness when making relative comparisons than when assigning absolute scores. In practice, the large language model is not required to directly output an absolute quality score; instead, it is required to make preference choices between pairs of patches based on logical correctness or fit of repair intent. This relative comparison mechanism effectively shields annotation noise caused by subjective scale differences or contextual dependencies.
[0125] S352. Based on the relative comparison results, insert the candidate patches into the sorted list maintained within the structured semantic cluster according to the principle of decreasing quality, so as to update the dynamic preference sequence reflecting logical correctness, and extract the sorting position of the candidate patches from the dynamic preference sequence.
[0126] S353. The basic quality score is obtained by quantizing the ranking position using an exponential decay function, and the historical failure frequency of the structured semantic clusters corresponding to the candidate patches is extracted as a failure statistical feature. The exponential decay function ensures that patches with higher rankings receive significantly higher basic scores.
[0127] S354. Determine if the historical failure frequency exceeds a preset frequency threshold. If the historical failure frequency exceeds the threshold, dynamically calculate the semantic cluster penalty coefficient based on the historical failure frequency and a preset normalized reference value. Simultaneously, to prevent invalid idling in frequently failing logical regions, a semantic cluster penalty coefficient is introduced, which is obtained by linearly mapping the deviation of the current cluster's historical failure frequency relative to the normalized reference value. The normalized reference value is the statistical average level of the failure frequencies of all explored semantic clusters in the system.
[0128] S355. Using the semantic cluster penalty coefficient as a penalty term, the base quality score is compressed and attenuated to obtain a quality score. If the failure rate of a semantic direction corresponding to a certain semantic cluster is significantly higher than the normalized reference value, the evaluation weight of that path will be compressed accordingly.
[0129] S36. The weighting ratio of semantic novelty score and quality score is dynamically adjusted through an online reinforcement learning mechanism, and the weighted fused score is determined as dynamic reward information.
[0130] This dual-dimensional fusion assessment not only robustly captures the quality dimensions of patches but also naturally formalizes preference issues using ranked data, improving generalization ability across different software projects. Through this sophisticated quantitative feedback, high-confidence remediation paths can be identified and locked within a limited search step, thereby driving the intelligent evolution of automated remediation from simple text generation to deep logic alignment. Furthermore, the fusion assessment results can be integrated into an improved upper bound principle for confidence intervals.
[0131] S4. In the updated heuristic search tree, extract the repair decision trajectory from the initial node to the node corresponding to the currently generated candidate patch, integrate the repair decision trajectory with dynamic reward information, and generate context-enhanced prompt information.
[0132] This step overcomes the technical limitations of isolated information in traditional repair methods by constructing a semantic panoramic view based on decision trajectories. Its core innovation lies in the structured extraction of the complete evolution path from the root node to the current node in Monte Carlo Tree Search (MCTS) and its transformation into a continuous context sequence that can be understood by a large language model, thereby providing background and logical support for the generation of each repair node.
[0133] Furthermore, such as Figure 1 and Figure 6 As shown, step S4 includes:
[0134] S41. In the updated heuristic search tree, extract the repair decision trajectory from the initial node to the corresponding child node of the currently generated candidate patch.
[0135] S42. Each sub-node on the repair decision trajectory is identified as a decision point, and multi-dimensional feature units are extracted for each decision point. Each multi-dimensional feature unit includes a summary of the natural language intent, novelty score, and quality score of the candidate patch for the corresponding sub-node.
[0136] S43. Arrange the multi-dimensional feature units in chronological order to construct a repair evolution chain. By arranging these nodes with evaluation feedback in chronological order, a clear repair evolution chain is constructed, intuitively presenting the semantic evolution logic of the repair intention.
[0137] S44. Based on the repair evolution chain, perform semantic falsification of failure paths to identify positive gain repair directions and falsified attempted repair actions. Specifically, based on each multi-dimensional feature unit in the repair evolution chain, compare the quality score of the multi-dimensional feature unit with a preset validity threshold, and compare the novelty score with a preset novelty interval. If the quality score is greater than the validity threshold and the novelty score is within the preset novelty interval, the logical direction corresponding to the natural language intent summary is identified as a positive gain repair direction. If the test verification feedback is a failure, the repair action corresponding to the natural language intent summary is identified as a falsified attempted repair action. With the help of the above processing method, it is possible to clearly perceive which logical directions have been verified as valid and which attempts have been falsified in previous iterations. This not only avoids repeated exploration in the known invalid repair space and significantly accelerates the convergence of the patch space to the high-quality region, but also ensures the semantic coherence between multiple consecutive repair actions.
[0138] S45. For project-level fixes involving multiple functions, extract cross-file global logical constraints from the fix evolution chain. For defects involving multiple code locations or complex logical jumps, this step identifies cross-file interface changes and variable dependencies by parsing candidate patches and natural language intent summaries of corresponding child nodes in the fix evolution chain, thereby extracting the corresponding global logical constraints. This maintains the cross-file logical constraints and historical decision-making context, effectively eliminating the problem of information loss during the fix process.
[0139] S46. The repair evolution chain, positive gain repair direction, and disproved trial repair actions are integrated, and the extracted global logical constraints are simultaneously integrated when multi-function-level project-level repairs are involved to construct enhanced background information. According to the preset prompt word template, the above-mentioned repair evolution chain, positive gain repair direction, disproved trial repair actions, and global logical constraints are mapped and filled into the corresponding semantic slots, performing structured organization and organic integration to construct enhanced background information. This organic integration of search history and current state greatly enhances the transparency and interpretability of the automated repair system. It transforms the originally "black box" random search process into a traceable and understandable logical evolution trajectory, presenting the decision-making path behind the repair results.
[0140] S47. The enhanced background information and dynamic reward information are concatenated to generate context-enhanced prompts. Using a preset sequence delimiter, the enhanced background information and dynamic reward information are concatenated into strings, transforming them into a continuous context sequence readable by a large language model, thus generating the final context-enhanced prompts. This comprehensive context-enhanced paradigm not only improves the targeting and accuracy of patch generation but also provides robust underlying support for building a highly reliable and intelligent software maintenance system.
[0141] S5. Feedback the context-enhanced hints to the large language model to guide it in generating the next round of candidate patches based on the logical relationship between the repair decision trajectory and the dynamic reward information, until the test verification is passed or the preset termination condition is met.
[0142] Furthermore, such as Figure 1 and Figure 7 As shown, step S5 includes:
[0143] S51. Call the large language model to parse the contextual enhancement prompts of the input, map the enhanced background information with the dynamic reward information, and determine the generation constraints.
[0144] S52. Based on the generation constraints, guide the large language model to combine with the repair evolution chain, avoid the falsified trial repair actions and follow the positive gain repair direction, and follow the global logical constraints when the enhanced background information contains global logical constraints to generate the next round of candidate patches.
[0145] S53. Dynamically integrate the candidate patches of the next round as new child nodes into the heuristic search tree, and feed the candidate patches of the next round back to the step of testing and verifying the candidate patches, so as to trigger a new round of automated repair cycle.
[0146] S54. During the execution of the automated repair loop, monitor the feedback results of the test verification and the iteration status of the heuristic search tree in real time.
[0147] S55. If the feedback result of the current test verification indicates that the candidate patch has passed the test verification, then the automatic repair loop ends and the candidate patch that has passed the test verification is output as the repair solution.
[0148] S56. If the number of iterations of the automatic repair loop reaches the preset iteration threshold, the preset termination condition is determined to be met, the automatic repair loop ends, and the candidate patch with the best search evaluation index is output as the repair solution based on the search evaluation index of each child node in the heuristic search tree.
[0149] Furthermore, embodiments of the present invention provide an apparatus, which specifically includes the following systems, devices, and media.
[0150] Specifically, the semantic exploration-based large language model code defect repair system includes: a heuristic path search decision module, used to construct a heuristic search tree using the acquired defective code as the initial node, and calling the large language model to parse the contextual semantic features of the defective code to generate candidate patches, updating the heuristic search tree based on the candidate patches; a patch verification module, used to test and verify the candidate patches; a semantic space representation and clustering module, used to perform semantic space representation and adaptive clustering on the candidate patches that fail verification, obtaining the corresponding structured semantic clusters; and a multi-dimensional semantic evaluation module, used to evaluate the failed verification based on the structured semantic clusters. The candidate patches undergo multi-dimensional semantic consistency evaluation to obtain dynamic reward information representing the semantic gain of the current repair action; the cross-domain context enhancement and integration module is used to extract the repair decision trajectory from the initial node to the corresponding node of the currently generated candidate patch in the updated heuristic search tree, integrate the repair decision trajectory with the dynamic reward information, and generate context enhancement prompt information; the feedback and iteration module is used to feed the context enhancement prompt information back to the large language model to guide the large language model to generate the next round of candidate patches based on the logical relationship between the repair decision trajectory and the dynamic reward information, until the test verification is passed or the preset termination condition is reached.
[0151] This system is used for automated defect repair and logic optimization in software projects. Users only need to provide the source code with defects and related test scripts, and the system can automatically conduct in-depth exploration of the correlation between defect semantics and repair paths, generating high-quality repair patches. The repair results indicate specific modification suggestions for each vulnerability point, as well as the semantic alignment degree between the repaired code and the original logic, achieving a precise mapping between defect characteristics and repair actions. The system quickly filters potential repair branches through a heuristic path search decision module, transforms source code information and clusters it in the semantic space through a semantic space representation and clustering module, and uses a multi-dimensional semantic evaluation module for deep logical consistency judgment. At the same time, the cross-domain context enhancement and integration module adds the results of preceding nodes to the patch evaluation process. Finally, the patch verification module uses corresponding test cases to verify the patch quality, thus efficiently and accurately completing automated repair from vulnerability awareness to logical closure without manual pre-set templates.
[0152] Meanwhile, embodiments of the present invention provide a large language model code defect repair device based on semantic exploration, which includes: at least one controller; and a memory communicatively connected to the at least one controller; wherein the memory stores instructions that can be executed by the at least one controller, and the instructions are executed by the at least one controller to enable the at least one controller to perform the large language model code defect repair method based on semantic exploration as described above.
[0153] Furthermore, embodiments of the present invention provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a controller, implement the above-described method for repairing defects in large language model code based on semantic exploration.
[0154] In summary, the embodiments of the present invention provide a method and apparatus for repairing code defects in a large language model based on semantic exploration, with reference to... Figure 8 Specifically, firstly, the source code fragment of the defect to be repaired is input into the system, triggering an automated repair loop. Then, an improved Monte Carlo tree search strategy is used for global modeling, generating candidate patch fragments with potential repair value through multiple iterations. Next, the generated patches enter a patch verification test: if the patch passes the test, the patch output is executed directly to complete the repair task; if the test fails, the patch enters a deep semantic processing loop. In this loop, failed patches are first subjected to high-dimensional embedding and adaptive clustering to extract their deep semantic features. Then, the semantic novelty of the patch is quantified and the reward signal is strengthened from two dimensions: static intent alignment and dynamic functional evaluation. Finally, the semantic information of the current attempt is logically integrated with historical repair paths to eliminate path gaps. The integrated semantic enhancement information is fed back to the heuristic path search decision module, guiding the next round of more targeted patch generation, thus constructing an intelligent exploration system from defect perception to logical closed loop.
[0155] The above-mentioned solution, through multi-module collaboration, automatically explores the high-dimensional repair space without human intervention, aiming to improve the semantic correctness and logical consistency of patch generation in complex software repair tasks, and effectively overcomes the defects of blind search, shallow semantics and logical discontinuity in existing technologies.
[0156] Firstly, regarding patch search efficiency and intelligent path decision-making, this invention achieves efficient pruning and targeted exploration of high-dimensional, non-convex patch spaces by integrating an improved Monte Carlo tree search algorithm based on the UCB principle. This method innovatively balances the "development" and "exploration" of repair paths, autonomously identifying high-potential semantic regions and overcoming the technical bottleneck of traditional random search or simple heuristic algorithms easily getting trapped in local optima within complex code logic.
[0157] Secondly, regarding the accuracy of semantic representation and spatial evolution capability, this invention innovatively proposes a granular adaptive semantic representation mechanism. It quantifies the importance of function structures using the PageRank algorithm and combines it with HDBSCAN dynamic hierarchical clustering to structurally partition the patch space. This method achieves a leap from "code syntax comparison" to "deep semantic alignment," automatically identifying and compressing semantically redundant paths, and greatly simplifying the width of the search tree.
[0158] Furthermore, regarding the logical coherence and robustness of the repair process, this invention employs a cross-domain context enhancement technique based on MCTS decision trajectories, shifting patch quality evaluation from "absolute scoring" to "relative ranking based on preference order." By introducing a dual-dimensional evaluation system of semantic novelty and failure cluster penalty terms, this method effectively shields annotation noise and logical gaps in the large language model LLM generation process, significantly enhancing the interpretability and logical closure capability of the automated repair process.
[0159] Finally, regarding engineering adaptability and automated closed-loop repair rate, this invention constructs a fully automated chain from defect perception to dynamic verification, capable of real-time correction of search bias based on sandbox feedback. In comparative testing on large-scale software projects, the overall repair success rate of this solution is approximately 10.8% higher than the best existing technology, significantly enhancing the practical value of automated maintenance of highly reliable software in unattended scenarios.
[0160] Therefore, through the organic combination of the above mechanisms, this invention can perfectly support a variety of complex automated software repair tasks, such as cross-file logical repair, multi-location defect collaborative handling, deep semantic vulnerability patching, and high-quality patch automatic evolution, providing robust underlying support for automated maintenance in the field of software engineering.
[0161] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0162] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.
[0163] It should be noted that, in this invention, any reference numerals within parentheses should not be construed as limiting the scope of the invention. The word "comprising" does not exclude the presence of unlisted components or steps. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. This invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In this invention, where several devices are listed, several of these devices may be embodied by the same hardware. The use of the terms first, second, third, etc., is merely for convenience and does not indicate any order. These terms can be understood as part of the component names.
[0164] Furthermore, it should be noted that in the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0165] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the invention should be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.
[0166] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of this invention and its equivalents, then this invention should also include these modifications and variations.
Claims
1. A method for fixing code defects in a large language model based on semantic exploration, characterized in that, include: The obtained defect code is used as the initial node to build a heuristic search tree, and a large language model is called to parse the contextual semantic features of the defect code to generate candidate patches. The heuristic search tree is then updated based on the candidate patches. Candidate patches are tested and verified. If the verification fails, the candidate patches that fail the verification are represented in semantic space and adaptively clustered to obtain the corresponding structured semantic clusters. Based on structured semantic clusters, multi-dimensional semantic consistency evaluation is performed on candidate patches that fail verification in order to obtain dynamic reward information that represents the semantic gain of the current repair action. In the updated heuristic search tree, the repair decision trajectory from the initial node to the node corresponding to the currently generated candidate patch is extracted, and the repair decision trajectory is integrated with dynamic reward information to generate context-enhanced prompt information; The contextual enhancement prompts are fed back to the large language model to guide it in generating the next round of candidate patches based on the logical relationship between the repair decision trajectory and the dynamic reward information, until the test verification is passed or the preset termination condition is met.
2. The method for fixing code defects in a large language model based on semantic exploration as described in claim 1, characterized in that, The obtained defect code is used as the initial node to construct a heuristic search tree, and a large language model is invoked to parse the contextual semantic features of the defect code to generate candidate patches. The heuristic search tree is then updated based on the candidate patches, including: The obtained defect code is used as the root node to construct the initial heuristic search tree; Starting from the root node, child nodes are recursively filtered in the search tree based on the improved upper bound principle of confidence intervals until a leaf node in a non-terminating state is reached; wherein, the improved upper bound principle of confidence intervals is configured to determine the filtering priority of each child node by weighting the cumulative semantic value and exploration gain of each child node. When a leaf node in a non-terminating state is reached, the large language model is called to parse the contextual semantic features of the code corresponding to the current leaf node at a preset level, so as to generate multiple candidate patches with corresponding semantic confidence, and the candidate patches are dynamically integrated into the search tree as new child nodes. For candidate patches, perform patch effect prediction. During the prediction process, recursively generate patches or execute preset test cases to verify along the target search path with the highest semantic confidence, and obtain preliminary value feedback of the target search path. The initial value feedback is propagated back along the target search path to the root node. The search evaluation index of each child node on the target search path is calculated and updated simultaneously. Based on the search evaluation index, the statistical weight of each child node in the search tree is adjusted to complete the update of the search tree.
3. The method for fixing code defects in a large language model based on semantic exploration as described in claim 1, characterized in that, If the verification fails, the candidate patches that fail the verification are then subjected to semantic space representation and adaptive clustering to obtain the corresponding structured semantic clusters, including: Determine the scope of impact of the fixes implemented by candidate patches that failed verification; If the scope of the repair action is a local repair at the single function level, then extract the text difference terms constructed by adding and deleting lines of code, call the large language model to generate natural language semantic summary, and use the pre-trained encoder to jointly map the text difference terms and natural language semantic summary to obtain semantic embedding vectors. If the scope of the repair action is a multi-function level project-level repair, then static analysis is performed on the preset code repository to construct a global program dependency graph. Based on the topological association features of the global program dependency graph, convergence iteration is performed to quantify the structural weight of each function change, and hierarchical semantic aggregation is performed based on the structural weight to obtain a semantic embedding vector. Based on the spatial density distribution features, dynamic hierarchical clustering is performed on the semantic embedding vectors to obtain the initial patch clusters, and the silhouette coefficients of the initial patch clusters are calculated: When the contour coefficient is lower than the preset merging threshold, a spatial merging operation is performed on the initial patch cluster to compress redundant search paths; When an outlier is detected outside the initial patch cluster, and the semantic space distance between the outlier and the initial patch cluster is greater than a preset splitting threshold, a cluster splitting operation is triggered. The initial patch clusters after spatial merging or cluster splitting operations are identified as structured semantic clusters.
4. The method for fixing code defects in a large language model based on semantic exploration as described in claim 1, characterized in that, Based on structured semantic clusters, multi-dimensional semantic consistency evaluation is performed on candidate patches that fail verification to obtain dynamic reward information representing the semantic gain of the current repair action, including: Build and dynamically maintain a collection of historical reference patches; Determine if the historical reference patch set is empty, or if the currently generated candidate patch belongs to a new repair attempt type; If the historical reference patch set is not empty, the average semantic space distance between the current semantic representation of the candidate patch and the historical semantic representation in the historical reference patch set is calculated, and the average semantic space distance is mapped to a normalized interval to obtain the semantic novelty score. If the historical reference patch set is empty or the candidate patch belongs to a new repair attempt type, the candidate patch is directly assigned the highest semantic novelty score; The large language model is invoked to insert candidate patches into the sorted list of the corresponding structured semantic cluster based on the relative preference mechanism. The sorting position of the candidate patch in the sorted list is obtained, and the quality score of the candidate patch is calculated based on the sorting position and the failure statistical features of the structured semantic cluster. By dynamically adjusting the weighting ratio of semantic novelty score and quality score through an online reinforcement learning mechanism, the weighted fusion score is determined as dynamic reward information.
5. The method for fixing code defects in a large language model based on semantic exploration as described in claim 4, characterized in that, The large language model is invoked to insert candidate patches into the sorted list of the corresponding structured semantic clusters based on a relative preference mechanism. The ranking position of the candidate patch in the sorted list is obtained, and a quality score for the candidate patch is calculated based on the ranking position and the failure statistical features of the structured semantic clusters, including: Once a candidate patch enters the corresponding structured semantic cluster, a relative evaluation mechanism based on preference order is triggered. The large language model is invoked to perform a pairwise relative preference comparison between the candidate patch and the historical patches within the structured semantic cluster, and the relative comparison results are obtained. Based on the relative comparison results, candidate patches are inserted into the sorted list maintained within the structured semantic cluster according to the principle of decreasing quality, so as to update the dynamic preference sequence reflecting logical correctness and extract the sorting position of candidate patches from the dynamic preference sequence. The basic quality score is obtained by quantizing the sorting position using the exponential decay function, and the historical failure frequency of the structured semantic cluster corresponding to the candidate patch is extracted as the failure statistical feature. Determine whether the frequency of historical failures is greater than a preset frequency threshold. If the frequency of historical failures is greater than the frequency threshold, dynamically calculate the semantic cluster penalty coefficient based on the frequency of historical failures and the preset normalized reference value. By using the semantic cluster penalty coefficient as a penalty term, the basic quality score is compressed and attenuated to obtain a quality score.
6. The method for fixing code defects in a large language model based on semantic exploration as described in claim 1, characterized in that, In the updated heuristic search tree, the repair decision trajectory from the initial node to the node corresponding to the currently generated candidate patch is extracted. This repair decision trajectory is then integrated with dynamic reward information to generate context-enhanced cue information, including: In the updated heuristic search tree, extract the repair decision trajectory from the initial node to the corresponding child node of the currently generated candidate patch; Each sub-node on the repair decision trajectory is identified as a decision point, and multi-dimensional feature units are extracted for each decision point. Each multi-dimensional feature unit includes the natural language intent summary, novelty score, and quality score of the candidate patch of the corresponding sub-node. Arrange the multidimensional feature units according to the time series to construct the repair evolution chain; Based on the repair evolution chain, semantic falsification of failure paths is performed to identify positive gain repair directions and falsified trial repair actions; For project-level repairs involving multiple functions, extract global logical constraints across files from the repair evolution chain; The repair evolution chain, positive gain repair direction and falsified trial repair actions are integrated, and the extracted global logical constraints are integrated in the same way when project-level repairs involving multiple functions are involved, so as to build enhanced background information. The enhanced background information is combined with the dynamic reward information to generate context-enhanced prompts.
7. The method for fixing code defects in a large language model based on semantic exploration as described in claim 6, characterized in that, Contextual enhancement prompts are fed back to the large language model to guide it in generating the next round of candidate patches based on the logical relationship between the repair decision trajectory and dynamic reward information, until the test verification is passed or the preset termination conditions are met, including: The large language model is invoked to parse the contextual enhancement prompts of the input, and the enhanced background information is mapped with dynamic reward information to determine the generation constraints. Based on the generative constraints, the large language model is guided to combine the repair evolution chain, avoid the falsified trial repair actions and follow the positive gain repair direction, and follow the global logical constraints when the enhanced background information contains global logical constraints to generate the next round of candidate patches. The next round of candidate patches are dynamically integrated into the heuristic search tree as new child nodes, and the next round of candidate patches are fed back to the step of testing and verifying the candidate patches to trigger a new round of automated repair loop; During the execution of the automated repair loop, the feedback results of the test verification and the iteration status of the heuristic search tree are monitored in real time. If the feedback result of the current test verification indicates that the candidate patch has passed the test verification, then the automated repair loop ends and the candidate patch that has passed the test verification is output as the repair solution. If the number of iterations in the automated repair loop reaches the preset iteration threshold, the preset termination condition is determined to have been met, the automated repair loop ends, and the candidate patch with the best search evaluation index is output as the repair solution based on the search evaluation index of each child node in the heuristic search tree.
8. A code defect repair system for a large language model based on semantic exploration, characterized in that, include: The heuristic path search decision module is used to construct a heuristic search tree using the obtained defective code as the initial node, and calls a large language model to parse the contextual semantic features of the defective code to generate candidate patches, and updates the heuristic search tree based on the candidate patches. The patch verification module is used to test and verify candidate patches; The semantic space representation and clustering module is used to perform semantic space representation and adaptive clustering on candidate patches that fail verification, so as to obtain the corresponding structured semantic clusters. The multi-dimensional semantic evaluation module is used to perform multi-dimensional semantic consistency evaluation on candidate patches that have not passed the verification based on structured semantic clusters, so as to obtain dynamic reward information that represents the semantic gain of the current repair action. The cross-domain context enhancement and integration module is used to extract the repair decision trajectory from the initial node to the corresponding node of the currently generated candidate patch in the updated heuristic search tree, integrate the repair decision trajectory with dynamic reward information, and generate context enhancement prompt information. The feedback and iteration module is used to feed contextual enhancement prompts back to the large language model, so as to guide the large language model to generate the next round of candidate patches based on the logical relationship between the repair decision trajectory and dynamic reward information, until the test verification is passed or the preset termination condition is reached.
9. A large language model code defect repair device based on semantic exploration, characterized in that, include: At least one controller; and a memory that is communicatively connected to at least one controller; The memory stores instructions that can be executed by at least one controller, which are executed by at least one controller to enable the at least one controller to perform a method for fixing code defects in a large language model based on semantic exploration as described in any one of claims 1-7.
10. A computer-readable storage medium storing computer-executable instructions thereon, characterized in that, When the executable instructions are executed by the controller, they implement a method for fixing code defects in a large language model based on semantic exploration as described in any one of claims 1-7.
