A SQL automatic generation system based on large model and complex query decomposition method
The SQL automatic generation system, which utilizes large models and complex query decomposition methods, addresses the issues of insufficient domain adaptability and complex query processing capabilities in the power grid auditing field. It achieves intelligent and automated power grid auditing, improves the compliance and accuracy of SQL statements, and enables continuous system optimization through a closed-loop feedback mechanism.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- STATE GRID SHANDONG ELECTRIC POWER CO
- Filing Date
- 2026-05-06
- Publication Date
- 2026-06-19
Smart Images

Figure CN122240654A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the interdisciplinary field of artificial intelligence, natural language processing, database technology and power grid auditing, and more specifically, to an automatic SQL generation system based on large models and complex query decomposition methods. Background Technology
[0002] In auditing, querying and analyzing massive amounts of business data is a core aspect. Traditional manual SQL query writing is inefficient and requires high levels of expertise from auditors. Therefore, utilizing Text-to-SQL technology to automatically convert natural language into executable SQL statements can significantly lower the data query threshold and improve the intelligence level of audit sampling and suspicious point analysis. However, current general Text-to-SQL technologies generally suffer from insufficient domain adaptability, poor module collaboration, and weak handling capabilities in complex scenarios when applied to vertical industries. These problems are particularly prominent in highly specialized and rule-based fields like power grid auditing. Related technologies can only achieve preliminary applications by simply modifying general Text-to-SQL systems, or only integrate basic domain knowledge retrieval and simple query decomposition functions with fixed templates, which is insufficient to meet the actual business needs of power grid auditing. For relevant technologies, refer to research on general intelligent query systems in the power auditing field and literature on the vertical domain transformation of general Text-to-SQL systems.
[0003] Disadvantages of existing technology: Insufficient depth of domain knowledge integration and poor adaptability: The general-purpose Text-to-SQL system has not built a structured and systematic domain knowledge system for power grid auditing scenarios. It can only achieve simple matching of a small number of professional terms and cannot embed the laws, regulations and business constraints of power grid auditing into the core links such as natural language parsing and SQL generation. As a result, the generated SQL statements are difficult to meet the actual needs in terms of audit compliance and semantic accuracy.
[0004] The system suffers from weak complex query processing capabilities and limited practicality: The existing system lacks an intelligent query decomposition mechanism adapted to power grid auditing business. For complex queries such as multi-table joins and deep nesting that frequently occur in power grid auditing, it can only be processed through fixed templates or simple logic, which is prone to SQL statement logic errors and execution failures, and cannot support the complex business query needs of power grid auditing. Summary of the Invention
[0005] To overcome the shortcomings of existing technologies, this invention provides an automatic SQL generation system based on a large model and complex query decomposition method. Specifically, it is an integrated Text-to-SQL auditing system that integrates natural language parsing for power grid auditing, intelligent decomposition of complex queries, SQL generation, and closed-loop optimization. It is applicable to the accurate conversion of natural language queries into executable SQL statements across all power grid auditing scenarios, achieving intelligent and automated power grid auditing. This invention solves the following problems: addressing the fragmented functional modules and low modularity of existing power grid auditing Text-to-SQL systems, constructing an integrated system architecture, and achieving the organic integration and efficient linkage of modules such as natural language parsing, complex query decomposition, SQL generation, and optimization verification.
[0006] (2) To address the problem of insufficient integration of power grid audit knowledge into the system, a natural language parsing method based on power grid audit rules and regulations is embedded throughout the system to achieve deep integration and semantic alignment of power grid audit knowledge in each module.
[0007] (3) To solve the problem of insufficient complex query processing capability of the system, integrate the step-by-step decomposition method of complex query in power grid audit, realize the accurate decomposition and SQL generation of typical complex queries in power grid audit, and improve the processing capability of complex queries.
[0008] This invention is achieved through the following technical solution: an automatic SQL generation system based on large models and complex query decomposition methods, comprising: The multi-source power grid audit knowledge structuring fusion module is used to collect structured and unstructured power grid audit knowledge, perform differentiated vectorized representation and fusion, generate unified power grid audit knowledge rule vectors and store them in a vector database to form a power grid audit knowledge rule base; The power grid audit natural language parsing module receives natural language queries input by auditors, transforms them into a query embedding matrix through an embedding layer, and performs cross-attention calculation with the retrieved power grid audit knowledge rule embedding matrix to generate an enhanced semantic representation after knowledge fusion. This enhanced semantic representation is then used as the basis for further processing. Generate a set of candidate schema items from the database schema. ; The complex query decomposition module for power grid auditing is used to determine the type of the query based on the enhanced semantic representation and the candidate pattern item set, and to adopt a differentiated step-by-step decomposition strategy to generate SQL substructures and perform structural integration. It also introduces a multi-loss supervision mechanism based on syntax matching, execution consistency and alignment with power grid auditing rules to optimize and verify the integrated SQL statement and generate a high-accuracy SQL statement. The execution verification and closed-loop feedback module is used to execute optimized SQL statements and perform multi-dimensional quality assessments, generate guiding feedback signals, and continuously improve system performance by updating system model parameters and the power grid audit knowledge rule base through three-stage domain adaptive fine-tuning.
[0009] As a preferred solution, the multi-source power grid audit knowledge structure fusion module specifically performs the following steps: Step A1, Multi-source knowledge collection: Collect two types of power grid audit knowledge sources: one is structured data, including power grid accounting charts, audit threshold standards, and database schema relationships; the other is unstructured text, including power grid audit regulations, industry standard documents, and internal inspection guidelines. Step A2, Differentiated Vectorization Representation: For structured data, a knowledge graph is constructed and a graph neural network (GNN) is used to generate structural feature vectors. For unstructured text, key elements are extracted using natural language processing techniques, and semantic feature vectors are generated through a pre-trained language model. ; Step A3, Knowledge Fusion and Storage: Align and fuse the two types of feature vectors from Step A2 to generate a unified power grid audit knowledge rule vector. The data is then stored in the high-performance vector database ChromaDB to form a power grid audit knowledge rule base. ; Step A4: Provide knowledge retrieval services: Encapsulate standardized knowledge retrieval interfaces to support subsequent steps in quickly retrieving and recalling the most relevant Top-K power grid audit knowledge rules from the vector database based on the semantics of the input information.
[0010] As a preferred solution, the power grid audit natural language parsing module specifically performs the following steps: Step B1, Query Vectorization: Used to vectorize user natural language queries. It is transformed into a query embedding matrix through the embedding layer. .
[0011] Step B2, Cross-Attention Knowledge Fusion: Used to embed the retrieved audit knowledge rules into the matrix. Cross-attention calculation with query embedding matrix , , ; Calculate the attention weight matrix : ; Augmented representation after knowledge fusion for: ; Through residual connections and layer normalization, the final enhanced semantic representation is obtained: ; Step B3, Pattern Linking: Used for augmented semantic representation and database schema Calculate semantic similarity and combine it with instance data matching to generate an accurate set of candidate pattern items. For pattern items Its overall score is: ; in, Based on pattern items Sample data and queries X Matching degree calculation Because the score exceeds the threshold The pattern items constitute the structure.
[0012] As a preferred solution, the complex query decomposition module for power grid auditing specifically executes the following steps: Step C1: Determining the type of complex queries in power grid auditing: Enhanced semantic representation that integrates power grid audit knowledge With candidate pattern set The concatenation is used as input to a large language model that has been fine-tuned with power grid audit corpus, and the accurate classification of complex power grid audit queries is achieved through probabilistic classification decision-making. Step C2: Query decomposition based on multi-level recursion mechanism: The result is determined based on the query type. A differentiated step-by-step decomposition strategy is adopted, and a multi-level recursive mechanism is used to decompose complex queries in power grid auditing layer by layer, generating corresponding SQL substructures. The power grid auditing knowledge rule base is embedded throughout the decomposition process. R Business constraints; Step C3: Integration of subquery structures specific to power grid auditing: To address the multiple SQL substructures generated after decomposition, a structural integration mechanism adapted to the power grid audit scenario is constructed to organically combine the subqueries into a complete SQL statement. This mechanism verifies whether the logical relationships between the subqueries meet the business requirements of power grid auditing; and, following SQL syntax specifications, concatenates the subqueries in the logical order of decomposition, supplementing necessary syntax keywords to generate a preliminary complete SQL statement. ; to create a preliminary complete SQL statement With the power grid audit knowledge rule base R Compare and verify whether the constraints, aggregation rules, and table join relationships in the statements fully comply with the business rules and compliance requirements of power grid auditing. Step C4, Optimization and Validation with Multi-Loss Supervision: A multi-loss supervision mechanism based on syntax matching, execution consistency, and alignment with power grid audit rules is introduced to optimize and verify the integrated complete SQL statement.
[0013] Furthermore, step C1 specifically includes the following steps: Step C1-1: Define the set of category tags for power grid audit queries. ,in: This is a single-table query, involving only one table in the power grid audit database. For multi-table join queries: involving ≥2 tables, and the natural language query contains commonly used related keywords for power grid auditing; Nested queries: Natural language queries contain aggregate conditions; Step C1-2: The model generates the probabilities of each class label through autoregression. The generation process is as follows: ; Step C1-3: Restrict the generation space to contain only the three labels mentioned above, calculate the joint probability of each label, and normalize it: ; Step C1-4: Select the tag with the highest probability as the final query type determination result: .
[0014] Furthermore, step C2 specifically includes the following steps: Step C2-1, Direct generation of single-table queries: If it is determined to be a single-table query, it is directly generated based on the candidate pattern item set. The process involves identifying a unique target power grid audit table, mapping the power grid audit constraints in natural language queries to standard SQL filter conditions, identifying the target fields of the query and generating SELECT clauses, and directly generating a normalized single-table SQL query statement with a projection-selection structure. During the generation process, the filter conditions are verified to ensure they conform to power grid audit rules. Step C2-2, Logical chain decomposition of multi-table join query: If it is determined to be a multi-table join query, based on the foreign key relationships and knowledge rule base of the power grid audit database. R The table-to-table business relationship rules enable the recursive decomposition of the table join logic chain, thereby enhancing semantic representation. Extract the core entities and table join relationships from the power grid audit query; then, based on the candidate pattern item set... In the table primary and foreign key constraints, combined with the power grid audit knowledge rule base RThe table-to-table business association rules employ a graph path search algorithm to deduce the optimal table join logic chain, avoiding syntactic ambiguity. Following the order of the join logic chain, multi-table join queries are recursively decomposed into pairwise table join subqueries. A corresponding JOIN clause is generated for each subquery, and the business association rules for power grid auditing are embedded in the ON condition. If the query contains aggregate conditions for power grid auditing, the aggregate function is embedded in the corresponding join substructure, generating a GROUP BY / HAVING clause.
[0015] Step C2-3: Hierarchical Decomposition of Nested Queries using a Tree-like Decoder: If a nested query is identified, a bottom-up tree-like decoder strategy is used for hierarchical recursive decomposition to generate nested SQL syntax subtrees, adapting to the nested query requirements of multi-level statistics and multi-condition filtering in power grid auditing: enhancing semantic representation. The algorithm identifies the innermost independent semantic unit of the nested query for power grid auditing. This unit forms the basis of the nested query and serves as the leaf node of the syntax tree. For each leaf node, a corresponding inner subquery SQL structure is generated, embedding aggregation and filtering constraints for power grid auditing. Based on the inner subqueries of the leaf nodes, outer query nodes are constructed layer by layer from bottom to top, using the subquery results of the previous layer as the input of the next layer. Corresponding power grid auditing constraints are embedded in each layer of the query, forming a complete nested SQL syntax tree. During the syntax tree construction process, SQL syntax constraints and power grid auditing business constraints are applied.
[0016] Furthermore, step C3 verifies whether the logical relationships between the subqueries meet the requirements of power grid auditing, including whether the ON conditions of the join subqueries are consistent, whether the inputs and outputs of the nested subqueries match, and whether the aggregation conditions are continuous.
[0017] As a preferred option, step C4 specifically includes the following steps: Step C4-1: Generate loss using SQL : Measures the degree of string-level matching between the generated SQL statements and the standard SQL statements for power grid auditing; Step C4-2, Loss of consistency in execution results The generated SQL statement and the standard SQL statement are executed in the real database environment of the power grid audit. The number of rows, column structure and data of each row of the result set are compared to see if they are completely consistent. If they are inconsistent, the loss value is calculated and optimization is performed. Step C4-3, Alignment of Power Grid Audit Knowledge Rules with Losses The constraints, aggregation rules, and power grid audit knowledge rule base in the generated SQL statement are calculated. R semantic similarity; Step C4-4: By weighting and combining the above three losses, a total loss function is formed. The decomposition and integration process is iteratively optimized to generate highly accurate SQL statements. .
[0018] As a preferred approach, the execution verification and closed-loop feedback module performs the following steps: Step D1, SQL execution verification: Execute the optimized SQL statement. Execute in a real or simulated power grid audit database, and record indicators including execution results, execution time, and resource consumption; Step D2, Multi-dimensional Quality Assessment: This step is used to quantitatively score SQL statements from four dimensions: syntactic correctness, semantic fidelity, execution result accuracy, and execution efficiency. Step D3, Feedback Signal Generation: This step generates guiding feedback signals based on a threshold grading strategy using quantitative scoring, including error type analysis and improvement suggestions. Step D4, Three-stage domain adaptive fine-tuning: The feedback signal and the corresponding <natural language query-SQL> pair are sent to the fine-tuning engine, and knowledge injection, inference alignment and feedback optimization are performed in sequence. The parsing module and decomposition module of the system are iteratively fine-tuned, and the model parameters and knowledge rule base are updated. Step D5, Optimization Results Implementation: Synchronize the fine-tuned model parameters and knowledge rule base to all modules of the system to achieve continuous improvement in system performance.
[0019] A method for automatically generating SQL based on large models and complex query decomposition methods specifically includes the following steps: Step S1, Offline Knowledge Building Phase (Executed during system initialization / update): The multi-source power grid audit knowledge fusion module collects structured and unstructured power grid audit knowledge, performs differentiated vectorization and fusion, and constructs a power grid audit knowledge rule base; it uses power grid audit corpus to pre-train and fine-tune the system's large language model to adapt to the semantic features and business logic of the power grid audit field. Step S2, Online Intelligent Processing Stage (executed when auditors query in real time): Natural language input: Input natural language queries for power grid auditing through the front-end interface; Semantic parsing: The natural language parsing module for power grid auditing vectorizes queries, integrates knowledge, and links patterns to generate enhanced semantic representations and a set of candidate pattern items; Complex Query Decomposition: The complex query decomposition module for power grid auditing determines the type of the query and uses a differentiated strategy to decompose it into SQL substructures. Then, the substructures are integrated into a preliminary complete SQL statement to complete compliance verification. Finally, the preliminary SQL statement is subjected to multi-loss calculation and optimization to generate a high-accuracy SQL statement. The optimized SQL statement can be output to the front-end interface. Step S3, Closed-Loop Continuous Evolution Stage: Execution Verification: The generated SQL statements are actually executed in the power grid audit database, and the system records key execution indicators such as execution time, resource consumption, and result set. Subsequently, the quality assessment module performs multi-dimensional quantitative scoring on the SQL statements from four dimensions: syntactic correctness, semantic fidelity, execution result accuracy, and execution efficiency, and generates feedback signals containing error type analysis and improvement suggestions. Based on these feedback signals, the model fine-tuning module implements three-stage domain-adaptive fine-tuning of the system's parsing and decomposition modules, sequentially completing knowledge injection of the power grid audit corpus, knowledge-enhanced supervised learning inference alignment, and reinforcement learning feedback optimization. At the same time, the power grid audit knowledge rule base is iteratively updated, and the newly verified effective audit rules and query paradigms are persistently stored. Finally, the performance iteration module synchronizes the fine-tuned model parameters and the updated knowledge base to all core modules of the system, achieving continuous improvement and closed-loop optimization of system performance.
[0020] By employing the above technical solutions, this invention has the following beneficial effects compared to existing technologies: Deep embedding of power grid audit knowledge and high accuracy of semantic parsing: This method embeds deep knowledge such as power grid audit rules and business constraints into the natural language parsing process through multi-source knowledge structured fusion and cross-attention mechanism. It fundamentally solves the problem of insufficient domain knowledge in general models, significantly improves the parsing accuracy of professional terms and fuzzy concepts, and the generated SQL statements strictly comply with audit business specifications at the semantic level.
[0021] The previous approach suffered from weak complex query processing capabilities and poor logical decomposition accuracy. This new method, however, features intelligent decomposition of complex queries, resulting in strong logical processing capabilities. It integrates probabilistic query type determination with differentiated recursive decomposition strategies, enabling precise handling of complex queries typical of power grid audits, such as multi-table joins and deep nesting. By breaking down complex logic into manageable substructures and supplementing them with business constraint checks, logical errors are effectively avoided, improving the accuracy of complex query processing by more than 10% compared to existing solutions.
[0022] Closed-loop feedback and self-evolution, high interpretability and human-machine trust: This method constructs a closed-loop feedback system of "generation-execution-evaluation-optimization." Through execution verification, quality assessment, and three-stage domain-adaptive fine-tuning, it achieves continuous learning and self-evolution from each query, enabling rapid adaptation to dynamic changes in audit rules and database schemas, with low maintenance costs. Simultaneously, the fully traceable reasoning chain makes the parsing, decomposition, and optimization steps transparent, allowing auditors to clearly pinpoint the root cause of problems and significantly improving human-machine trust.
[0023] Additional aspects and advantages of the invention will become apparent in the following description or may be learned by practice of the invention. Attached Figure Description
[0024] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a schematic diagram of the overall system architecture of the present invention; Figure 2 This is a flowchart illustrating the linkage of the core functional modules of the system of this invention. Figure 3 A flowchart for the structured integration of knowledge in multi-source power grid auditing; Figure 4 Flowchart for the closed-loop feedback optimization mechanism; Figure 5 A flowchart for breaking down complex queries. Detailed Implementation
[0025] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0026] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0027] The following is combined Figures 1 to 5 The SQL automatic generation system based on large model and complex query decomposition method of the present invention will be described in detail in the embodiments of the present invention.
[0028] This invention proposes an automatic SQL generation system based on a large model and complex query decomposition method, aiming to achieve high-precision and high-compliance conversion from natural language queries to executable SQL statements. This method deeply integrates knowledge from the power grid auditing field and introduces intelligent decomposition and closed-loop optimization mechanisms, forming a complete technical system of "offline knowledge construction - online intelligent processing - closed-loop continuous evolution." The core is the complex query decomposition module for power grid auditing. Through precise type determination and differentiated recursive decomposition strategies, it can accurately decompose complex queries such as multi-table joins and deep nesting into manageable substructures, effectively avoiding logical errors and execution failures that are prone to occur in traditional methods, providing solid technical support for complex power grid auditing business scenarios.
[0029] like Figure 2 As shown, an automatic SQL generation system based on large models and complex query decomposition methods includes: The multi-source power grid audit knowledge fusion module is used to collect structured and unstructured power grid audit knowledge, perform differentiated vectorized representation and fusion, generate unified power grid audit knowledge rule vectors and store them in a vector database to form a power grid audit knowledge rule base; such as Figure 3 As shown, the specific steps are as follows: Step A1, Multi-source knowledge collection: Collect two types of power grid audit knowledge sources: one is structured data, including power grid accounting charts, audit threshold standards, and database schema relationships; the other is unstructured text, including power grid audit regulations, industry standard documents, and internal inspection guidelines. Step A2, Differentiated Vectorization Representation: For structured data, a knowledge graph is constructed and a graph neural network (GNN) is used to generate structural feature vectors. For unstructured text, natural language processing techniques are used to extract key elements (such as entities and relationships), and semantic feature vectors are generated through a pre-trained language model. ; Step A3, Knowledge Fusion and Storage: Align and fuse the two types of feature vectors from Step A2 to generate a unified power grid audit knowledge rule vector. The data is then stored in the high-performance vector database ChromaDB to form a power grid audit knowledge rule base. The library supports incremental iterative updates based on expert experience feedback. At the same time, the knowledge rule base can also be directly used as corpus in the power grid audit domain for pre-training and fine-tuning of large language models to enhance the model's adaptability to domain semantics and business logic.
[0030] Step A4: Provide knowledge retrieval services: Encapsulate standardized knowledge retrieval interfaces to support subsequent steps in quickly retrieving and recalling the most relevant Top-K power grid audit knowledge rules from the vector database based on the semantics of the input information.
[0031] The power grid audit natural language parsing module receives natural language queries input by auditors, transforms them into a query embedding matrix through an embedding layer, and performs cross-attention calculation with the retrieved power grid audit knowledge rule embedding matrix to generate an enhanced semantic representation after knowledge fusion. This enhanced semantic representation is then used as the basis for further processing. Generate a set of candidate schema items from the database schema. The specific steps are as follows: Step B1, Query Vectorization: Used to vectorize user natural language queries. It is transformed into a query embedding matrix through the embedding layer. .
[0032] Step B2, Cross-Attention Knowledge Fusion: Used to embed the retrieved audit knowledge rules into the matrix. Cross-attention calculation with query embedding matrix , , ; Calculate the attention weight matrix : ; Augmented representation after knowledge fusion for: ; Through residual connections and layer normalization, the final enhanced semantic representation is obtained: ; Step B3, Pattern Linking: Used for augmented semantic representation and database schema Calculate semantic similarity and combine it with instance data matching to generate an accurate set of candidate pattern items. For pattern items Its overall score is: ; in, Based on pattern items Sample data and queries X Matching degree calculation Because the score exceeds the threshold The pattern items constitute the structure.
[0033] like Figure 5As shown, the complex query decomposition module for power grid auditing is used to determine the type of the query based on the enhanced semantic representation and candidate pattern item set, and to adopt a differentiated step-by-step decomposition strategy to generate SQL substructures and perform structural integration. It also introduces a multi-loss supervision mechanism based on syntax matching, execution consistency, and alignment with power grid auditing rules to optimize and verify the integrated SQL statement, generating a high-accuracy SQL statement. Specifically, the following steps are executed: Step C1, Type determination of complex queries in power grid auditing: Enhanced semantic representation that integrates power grid audit knowledge With candidate pattern set The concatenated data is used as input to a large language model fine-tuned from the power grid audit corpus. Probabilistic classification decisions are then used to achieve accurate classification of complex power grid audit queries. Specifically, the following steps are included: Step C1-1: Define the set of category tags for power grid audit queries. ,in: This is a single-table query, involving only one table in the power grid audit database. For multi-table join queries: involving ≥2 tables, and the natural language query contains commonly used related keywords for power grid auditing; Nested queries: Natural language queries contain aggregate conditions; Step C1-2: The model generates the probabilities of each class label through autoregression. The generation process is as follows: ; Step C1-3: Restrict the generation space to contain only the three labels mentioned above, calculate the joint probability of each label, and normalize it: ; Step C1-4: Select the tag with the highest probability as the final query type determination result: , This provides a basis for subsequent customized decomposition strategies.
[0034] Step C2: Query decomposition based on multi-level recursion mechanism: The result is determined based on the query type. A differentiated step-by-step decomposition strategy is adopted, and a multi-level recursive mechanism is used to decompose complex queries in power grid auditing layer by layer, generating corresponding SQL substructures. The power grid auditing knowledge rule base is embedded throughout the decomposition process. R Business constraints; specifically including the following steps: Step C2-1, Direct generation of single-table queries: If it is determined to be a single-table query, it is directly generated based on the candidate pattern item set. The system identifies a unique target power grid audit table, maps power grid audit constraints (such as thresholds, time, and region) in natural language queries to standard SQL filtering conditions (WHERE clauses), identifies the target fields of the query and generates SELECT clauses, and directly generates a normalized SQL single-table query statement with a projection-selection structure; during the generation process, it verifies whether the filtering conditions conform to power grid audit rules (such as whether the thresholds match audit standards). Step C2-2, Logical chain decomposition of multi-table join query: If it is determined to be a multi-table join query, based on the foreign key relationships and knowledge rule base of the power grid audit database. R The table-to-table business relationship rules enable the recursive decomposition of the table join logic chain, thereby enhancing semantic representation. Extract the core entities and table join relationships from the power grid audit query; then, based on the candidate pattern item set... In the table primary and foreign key constraints, combined with the power grid audit knowledge rule base R The table join rules are derived using a graph path search algorithm to deduce the optimal table join logic chain, avoiding syntactic ambiguity. Following the order of the join logic chain, multi-table join queries are recursively decomposed into pairwise table join subqueries. A corresponding JOIN clause (INNER JOIN / LEFT JOIN, etc., selected according to the power grid audit business requirements) is generated for each subquery, and the power grid audit business join rules are embedded in the ON condition to ensure that the join conditions conform to the power grid audit table join logic. If the query contains power grid audit aggregation conditions (such as summation, counting), the aggregation function (SUM / COUNT, etc.) is embedded in the corresponding join substructure to generate GROUP BY / HAVING clauses, ensuring that the aggregation conditions conform to the power grid audit statistical specifications.
[0035] Step C2-3: Hierarchical Decomposition of Nested Queries using a Tree-like Decoder: If a nested query is identified, a bottom-up tree-like decoder strategy is used for hierarchical recursive decomposition to generate nested SQL syntax subtrees, adapting to the nested query requirements of multi-level statistics and multi-condition filtering in power grid auditing: enhancing semantic representation. The algorithm identifies the innermost independent semantic unit of nested queries in power grid auditing. This unit forms the basis of the nested queries and serves as the leaf node of the syntax tree. For each leaf node, a corresponding inner subquery SQL structure is generated, embedding aggregation and filtering constraints for power grid auditing to ensure that the results of the inner subqueries meet the business requirements of power grid auditing. Based on the inner subqueries of the leaf nodes, outer query nodes are constructed layer by layer from bottom to top, using the subquery results of the previous layer as the input of the next layer. Corresponding power grid auditing constraints are embedded in each layer of queries to form a complete nested SQL syntax tree. During the syntax tree construction process, SQL syntax constraints (such as the generation order of WHERE / HAVING clauses and the rules for using aggregate functions) and power grid auditing business constraints (such as the calculation standards of statistical indicators and the compliance of screening conditions) are applied to ensure that the substructure of each node is syntactically correct and business compliant.
[0036] Step C3: Integration of subquery structures specific to power grid auditing: For the multiple SQL substructures generated after decomposition (pairwise join subqueries in multi-table joins, and subqueries at each level of nested queries), a structural integration mechanism adapted to the power grid audit scenario is constructed to organically combine the subqueries into a complete SQL statement: This verifies whether the logical relationships between the subqueries meet the business requirements of power grid auditing (whether the ON conditions of join subqueries are consistent, whether the inputs and outputs of nested subqueries match, and whether aggregation conditions are continuous); and according to SQL syntax specifications, the subqueries are concatenated in the logical order of decomposition, supplementing necessary syntax keywords to generate a preliminary complete SQL statement. ; to create a preliminary complete SQL statement With the power grid audit knowledge rule base R Compare and verify whether the constraints, aggregation rules, and table join relationships in the statements fully comply with the business rules and compliance requirements of power grid auditing. If there are deviations, make local adjustments. Step C4, Optimization and Validation with Multi-Loss Supervision: A multi-loss supervision mechanism based on syntax matching, execution consistency, and alignment with power grid audit rules is introduced to optimize and verify the integrated complete SQL statement, ensuring its accuracy, validity, and compliance. Specifically, this includes the following steps: Step C4-1: Generate loss using SQL : Measure the degree of matching between the generated SQL statements and the standard SQL statements for power grid auditing at the string level, and optimize the syntactic integrity of the statements; Step C4-2, Loss of consistency in execution results The generated SQL statement and the standard SQL statement are executed in the real database environment of the power grid audit. The number of rows, column structure and data of each row of the result set are compared to see if they are completely consistent. If they are inconsistent, the loss value is calculated and optimization is performed. Step C4-3, Alignment of Power Grid Audit Knowledge Rules with Losses The constraints, aggregation rules, and power grid audit knowledge rule base in the generated SQL statement are calculated. R The semantic similarity is used to ensure that the statements fully comply with the business rules of power grid auditing. If the similarity is lower than the threshold, adjustments are made. Step C4-4: By weighting and combining the above three losses, a total loss function is formed. The decomposition and integration process is iteratively optimized to generate highly accurate SQL statements. .
[0037] like Figure 4 As shown, the execution verification and closed-loop feedback module is used to execute the optimized SQL statement and perform multi-dimensional quality assessment, generate guiding feedback signals, and continuously improve system performance by updating the system model parameters and the power grid audit knowledge rule base through three-stage domain adaptive fine-tuning; specifically, the following steps are executed: Step D1, SQL execution verification: Execute the optimized SQL statement. Execute in a real or simulated power grid audit database, and record indicators including execution results, execution time, and resource consumption; Step D2, Multi-dimensional Quality Assessment: This step is used to quantitatively score SQL statements from four dimensions: syntactic correctness, semantic fidelity, execution result accuracy, and execution efficiency. Step D3, Feedback Signal Generation: This step generates guiding feedback signals based on a threshold grading strategy using quantitative scoring, including error type analysis and improvement suggestions. Step D4, Three-stage domain adaptive fine-tuning: The feedback signal and the corresponding <natural language query-SQL> pair are sent into the fine-tuning engine, and knowledge injection (pre-training of power grid audit corpus), inference alignment (supervised learning with knowledge enhancement), and feedback optimization (reinforcement learning) are performed in sequence. The parsing module and decomposition module of the system are iteratively fine-tuned, and the model parameters and knowledge rule base are updated. Step D5, Optimization Results Implementation: Synchronize the fine-tuned model parameters and knowledge rule base to all modules of the system to achieve continuous improvement in system performance.
[0038] A method for automatically generating SQL based on large models and complex query decomposition is proposed. The system's workflow is divided into three stages: offline knowledge construction, online intelligent processing, and closed-loop continuous evolution. These stages are seamlessly connected. Figure 1 As shown, the specific steps include: a multi-source power grid audit knowledge structure fusion module. Step S1, Offline Knowledge Building Phase (Executed during system initialization / update): The multi-source power grid audit knowledge fusion module collects structured and unstructured power grid audit knowledge, performs differentiated vectorization and fusion, and constructs a power grid audit knowledge rule base; it uses power grid audit corpus to pre-train and fine-tune the system's large language model to adapt to the semantic features and business logic of the power grid audit field. Step S2, Online Intelligent Processing Stage (executed when auditors query in real time): Natural language input: Auditors can input natural language queries for power grid audits (such as queries related to fund audits, engineering audits, and financial audits) through the front-end interface. Semantic parsing: The natural language parsing module for power grid auditing vectorizes queries, integrates knowledge, and links patterns to generate enhanced semantic representations and a set of candidate pattern items; Complex Query Decomposition: The complex query decomposition module for power grid auditing determines the type of the query and uses a differentiated strategy to decompose it into SQL substructures. Then, the substructures are integrated into a preliminary complete SQL statement to complete compliance verification. Finally, the preliminary SQL statement is subjected to multi-loss calculation and optimization to generate a high-accuracy SQL statement. The optimized SQL statement can be output to the front-end interface, where auditors can execute it directly or adjust it manually. Step S3, Closed-loop continuous evolution stage (continuously executed in the system background): Execution Verification: The generated SQL statements are actually executed in the power grid audit database, and the system records key execution indicators such as execution time, resource consumption, and result sets. Subsequently, the quality assessment module performs multi-dimensional quantitative scoring on the SQL statements from four dimensions: syntactic correctness, semantic fidelity, execution result accuracy, and execution efficiency, and generates feedback signals containing error type analysis and improvement suggestions. Based on these feedback signals, the model fine-tuning module performs three-stage domain-adaptive fine-tuning on the system's parsing and decomposition modules, sequentially completing knowledge injection of the power grid audit corpus, knowledge-enhanced supervised learning inference alignment, and reinforcement learning feedback optimization. Simultaneously, the knowledge base update module iteratively updates the power grid audit knowledge rule base based on the fine-tuning results and expert feedback, persistently storing the newly verified effective audit rules and query paradigms. Finally, the performance iteration module synchronizes the fine-tuned model parameters and the updated knowledge base to all core modules of the system, achieving continuous improvement and closed-loop optimization of system performance.
[0039] The embodiments of the present invention will be further described below with reference to specific application scenarios. These embodiments should not be construed as limiting the present invention.
[0040] 1. Application Scenarios: The user inputs a natural language query: "Find suppliers in the 'East China' and 'Central China' regions in the second half of 2024 whose 'equipment procurement' contracts exceed 20% of the average contract amount for similar contracts in those regions, and list the supplier names, their regions, total contract amounts, and the percentage exceeding the average amount." This query involves multiple table joins and nested aggregations, and is a typical complex query in power grid auditing.
[0041] 2. Implementation steps: (1) Determination of the type of complex query in power grid audit The enhanced semantic representation is concatenated with candidate pattern items and input into a large language model fine-tuned from the power grid audit corpus. The probabilities of each category label are calculated: single-table query probability 0.01, multi-table join probability 0.35, and nested query probability 0.64. The "nested query" with the highest probability is selected as the judgment result, while implicit multi-table join requirements are also identified.
[0042] (2) Query step-by-step decomposition based on multi-level recursion mechanism Tree-based decoder hierarchical decomposition (handling nested logic): Identifying the innermost semantic unit "calculate the average amount of equipment procurement contracts in East and Central China", generating an inner subquery: SELECT region_id, AVG(contract_amount)as avg_amount FROM contract JOIN region ON contract.region_id=region.id JOIN contract_type ON contract.contract_type_id=contract_type.id WHERE region_nameIN ('East China','Central China') AND type_name='Equipment Procurement' AND contract_date BETWEEN '2024-07-01' AND '2024-12-31' GROUP BY region_id Multi-table join logical chain decomposition: Extract the core entities "supplier, contract, region, and contract type", and infer the join path based on foreign key relationships: contract.supplier_id = supplier.id, contract.region_id = region.id, contract.contract_type_id = contract_type.id, generating the JOIN substructure of the outer query.
[0043] Composite condition handling: The outer query and the inner subquery are associated through region_id, the condition HAVINGSUM(contract_amount)>avg_amount * 1.2 is added, and the excess ratio (SUM(contract_amount)-avg_amount) / avg_amount is calculated.
[0044] (3) Integration of subquery structures specific to power grid auditing Verify the logical relationships between subqueries (e.g., the region_id of the inner subquery matches the region_id of the outer contract table, and the aggregate functions used comply with power grid audit statistical standards), concatenate them according to the SQL syntax order, supplement necessary keywords, and generate a preliminary complete SQL statement. Compare with the power grid audit knowledge rule base to verify that the "equipment procurement" type code, regional division, time range, etc., all comply with audit business rules and have no deviations.
[0045] (4) Optimization verification of multi-loss supervision SQL generation loss: Calculate the string matching degree with the standard SQL template, with a score of 0.94.
[0046] Consistency loss of execution results: When executed in the test database, the number of rows and column structure of the result set are consistent with the manual verification logic, and the loss value is 0.02.
[0047] Alignment loss of knowledge rules in power grid audit: The semantic similarity between region_name, type_name, aggregate function and knowledge base in the query is calculated. The average similarity is 0.96, which is higher than the threshold of 0.85.
[0048] The total loss function, after weighted combination, is 0.05. After one iteration of optimization, the final high-accuracy SQL statement is generated.
[0049] 3. Implementation Results: The module successfully and accurately decomposes complex compound queries into manageable substructures, ultimately generating syntactically correct, logically rigorous SQL statements that fully comply with power grid auditing business rules. The accuracy of complex query processing is improved by 12% compared to traditional methods, and the entire decomposition and optimization process takes only 0.8 seconds, meeting the needs of real-time audit interaction. Simultaneously, the entire inference process (type determination, subquery decomposition, integration verification, and loss optimization) is traceable, providing transparent support for human-machine trust.
[0050] In the description of this specification, the terms "one embodiment," "some embodiments," "specific embodiment," etc., refer to a specific feature, structure, material, or characteristic described in connection with that embodiment or example, which is 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. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0051] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. An automatic SQL generation system based on large models and complex query decomposition methods, characterized in that... ,include: The multi-source power grid audit knowledge structuring fusion module is used to collect structured and unstructured power grid audit knowledge, perform differentiated vectorized representation and fusion, generate unified power grid audit knowledge rule vectors and store them in a vector database to form a power grid audit knowledge rule base; The power grid audit natural language parsing module receives natural language queries input by auditors, transforms them into a query embedding matrix through an embedding layer, and performs cross-attention calculation with the retrieved power grid audit knowledge rule embedding matrix to generate an enhanced semantic representation after knowledge fusion. This enhanced semantic representation is then used as the basis for further processing. Generate a set of candidate schema items from the database schema. ; The complex query decomposition module for power grid auditing is used to determine the type of the query based on the enhanced semantic representation and the candidate pattern item set, and to adopt a differentiated step-by-step decomposition strategy to generate SQL substructures and perform structural integration. It also introduces a multi-loss supervision mechanism based on syntax matching, execution consistency and alignment with power grid auditing rules to optimize and verify the integrated SQL statement and generate a high-accuracy SQL statement. The execution verification and closed-loop feedback module is used to execute optimized SQL statements and perform multi-dimensional quality assessments, generate guiding feedback signals, and continuously improve system performance by updating system model parameters and the power grid audit knowledge rule base through three-stage domain adaptive fine-tuning.
2. The SQL automatic generation system based on large model and complex query decomposition method according to claim 1, characterized in that... The multi-source power grid audit knowledge structure fusion module specifically performs the following steps: Step A1, Multi-source knowledge collection: Collect two types of power grid audit knowledge sources: one is structured data, including power grid accounting charts, audit threshold standards, and database schema relationships; the other is unstructured text, including power grid audit regulations, industry standard documents, and internal inspection guidelines. Step A2, Differentiated Vectorization Representation: For structured data, a knowledge graph is constructed and a graph neural network (GNN) is used to generate structural feature vectors. For unstructured text, key elements are extracted using natural language processing techniques, and semantic feature vectors are generated through a pre-trained language model. ; Step A3, Knowledge Fusion and Storage: Align and fuse the two types of feature vectors from Step A2 to generate a unified power grid audit knowledge rule vector. The data is stored in the high-performance vector database ChromaDB to form a power grid audit knowledge rule base. ; Step A4: Provide knowledge retrieval services: Encapsulate standardized knowledge retrieval interfaces to support subsequent steps in quickly retrieving and recalling the most relevant Top-K power grid audit knowledge rules from the vector database based on the semantics of the input information.
3. The SQL automatic generation system based on large model and complex query decomposition method according to claim 1, characterized in that... The power grid audit natural language parsing module specifically performs the following steps: Step B1, Query Vectorization: Used to vectorize user natural language queries. It is transformed into a query embedding matrix through the embedding layer. ; Step B2, Cross-Attention Knowledge Fusion: Used to embed the retrieved audit knowledge rules into the matrix. Cross-attention calculation with query embedding matrix , , ; Calculate the attention weight matrix : ; Augmented representation after knowledge fusion for: ; Through residual connections and layer normalization, the final enhanced semantic representation is obtained: ; Step B3, Pattern Linking: Used for augmented semantic representation Based on the database pattern S, semantic similarity is calculated and combined with instance data matching to generate an accurate set of candidate pattern items. For pattern items Its overall score is: ; in, Based on pattern items Sample data and queries X Matching degree calculation Because the score exceeds the threshold The pattern items constitute the structure.
4. The SQL automatic generation system based on large model and complex query decomposition method according to claim 1, characterized in that... The complex query decomposition module for power grid auditing specifically performs the following steps: Step C1: Determining the type of complex queries in power grid auditing: Enhanced semantic representation that integrates power grid audit knowledge With candidate pattern set The concatenation is used as input to a large language model that has been fine-tuned with power grid audit corpus, and the accurate classification of complex power grid audit queries is achieved through probabilistic classification decision-making. Step C2: Query decomposition based on multi-level recursion mechanism: The result is determined based on the query type. A differentiated step-by-step decomposition strategy is adopted, and a multi-level recursive mechanism is used to decompose complex queries in power grid auditing layer by layer, generating corresponding SQL substructures. The power grid auditing knowledge rule base is embedded throughout the decomposition process. R Business constraints; Step C3: Integration of subquery structures specific to power grid auditing: To address the multiple SQL substructures generated after decomposition, a structural integration mechanism adapted to the power grid audit scenario is constructed to organically combine the subqueries into a complete SQL statement. This mechanism verifies whether the logical relationships between the subqueries meet the business requirements of power grid auditing; and, following SQL syntax specifications, concatenates the subqueries in the logical order of decomposition, supplementing necessary syntax keywords to generate a preliminary complete SQL statement. ; A preliminary complete SQL statement With the power grid audit knowledge rule base R Compare and verify whether the constraints, aggregation rules, and table join relationships in the statements fully comply with the business rules and compliance requirements of power grid auditing. Step C4, Optimization and Validation with Multi-Loss Supervision: A multi-loss supervision mechanism based on syntax matching, execution consistency, and alignment with power grid audit rules is introduced to optimize and verify the integrated complete SQL statement.
5. The SQL automatic generation system based on large model and complex query decomposition method according to claim 4, characterized in that... Step C1 specifically includes the following steps: Step C1-1: Define the set of category tags for power grid audit queries. ,in: This is a single-table query, involving only one table in the power grid audit database. For multi-table join queries: involving ≥2 tables, and the natural language query contains commonly used related keywords for power grid auditing; Nested queries: Natural language queries contain aggregate conditions; Step C1-2: The model generates the probabilities of each class label through autoregression. The generation process is as follows: ; Step C1-3: Restrict the generation space to contain only the three labels mentioned above, calculate the joint probability of each label, and normalize it: ; Step C1-4: Select the tag with the highest probability as the final query type determination result: 。 6. The SQL automatic generation system based on large model and complex query decomposition method according to claim 4, characterized in that... Step C2 specifically includes the following steps: Step C2-1, Direct generation of single-table queries: If it is determined to be a single-table query, it is directly generated based on the candidate pattern item set. The process involves identifying a unique target power grid audit table, mapping the power grid audit constraints in natural language queries to standard SQL filter conditions, identifying the target fields of the query and generating SELECT clauses, and directly generating a normalized single-table SQL query statement with a projection-selection structure. During the generation process, the filter conditions are verified to ensure they conform to power grid audit rules. Step C2-2, Logical chain decomposition of multi-table join query: If it is determined to be a multi-table join query, based on the foreign key relationships and knowledge rule base of the power grid audit database. R The table-to-table business relationship rules enable the recursive decomposition of the table join logic chain, thereby enhancing semantic representation. Extract the core entities and table join relationships from the power grid audit query; then, based on the candidate pattern item set... In the table primary and foreign key constraints, combined with the power grid audit knowledge rule base R The table-to-table business association rules are derived using a graph path search algorithm to deduce the optimal table join logic chain and avoid syntactic ambiguity. Following the order of the join logic chain, multi-table join queries are recursively decomposed into pairwise table join subqueries. A corresponding JOIN clause is generated for each subquery, and the business association rules for power grid auditing are embedded in the ON condition. If the query contains aggregate conditions for power grid auditing, the aggregate function is embedded in the corresponding join substructure to generate GROUP BY / HAVING clauses. Step C2-3: Hierarchical Decomposition of Nested Queries using a Tree-like Decoder: If a nested query is identified, a bottom-up tree-like decoder strategy is used for hierarchical recursive decomposition to generate nested SQL syntax subtrees, adapting to the nested query requirements of multi-level statistics and multi-condition filtering in power grid auditing: enhancing semantic representation. The algorithm identifies the innermost independent semantic unit of the nested query for power grid auditing. This unit forms the basis of the nested query and serves as the leaf node of the syntax tree. For each leaf node, a corresponding inner subquery SQL structure is generated, embedding aggregation and filtering constraints for power grid auditing. Based on the inner subqueries of the leaf nodes, outer query nodes are constructed layer by layer from bottom to top, using the subquery results of the previous layer as the input of the next layer. Corresponding power grid auditing constraints are embedded in each layer of the query, forming a complete nested SQL syntax tree. During the syntax tree construction process, SQL syntax constraints and power grid auditing business constraints are applied.
7. The SQL automatic generation system based on large model and complex query decomposition method according to claim 4, characterized in that... In step C3, verifying whether the logical relationships between subqueries meet the requirements of power grid auditing business includes checking whether the ON conditions of the join subqueries are consistent, whether the inputs and outputs of nested subqueries match, and whether the aggregation conditions are continuous.
8. The SQL automatic generation system based on large model and complex query decomposition method according to claim 4, characterized in that... Step C4 specifically includes the following steps: Step C4-1: Generate loss using SQL : Measures the degree of string-level matching between the generated SQL statements and the standard SQL statements for power grid auditing; Step C4-2, Loss of consistency in execution results The generated SQL statement and the standard SQL statement are executed in the real database environment of the power grid audit. The number of rows, column structure and data of each row in the result set are compared to see if they are completely consistent. If they are inconsistent, the loss value is calculated and optimization is performed. Step C4-3, Alignment of Power Grid Audit Knowledge Rules with Losses The constraints, aggregation rules, and power grid audit knowledge rule base in the generated SQL statement are calculated. R semantic similarity; Step C4-4: By weighting and combining the above three losses, a total loss function is formed. The decomposition and integration process is iteratively optimized to generate highly accurate SQL statements. .
9. The SQL automatic generation system based on large model and complex query decomposition method according to claim 1, characterized in that... The execution verification and closed-loop feedback module specifically performs the following steps: Step D1, SQL execution verification: Execute the optimized SQL statement. Execute in a real or simulated power grid audit database, and record indicators including execution results, execution time, and resource consumption; Step D2, Multi-dimensional Quality Assessment: This step is used to quantitatively score SQL statements from four dimensions: syntactic correctness, semantic fidelity, execution result accuracy, and execution efficiency. Step D3, Feedback Signal Generation: This step generates guiding feedback signals based on a threshold grading strategy using quantitative scoring, including error type analysis and improvement suggestions. Step D4, Three-stage domain adaptive fine-tuning: The feedback signal and the corresponding <natural language query-SQL> pair are sent to the fine-tuning engine, and knowledge injection, inference alignment and feedback optimization are performed in sequence. The parsing module and decomposition module of the system are iteratively fine-tuned, and the model parameters and knowledge rule base are updated. Step D5, Optimization Results Implementation: Synchronize the fine-tuned model parameters and knowledge rule base to all modules of the system to achieve continuous improvement in system performance.
10. The method of an automatic SQL generation system based on a large model and complex query decomposition method as described in any one of claims 1 to 9, characterized in that, Specifically, the following steps are included: Multi-source power grid audit knowledge structure fusion module Step S1, Offline Knowledge Construction Phase: The multi-source power grid audit knowledge fusion module collects structured and unstructured power grid audit knowledge, performs differentiated vectorization and fusion, and constructs a power grid audit knowledge rule base; it uses power grid audit corpus to pre-train and fine-tune the system's large language model to adapt to the semantic features and business logic of the power grid audit field. Step S2, Online Intelligent Processing Stage: Natural language input: Input natural language queries for power grid auditing through the front-end interface; Semantic parsing: The natural language parsing module for power grid auditing vectorizes queries, integrates knowledge, and links patterns to generate enhanced semantic representations and a set of candidate pattern items; Complex Query Decomposition: The complex query decomposition module for power grid auditing determines the type of the query and uses a differentiated strategy to decompose it into SQL substructures; Subsequently, the substructures are integrated into a preliminary complete SQL statement to complete compliance verification; finally, multiple loss calculations and optimizations are performed on the preliminary SQL statement to generate a high-accuracy SQL statement; the optimized SQL statement can be output to the front-end interface. Step S3, Closed-Loop Continuous Evolution Stage: Execution verification: The generated SQL statements are actually executed in the power grid audit database, and the system records key execution indicators such as execution time, resource consumption, and result set. Subsequently, the quality assessment module performs multi-dimensional quantitative scoring on the SQL statements from four dimensions: syntax correctness, semantic fidelity, execution result accuracy, and execution efficiency, and generates feedback signals containing error type analysis and improvement suggestions accordingly. Based on this feedback signal, the model fine-tuning module implements three-stage domain adaptive fine-tuning of the system's parsing and decomposition modules, sequentially completing knowledge injection of the power grid audit corpus, knowledge-enhanced supervised learning reasoning alignment, and reinforcement learning feedback optimization. At the same time, the power grid audit knowledge rule base is updated iteratively, and newly verified valid audit rules and query paradigms are persistently stored. Finally, the performance iteration module synchronizes the fine-tuned model parameters and the updated knowledge base to all core modules of the system, achieving continuous improvement and closed-loop optimization of system performance.