Intelligent number asking method and device, electronic equipment and storage medium

By receiving natural language questions and converting them into power grid business query intent categories, and generating SQL statements to automatically query power grid indicator data, the problem of low efficiency in manual queries by power grid companies has been solved, achieving efficient data acquisition and decision support.

CN121807889APending Publication Date: 2026-04-07GUANGDONG POWER GRID CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-01-12
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

In existing technologies, manual queries of power grid operation indicator data by power grid companies require business personnel to master professional SQL syntax, resulting in low query efficiency and an inability to efficiently obtain decision support information.

Method used

By receiving users' natural language questions, the intent recognition model is used to convert them into power grid business query intent categories. Combined with customized prompt word templates and power grid domain semantic models, SQL statements are generated to automatically query power grid indicator data from the target database.

Benefits of technology

It enables automated querying of power grid indicator data without requiring mastery of SQL syntax, improving data query efficiency and decision support agility, and reducing technical barriers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807889A_ABST
    Figure CN121807889A_ABST
Patent Text Reader

Abstract

The invention discloses an intelligent number asking method and device, electronic equipment and a storage medium, and belongs to the technical field of intelligent number asking, and the method comprises the steps: inputting a natural language question of a user into a preset intention recognition model, and recognizing a power grid business query intention type to which the natural language question belongs; matching a customized cue word template corresponding to the power grid service query intention category from a preset cue word template library; the natural language question and the customized cue word template are combined and then input to a preset power grid field semantic model, and a corresponding SQL statement is generated and output; the SQL statement is executed, the corresponding power grid index data is inquired from the preset target database, and the inquiry result of the power grid index data is obtained, so that the problems that in the prior art, manual inquiry operation has high requirements for professional skills of business personnel and is low in efficiency can be solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent questioning technology, and in particular to an intelligent questioning method, apparatus, electronic device, and storage medium. Background Technology

[0002] In the daily operations and decision-making of power grid companies, managers and business personnel frequently need to query and analyze various power grid operation indicators (such as line loss rate and power supply reliability). The current query method is manual, which requires a high level of professional skill from business personnel and is inefficient. Since this data is typically stored in large databases, query operations require users to possess professional Structured Query Language (SQL) writing skills. Each query necessitates business personnel manually writing the corresponding SQL. However, for most business personnel, SQL syntax is complex and has a high learning curve. They need to master relatively specialized SQL syntax and database knowledge, making it impossible to directly and efficiently obtain the required data, severely impacting the efficiency of data-driven decision-making. Summary of the Invention

[0003] This invention provides an intelligent query method, device, electronic device, and storage medium, which can solve the problem that manual query operations in the prior art require high professional skills from business personnel and are inefficient.

[0004] To address the aforementioned technical problems, embodiments of the present invention provide an intelligent questioning method, comprising: Receiving natural language questions from users; The natural language question is input into a preset intent recognition model, which compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. Based on the power grid business query intent category, a customized prompt word template corresponding to the power grid business query intent category is matched from a preset prompt word template library; The natural language question and the customized prompt word template are combined and then input into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. Execute the SQL statement to query the corresponding power grid indicator data from the preset target database and obtain the query results of the power grid indicator data.

[0005] As a preferred embodiment, the step of comparing the natural language question with preset standard questions, and taking the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs and outputting it, includes: The natural language question is converted into a corresponding semantic vector; wherein the dimension of the semantic vector is consistent with the dimension of the standard question vector in the preset standard question semantic vector library; Calculate the similarity between the semantic vector and each standard question vector in the standard question semantic vector library, and take the intent category corresponding to the standard question vector with the highest similarity as the power grid business query intent category to which the natural language question belongs and output it.

[0006] As a preferred embodiment, the generation of the intent recognition model includes: Obtain several user question samples, and classify and label the intent categories of the user question samples. Use the user question samples with labeled intent categories as the training set. The training set is input into a preset neural network model. The encoding layer of the neural network model converts the user question samples in the training set into corresponding semantic vector samples. The semantic vector samples are then input into the fully connected layer of the neural network model to obtain the probability distribution of the semantic vector samples belonging to each intent category. Calculate the loss value between the probability distribution and the true intent category label of the semantic vector sample, and update the model parameters of the neural network model using the gradient descent algorithm until the loss value is less than a preset threshold to obtain the intent recognition model.

[0007] As a preferred embodiment, the customized prompt word template includes several of the following: role definition information, business rule information, query constraint information, and output format information; The business rule information includes: positive and negative attribute classifications and quality judgment criteria for various power grid indicators; The query constraint information includes: when the natural language question contains a time description, the time function representation of the SQL statement generated by the constraint; and when the natural language question does not contain a time description, the default time query condition of the SQL statement generated by the constraint.

[0008] As a preferred embodiment, the generation of the semantic model in the power grid domain includes: Obtain several paired samples consisting of natural language question samples and corresponding standard SQL statements, and use the paired samples as training samples; Using a pre-defined large language model as a base model, the original weight matrix of the self-attention layer in the base model is extracted, and a trainable first low-rank parameter matrix and a second low-rank parameter matrix are introduced into the original weight matrix; wherein, the first low-rank parameter matrix is ​​an increased-dimensional matrix, the second low-rank parameter matrix is ​​a reduced-dimensional matrix, and the ranks of the first low-rank parameter matrix and the second low-rank parameter matrix are much smaller than the dimension of the original weight matrix. The base model is trained based on the training samples. During the training process, the original weight matrix remains unchanged, and the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix are updated using the gradient descent algorithm until the loss value of the base model is minimized, thereby obtaining the semantic model of the power grid domain.

[0009] As a preferred embodiment, the step of training the base model based on the training samples, keeping the original weight matrix unchanged during training, and updating the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix using a gradient descent algorithm until the loss value of the base model is minimized, thereby obtaining the power grid domain semantic model, includes: The training samples are input into the fine-tuning model consisting of the base model, the original weight matrix, the first low-rank parameter matrix, and the second low-rank parameter matrix, so that the fine-tuning model outputs the SQL logical sequence corresponding to the natural language question sample after forward propagation. Calculate the loss value between the SQL logical sequence and the corresponding standard SQL statement, and calculate the gradient of the first low-rank parameter matrix and the second low-rank parameter matrix using the backpropagation algorithm based on the loss value; Based on the gradients of the first low-rank parameter matrix and the second low-rank parameter matrix, the parameter values ​​of the first low-rank parameter matrix and the second low-rank parameter matrix are updated using the gradient descent algorithm until the loss value is minimized, thereby obtaining the semantic model of the power grid domain.

[0010] As a preferred embodiment, executing the SQL statement to query the corresponding power grid indicator data from a preset target database and obtaining the query results of the power grid indicator data includes: The SQL statement is executed by calling a preset database adapter to query the corresponding power grid indicator data from the preset target database and obtain the query results of the power grid indicator data; wherein, the database adapter is used to be compatible with different types of target databases, including: MySQL, Oracle, DM or HIVE database.

[0011] Based on the above embodiments, another embodiment of the present invention provides an intelligent query device, including: a natural language question acquisition module, a power grid business query intent category recognition module, a customized prompt word template matching module, an SQL statement generation module, and a power grid indicator data query module; The natural language question acquisition module is used to receive natural language questions from users; The power grid business query intent category identification module is used to input the natural language question into a preset intent identification model, so that the intent identification model compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. The customized prompt word template matching module is used to match a customized prompt word template corresponding to the power grid business query intent category from a preset prompt word template library; The SQL statement generation module is used to combine the natural language question with the customized prompt word template and input it into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. The power grid indicator data query module is used to execute the SQL statement, query the corresponding power grid indicator data from the preset target database, and obtain the query results of the power grid indicator data.

[0012] Based on the above embodiments, another embodiment of the present invention provides an electronic device, the device including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the intelligent questioning method described in the above embodiments of the invention.

