Dynamic adaptive Text2SQL (Structured Query Language) generation method and system for power field
By introducing schema parsing optimization and logical decomposition strategies into the Text2SQL system in the power sector, the problems of schema mismatch and insufficient dynamic adaptability have been solved, achieving high-precision and efficient SQL generation and improving the accuracy and stability of power data queries.
Patent Information
- Application Number
- CN202511074428.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-01
- Publication Date
- 2025-11-21
AI Technical Summary
Existing Text2SQL solutions based on large language models suffer from schema mismatch, logical illusion, and insufficient dynamic adaptability in power sector applications, resulting in poor accuracy and reliability of SQL queries and difficulty in adapting to frequent schema structure adjustments in power grid databases.
By employing schema parsing optimization, task alignment training, and logical decomposition strategies, combined with knowledge base reuse and query feedback mechanisms, a high-precision and highly adaptive Text2SQL generation system is constructed. This system includes power terminology recognition, diverse dataset generation, logical decomposition optimization, and model compression, ensuring the accuracy and stability of SQL generation.
It significantly improves the accuracy and efficiency of power data query, enhances the intelligent query capability of the power system, and improves operation and maintenance efficiency and the long-term applicability of the model.
Smart Images

Figure CN120994685A_ABST
Abstract
Description
[0001] This invention relates to the fields of natural language processing and database technology, and in particular to a Text2SQL generation method and system for dynamic adaptation in the power industry. It aims to solve the problems of pattern mismatch, logical illusion and dynamic adaptability in complex database queries in the power industry, and improve the accuracy, execution efficiency and business adaptability of natural language to SQL conversion. Background Technology
[0002] In the power sector, a large amount of power grid operation data (such as substation load, equipment status, alarm logs, etc.) is stored in SQL databases. Non-technical personnel (such as dispatchers and maintenance personnel) often need to obtain key information through SQL queries. However, writing SQL queries requires certain database knowledge, which presents these users with a high technical barrier in the data acquisition process. Text2SQL technology can convert natural language into SQL queries, allowing users to efficiently retrieve the required data without mastering database management systems and query languages. However, the application of existing Text2SQL solutions based on Large Language Models (LLM) in the power sector still faces many challenges. First, the power system contains a large number of technical terms (such as "reactive power" and "relay protection") and complex business logic (such as multi-table joins and nested aggregations). When generating SQL queries, LLM often struggles to accurately understand these domain-specific concepts, which can easily lead to schema mismatch (incorrectly introducing, omitting, or misunderstanding fields in the database schema) and logical illusion (generating redundant joins, abusing SQL clauses, or misusing mathematical operations), thereby affecting the accuracy and reliability of SQL queries. Secondly, the schema structure of the power grid database is frequently adjusted with equipment upgrades and changes in business needs. Traditional methods usually rely on static rules or general domain fine-tuning, which makes it difficult to quickly adapt to new table structures or query requirements, affecting the availability and long-term stability of the model. To address the above issues, this invention proposes a dynamic adaptable Text2SQL generation method and system for the power sector. It integrates schema parsing optimization, task alignment training, and logic decomposition strategies. Through knowledge base reuse, schema linking optimization, and query feedback mechanisms, it achieves high-precision and highly adaptable SQL generation, improving the intelligent query capabilities and execution efficiency of power data. Summary of the Invention
[0003] Purpose of the Invention: To overcome the problems of schema mismatch, logical illusion, and rapid schema updates in existing Text-to-SQL conversion in the power industry, this invention discloses a dynamically adaptable Text2SQL generation method and system for the power industry. Through knowledge base reuse, schema link optimization, and query feedback mechanisms, it significantly improves the accuracy, business adaptability, and execution efficiency of natural language query to SQL statement conversion.
[0004] Technical solution: This invention discloses a Text2SQL generation method and system for dynamic adaptation in the power sector, comprising the following steps:
[0005] S1 parses the schema information of the power database and automatically generates diverse natural language-SQL pair datasets to support the training and optimization of Text2SQL tasks.
[0006] S11 extracts schema information such as table names, field names, and primary and foreign key relationships from the power grid database, and parses key equipment parameters to enrich the database schema structure;
[0007] S12 utilizes LLM for power terminology recognition and semantic mapping, constructs a power terminology lookup table, and combines manual annotation verification to improve the accuracy of pattern linking.
[0008] S13 collects high-frequency SQL query patterns from the power grid database and combines them with the power terminology lookup table built by S12 to generate natural language query templates that cover typical power query scenarios.
[0009] S14 further expands the natural language-SQL pair through synonym conversion, syntactic variants, numerical perturbations, and colloquial expressions, thereby improving the diversity and generalization ability of the dataset.
[0010] S2 cleans, optimizes, and standardizes the format of the data generated by S1 to build high-quality training and testing datasets.
[0011] S21 parses natural language-SQL pairs, standardizes SQL format, optimizes query structure, and performs syntax validation to ensure correct SQL execution. Simultaneously, it optimizes natural language queries, improves wording standardization, and reduces redundancy and ambiguity to enhance query accuracy.
[0012] S22, in conjunction with the S13 power terminology lookup table, checks the pattern linking after data cleaning, corrects erroneous mappings in natural language queries and SQL statements, and ensures the accuracy of terminology matching.
[0013] S23 constructs a data quality scoring mechanism that combines automatic evaluation and manual sampling to screen high-quality data and correct or eliminate unreasonable queries in order to improve the reliability of the dataset.
[0014] Based on the filtered data, S24 rationally divides the training set and test set, and standardizes the storage structure to support the subsequent training and evaluation of the Text2SQL model.
[0015] S3 relies on the training set partitioned by S24, inputs natural language queries into LLM, predicts the power system database schema involved in the query, and generates SQL statements with precise pattern matching.
[0016] S31 combines natural language queries, the power industry database structure, and historical query data to calculate the relevant weights of the database schema, prioritizing the matching of highly relevant tables and fields while reducing interference from irrelevant tables to optimize the accuracy of query matching.
[0017] S32 uses LLM to parse natural language queries, extracts possible query-related items, and constructs preliminary virtual SQL based on these items. This SQL is only used for pattern matching and does not directly execute database queries.
[0018] S33 combines the highly relevant table fields selected by S31 with the virtual SQL generated by S32, uses vector embedding to calculate the similarity between query items and schema items, and corrects possible pattern matching errors to improve the accuracy and consistency of SQL generation.
[0019] S4 introduces a logic decomposition and optimization mechanism to ensure that SQL queries generated based on S33 not only conform to the logical rules of the database but also meet the business needs of the power industry.
[0020] To improve the accuracy of SQL generation, S41 optimizes query construction and reduces misuse of SQL structures in large language models. It introduces pandas-style symbolic representation and employs logical decomposition methods to optimize the transformation of filtering conditions (WHERE) and the construction of SQL statements.
[0021] Building upon S41, S42 parses the database schema, identifies the tables involved in the query, and constructs reasonable JOIN relationships to ensure that foreign key constraints meet query requirements. It also optimizes inter-table matching and improves the logical consistency of SQL statements.
[0022] S43 further identifies aggregation needs in the query, constructs a GROUP BY statement to ensure the accuracy of data statistics, and optimizes the selection of aggregation functions to improve the rationality of SQL generation.
[0023] S5 aims to fine-tune the large language model based on the SQL statements revised by S4, enhancing its understanding of the business needs and database logic of the power industry, and ensuring that the generated SQL statements are more accurate and efficient.
[0024] S51 uses the SQL statements processed by S4 to train the LLM for task alignment, enabling it to accurately identify query requirements in the power industry and generate SQL statements that conform to the database schema and business logic.
[0025] S52 constructs a query semantic matching loss function to optimize the matching between natural language queries and SQL structures. At the same time, it introduces schema constraints to reduce schema mismatch problems and improve the reliability of schema links.
[0026] To ensure the executability of generated SQL statements, S53 introduces a query result consistency loss and optimizes model parameters to improve its generalization ability, ensuring stable performance in complex query scenarios.
[0027] S6 compresses the trained Text2SQL model and establishes a continuous optimization mechanism to improve inference performance, system stability, and query accuracy.
[0028] S61 uses knowledge distillation to train lightweight inference models and combines ONNX / TensorRT for model compression. It reduces computational resource consumption through model quantization and graph optimization, while improving inference speed and execution efficiency.
[0029] S62 pre-executes generated SQL statements in an SQL sandbox environment, detecting issues such as missing fields, non-existent tables, and incorrect data types to ensure query executability. Simultaneously, it incorporates historical human-generated SQL query data to optimize query semantic matching scores, improving the accuracy and stability of generated SQL.
[0030] S63 uses schema change detection to monitor updates to database table structure, field types, and indexes in real time, ensuring query compatibility. The system can automatically adjust the mapping relationship between tables, fields, and business entities to adapt to database updates, preventing query errors caused by schema changes and improving the long-term applicability of the model.
[0031] S7 deploys the optimized power big data language model to the production environment and ensures system stability, response speed, and model performance through real-time monitoring.
[0032] The beneficial effects of this invention are as follows: This invention innovatively designs a Text2SQL generation system for the power industry, effectively solving the problems of insufficient database schema adaptability, low query matching accuracy, and difficulty in generalizing large language models, achieving significant results. Specifically, addressing the issues of complex database structures and frequent schema updates in the power industry, this invention proposes a data generation method based on schema parsing optimization. By automatically extracting the table structure, field relationships, and business terms from the power grid database, and combining this with a large language model to construct a high-quality training dataset, schema adaptability is improved. Secondly, to solve the problems of logical errors and schema mismatches during SQL generation, this invention introduces a logical decomposition optimization mechanism, combined with task-aligned training, to improve the model's understanding of complex queries, enabling it to generate more accurate SQL statements in scenarios such as multi-table joins and nested queries. Furthermore, this invention incorporates a query feedback optimization mechanism to dynamically correct the executability of SQL statements, ensuring the accuracy and business adaptability of query results, thereby enhancing the intelligent query capability of power data, improving operation and maintenance efficiency, and assisting in data analysis and decision optimization of the power system. Attached Figure Description
[0033] Figure 1 This is a flowchart of the method of the present invention;
[0034] Figure 2 This is a schematic diagram of the present invention used to filter tables that are highly relevant to natural language queries;
[0035] Figure 3 This is a schematic diagram illustrating the virtual SQL generation method and pattern matching correction method designed in this invention;
[0036] Figure 4 This is a schematic diagram of the logic decomposition and optimization mechanism designed in this invention. Detailed Implementation
[0037] The specific embodiments of the present invention will now be described in conjunction with the accompanying drawings to enable those skilled in the art to better understand the present invention.
[0038] like Figure 1 As shown, the specific process of the present invention includes the following steps:
[0039] S1 parses the schema information of the power database and automatically generates a preliminary, diverse dataset of natural language-SQL pairs to support the training and optimization of the Text2SQL task. The specific implementation steps are as follows:
[0040] S11 uses an automatic database parsing tool to extract schema information such as table names, field names, and primary and foreign key relationships from the power grid database, and automatically parses equipment parameters (such as voltage level, measurement unit, and time series marker) to enrich the database schema information.
[0041] S12 uses LLM for power terminology recognition and semantic mapping, automatically constructing a power terminology lookup table (e.g., "peak load" is mapped to peak_load, and "circuit breaker" is mapped to circuit_breaker). Based on this, a small amount of manual annotation can be used for verification to improve the accuracy of pattern linking.
[0042] The S13 analyzes system logs, automatically collects commonly used SQL query statements from the power grid database, and extracts high-frequency query patterns. Based on these SQL statements and the power terminology lookup table built in S12, corresponding natural language query templates are generated using LLM, covering typical query scenarios in the power field, such as equipment status queries, fault statistics, and load analysis.
[0043] Building upon S13, S14 combines methods such as synonym conversion, syntax variations, numerical perturbation, and colloquial expressions to automatically generate diverse natural language-SQL pairs.
[0044] S2 cleans, optimizes, and standardizes the data generated by S1 to construct training and testing datasets. The specific implementation steps are as follows:
[0045] S21 parses the natural language-SQL pairs generated by S14, standardizes the SQL format (e.g., case normalization, removal of redundant spaces, optimization of JOIN order), and performs syntax validation to ensure correct SQL execution. Simultaneously, it optimizes natural language queries, including word standardization, sentence structure optimization, simplification of redundant information, and disambiguation, to improve query accuracy.
[0046] S22, based on the power terminology lookup table built in S12, checks the schema linking in natural language queries and SQL statements after data cleaning in S21, and corrects erroneous mappings (such as "maximum load" being incorrectly mapped to "average_load").
[0047] i = argmaxSim(s′, q)
[0048] Where q represents a term in the natural language query, s′ represents any schema item in the power term lookup table, Sim(·) is the similarity calculation function, and i is the index position of the schema item in the power term lookup table with the highest similarity to q. The schema linking between the natural language query and the SQL statement is then re-established based on the index position.
[0049] S23 constructs a data quality scoring mechanism that combines automatic evaluation and manual sampling to filter high-quality data. Syntactic errors or unreasonable queries are automatically corrected or removed to ensure the dataset is suitable for training the Text2SQL model.
[0050] P=ω1P exec +ω2P match +ω3P var
[0051] Among them, P exec For SQL executability scoring, P match To score the term pattern matching, P var To score data diversity, ω i These are the weight parameters.
[0052] Based on the natural language-SQL data selected in S23, S24 rationally divides the training set and test set, and standardizes the storage to support subsequent Text2SQL model training and evaluation.
[0053] S3 relies on the training set partitioned by S24. It inputs natural language queries into the LLM, predicts the power system database schema involved in the query, and generates accurate pattern-matching SQL statements based on this. The specific implementation steps are as follows:
[0054] S31 combines the input natural language query, the database structure of the power industry, and historical query data to calculate the relevant weights of the database schema, increasing the priority of tables and fields highly relevant to the query while reducing interference from irrelevant tables, thereby optimizing the accuracy of query matching.
[0055] score(T)=λ1·freq(T)+λ2·complexity(T)+λ3·relevance(T)
[0056] Where score(T) is the sorting score of table T, freq(T) is the access frequency of the table, complexity(T) measures the participation complexity of the table, relevance(T) calculates the query relevance, and λ1, λ2, and λ3 are adjustment parameters. Finally, with Figure 2 As shown in the example, the table field combination with the highest score is selected as the basis for SQL generation.
[0057] S32 uses LLM to parse natural language queries, extracting potentially relevant query terms, including tables, fields, and their possible values. Then, based on these terms, it constructs a preliminary virtual SQL statement, which is used only for pattern matching and does not directly execute database queries.
[0058] S33 combines the highly relevant table field combinations selected by S31 with the virtual SQL generated by S32, and uses vector embedding (Word2Vec) to calculate the similarity between natural language query terms and schema terms. For example... Figure 3 As shown, the pattern matching errors that may exist in the virtual SQL are corrected based on the schema item with the highest similarity, in order to improve the matching accuracy:
[0059]
[0060] Where sim(Q,F) represents the similarity between query Q and SchemaF, q i and f j These are the query term and the schema candidate terms, respectively, and f(·) is the semantic similarity function.
[0061] S4 Figure 4 As shown, this invention introduces a logical decomposition and optimization mechanism to ensure that SQL queries generated based on S33 both conform to the logical rules of the database and meet the business needs of the power industry. The specific implementation steps are as follows:
[0062] During SQL generation, the large language model may misuse SQL structures (such as incorrect JOIN or GROUPBY). To improve the accuracy of generated SQL, a pandas-style symbolic representation is introduced, and a logical decomposition approach is used to optimize the SQL query construction process. Specifically, the filtering conditions in the query are first extracted and converted into the SQL WHERE clause, i.e.:
[0063] Filtering:Q filter →WHERE{C i}
[0064] Among them, Q filter C represents the set of filter conditions in the query. i This represents specific constraints, such as A>υ or A=υ, etc.
[0065] Building upon S41, S42 parses the tables involved in the query based on the database schema and constructs reasonable JOIN relationships to ensure compliance with foreign key constraints. It also accurately matches query semantics to improve the logical consistency of generated SQL.
[0066] Joining: T = {T1, T2, ..., T} n}, R={(T i ,T j )|T i ASSOCIATED T j}
[0067]
[0068] Where T represents the set of tables involved in the query, R is the set of relationships between the tables, and K represents the foreign key constraint field.
[0069] Building upon S42, S43 identifies aggregation needs in queries and constructs a GROUP BY statement to ensure the accuracy of data statistics.
[0070] Aggregation: Q agg →GROUP BY A k ,Agg(A m )
[0071] Among them, A k This is the field that needs to be grouped, Agg(A m ) represents a specific aggregate function (such as SUM, AVG, COUNT).
[0072] S5 aims to fine-tune the large language model based on the revised SQL statements of S4, enhancing its understanding of the business needs and database logic of the power industry, and ensuring that the generated SQL statements are more accurate and efficient. The specific implementation steps are as follows:
[0073] Based on the SQL statements processed by S4, S51 uses LLM for task alignment training to ensure that the model can accurately identify the query requirements of the power industry and generate SQL statements that conform to the database schema and business logic.
[0074]
[0075] Where N is the number of queries, M is the total number of tables and fields, and y ij It's the actual tag, p ij It is the probability predicted by the model.
[0076] S52 constructs a query semantic matching loss function to ensure more accurate matching between natural language queries and SQL structures, while introducing schema constraint optimization to reduce schema mismatches (schema linking failures, field misuse, etc.).
[0077] L match =λ1||v q ,v s ||
[0078]
[0079] Among them, v q and v s s represents the vector representation of a natural language query and an SQL statement, respectively. k and These are the target schema structure and the schema structure predicted by the model, respectively.
[0080] To ensure the executability of generated SQL statements, S53 introduces a query result consistency loss, requiring that the SQL generated by the model be semantically consistent with the actual execution result. Furthermore, the Adam optimizer is used to tune parameters and improve the model's generalization ability on power sector data.
[0081] L cons =λ3||R g -R t || 2
[0082]
[0083] Among them, R g and R t These are the query results returned by the model-generated SQL and the target SQL, respectively, and represent the weights of the loss function. η is the learning rate, which is set to 0.001 by default, and the weight decay is set to 0.4.
[0084] S6 compresses the trained Text2SQL model and establishes a continuous optimization mechanism to improve inference performance, system stability, and query accuracy.
[0085] S61 uses knowledge distillation to train lightweight inference models and combines ONNX / TensorRT for model compression. It reduces computational resource consumption through model quantization and graph optimization, while significantly improving inference speed and execution efficiency.
[0086] S62 pre-executes generated SQL statements in an SQL sandbox environment, checking for issues such as missing fields, non-existent tables, and incorrect data types to ensure query executability. Furthermore, by combining historical manually generated SQL query data with the execution results of standard SQL statements, it calculates errors and optimizes the query semantic matching score, further improving the accuracy and stability of SQL generation.
[0087] S63 uses schema change detection to monitor updates to database table structures, field types, and indexes in real time, ensuring query compatibility. When the database structure changes, the system automatically adjusts the mapping relationships between tables, fields, and business entities to prevent query errors caused by schema updates, improving the model's adaptability and long-term availability.
[0088] S7 efficiently deploys the optimized power big data language model to the production environment and ensures system stability, response speed, and model performance through real-time monitoring. Specific implementation methods include containerizing the model using Docker, managing the cluster and automatically scaling with Kubernetes, and combining Prometheus and Grafana for real-time performance monitoring and runtime status visualization.
[0089] It needs to be further explained that:
[0090] The method of this invention relies on a computer program to control hardware to execute each step in order to achieve the described technical solution. Specifically, all or part of the process of the above method can be completed by computer program instructions controlling related hardware. This program can be stored in a non-volatile computer-readable storage medium and operates according to the process of each embodiment during execution. The memory, database, and other storage media involved in this application can all include non-volatile memory and / or volatile memory to ensure long-term stable storage and access of data.
[0091] Those skilled in the art should understand that, for ease of description, we have provided examples of functional unit or module division. However, in specific applications, the division of functional units or modules can be adjusted according to actual needs to achieve all or part of the functions of the present invention. The embodiments described above are only for illustrating the technical solutions of the present invention and are not intended to limit it. Although specific embodiments have been described in detail herein, those skilled in the art can still modify them or replace some technical features in an equivalent manner, and these changes do not depart from the core ideas and protection scope embodied in the embodiments of the present invention.
Claims
1. A Text2SQL generation method for dynamic adaptation in the power sector, characterized in that, The method includes the following steps: S1 parses the schema information of the power database and automatically generates diverse natural language-SQL pair datasets to support the training and optimization of Text2SQL tasks; S2 cleans, optimizes, and standardizes the format of the data generated by S1 to build high-quality training and testing datasets. S3 relies on the training set partitioned by S2, inputs natural language queries into LLM, predicts the power system database schema involved in the query, and generates SQL statements with precise pattern matching. S4 introduces a logic decomposition and optimization mechanism to ensure that SQL queries generated based on S3 not only conform to the logical rules of the database but also meet the business needs of the power industry. S5 aims to fine-tune the large language model based on the SQL statements revised by S4, enhance its understanding of the business needs and database logic of the power industry, and ensure that the generated SQL statements are more accurate and efficient. S6 compresses the trained Text2SQL model and establishes a continuous optimization mechanism to improve inference performance, system stability, and query accuracy. S7 deploys the optimized power big data language model to the production environment and ensures system stability, response speed, and model performance through real-time monitoring.
2. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S1 includes the following steps: S11 extracts table names, field names, and primary and foreign key relationships from the power grid database, and parses key equipment parameters to enrich the database schema structure; S12 utilizes LLM for power terminology recognition and semantic mapping, constructs a power terminology lookup table, and combines manual annotation verification to improve the accuracy of pattern linking. S13 collects high-frequency SQL query patterns from the power grid database and combines them with the power terminology lookup table built by S12 to generate natural language query templates that cover typical power query scenarios. S14 further expands the natural language-SQL pair through synonym conversion, syntactic variations, numerical perturbations, and colloquial expressions, thereby improving the diversity and generalization ability of the dataset.
3. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S2 includes the following steps: S21 parses natural language-SQL pairs, standardizes SQL format, optimizes query structure, and performs syntax validation to ensure SQL can be executed correctly. At the same time, it optimizes natural language queries, improves wording standardization, and reduces redundancy and ambiguity to improve query accuracy. S22, in conjunction with the S13 power terminology lookup table, checks the pattern linking after data cleaning, corrects erroneous mappings in natural language queries and SQL statements, and ensures the accuracy of terminology matching. S23 constructs a data quality scoring mechanism that combines automatic evaluation and manual sampling to screen high-quality data and correct or eliminate unreasonable queries in order to improve the reliability of the dataset. Based on the filtered data, S24 rationally divides the training set and test set, and standardizes the storage structure to support the subsequent training and evaluation of the Text2SQL model.
4. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S3 includes the following steps: S31 combines natural language queries, the power industry database structure, and historical query data to calculate the relevant weights of the database schema, prioritizing the matching of highly relevant tables and fields while reducing interference from irrelevant tables to optimize the accuracy of query matching. S32 uses LLM to parse natural language queries, extracts possible query-related items, and constructs preliminary virtual SQL based on these items. This SQL is only used for pattern matching and does not directly execute database queries. S33 combines the highly relevant table fields selected by S31 with the virtual SQL generated by S32, uses vector embedding to calculate the similarity between query items and schema items, and corrects possible pattern matching errors to improve the accuracy and consistency of SQL generation.
5. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S4 includes the following steps: To improve the accuracy of SQL generation, optimize query construction, reduce misuse of SQL structure in large language models, introduce pandas-style symbolic representation, and adopt logical decomposition methods to optimize the transformation of filtering conditions and the construction of SQL statements; Building upon S41, S42 parses the database schema, identifies the tables involved in the query, and constructs reasonable JOIN relationships to ensure that foreign key constraints meet query requirements. It also optimizes inter-table matching and improves the logical consistency of SQL statements. S43 further identifies aggregation needs in the query, constructs a GROUP BY statement to ensure the accuracy of data statistics, and optimizes the selection of aggregation functions to improve the rationality of SQL generation.
6. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S5 includes the following steps: S51 uses the SQL statements processed by S4 to train the LLM for task alignment, enabling it to accurately identify query requirements in the power industry and generate SQL statements that conform to the database schema and business logic. S52 constructs a query semantic matching loss function to optimize the matching between natural language queries and SQL structures. At the same time, it introduces schema constraints to reduce schema mismatch problems and improve the reliability of schema links. To ensure the executability of generated SQL statements, S53 introduces a query result consistency loss and optimizes model parameters to improve its generalization ability, ensuring stable performance in complex query scenarios.
7. The Text2SQL generation method for dynamic adaptation in the power sector according to claim 1, wherein step S6 includes the following steps: S61 uses knowledge distillation to train lightweight inference models and combines ONNX / TensorRT for model compression. It reduces computational resource consumption through model quantization and graph optimization, while improving inference speed and execution efficiency. S62 pre-executes generated SQL statements in the SQL sandbox environment to detect issues such as missing fields, non-existent tables, and incorrect data types, ensuring the executability of queries. At the same time, it combines historical manual SQL query data to optimize query semantic matching scores, improving the accuracy and stability of SQL generation. S63 uses schema change detection to monitor updates to database table structure, field types, and indexes in real time, ensuring query compatibility. The system can automatically adjust the mapping relationship between tables, fields, and business entities to adapt to database updates, prevent query errors caused by schema changes, and improve the long-term applicability of the model.
8. A Text2SQL generation system for dynamic adaptation in the power sector, characterized in that, The system includes: The parsing module is used to parse the schema information of the power database and automatically generate diverse natural language-SQL pair datasets to support the training and optimization of the Text2SQL task; The preprocessing module is used to clean, optimize, and standardize the generated data to build high-quality training and testing datasets. The prediction module, which depends on the partitioned training set, takes a natural language query as input to the LLM, predicts the power system database schema involved in the query, and generates an SQL statement that precisely matches the pattern. The optimization module is used to introduce a logic decomposition and optimization mechanism to ensure that the generated SQL queries not only conform to the logical rules of the database, but also meet the business needs of the power industry. The correction module aims to fine-tune the large language model based on the corrected SQL statements, enhance its understanding of the business needs and database logic of the power industry, and ensure that the generated SQL statements are more accurate and efficient. The compression module is used to compress the trained Text2SQL model and establish a continuous optimization mechanism to improve inference performance, system stability and query accuracy. The deployment module is used to deploy the optimized power big data language model to the production environment and ensure the stability, response speed and model performance of the system through real-time monitoring.
Citation Information
Cited By
Text2SQL (Structured Query Language) system oriented to actual power scene and control method thereof
CN121501826A
Text2SQL system and control method thereof for actual power scenario
CN121501826B