Electric power intelligent number asking method fusing adaptive reasoning and SQL (Structured Query Language) correction
By integrating adaptive reasoning and SQL correction methods, and utilizing large language models and abstract AST parsing correction techniques, accurate SQL query expressions are generated. This solves the problems of low query accuracy and multi-turn dialogue complexity in power control operations, and achieves efficient and accurate data querying and decision support.
Patent Information
- Application Number
- CN202511946870.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-23
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2045-12-23
AI Technical Summary
In power dispatching operations, existing technologies based on natural language dialogue querying suffer from low query accuracy, numerous ambiguities, and difficulty in meeting real-time business needs. Furthermore, deep learning models are insufficient in multi-turn dialogues and complex multi-table join queries, affecting data query efficiency and decision support capabilities.
We employ a method that integrates adaptive reasoning and SQL correction. We use a large language model to understand natural language query requests, use an abstract AST to perform SQL syntax and semantic parsing and correction, combine a Transformer neural network to generate accurate SQL query expressions, and perform security and integrity verification.
It improves the accuracy and efficiency of data query in power dispatching operations, reduces the probability of model generation errors, enhances cross-system applicability and scalability, supports non-technical personnel in acquiring and analyzing complex data, and improves the operational efficiency and decision support capabilities of dispatching operations.
Smart Images