[0013] Based on the above embodiments, another embodiment of the present invention provides a storage medium, the storage medium including a stored computer program, wherein, when the computer program is running, it controls the device where the storage medium is located to execute the intelligent query method described in the above embodiments of the invention.

[0014] Compared with the prior art, the embodiments of the present invention have the following beneficial effects: This invention provides an intelligent query method that receives a user's natural language question; inputs the natural language question into a preset intent recognition model, which compares the natural language question with preset standard questions, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs; matches a customized prompt word template corresponding to the power grid business query intent category from a preset prompt word template library; combines the natural language question and the customized prompt word template and inputs them into a preset power grid domain semantic model, which generates and outputs a corresponding SQL statement based on the combined natural language question and customized prompt word template; wherein, the power grid domain semantic model is trained on a preset large language model using several paired samples composed of natural language question samples and standard SQL statements as training samples; executes the SQL statement to query corresponding power grid indicator data from a preset target database to obtain the query results of power grid indicator data. This invention enables automated querying of power grid indicator data, allowing business personnel to directly and automatically query complex power grid indicator data through users' natural language questions without needing to master professional SQL syntax and database knowledge. This reduces the technical barriers to data querying, enabling frontline business personnel to independently and efficiently obtain decision support information, thereby improving work efficiency and the agility of data analysis. Attached Figure Description

[0015] Figure 1 This is a flowchart illustrating an intelligent question-and-answer method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of an intelligent questioning device provided in an embodiment of the present invention. Detailed Implementation

[0016] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0017] Example 1 Please refer to Figure 1 To address the problem that manual query operations in existing technologies require high levels of professional skills from business personnel and are inefficient, an embodiment of the present invention provides a flowchart of an intelligent query method, including the following specific steps: S1, Receiving the user's natural language problem; In a specific embodiment, for step S1 above, the natural language question refers to a user's inquiry about power grid indicators raised in everyday conversational language, such as "What was the line loss rate of Liuzhou Power Supply Bureau in March 2025?" or "How was the electricity sales situation of various municipal bureaus during last year's flood season?", without needing to follow a specific format or professional grammar. The process of receiving natural language questions is as follows: user input is received through the front-end interactive interface of the intelligent agent system, supporting common methods such as text input to ensure that users can easily submit questions.

[0018] S2. Input the natural language question into a preset intent recognition model, so that the intent recognition model compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. Preferably, the step of comparing the natural language question with a preset standard question and outputting the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs includes: converting the natural language question into a corresponding semantic vector; wherein the dimension of the semantic vector is consistent with the dimension of the standard question vector in the preset standard question semantic vector library; calculating the similarity between the semantic vector and each standard question vector in the standard question semantic vector library, and outputting the intent category corresponding to the standard question vector with the highest similarity as the power grid business query intent category to which the natural language question belongs.

[0019] Preferably, the generation of the intent recognition model includes: acquiring a number of user question samples and classifying and labeling the intent categories of the user question samples; using the labeled user question samples as a training set; inputting the training set into a preset neural network model; converting the user question samples in the training set into corresponding semantic vector samples through the encoding layer of the neural network model; inputting the semantic vector samples into the fully connected layer of the neural network model to obtain the probability distribution of the semantic vector samples belonging to each intent category; calculating the loss value between the probability distribution and the true intent category label of the semantic vector samples; and updating the model parameters of the neural network model through a gradient descent algorithm until the loss value is less than a preset threshold to obtain the intent recognition model.

[0020] In a specific embodiment, for step S2 above, the intent recognition model refers to a model used to classify user natural language questions into predefined power grid business query intent categories. Its core is to convert the question into a high-dimensional semantic vector through Embedding training, and then determine the intent by calculating similarity.

[0021] In this embodiment, the process of identifying the category of power grid service query intent includes: The intent recognition model converts the natural language question input by the user into a high-dimensional semantic vector; that is, it converts the natural language text (user question) into a vector with high dimension (usually hundreds to thousands of dimensions) through the embedding technology. This vector can represent the semantic information of the text in mathematical space. The distance or similarity between vectors can reflect the degree of similarity of the semantics of the text. For example, the high-dimensional semantic vectors of "query line loss rate" and "what is the line loss rate" have a high degree of similarity. The similarity between the high-dimensional semantic vector and each vector in the pre-stored standard question semantic vector library is calculated. The standard question vectors in the library are associated with predefined intent categories. The standard question semantic vector library stores a database of standard question semantic vectors corresponding to predefined power grid business query intent categories. Each standard question is a typical question expression under that intent category. After embedding processing, standard question semantic vectors are generated, and each vector is mapped to its corresponding intent category. For example, the standard vector for "latest line loss rate of each municipal bureau" is associated with the intent for "latest time indicator lighting status of each region." Furthermore, similarity is a quantitative indicator used to measure the semantic similarity between two high-dimensional semantic vectors. Commonly used calculation methods include cosine similarity, Euclidean distance, and Pearson correlation coefficient. This method mainly uses cosine similarity, which ranges from [-1, 1]. The closer the value is to 1, the more semantically similar the two vectors are; the closer the value is to -1, the more semantically distant the two vectors are. The intent category corresponding to the standard question vector with the highest similarity is determined as the intent category to which the user question belongs.

[0022] In a specific application, the intent recognition model is constructed and trained as follows: Model selection: Pre-trained language models based on the Transformer architecture (such as BERT and RoBERTa) are selected as the basic architecture of the intent recognition model. These models have excellent performance in natural language semantic understanding tasks and can effectively convert text into high-dimensional semantic vectors. In combination with the characteristics of the power grid field, a model that is pre-trained on a general corpus and then fine-tuned on power grid text data can be selected to further improve the ability to understand power grid proper nouns. Training data preparation: Collect user question samples from various business query scenarios in the power grid field, and classify and label them according to predefined intent categories (such as "the status of lighting in various regions at the latest time indicators", "query of year-on-year changes in indicators", "query of the merits and demerits of indicators", etc., nearly 100 kinds of intents). Each intent category is labeled with tens of thousands of extended question samples. The labeled question samples are divided into training set, validation set and test set for model training, parameter tuning and performance evaluation. Model training process: Input the problem samples from the training set into the model. The model's encoding layer converts the text into high-dimensional semantic vectors. Then, the semantic vectors are input into the fully connected layer, and the softmax activation function is used to obtain the probability distribution of each intent category to which the sample belongs. The cross-entropy loss function is used to calculate the loss value between the predicted probability distribution and the true intent category label. The model parameters are updated using the gradient descent algorithm to continuously reduce the loss value. During training, the model performance (such as accuracy and recall) is evaluated periodically using a validation set, and the model hyperparameters (such as learning rate and batch size) are adjusted according to the evaluation results. After training, the model is finally evaluated using a test set to ensure that the model has good intent recognition capabilities on unseen data. Embedding layer extraction: In the trained intent recognition model, the Embedding layer (usually the output of the last hidden layer of the model or the CLS position vector) is extracted to convert the text into a high-dimensional semantic vector. The vector output by this layer is the high-dimensional semantic vector of the question, which can accurately represent the semantic information of the question.

[0023] In a specific application, the standard question semantic vector library is constructed as follows: Standard question selection: For each predefined power grid business query intent category, select representative questions that accurately reflect the core needs of the intent as standard questions. For example, for the intent "Latest time indicator lighting status in various regions", standard questions could be "What is the latest line loss rate completion status of each secondary unit?" or "Latest monthly indicator lighting status of each municipal bureau", etc. Multiple standard questions are selected for each intent category to cover different ways of expressing the intent and improve the robustness of intent recognition. Standard question semantic vector generation: The selected standard questions are input into the Embedding layer of the trained intent recognition model, and the model generates corresponding high-dimensional semantic vectors. Multiple standard question semantic vectors under each intent category are processed, and their average vector can be calculated as the representative semantic vector of the intent category, or all standard question semantic vectors can be stored directly to establish a mapping relationship between each standard question vector and the corresponding intent category. For example, the semantic vector of "What is the latest line loss rate completion status of each secondary unit?" can be associated with the intent "The latest time indicator of regional lighting status". Vector library storage and index construction: All generated standard question semantic vectors and their corresponding intent category information are stored in the database to construct a standard question semantic vector library; to improve the efficiency of similarity calculation, vector indexing technology (such as FAISS, Annoy) is used to index the vector library. Through the index structure (such as KD tree, ball tree), standard question vectors with high similarity to user question semantic vectors are quickly retrieved, reducing the calculation time under large-scale vector library and improving the speed of intent recognition.

[0024] In a specific application, the intent recognition model is optimized and updated as follows: As the power grid business develops and user query needs change, new user question samples are collected regularly to supplement and adjust the predefined intent categories (such as adding the intent "new energy access index query"). The intent recognition model is incrementally trained using new labeled samples to update model parameters and improve the model's ability to recognize new intents and new question expressions. At the same time, the standard question semantic vector library is updated, and standard questions and their semantic vectors corresponding to new intents are added to ensure that the intent recognition system can continuously adapt to business changes and maintain a high recognition accuracy.

[0025] Based on the above, the intelligent query method for power grid indicators in this embodiment accurately captures the core semantic needs of user questions by converting user questions into high-dimensional semantic vectors and matching them with a standard question vector library. Even if user questions are expressed in various ways (such as "what is the line loss rate?" or "query line loss rate data"), they can be correctly classified into the corresponding intent category, avoiding intent recognition errors caused by differences in expression, and improving the accuracy and robustness of intent recognition. By constructing an intent system containing multiple intents and tens of thousands of extended questions for each intent, as well as a standard question semantic vector library, it can cover various power grid business query scenarios such as full indicators, full organization, and full scope, meeting the diverse query needs of users and avoiding the incompleteness of user questions due to incomplete intent coverage. The method effectively addresses the issue, improving the system's applicability. Optimizing the standard question semantic vector library using vector indexing technology significantly reduces the time complexity of similarity calculations, enabling rapid intent recognition. Even with a large vector library, recognition results can be returned quickly, reducing user waiting time and improving system response speed and user experience. Accurate intent recognition is a prerequisite for matching the corresponding customized prompt word template from the prompt word template library. Only by correctly classifying the user's question into the intent category can the appropriate template be called to guide the model in generating SQL statements that meet business requirements. This avoids template matching errors due to intent recognition errors, ensuring the accuracy of SQL statement generation and guaranteeing the smooth operation of the entire intelligent questioning process.

[0026] S3. Based on the power grid business query intent category, match the customized prompt word template corresponding to the power grid business query intent category from the preset prompt word template library; Preferably, the customized prompt word template includes several types of role definition information, business rule information, query constraint information, and output format information; wherein, the business rule information includes: positive and negative attribute classifications and quality judgment criteria for various power grid indicators; the query constraint information includes: when the natural language question contains a time description, the time function representation of the SQL statement generated by the constraint, and when the natural language question does not contain a time description, the default time query condition of the SQL statement generated by the constraint.

[0027] In a specific embodiment, for step S3 above, the customized prompt word template encapsulates power grid business rules and SQL generation constraints related to the power grid business query intent category. The prompt word template library is a database that stores multiple sets of customized prompt word templates corresponding to different power grid business query intent categories. Each template encapsulates power grid business rules and SQL generation constraints according to the business requirements of the corresponding intent. For example, the template for the intent "lighting status of various latest time indicators in different regions" will include relevant content such as warning color field queries.