Figure CN121365081A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of power system intelligent query, and in particular to a power intelligent query method fusing adaptive reasoning and SQL rectification. BACKGROUND
[0002] As the underlying technical foundation of the new generation of dispatching and control system, the regulation and control cloud provides support for the construction of the analysis and decision center of the new generation of dispatching and control system. Various types of power grid data are contained in the regulation and control cloud platform, such as power grid equipment asset data, power grid operation load data, power grid transaction data, power grid fault alarm data and the like. Since the data covers key information required for different business decisions, it is necessary to customize relevant query SQL services according to different business needs, which has a large maintenance workload and cannot meet the query needs of business changes in a timely manner. Therefore, a query technology based on natural language dialogue is needed to obtain relevant data results from the regulation and control cloud according to the user's description of the problem.
[0003] In the prior art, there are mainly two implementation ways for the query technology based on natural language dialogue: one is based on the traditional natural language processing (NLP) mode, including word segmentation, entity recognition and syntax structure analysis, to extract the query intention and conditions from the user's question and splice the SQL statement. This mode has problems such as low query accuracy, easy introduction of ambiguity and fuzzy query results in actual application, and it is difficult to meet the high accuracy requirements of the power grid real-time business scene; the other is the Text2SQL technology based on deep learning, which directly converts the natural language question into an SQL statement by training a neural network model. Although this method has higher query accuracy than the traditional NLP mode, it is highly dependent on data annotation quality and sample quantity, and the data annotation task is heavy in the early stage. At the same time, the existing Text2SQL model has insufficient ability to face the multi-round dialogue scene, multi-table complex association query and data summary in the power business, which seriously affects the application effect in the actual business scene. SUMMARY
[0004] The technical problem to be solved by the present application is to provide a power intelligent query method fusing adaptive reasoning and SQL rectification, which can solve the deficiencies of the prior art and improve the data query efficiency and decision support capability of the power regulation and control business.
[0005] To solve the above technical problems, the technical solutions adopted by the present application are as follows.
[0006] A power intelligent query method fusing adaptive reasoning and SQL rectification, comprising the following steps: A. converting the natural language query request proposed by the user into a SQL query expression conforming to the power business scene; B. Introducing an SQL rectification scheme based on abstract AST, structurally parsing the SQL query expression, identifying logical errors in SQL syntax and semantics, and rectifying and optimizing; C. Large language model structured summary of the original data obtained by query, feedback to the user in natural language form.
[0007] As a preferred, in step A, the natural language query request is processed by word segmentation, and the noise words are removed, and then the characters are uniformly encoded to realize the standardization of the natural language query request.
[0008] As a preferred, the word segment obtained after word segmentation is converted into a one-dimensional vector to form an original data matrix, the covariance matrix of the original data matrix is calculated, the eigenvectors of the covariance matrix are calculated, the feature matrix is composed of all eigenvectors, and the original data matrix is convolved using the feature matrix to remove noise words.
[0009] As a preferred, the standardized natural language query request is input into the twin neural network to generate the semantic vector of the query request, and then the cosine similarity calculation is performed with the system pre-stored regulation cloud table structure information semantic vector to obtain the table structure information closest to the query request; The dot product of the query request semantic vector and the query expression vector is used as the semantic similarity, the query expression with the highest semantic similarity is taken, the BM25 algorithm is used to calculate the similarity of the structure information semantic and the query expression, and the query expression with the highest semantic similarity is taken, and the two query expressions are input into the Transformer neural network to generate the SQL query expression.
[0010] As a preferred, the Transformer neural network includes an equal number of encoders and decoders, the encoders and decoders correspond one by one, and each of the encoders and decoders includes a feedforward neural network unit. The hidden layer of the feedforward neural network unit in the decoder is updated in real time, and when the corresponding encoder feedforward neural network unit is operated, the input and output data of the encoder feedforward neural network unit are used to train the hidden layer of the corresponding decoder feedforward neural network unit.
[0011] As a preferred, in step B, the SQL query expression is split and converted into an abstract syntax tree, and the abstract syntax tree is traversed to perform safety and integrity checking; The abstract syntax tree includes a plurality of statement nodes, each statement node includes a plurality of block nodes, and each block node includes a plurality of expression nodes; the sensitivity of each statement node is calculated using a differential privacy function, the statement nodes are arranged in descending order of sensitivity, a test vector is input into the statement node with the lowest sensitivity, feedback data of the statement node is obtained, if the feedback data is illegal, the statement node and other statement nodes with sensitivity greater than or equal to the sensitivity of the statement node are corrected according to a preset rule, and if the feedback data is legal, the above process is repeated to check and correct the next statement node.
[0012] The beneficial effects brought by the above technical solutions are that the natural language understanding, adaptive reasoning and data summarization technical capabilities of a large language model (LLM) are comprehensively used, and a SQL statement analysis and correction mechanism based on an abstract syntax tree (AST) is combined, so that the data query accuracy and execution efficiency in the power regulation business scenario are effectively improved. BRIEF DESCRIPTION OF DRAWINGS
[0013] Figure 1 is a schematic diagram of one embodiment of the present application. DETAILED DESCRIPTION
[0014] In the following description of embodiments, specific details are set forth, such as particular system configurations, techniques, etc., in order to provide a thorough understanding of the present application. However, it will be apparent to one skilled in the art that the present application can be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
[0015] Referring to Figure 1 The power intelligent query method provided by the present application fuses adaptive reasoning and SQL correction, and includes the following steps: A. converting a natural language query request proposed by a user into a SQL query expression conforming to a power business scenario.
[0016] B. introducing an AST-based SQL correction scheme to structurally analyze the SQL query expression, identify logical errors existing in the SQL syntax and semantics, and correct and optimize the errors.
[0017] C. structurally summarizing the original data obtained by the query by a large language model, and feeding back the user in a natural language form.
[0018] In step A, the natural language query request is subjected to word segmentation processing to remove noise words, and then the characters are uniformly encoded (uniformly into UTF-8 format) to standardize the natural language query request.
[0019] Specifically, the user inputs a natural language query question "query the maximum load value of Anjiaozhuang station in the past week" through the web front end of the cloud platform. The system receives the question through the API interface and performs word segmentation processing (divides the question into "query / past week / Anjiaozhuang station / maximum load value"). The word segments obtained after word segmentation processing are converted into a one-dimensional vector to form an original data matrix. The covariance matrix of the original data matrix is calculated, the eigenvectors of the covariance matrix are calculated, the feature matrix is formed by all eigenvectors, and the convolution operation is performed on the original data matrix using the feature matrix to remove noise words. The present application proposes a new noise word removal method, which is different from the traditional PCA dimensionality reduction denoising method and can reduce the information loss rate.
[0020] The standardized natural language query request is input into the twin neural network to generate a semantic vector of the query request, and then the cosine similarity calculation is performed with the system pre-stored table structure information semantic vector to obtain the table structure information closest to the query request.
[0021] The dot product of the query request semantic vector and the query expression vector is used as the semantic similarity, the query expression with the highest semantic similarity is used, the BM25 algorithm is used to calculate the similarity of the structure information semantic and the query expression, and the query expression with the highest semantic similarity is used. The two query expressions to be used are input into the Transformer neural network to generate an SQL query expression.
[0022] The feedforward neural network unit of the Transformer neural network is redesigned. The Transformer neural network includes an equal number of encoders and decoders, the encoders and decoders correspond one-to-one, the encoders and decoders each include a feedforward neural network unit, the hidden layer of the feedforward neural network unit in the decoder is updated in real time training mode, and when the feedforward neural network unit of the corresponding encoder is operated, the input and output data of the feedforward neural network unit of the encoder are used to train the hidden layer of the feedforward neural network unit in the corresponding decoder. This training process can keep the Transformer neural network highly sensitive to input data.
[0023] For example, the final SQL query expression generated by the natural language query request "query the maximum load of Anjiaozhuang station in the past week" is: ELECT MAX(MAX_LOAD) AS MAX_LOAD FROM station_load WHERE STATION_NAME = 'Anjiaozhuang station' AND CREATE_TIME>= DATE_SUB(CURDATE(), INTERVAL 7 DAY).
[0024] In step B, the SQL query expression is decomposed and converted into an abstract syntax tree (Abstract Syntax Tree). The Abstract Syntax Tree is traversed for security and integrity checks. The Abstract Syntax Tree includes several statement nodes, each containing several block nodes, and each block node containing several expression nodes. A differential privacy function is used to calculate the sensitivity of each statement node. The statement nodes are then sorted from lowest to highest sensitivity. The test vector is input to the statement node with the lowest sensitivity to obtain feedback data. If the feedback data is invalid, this statement node and other statement nodes with a sensitivity greater than or equal to this node are corrected according to preset rules. If the feedback data is valid, the above process is repeated for the next statement node. This invention's correction of the Abstract Syntax Tree differs from the traditional method of directly traversing each node. Instead, it sorts each statement node based on its sensitivity and performs multiple rounds of correction, effectively improving the accuracy of the SQL query expression.
[0025] The SQL query expression above has been validated and corrected, resulting in: SELECT MAX(MAX_LOAD) AS MAX_LOAD FROM station_load WHERE STATION_NAME = 'Angezhuang Station' AND CREATE_TIME>= TO_DATE(TO_CHAR(SYSDATE - 7, 'YYYY-MM-DD'), 'YYYY-MM-DD').
[0026] The application proposes a data construction method and task design specification for power services, enhances the understanding ability of a large language model for power service data, and improves the accuracy performance of the trained model by 20% compared with a general large language model with the same parameter quantity. The syntax structure checking mechanism is introduced into SQL generation, realizing double constraint generation from semantics to structure, significantly reducing the error probability of model generation (reducing 5% of SQL syntax problems), and improving the executability and stability. Based on the AST syntax mapping mechanism, multi-database adaptation is realized, the cross-system and cross-platform applicability is enhanced, and the universality and expansibility of the whole question and answer system are improved. The application can reduce the dependence on traditional manual SQL writing and debugging, support non-technical personnel to realize high-complexity data acquisition and analysis operations through natural language, and significantly improve the operation efficiency and data service ability of regulation and control business. At the same time, it supports complex SQL logic construction and execution such as multi-table joint, historical trend, and anomaly detection, and is suitable for device monitoring, load analysis, operation and maintenance evaluation and other power regulation and control cloud application scenarios. The efficient data acquisition and analysis capability of the application can provide real-time and accurate data support for core business links such as regulation strategy making, emergency response, and energy efficiency evaluation, and promote the evolution of regulation business from "rule-driven" to "intelligent-driven".
[0027] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional units and modules is exemplified, and in actual application, the above functions can be completed by different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit, and the integrated unit can be realized in the form of hardware or software. In addition, the specific names of each functional unit and module are only for convenient distinction, and do not limit the protection scope of the application. The specific working process of the units and modules in the system can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.
[0028] The present application realizes all or part of the processes in the above-mentioned embodiment methods, and can also be completed by a computer program instructing related hardware. The computer program can be stored in a computer readable storage medium, and when executed by a processor, can realize the steps of the above-mentioned various method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files or some intermediate forms, etc. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier wave signal, telecommunication signal and software distribution medium, etc. It should be noted that the content included in the computer readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction, for example, in some jurisdictions, according to legislation and patent practice, the computer readable medium does not include electric carrier wave signal and telecommunication signal.
[0029] The basic principles and main features of the present application and the advantages of the present application are shown and described above. It should be understood by those skilled in the art that the present application is not limited by the above-mentioned embodiments, and the above-mentioned embodiments and descriptions in the specification are only to illustrate the principles of the present application. Without departing from the spirit and scope of the present application, various changes and improvements can be made to the present application, and these changes and improvements all fall within the scope of the present application. The scope of protection of the present application is defined by the appended claims and their equivalents.
Claims
1. A power intelligent query method fusing adaptive inference and SQL rectification, characterized in that The method comprises the following steps: A. converting a natural language query request proposed by a user into a SQL query expression conforming to a power business scenario; B. introducing an SQL rectification scheme based on an abstract AST, structurally analyzing the SQL query expression, identifying logical errors existing in the SQL syntax and semantics, and rectifying and optimizing the SQL query expression; C. using a large language model to structurally summarize the original data obtained by the query and feeding back the user in a natural language form.
2. The method of claim 1, wherein the method comprises: In step A, the natural language query request is subjected to word segmentation processing, noise words are removed, and then the characters are uniformly coded to standardize the natural language query request.
3. The method of claim 2, wherein the method further comprises: The word segments obtained after the word segmentation processing are converted into a one-dimensional vector to form an original data matrix, a covariance matrix of the original data matrix is calculated, the eigenvectors of the covariance matrix are calculated, and all the eigenvectors are combined into a feature matrix, The feature matrix is used to perform convolution operation on the original data matrix to remove noise words.
4. The power intelligent query method of claim 3, wherein: The standardized natural language query request is input into a twin neural network to generate a semantic vector of the query request, and then cosine similarity calculation is performed with the system pre-stored table structure information semantic vector to obtain the table structure information closest to the query request; The dot product of the query request semantic vector and the query expression vector is used as the semantic similarity, the query expression with the highest semantic similarity is selected, the similarity between the structure information semantic and the query expression is calculated using the BM25 algorithm, the query expression with the highest semantic similarity is selected, and the two selected query expressions are input into a Transformer neural network to generate a SQL query expression.
5. The method of claim 4, wherein the method further comprises: The Transformer neural network comprises equal numbers of encoders and decoders, the encoders and the decoders correspond to each other, each of the encoders and the decoders comprises a feedforward neural network unit, the hidden layer of the feedforward neural network unit in the decoder is updated in a real-time training mode, and when the feedforward neural network unit in the corresponding encoder is operated, the input and output data of the feedforward neural network unit in the encoder are used to train the hidden layer of the feedforward neural network unit in the corresponding decoder.
6. The method of claim 1, wherein the method further comprises: In step B, the SQL query expression is split, converted into an abstract syntax tree, and the abstract syntax tree is traversed to perform safety and integrity checking; The abstract syntax tree comprises a plurality of statement nodes, each statement node comprises a plurality of block nodes, and each block node comprises a plurality of expression nodes; The sensitivity of each statement node is calculated using a differential privacy function, the statement nodes are arranged in order of sensitivity from low to high, a test vector is input into the statement node with the lowest sensitivity, feedback data of the statement node is obtained, if the feedback data is illegal, the statement node and other statement nodes with sensitivity greater than or equal to the sensitivity of the statement node are rectified and modified according to a preset rule, and if the feedback data is legal, the above process is repeated to check and rectify the next statement node.
Citation Information
Patent Citations
Self-adaptive SQL (Structured Query Language) differential privacy noise adding method
CN119201981A
Zero training method for SQL (Structured Query Language) generation based on large language model
CN119691096A
SQL generation method and apparatus based on large language model, device and storage medium
WO2025179827A1