[0028] Specifically, the customized prompt template includes several of the following: role definition information, business rule information, query constraint information, or output format information. Feasibly, the query constraint information may include: For relative time descriptions in natural language questions (referring to non-specific date or time expressions used by users in natural language questions; these expressions need to be combined with the current time or a specific reference time to determine the specific time range, such as "today," "yesterday," "last year," "this month," "last quarter," "last year's flood season," etc., for example, "last year" in "query last year's electricity sales" is a relative time description), the SQL statement generated by the constraints must use database time functions (referring to functions built into database systems (such as MySQL, Oracle) for processing time and date, which can calculate the corresponding specific time value or time range based on the current system time or a specified reference time, such as CURDATE() (returns the current date), NOW() (returns the current date and time), DATE_SUB() (subtracts a specified time interval from a specified date), YEAR() (extracts the year from a date), QUARTER() (extracts the quarter from a date), etc., for example, in MySQL, "YEAR(CURDATE())-1" can represent last year). For natural language questions that do not mention time information, the SQL statement generated by the constraints must embed default time query conditions (which refer to fixed time query conditions set in the custom prompt word template in advance to ensure that the SQL statement can query valid data when the user's natural language question does not mention any time information. These conditions are determined according to the common needs and business habits of power grid indicator queries, and have universality and rationality, such as the default year being 2025, the default month being March, and the default query period type being p1m (monthly).

[0029] In addition, the business rules information includes positive or negative attribute classifications of power grid indicators, as well as the criteria for judging the quality of various power grid indicators. Power grid indicators refer to quantitative indicators used to measure the operating status, efficiency, effectiveness, and quality of the power grid. They are important bases for power grid companies to conduct business management, data analysis, and decision-making. Common power grid indicators include line loss rate, medium-voltage line failure rate, electricity sales, net profit, power supply reliability, and voltage qualification rate. Positive attribute classifications (positive indicators) refer to power grid indicators where a higher value indicates a better operating status, higher efficiency, and better effectiveness of the power grid. The goal of these indicators is to maximize their value. Examples include electricity sales (reflecting the power grid company's power supply scale and market share; a higher value is better), net profit (reflecting the company's profitability; a higher value is better), and power supply reliability (reflecting power supply stability; a higher value is better). Negative attribute classification (negative indicators) refers to a category of power grid indicators where smaller values ​​represent better power grid operation, lower risk, and less loss. The goal of these indicators is to minimize their values. Examples include line loss rate (reflecting the degree of power loss in the grid, lower values ​​are better), medium-voltage line fault rate (reflecting line operation reliability, lower values ​​are better), and voltage non-compliance rate (reflecting power supply quality, lower values ​​are better). Quality judgment standards refer to criteria established based on the positive or negative attributes of power grid indicators to evaluate the quality of indicator values. These standards clarify the range within which indicator values ​​are considered excellent, acceptable, or unacceptable, providing a basis for power grid operation assessment and decision-making. For example, for the positive indicator of electricity sales, "a year-on-year growth of more than 5% is excellent"; for the negative indicator of line loss rate, "below 5% is excellent, above 8% is unacceptable."

[0030] In this embodiment, each template in the prompt word template library includes a role definition (a description of the model's identity in the customized prompt word template, clarifying the role the model should play when handling questions of the current intent category. This role possesses professional knowledge and skills in a specific field, used to constrain the model's answer style and professionalism, such as setting the model as a "MySQL expert" or "power grid indicator query expert"), business rules (a description of rules based on the business logic and indicator characteristics of the power grid industry, including key content such as the attribute classification, quality judgment criteria, and data statistical caliber of power grid indicators, providing a basis for the model to understand the power grid business scenario and accurately handle indicator-related issues, such as clarifying the division and judgment criteria of positive and negative indicators), and query constraints (the query scope, conditions, etc. of the SQL statements generated by the model). The system includes restrictions and specifications on parameters, data requirements, etc., to ensure that the generated SQL statements can accurately retrieve the required data and avoid problems such as excessively large query scope, missing conditions, or invalid data. For example, it includes constraints on time query conditions, organizational scope, and indicator fields. The output format (specifies the format specifications that the model should follow when generating SQL statements, including syntax, symbol usage, and result presentation, to ensure that the generated SQL statements conform to database syntax requirements, are easy to execute directly, and improve the readability of the statements, such as specifying the use of backticks to mark table names and column names, and specifying aliases for query results) is also defined. Based on the identified intent category, the system calls the corresponding template from the database. For example, when the intent "the latest time indicator regional lighting status" is matched, the template containing query constraints for the warning color field is called.

[0031] Specifically, regarding the design and integration of role definition information: based on the needs of different power grid business query intent categories, corresponding professional roles are set for the templates. For example, in intent templates involving SQL generation, the role is defined as "MySQL expert, proficient in the database structure and SQL query syntax of the power grid industry, and able to accurately write MySQL statements that meet the query requirements of power grid indicators based on the user's natural language questions." The role positioning is clearly stated in the template, such as "You are a MySQL expert. For the given user question, please write a grammatically correct MySQL query statement," so that the model can quickly enter the corresponding role state after receiving the prompt and handle user questions from a professional perspective.

[0032] Secondly, regarding the sorting and integration of business rules information: We conducted in-depth research into the business processes and indicator systems of the power grid industry, sorting out the business rules for various power grid indicators, including indicator attribute classification (e.g., classifying medium-voltage line failure rate and line loss rate as negative indicators, and electricity sales and net profit as positive indicators), evaluation criteria (the smaller the negative indicator value, the better; the larger the positive indicator value, the better), and data statistics rules (e.g., the calculation caliber and statistical period definition of the indicators). These rules were then integrated into a customized prompt template with clear and unambiguous language. For example, the template could include statements such as "medium-voltage line failure rate (excluding user boundary switches) and line loss rate are negative indicators, while electricity sales and net profit are positive indicators; the smaller the negative indicator value, the better; the larger the positive indicator value, the better," providing an accurate basis for the model to understand the power grid business logic.

[0033] On the other hand, regarding the formulation and refinement of query constraints: Specific query constraints are formulated for query scenarios corresponding to different intent categories, covering multiple dimensions such as time, organization, indicator fields, and data validity. Regarding time constraints, it is stipulated that "for queries involving time, if it is a relative time (e.g., today, last year), use time functions (e.g., CURDATE(), NOW()) to obtain the result; if a specific time is specified (e.g., 2023, July), directly use the specific value; if the question does not specify a year, the year = 2025; if the question does not specify a month, the month = 3"; regarding organizational scope constraints, it is clearly stated that "organization name IN (Liuzhou Power Supply Bureau, Qinzhou Power Supply Bureau, Yulin Power Supply Bureau)" and "please do not omit queries for organization names"; regarding indicator field constraints, it is required that " "Please use only the provided column names (such as organization name, warning color, indicator name, year, month, cycle type, result value, year-on-year, month-on-month, target value, indicator unit, etc.) for your query." "Please do not query non-existent columns." "Please do not omit the query conditions for indicator names." "Please do not omit the query fields for warning colors." Regarding query efficiency constraints, it is suggested that "please try not to query all columns, only query the columns required to answer the question." These constraints are systematically integrated into the customized prompt word template and clearly presented in the form of a list or paragraphs to ensure that the model strictly follows them when generating SQL statements.

[0034] Furthermore, regarding the standardization and clarification of output format information: Referencing the SQL syntax specifications of various target databases (such as MySQL and Oracle), and combining them with the actual needs of power grid indicator queries, unified output format requirements were formulated. In terms of syntax, it was stipulated that "please use backticks (`) to mark table names and column names" and "ensure the SQL statement is syntactically correct and free of syntax errors." Regarding result presentation, it was required that "please specify aliases for the query results to make them easy for users to understand." In terms of output format, it was clarified that "please use the following output format: sql SQL query statement," meaning the SQL statement must be enclosed in "sql" and quotation marks for easy system recognition and extraction. These format specifications were written in detail into a customized prompt word template as the format standard for the model to generate SQL statements. For example, the template would list the output format requirements in detail to guide the model in generating statements according to the specifications.

[0035] Furthermore, regarding the integration and storage of customized prompt word templates: the aforementioned role definition information, business rule information, query constraint information, and output format information are combined and integrated according to the needs of different intent categories to form complete customized prompt word templates. For example, the template for the intent "lighting status of various latest time indicators in different regions" integrates the "MySQL expert" role definition, positive and negative indicator business rules, the default time of March 2025, the organizational scope including power supply bureaus such as Liuzhou, the query field including warning colors, and output format specifications, etc. All customized prompt word templates are classified and labeled according to intent categories and stored in the prompt word template library. A mapping relationship between intent categories and templates is established to facilitate quick matching and calling of the corresponding template after intent recognition.

[0036] Based on the above, the intelligent query method for power grid indicators in this embodiment, through role definition information, clarifies the model's identity and responsibilities when handling specific intent questions, avoiding unprofessional responses or deviations from task objectives. This ensures the model generates SQL statements from a professional perspective that aligns with the needs of the power grid industry. Business rule information provides the model with professional knowledge and business standards for the power grid industry, enabling it to accurately understand key business content such as indicator attributes and performance evaluations. This avoids SQL generation errors due to a lack of understanding of business rules (such as mistakenly querying negative indicators as positive indicators), improving the fit between SQL statements and business requirements. Query constraint information restricts the generation of SQL statements from multiple dimensions, effectively preventing query errors. Issues such as inappropriate scope, missing conditions, and incorrect fields are addressed to ensure that the generated SQL statements accurately retrieve the required power grid indicator data. The output format information standardizes the SQL statement format, making it conform to database syntax requirements and directly executable. This also improves the readability and maintainability of the statements, reducing execution errors caused by formatting issues. Different intent categories correspond to fixed, customized prompt word templates. All information within these templates is clear and consistent, ensuring that the model follows the same rules and standards when processing the same type of intent, resulting in consistent SQL statements. Furthermore, the constraints and formatting specifications in the templates reduce the probability of the model generating erroneous statements, improving the reliability of the model's response and guaranteeing the accuracy and efficiency of power grid indicator queries.

[0037] In a specific application, the process of identifying relative time descriptions and matching them with corresponding database time functions is as follows: First, clearly define the correspondence rules between common relative time descriptions and database time functions in the customized prompt word template, and specify the matching relationships for different database types (such as MySQL and Oracle). For MySQL databases, an example rule is as follows: "Today" corresponds to "CURDATE()". For example, in the question "Query today's line loss rate", the time condition in the generated SQL statement is "date=CURDATE()". "Yesterday" corresponds to "DATE_SUB(CURDATE(),INTERVAL1DAY)", such as "Yesterday's indicators of various municipal bureaus" which corresponds to the time condition "date=DATE_SUB(CURDATE(),INTERVAL1DAY)"; "Last year" corresponds to "YEAR(CURDATE())-1", such as "last year's electricity sales" which corresponds to the time condition "year=YEAR(CURDATE())-1"; "This month" corresponds to "DATE_FORMAT(CURDATE(),'%Y-%m')", such as "This month's medium voltage line failure rate" which corresponds to the time condition "DATE_FORMAT(date,'%Y-%m')=DATE_FORMAT(CURDATE(),'%Y-%m')"; "Previous quarter" corresponds to "QUARTER(CURDATE())-1" (it needs to handle cross-year cases, such as the previous quarter being the fourth quarter of the previous year). The time condition corresponding to "net profit of the previous quarter" needs to be judged by combining the year and quarter function. The time condition for “last year’s flood season” (assuming the power grid’s flood season is from June to August each year) is “year = YEAR(CURDATE()) - 1 AND month BETWEEN6 AND 8”. For example, the time condition for “line loss rate of local bureaus during last year’s flood season” is “year = YEAR(CURDATE()) - 1 AND month BETWEEN6 AND 8”. In the customized prompt word template, these corresponding rules are expressed in clear language as query constraint information. For example, "For questions involving time, if it is a relative time (such as today, last year), use time functions (such as CURDATE(), NOW()) to get it; if a specific time is specified (such as 2023, July), use the specific value directly." This guides the semantic model in the power grid field to automatically match and use the corresponding database time functions to generate the time conditions of the SQL statement when it recognizes the relative time description in the user's question.

[0038] S4. The natural language question and the customized prompt word template are combined and then input into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. Preferably, the generation of the power grid domain semantic model includes: acquiring several paired samples consisting of natural language question samples and corresponding standard SQL statements, and using the paired samples as training samples; using a preset large language model as a base model, extracting the original weight matrix of the self-attention layer in the base model, and introducing a trainable first low-rank parameter matrix and a second low-rank parameter matrix into the original weight matrix; wherein, the first low-rank parameter matrix is ​​an increased-dimensional matrix, the second low-rank parameter matrix is ​​a reduced-dimensional matrix, and the ranks of the first low-rank parameter matrix and the second low-rank parameter matrix are much smaller than the dimension of the original weight matrix; training the base model according to the training samples, keeping the original weight matrix unchanged during the training process, and updating the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix through a gradient descent algorithm until the loss value of the base model is minimized, thereby obtaining the power grid domain semantic model.

[0039] Preferably, the step of training the base model based on the training samples, keeping the original weight matrix unchanged during training, and updating the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix using a gradient descent algorithm until the loss value of the base model is minimized, to obtain the power grid domain semantic model, includes: inputting the training samples into a fine-tuning model composed of the base model, the original weight matrix, the first low-rank parameter matrix, and the second low-rank parameter matrix, so that the fine-tuning model outputs the SQL logical sequence corresponding to the natural language question sample after forward propagation; calculating the loss value between the SQL logical sequence and the corresponding standard SQL statement, and calculating the gradient of the first low-rank parameter matrix and the second low-rank parameter matrix using a backpropagation algorithm based on the loss value; updating the parameter values ​​of the first low-rank parameter matrix and the second low-rank parameter matrix using a gradient descent algorithm based on the gradient of the first low-rank parameter matrix and the second low-rank parameter matrix until the loss value is minimized, to obtain the power grid domain semantic model.

[0040] In a specific embodiment, the training process of the power grid domain semantic model in step S4 above includes: Obtain training datasets in the power grid field; A general-purpose large language model is provided as the base model. The base model refers to a pre-trained model with general language understanding and generation capabilities. As mentioned above, the DeepSeekR1-70B inference-type large model is selected as the base model in this method. This model has strong performance in general natural language processing tasks, which lays a good foundation for subsequent fine-tuning for the power grid field. The original weight matrix W in the self-attention layer of the selected base model is used to calculate the degree of correlation between various positions in the input sequence and capture the dependencies in the sequence. In the semantic model of the power grid domain, this layer is crucial for understanding the correlation between power grid indicators, organization, time and other elements in natural language problems. The original weight matrix W refers to the pre-trained weight matrix in the self-attention layer of the base model. Its dimension is determined according to the model structure and remains unchanged during the fine-tuning process, providing the model with a basic framework for language understanding. Trainable low-rank parameter matrices B (i.e., the first low-rank parameter matrix) and A (i.e., the second low-rank parameter matrix) are introduced alongside the original weight matrix W, where the low-rank parameter matrix... Low-rank parameter matrix The rank r is much smaller than the dimensions d and k. The low-rank parameter matrices B and A are used to simulate the trainable matrices for weight updates. A is a dimension reduction matrix and B is an dimension increase matrix. The rank r usually takes the value 4-64, which is much smaller than the dimensions d and k. The incremental update of the original weight matrix W is achieved through the BA low-rank decomposition, which greatly reduces the number of parameters in the fine-tuning process. During the forward propagation process, the input data is passed through a weight matrix. Defined as The input data comes from the power grid domain training dataset. Forward propagation is a process in model training, which refers to passing the input data (natural language problem samples in the power grid domain training dataset) from the input layer of the model through each hidden layer (such as the encoding layer, TransformerEncoder module, and fully connected layer) to the output layer, and calculating the model prediction result (predicted SQL logical sequence). In this training process, the input data is passed through the weight matrix W'. During training, the original weight matrix W is kept unchanged, and the parameters of the low-rank parameter matrix B and the low-rank parameter matrix A are updated by the gradient descent algorithm to fine-tune the base model (thereby achieving the goal of low computational overhead) and obtain the semantic model of the power grid domain.

[0041] Specifically, for sample pair acquisition: sample pairs are selected from the power grid domain training dataset using random sampling. The sampling process ensures the randomness and representativeness of the samples, avoiding model training bias towards a certain type of problem due to sample selection bias. Before each training iteration (batch training), a fixed number of sample pairs (such as 32 or 64, adjusted according to the size of the graphics memory) are extracted from the dataset to form a batch, which serves as the training data for that iteration. Through multiple batch training, the entire dataset is covered, enabling the model to learn comprehensive knowledge of the power grid domain.

[0042] Secondly, regarding the input and forward propagation of natural language problem samples: the natural language problem samples from the acquired sample pairs are input into the model to be fine-tuned. First, they pass through the model's encoding layer, which uses a pre-trained word embedding model (such as BERT's word embeddings) to convert the text problem into fixed-dimensional word vectors. These word vectors represent the semantic information of words. Next, the word vectors enter a multi-layer TransformerEncoder module. In the module's self-attention layer, the weight matrix W' is used to calculate the attention weights of each word vector with other word vectors. Through the allocation of attention weights, the importance of key information in the problem (such as indicator names, organization names, and time) is highlighted. After processing by the TransformerEncoder module, the global semantic vector of the problem is output (usually the vector at the CLS position). This vector integrates the semantic information of the entire problem. Finally, the global semantic vector is input into a fully connected layer. The fully connected layer maps the vector to the prediction space of the SQL logical sequence through a linear transformation. Then, it passes through a softmax activation function to obtain the probability distribution of the predicted SQL logical sequence, completing the forward propagation process and outputting the prediction result.

[0043] On the other hand, for loss calculation: the probability distribution of the predicted SQL logical sequence output by the forward propagation is compared with the standard SQL statement in the sample pair, and the Softmax loss function is used to calculate the loss value between the two. First, the standard SQL statement is processed and converted into a label vector consistent with the format of the prediction result. Each position in the label vector corresponds to an element in the SQL logical sequence. The correct element position is marked as 1, and the rest are marked as 0. Then, according to the Softmax loss function formula, the loss value of each sample is calculated, and the loss values ​​of all samples in the batch are averaged to obtain the average loss value of the batch. This value is the indicator for measuring the current prediction performance of the model.

[0044] Furthermore, for gradient calculation (backpropagation): the backpropagation algorithm is initiated based on the calculated batch average loss value. Starting from the output layer of the model, the partial derivatives of the loss value with respect to the output of the neurons in the output layer are calculated. Then, according to the chain rule, the partial derivatives of the loss value with respect to the parameters of the fully connected layer and the parameters of the TransformerEncoder module (mainly the low-rank parameter matrices A and B) are calculated sequentially. During the calculation process, since the original weight matrix W is fixed, it is only necessary to calculate the partial derivatives of the loss value with respect to each element in A and B, thus obtaining the gradients of A and B. During backpropagation, to avoid the problems of gradient vanishing or gradient exploding, gradient clipping is used to limit the norm of the gradient to a certain range (such as 5.0) to ensure the stability of model training.

[0045] Furthermore, for parameter updates (gradient descent): Stochastic gradient descent (SGD) or optimizers such as Adam are used to perform gradient descent algorithms for parameter updates. First, an initial learning rate is set (e.g., 1e-4), which determines the step size for each parameter update. Then, based on the calculated gradients of A and B, each element in A and B is updated according to the formula "parameter = parameter - learning rate × gradient". For example, for a certain element in matrix A... The update formula is (This is the gradient of the element). During training, a learning rate decay strategy is adopted. As the number of training rounds increases, the learning rate is gradually reduced. A larger learning rate is used in the early stage of training to speed up the convergence speed, and a smaller learning rate is used in the later stage of training to finely adjust the parameters so that the model loss value gradually converges to the minimum value. After each parameter update, the training of the next batch of samples begins. The above process of sample input, forward propagation, loss calculation, gradient calculation and parameter update is repeated until the model training reaches the preset number of rounds or the loss value stabilizes at a low level.

[0046] Based on the above, the intelligent query method for power grid indicators in this embodiment, through batch sample training combined with loss value calculation and gradient descent parameter updates, enables the parameters of low-rank parameter matrices A and B to be specifically adjusted according to the characteristics of training data in the power grid field, gradually reducing the difference between the predicted SQL logical sequence and the standard SQL statement, and improving the accuracy of SQL generation in the power grid field; it uses random sampling to obtain sample pairs to avoid the impact of sample bias on model training; it solves the gradient vanishing or exploding problem in the backpropagation process through gradient pruning technology; and it combines a learning rate decay strategy to ensure that parameter updates maintain a reasonable step size at different stages of training, effectively guaranteeing the model training... To ensure the stability of the training process and avoid training oscillations or non-convergence, a batch training approach is used. Large-scale power grid training datasets are input into the model in batches, allowing the model to fully learn the knowledge from each sample pair. This avoids memory shortages caused by excessive single-input data, improving the efficiency of training data utilization and model training speed. By continuously iteratively updating the low-rank parameter matrices A and B, the model's loss value gradually decreases, and the consistency between the predicted SQL logical sequence and standard SQL statements continuously improves. This leads to continuous performance optimization in power grid indicator query scenarios, ultimately enabling the model to accurately understand users' natural language questions and generate correct SQL statements.

[0047] S5. Execute the SQL statement to query the corresponding power grid indicator data from the preset target database and obtain the query results of the power grid indicator data.

[0048] Preferably, executing the SQL statement to query the corresponding power grid indicator data from the preset target database and obtain the query result of the power grid indicator data includes: calling a preset database adapter to execute the SQL statement, querying the corresponding power grid indicator data from the preset target database, and obtaining the query result of the power grid indicator data; wherein, the database adapter is used to be compatible with different types of target databases, and the target databases include: MySQL, Oracle, DM, or HIVE databases.

[0049] In a specific embodiment, for step S5 above, executing an SQL statement includes: This process invokes a database adapter to execute SQL statements. This database adapter is designed to be compatible with different types of target databases. These target databases include MySQL (a relational database suitable for small to medium-sized structured data storage and retrieval), Oracle (a large-scale relational database suitable for large-scale, high-concurrency enterprise-level data management), DM (a domestic relational database with high security and compatibility, meeting the needs of domestic substitution), or HIVE (a Hadoop-based data warehouse tool suitable for large-scale unstructured and semi-structured data storage and offline analysis). The database adapter is a middleware component used to enable data interaction between different types of databases and application systems. It shields the differences between different databases in SQL syntax, connection methods, data type mapping, etc., providing a unified database access interface for application systems. This allows application systems to achieve compatible access to multiple databases without needing to develop separate access logic for each database. Secondly, SQL syntax differences refer to the variations in SQL syntax details between different types of databases. These differences mainly manifest in function usage (such as time functions and string functions), data type definitions, table join methods, and syntax keywords. For example, the "LIMIT" keyword in MySQL limits the number of rows in a query result, while Oracle uses "ROWNUM." Similarly, MySQL's time function "CURDATE()" extracts the date portion of "SYSDATE" in Oracle. Furthermore, a unified database access interface refers to the standardized data access interface provided by the database adapter to application systems. This interface defines unified methods (such as connecting to the database, executing SQL statements, retrieving query results, and closing connections). Application systems can operate on different databases by calling these unified methods without needing to concern themselves with the specific implementation details of the underlying databases.

[0050] In a specific application, the database adapter architecture is designed as follows: The database adapter is constructed using a layered design approach, mainly comprising an interface definition layer, a database driver layer, a syntax conversion layer, a data interaction layer, and a connection management layer. The functions of each layer are as follows: Interface Definition Layer: Defines a unified database access interface, including methods such as getConnection() (gets a database connection), executeQuery(String sql) (executes a query SQL statement), executeUpdate(String sql) (executes an update SQL statement), and closeConnection() (closes a database connection). Application systems implement database operations by calling these interface methods, ensuring the universality and stability of the interface.

[0051] Database driver layer: Integrates official JDBC (Java Database Connectivity) or ODBC (Open Database Connectivity) drivers for different types of target databases (MySQL, Oracle, DM, HIVE). Each database has a corresponding driver module, which is responsible for establishing a physical connection with the underlying database. For example, the MySQL driver module uses com.mysql.cj.jdbc.Driver, and the Oracle driver module uses oracle.jdbc.driver.OracleDriver. The driver layer dynamically loads the corresponding driver according to the target database type to provide support for database connections.

[0052] Syntax Conversion Layer: One of the core layers, responsible for converting standard SQL statements (usually based on MySQL syntax) generated by the power grid domain semantic model into SQL syntax supported by the target database, resolving the SQL syntax differences between different databases. This is achieved by establishing an SQL syntax difference mapping table and defining conversion rules for different syntax elements, for example: Function conversion: MySQL's "CURDATE()" is converted to Oracle's "TRUNC(SYSDATE)" and HIVE's "current_date"; MySQL's "DATE_FORMAT(date,format)" is converted to Oracle's "TO_CHAR(date,format)" and DM's "TO_CHAR(date,format)". Result constraint conversion: MySQL's "SELECT * FROM table LIMIT 10" is converted to Oracle's "SELECT * FROM (SELECT * FROM table) WHERE ROWNUM <= 10", DM's "SELECT TOP 10 * FROM table", and HIVE's "SELECT * FROM table LIMIT 10" (HIVE supports the LIMIT syntax and does not require conversion). Data type conversion: MySQL's "INT" type corresponds to "NUMBER(10)" in Oracle, and MySQL's "VARCHAR" corresponds to "VARCHAR2" in DM, etc.; the syntax conversion layer adapts the data type-related syntax while converting SQL statements.

[0053] Data Interaction Layer: Responsible for executing the transformed SQL statements and converting the result sets returned by the database into a unified data format (such as JSON, DataTable) that the application system can recognize, thus shielding the differences in result set formats between different databases; for example, it can uniformly convert MySQL ResultSet and Oracle ResultSet into JSON format data, including information such as data rows, column names, and data types, to facilitate subsequent processing and display by the application system.

[0054] Connection Management Layer: Responsible for the creation, reuse, and release of database connections. It uses connection pooling technology (such as C3P0, Druid) to manage connection resources and configures corresponding connection pool parameters (such as maximum number of connections, minimum number of connections, connection timeout, and maximum idle time) according to the target database type. Connection pools can avoid the performance overhead caused by frequent connection creation and closure, improve database access efficiency, and ensure the rational use of connection resources and prevent connection leaks through connection monitoring and recycling mechanisms.

[0055] In a specific application, the database adapter workflow is implemented as follows: Determine the target database type: Based on the user configuration or the database deployment of the power grid enterprise, the application system determines the type of the target database that needs to be accessed (such as MySQL or Oracle) and passes the database connection information (such as database URL, username, password, and port number) to the database adapter; Obtaining a database connection: The database adapter's connection management layer calls the getConnection() method of the interface definition layer based on the target database type. This method triggers the database driver layer to load the corresponding database driver, and then connects to the database through the driver. It obtains an available connection from the connection pool (if there are no available connections in the connection pool and the maximum number of connections has not been reached, a new connection is created) and returns it to the application system. SQL statement syntax conversion: The application system passes the SQL statement generated by the power grid domain semantic model to the database adapter. The syntax conversion layer first parses the SQL statement and identifies the syntax elements such as functions, keywords, and data types. Then, according to the target database type, it queries the SQL syntax difference mapping table and performs syntax conversion on the SQL statement according to the preset conversion rules to generate an SQL statement that conforms to the syntax specifications of the target database. After the conversion is completed, the converted SQL statement is syntax-checked to ensure that there are no syntax errors. Execute SQL statements and retrieve results: The data interaction layer calls the executeQuery() method (for query-type SQL) of the interface definition layer, sending the transformed SQL statement to the target database for execution; after the database executes the SQL statement, it returns a result set, which the data interaction layer reads and converts into a unified JSON or DataTable format; if an exception occurs during execution (such as an SQL syntax error or database connection interruption), the adapter will capture the exception and return it to the application system for error handling and prompting; Closing the database connection: After the application system obtains the query results, it calls the closeConnection() method in the interface definition layer. The connection management layer then returns the database connection to the connection pool for reuse in subsequent requests, rather than directly closing the connection, thereby improving connection utilization.

[0056] Based on the above, the intelligent query method for power grid indicators in this embodiment uses a database adapter to shield the differences in SQL syntax and connection methods between different target databases. This allows application systems to access multiple databases such as MySQL, Oracle, DM, and Hive through a unified interface without needing to develop separate access logic for each database. This satisfies the situation where different power grid companies use different databases due to technology selection, data scale, or localization requirements, significantly improving the system's compatibility and applicability. The unified database access interface and syntax conversion mechanism reduce the amount of code development required for application systems to interact with different databases, avoiding extensive code modifications due to changes in database type. Furthermore, maintenance personnel only need to maintain the database adapter middleware to handle issues related to multiple databases, eliminating the need to maintain separate access modules for each database, significantly reducing system development costs and maintenance difficulty. The syntax conversion layer... Through preset conversion rules and syntax verification mechanisms, standard SQL statements are accurately converted into syntax supported by the target database, avoiding execution errors caused by SQL syntax differences. Connection pooling technology ensures the stability and efficient utilization of database connections, reducing the occurrence of abnormal situations such as connection interruptions. These mechanisms together guarantee that SQL statements can be executed accurately, retrieving reliable power grid indicator data from the target database and preventing data query errors from affecting business decisions. Connection pooling technology avoids the performance overhead of frequently creating and closing database connections, improves connection reuse rate, and shortens database connection establishment time. The optimized syntax conversion algorithm reduces the time cost of SQL statement conversion. At the same time, connection pool parameters are optimized for the performance characteristics of different databases, further improving database access efficiency. In multi-user concurrent access scenarios, the adapter can stably handle a large number of query requests, avoiding system performance bottlenecks and ensuring the efficient operation of the entire intelligent data query system.

[0057] In this embodiment, the query results for outputting power grid indicator data include: The query results include a power grid indicator data table retrieved from the target database, which is then formatted and integrated. The power grid indicator data table refers to the original query results returned after executing SQL statements from the target database. It is typically presented in tabular form, containing rows and columns. Rows represent different query records (e.g., indicator data from different municipal bureaus or at different times), and columns represent relevant fields of the power grid indicator (e.g., organization name, indicator name, year, month, result value, year-on-year comparison, month-on-month comparison, warning color, indicator unit, etc.). For example, a table containing records such as "Liuzhou Power Supply Bureau, line loss rate, 2025, 3, 4.5%, -0.3%, -0.2%, green, %". Formatting and integration refers to processing the original power grid indicator data table through data cleaning, structural adjustment, and content standardization. This involves removing redundant information, correcting data format errors, and standardizing data representation to ensure the integrated data structure is clear, accurate, easy to understand, and suitable for subsequent display. Examples include removing duplicate records, standardizing "line loss rate: 4.5%" to "line loss rate: 4.5%" (uniform format), and supplementing missing indicator units. The integrated data will be presented in at least one of the following formats: text summary or visual chart. Text summaries refer to summarizing and describing the formatted and integrated power grid indicator data in natural language, extracting key information from the data (such as indicator values, trends, performance, rankings, etc.) to form concise and easy-to-understand text reports, facilitating users to quickly obtain core data information. For example, "In March 2025, the line loss rate of Liuzhou Power Supply Bureau was 4.5%, a year-on-year decrease of 0.3% and a month-on-month decrease of 0.2%, with a green warning color, indicating an excellent level; the line loss rate of Qinzhou Power Supply Bureau was 5.2%, a year-on-year decrease of 0.1%, with a yellow warning color, indicating a qualified level." Visual charts refer to using data visualization technology to display the formatted and integrated power grid indicator data in graphical or image form. Through intuitive visual elements (such as bar charts, line charts, pie charts, tables, maps, etc.), the distribution, trends, and comparisons of the data are presented, helping users to more intuitively understand the data patterns and characteristics. For example, a bar chart can be used to compare the line loss rates of different municipal bureaus, and a line chart can be used to show the monthly trend of the line loss rate of a certain municipal bureau.

[0058] Based on the above, the intelligent data query method for power grid indicators in this embodiment removes redundancy and errors from the original data through formatted integration, unifies the data representation, and solves the problems of chaotic original data table structure, inconsistent format, and missing information. This makes the data more accurate and easier to understand, laying a high-quality data foundation for subsequent text summaries and chart displays. Text summaries extract core data, suitable for scenarios that quickly obtain key information (such as management quickly understanding the overview of indicators). Visual charts intuitively present data comparisons and trends, suitable for in-depth analysis scenarios (such as business personnel analyzing the differences in indicators among various municipal bureaus and monthly change patterns). The two display formats cover the needs of quick browsing and in-depth analysis, improving the user experience for different users and reducing the data analysis difficulty for users with zero SQL skills. Text summaries, combined with business rules (judging the merits of positive / negative indicators), directly inform users whether the indicators are good or bad. Visual charts highlight key information through visual elements (color, trend lines) (such as red bars marking unqualified indicators and downward lines marking the improvement trend of indicators), helping users quickly identify data patterns and problems (such as a municipal bureau with a persistently high line loss rate), transforming power grid indicator data from raw numbers into decision-making basis and enhancing the business value of the data.

[0059] Therefore, this invention provides an intelligent number-finding method, which can achieve the following beneficial effects: Through the natural language interaction interface, business personnel can directly query complex power grid indicator data using everyday business terms without needing to master professional SQL syntax and database knowledge. This reduces the technical barriers to data querying, enabling front-line business personnel to obtain decision support information independently and efficiently, thereby improving work efficiency and the agility of data analysis. By using a training dataset from the power grid domain to supervise and fine-tune a general large language model and integrating low-rank adaptation (LoRA) technology, the resulting semantic model for the power grid domain has a deep understanding of power grid proper nouns, indicator aliases, and business logic. Combined with dynamic prompt word templates based on multi-scenario intent recognition, it can accurately constrain the SQL generation logic, avoiding semantic understanding biases and SQL syntax errors that occur in general models in professional scenarios, thereby generating accurate, executable, and high-quality SQL statements with reliable query results. For the vague time or non-standardized descriptions commonly found in user queries, the model is guided to intelligently parse them into precise time functions or default query conditions that can be recognized by the database through preset business rules and prompt word constraints. This solves the problem of query failure or inaccurate results caused by unclear time descriptions in traditional methods, and enhances the practicality and intelligence of the technology. The LoRA technology employed in the model fine-tuning phase requires only a minimal number of parameter updates. While maintaining performance comparable to full-parameter fine-tuning, it significantly reduces computational resource consumption and storage overhead, enabling rapid deployment and iteration in real-world business environments at a lower cost. Furthermore, the system's modular design supports adaptation to various target databases and can cover more business scenarios by expanding the intent library and prompt word templates, demonstrating excellent scalability and adaptability.

[0060] Example 2 Please refer to Figure 2 This is a schematic diagram of the structure of an intelligent query device provided in an embodiment of the present invention. The device includes: a natural language question acquisition module, a power grid business query intent category recognition module, a customized prompt word template matching module, an SQL statement generation module, and a power grid indicator data query module. The natural language question acquisition module is used to receive natural language questions from users; The power grid business query intent category identification module is used to input the natural language question into a preset intent identification model, so that the intent identification model compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. The customized prompt word template matching module is used to match a customized prompt word template corresponding to the power grid business query intent category from a preset prompt word template library; The SQL statement generation module is used to combine the natural language question with the customized prompt word template and input it into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. The power grid indicator data query module is used to execute the SQL statement, query the corresponding power grid indicator data from the preset target database, and obtain the query results of the power grid indicator data.

[0061] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.

[0062] Those skilled in the art will clearly understand that, for convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0063] Example 3 Accordingly, embodiments of the present invention provide an electronic device, the device including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor executes the computer program to implement the intelligent questioning method described in the above embodiments of the invention.

[0064] The electronic device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The device may include, but is not limited to, a processor and a memory.

[0065] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the device, connecting various parts of the device via various interfaces and lines.

[0066] Example 4 Accordingly, embodiments of the present invention provide a storage medium, the storage medium including a stored computer program, wherein, when the computer program is running, it controls the device where the storage medium is located to execute the intelligent query method described in the above embodiments of the invention.

[0067] The memory can be used to store the computer program. The processor implements various functions of the device by running or executing the computer program stored in the memory and calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function, etc.; the data storage area may store data created based on the use of the mobile phone, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0068] The storage medium is a computer-readable storage medium, and the computer program is stored in the computer-readable storage medium. When the computer program is executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0069] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.

Claims

1. A method for intelligent number retrieval, characterized in that, include: Receiving natural language questions from users; The natural language question is input into a preset intent recognition model, which compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. Based on the power grid business query intent category, a customized prompt word template corresponding to the power grid business query intent category is matched from a preset prompt word template library; The natural language question and the customized prompt word template are combined and then input into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. Execute the SQL statement to query the corresponding power grid indicator data from the preset target database and obtain the query results of the power grid indicator data.

2. The intelligent questioning method as described in claim 1, characterized in that, The step of comparing the natural language question with preset standard questions, and taking the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs and outputting it, includes: The natural language question is converted into a corresponding semantic vector; wherein the dimension of the semantic vector is consistent with the dimension of the standard question vector in the preset standard question semantic vector library; Calculate the similarity between the semantic vector and each standard question vector in the standard question semantic vector library, and take the intent category corresponding to the standard question vector with the highest similarity as the power grid business query intent category to which the natural language question belongs and output it.

3. The intelligent questioning method as described in claim 2, characterized in that, The generation of the intent recognition model includes: Obtain several user question samples, and classify and label the intent categories of the user question samples. Use the user question samples with labeled intent categories as the training set. The training set is input into a preset neural network model. The encoding layer of the neural network model converts the user question samples in the training set into corresponding semantic vector samples. The semantic vector samples are then input into the fully connected layer of the neural network model to obtain the probability distribution of the semantic vector samples belonging to each intent category. Calculate the loss value between the probability distribution and the true intent category label of the semantic vector sample, and update the model parameters of the neural network model using the gradient descent algorithm until the loss value is less than a preset threshold to obtain the intent recognition model.

4. The intelligent questioning method as described in claim 1, characterized in that, The customized prompt word template includes several types of role definition information, business rule information, query constraint information, and output format information. The business rule information includes: positive and negative attribute classifications and quality judgment criteria for various power grid indicators; The query constraint information includes: when the natural language question contains a time description, the time function representation of the SQL statement generated by the constraint; and when the natural language question does not contain a time description, the default time query condition of the SQL statement generated by the constraint.

5. The intelligent questioning method as described in claim 1, characterized in that, The generation of the semantic model in the power grid domain includes: Obtain several paired samples consisting of natural language question samples and corresponding standard SQL statements, and use the paired samples as training samples; Using a pre-defined large language model as a base model, the original weight matrix of the self-attention layer in the base model is extracted, and a trainable first low-rank parameter matrix and a second low-rank parameter matrix are introduced into the original weight matrix; wherein, the first low-rank parameter matrix is ​​an increased-dimensional matrix, the second low-rank parameter matrix is ​​a reduced-dimensional matrix, and the ranks of the first low-rank parameter matrix and the second low-rank parameter matrix are much smaller than the dimension of the original weight matrix. The base model is trained based on the training samples. During the training process, the original weight matrix remains unchanged, and the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix are updated using the gradient descent algorithm until the loss value of the base model is minimized, thereby obtaining the semantic model of the power grid domain.

6. The intelligent questioning method as described in claim 5, characterized in that, The step of training the base model based on the training samples, keeping the original weight matrix unchanged during training, and updating the parameters of the first low-rank parameter matrix and the second low-rank parameter matrix using a gradient descent algorithm until the loss value of the base model is minimized, thereby obtaining the semantic model of the power grid domain, includes: The training samples are input into the fine-tuning model consisting of the base model, the original weight matrix, the first low-rank parameter matrix, and the second low-rank parameter matrix, so that the fine-tuning model outputs the SQL logical sequence corresponding to the natural language question sample after forward propagation. Calculate the loss value between the SQL logical sequence and the corresponding standard SQL statement, and calculate the gradient of the first low-rank parameter matrix and the second low-rank parameter matrix using the backpropagation algorithm based on the loss value; Based on the gradients of the first low-rank parameter matrix and the second low-rank parameter matrix, the parameter values ​​of the first low-rank parameter matrix and the second low-rank parameter matrix are updated using the gradient descent algorithm until the loss value is minimized, thereby obtaining the semantic model of the power grid domain.

7. The intelligent questioning method as described in claim 1, characterized in that, The execution of the SQL statement queries the corresponding power grid indicator data from the preset target database to obtain the query results of the power grid indicator data, including: The SQL statement is executed by calling a preset database adapter to query the corresponding power grid indicator data from the preset target database and obtain the query results of the power grid indicator data; wherein, the database adapter is used to be compatible with different types of target databases, including: MySQL, Oracle, DM or HIVE database.

8. An intelligent counting device, characterized in that, include: The module includes a natural language question acquisition module, a power grid business query intent category recognition module, a customized prompt word template matching module, an SQL statement generation module, and a power grid indicator data query module. The natural language question acquisition module is used to receive natural language questions from users; The power grid business query intent category identification module is used to input the natural language question into a preset intent identification model, so that the intent identification model compares the natural language question with a preset standard question, and outputs the intent category corresponding to the standard question with the highest similarity as the power grid business query intent category to which the natural language question belongs. The customized prompt word template matching module is used to match a customized prompt word template corresponding to the power grid business query intent category from a preset prompt word template library; The SQL statement generation module is used to combine the natural language question with the customized prompt word template and input it into a preset power grid domain semantic model, so that the power grid domain semantic model generates and outputs the corresponding SQL statement based on the combined natural language question and the customized prompt word template; wherein, the power grid domain semantic model is obtained by training a preset large language model with several paired samples composed of natural language question samples and standard SQL statements as training samples. The power grid indicator data query module is used to execute the SQL statement, query the corresponding power grid indicator data from the preset target database, and obtain the query results of the power grid indicator data.

9. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor, when executing the computer program, implements the intelligent questioning method as described in any one of claims 1 to 7.

10. A storage medium, characterized in that, The storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device where the storage medium is located to perform the intelligent questioning method as described in any one of claims 1 to 7.