Power field natural language query method and device, terminal equipment and storage medium

By combining historical context with semantic disambiguation and causal graph optimization in a natural language query system for the power industry, the problems of accuracy and interpretability of power data queries have been solved, and efficient identification and result optimization of complex queries have been achieved.

CN120804145BActive Publication Date: 2025-12-09STATE GRID ZHEJIANG ELECTRIC POWER CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511325903.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-17
Publication Date
2025-12-09
Estimated Expiration
2045-09-17

AI Technical Summary

Technical Problem

Existing natural language query systems in the power sector are unable to perform semantic disambiguation by incorporating historical context. This makes it difficult to accurately identify users' progressive query intentions in multi-turn dialogues and to support complex query needs and causal reasoning, resulting in insufficient accuracy and interpretability of query results.

Method used

By receiving natural language queries input by users, semantic disambiguation is performed using historical context, prompt words are constructed and input into a large language model to generate SQL statements, a causal graph is built and the SQL statements are optimized to improve the accuracy and interpretability of queries.

Benefits of technology

It achieves accurate parsing of complex semantic structures, improves the coverage and accuracy of intent recognition, and the generated SQL statements meet the needs of the power scenario in terms of syntax and business logic, thereby improving the accuracy and interpretability of query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120804145B_ABST
    Figure CN120804145B_ABST
Patent Text Reader

Abstract

The application discloses a power field natural language query method and device, terminal equipment and storage medium, belongs to the field of natural language processing, the method is: receiving the natural language query sentence input by the user, performing semantic disambiguation on the natural language query sentence according to the history context of the natural language query sentence, obtaining a target entity;According to the natural language query sentence, the target entity and the preset task target, the prompt word is constructed, and the prompt word is input into the pre-trained large language model to obtain a first SQL sentence;Executing the first SQL sentence, obtaining structured business data, and constructing a first causal graph according to the structured business data;According to the causal graph, the first SQL statement is optimized to obtain a second SQL statement, and the second SQL statement is executed to obtain a query result. The application can solve the problem of low accuracy of power data query in the power field.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of natural language processing, and in particular to a power field natural language query method and device, a terminal device and a storage medium. BACKGROUND

[0002] With the continuous development of smart grids and power information systems, users' interaction needs in scenarios such as operation and maintenance scheduling, device alarm analysis, index query and historical event tracing gradually shift from traditional form-based queries to more flexible natural language queries.

[0003] However, the existing natural language query system still has obvious deficiencies in the power field: on the one hand, most systems use a single round of interaction architecture, which cannot combine historical context for semantic disambiguation, making it difficult to accurately identify users' progressive query intentions in multi-round dialogues; on the other hand, power businesses involve a large number of professional terms, complex index links and cross-event causal relationships, and existing methods mostly rely on static rules or keyword matching, making it difficult to support complex query needs under users' free expression. In addition, in the power scenario, queries often go beyond data retrieval and involve potential causal reasoning between variables. Existing technologies often ignore the impact of potential causal relationships when generating structured query statements, resulting in structured query statements that lack logic and accuracy, ultimately reducing query result accuracy and explainability.

[0004] Therefore, how to improve the accuracy of power data query in the power field is a technical problem to be solved at present. SUMMARY

[0005] The present application provides a power field natural language query method, which can solve the problem of low accuracy of power data query in the power field in the prior art.

[0006] An embodiment of the present application provides a power field natural language query method, comprising:

[0007] receiving a natural language query sentence input by a user, performing semantic disambiguation on the natural language query sentence according to historical context of the natural language query sentence, and obtaining a target entity;

[0008] constructing a prompt word according to the natural language query sentence, the target entity and a preset task target, and inputting the prompt word into a pre-trained large language model to obtain a first SQL statement;

[0009] executing the first SQL statement to obtain structured business data, and constructing a first causal graph according to the structured business data;

[0010] According to the causal graph, the first SQL statement is optimized to obtain a second SQL statement, the second SQL statement is executed to obtain a query result.

[0011] Compared with the prior art, the above embodiment has the following beneficial effects: by introducing historical context, the natural language query statement input by the current user is semantically disambiguated, effectively solving the problems of ambiguous expression, unclear reference and context dependence of the user in the continuous query process, realizing accurate analysis of complex semantic structure, and significantly improving the coverage and accuracy of intent recognition. Further, by introducing adaptively generated prompt words, the system can automatically generate the most semantically consistent query prompt according to the current dialogue state and target entity, effectively guiding the large language model to generate a complete structure and semantically consistent SQL expression, improving the accuracy of the generated SQL statement and the consistency of the business meaning in the complex constraint and multi-variable interaction scene. Finally, the first causal graph is constructed by querying the business data through the first SQL statement, thereby reasoning the logical path between the relationship and the variable implied in the query process, so that the system has the ability of causal reasoning, and the first SQL statement is optimized based on the first causal graph to generate a second SQL statement that is more consistent with the business logic, further improving the accuracy and explainability of the query result.

[0012] Further, the semantic disambiguation of the natural language query statement according to the historical context of the natural language query statement comprises:

[0013] calculating a first semantic similarity between the natural language query statement and the historical context corresponding to the natural language query statement;

[0014] when the first semantic similarity exceeds a first threshold, extracting a plurality of candidate entities from the natural language query statement;

[0015] calculating a second semantic similarity between each of the candidate entities and the natural language query statement, and taking the candidate entity with the highest second semantic similarity as the target entity.

[0016] Compared with the prior art, the above-mentioned embodiment has the following beneficial effects: by calculating the first semantic similarity between the natural language query statement and the historical context, it is judged whether the natural language query statement input by the current user is an intent continuation of the historical context according to the first semantic similarity, when it is determined that the natural language query statement input by the current user is an intent continuation of the historical context, further extracting and identifying each candidate entity from the natural language query statement, selecting the candidate entity with the second semantic similarity as the target entity from the candidate entity by calculating the second semantic similarity between each candidate entity and the natural language query statement, thereby avoiding the noise influence of invalid candidate entities on the subsequent query statement generation, realizing semantic accurate disambiguation, and improving the target locking accuracy in the query process.

[0017] Further, the constructing prompt word according to the natural language query statement, the target entity, and a preset task target, and inputting the prompt word into the pre-trained large language model to obtain a first SQL statement comprises:

[0018] When the first semantic similarity exceeds a first threshold value, the natural language query statement and the corresponding historical context are spliced to obtain a first splicing result, and the first splicing result is encoded by a pre-trained language representation model to obtain a query intent vector;

[0019] According to the embedding vector representation of the target entity and the preset task target, and the query intent vector, a prompt word guide vector is constructed;

[0020] The prompt word guide vector is decoded into a prompt word template, and the prompt word is generated according to the prompt word template;

[0021] The embedding vector representations corresponding to the prompt word, the natural language query statement, and the historical context are spliced to obtain a second splicing result, and the second splicing result is input into the large language model to obtain the first SQL statement.

[0022] Compared with the prior art, the above-mentioned embodiment has the following beneficial effects: by splicing the vector representations of the historical context, the natural language statement, and the target entity, the system can better capture the real query intent of the user, and further generate a prompt word template with better semantic fit. Further, the prompt word is generated by the prompt word template, and since the prompt word template supports dynamic slot filling, multiple expression style generation, and context binding, the generated prompt word can improve the understanding accuracy of the language model for the query scene and the user intent. Finally, the embedding vectors corresponding to the prompt word, the natural language query statement, and the historical context are spliced, which improves the comprehensiveness of the information input into the large language model, thereby improving the accuracy and comprehensiveness of the first SQL statement generation.

[0023] Further, the second splicing result is input into the large language model to obtain the first SQL statement, including:

[0024] The second splicing result is input into the large language model and transmitted to the forward layer of the large language model in a multi-modal embedding manner to obtain a plurality of candidate structured query semantic expressions.

[0025] For each candidate structured query semantic expression, a corresponding third SQL statement is constructed.

[0026] The third SQL statement with the highest business consistency and context relevance is taken as the first SQL statement.

[0027] Compared with the prior art, the above embodiment has the following beneficial effects: by introducing a multi-modal embedding manner, the second splicing result is input into the forward layer of the large language model, and a plurality of candidate structured query expressions are generated, and then the business consistency and context relevance are combined for screening, thereby establishing multiple alternative paths in the SQL generation process, so as to avoid the error risk caused by a single candidate. At the same time, the context relevance and business logic consistency are used as screening criteria to ensure that the first SQL statement generated finally is not only correct in syntax but also meets the real needs of the power scene in business logic, effectively improving the fault tolerance and robustness of the system to complex natural language input, making the SQL generation result more stable and reliable, thereby significantly enhancing the accuracy and practicality of the query.

[0028] Further, the first SQL statement is executed to obtain structured business data, and a first causal graph is constructed according to the structured business data, including:

[0029] According to the structured business data, a causal node set is constructed, and a second causal graph is obtained by performing causal structure search on the causal node set through a preset algorithm.

[0030] According to a preset domain business rule, a third causal graph is obtained by performing causal edge constraint on the second causal graph.

[0031] By evaluating the relevance between each two adjacent nodes in the third causal graph, the confidence weight of each causal edge in the second causal graph is set to obtain the first causal graph.

[0032] Compared to existing technologies, the above embodiments have the following advantages: Causal nodes are constructed based on the relatively comprehensive structured business data obtained from the initially generated first SQL statement, ensuring the comprehensiveness of the final generated first causal graph. Furthermore, by using domain rule constraints, potential causal relationships between different business variables are revealed, thereby further optimizing the structure of the second causal graph and improving the interpretability and logical consistency of the final first causal graph. Finally, by judging the correlation between nodes and setting the confidence weight of each causal edge, a basis is provided for subsequent path selection, thereby improving the optimization efficiency and accuracy of the first SQL statement.

[0033] Further, optimizing the first SQL statement based on the causal graph to obtain the second SQL statement includes:

[0034] In the first cause-effect graph, query all causal paths to which the target field of the first SQL statement belongs;

[0035] For each causal path, the validity score of the corresponding causal path is evaluated based on the confidence weight of each causal edge in the causal path.

[0036] The first causal path with the highest effective score is selected from all the causal paths, and the first SQL statement is optimized based on the first causal path to obtain the second SQL statement.

[0037] Compared to existing technologies, the above embodiments have the following beneficial effects: By searching all causal paths related to the query target and calculating their validity scores based on confidence weights, the optimal causal path is ultimately selected to correct the first SQL statement. This eliminates low-relevance or noisy paths in the causal graph, improves the execution efficiency of the SQL statement correction process, and ensures that the final generated second SQL statement is closer to the actual business logic. The optimized first SQL statement can better reflect the user's true intent, reducing the deviation between the query results and expectations, thereby improving the accuracy and reliability of the query. Especially in complex dependency scenarios involving power data, the above method can ensure that the query results have higher logical consistency and decision-making reference value.

[0038] Further, evaluating the validity score of the corresponding causal path based on the confidence weights of each causal edge in the causal path includes:

[0039] The specific formula for calculating the validity score is as follows:

[0040]

[0041] in, The validity score of the causal path; for a causal path; representing a causal edge between two connected causal nodes in a causal path, for a starting causal node of the causal edge, for an ending causal node of the causal edge; representing and a confidence weight of a causal edge between them; representing or whether it has appeared in a historical context or a natural language query sentence, if it appears, if it does not appear, .

[0042] Compared with the prior art, the above-mentioned embodiments have the following beneficial effects: by judging whether the nodes at both ends of the causal edge appear in a historical context or a natural language query sentence, the relevance of the causal edge to the user's target query intention is judged, and the effectiveness score of the entire causal path is statistically calculated on the basis of this, so that the actual contribution degree of different causal paths is more reasonably evaluated, and the effectiveness of the finally selected causal path is improved.

[0043] Another embodiment of the present application also provides an electric power field natural language query device, comprising: a semantic disambiguation module, a first SQL statement acquisition module, a first causal graph construction module and a first SQL statement optimization module;

[0044] The semantic disambiguation module is used for receiving a natural language query sentence input by a user, performing semantic disambiguation on the natural language query sentence according to a historical context of the natural language query sentence, and obtaining a target entity.

[0045] The first SQL statement acquisition module is used for constructing a prompt word according to the natural language query sentence, the target entity and a preset task target, inputting the prompt word into a pre-trained large language model to obtain a first SQL statement.

[0046] The first causal graph construction module is used for executing the first SQL statement, obtaining structured business data, and constructing a first causal graph according to the structured business data.

[0047] The first SQL statement optimization module is used for optimizing the first SQL statement according to the causal graph, obtaining a second SQL statement, executing the second SQL statement, and obtaining a query result.

[0048] Another embodiment of the present application also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, when the computer program is executed by the processor, the steps of the power field natural language query method of the present application are implemented.

[0049] Another embodiment of the present application also provides a computer readable storage medium item, comprising a stored computer program, when the computer program is run, the device where the computer readable storage medium is located is controlled to execute the steps of the power field natural language query method of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0050] In order to more clearly illustrate the technical solutions of the present application, the following will briefly introduce the drawings needed to be used in the embodiments, obviously, the drawings in the following description are only some embodiments of the present application, and for the ordinary skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.

[0051] Figure 1 The flowchart of the power field natural language query method provided in some embodiments of the present application;

[0052] Figure 2 The structural diagram of the power field natural language query device provided in some embodiments of the present application. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical solutions and advantages of the present application more clear, the following will combine the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the present application, obviously, the described embodiments are some embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by the ordinary skilled in the art without creative labor are within the scope of protection of the present application.

[0054] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs; the terms used herein are only for the purpose of describing specific embodiments of the present application, not intended to limit the present application; the terms in the specification and claims of the present application and the above drawing description, and any modification of them, are intended to cover non-exclusive inclusion.

[0055] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "a plurality of" is more than two, unless otherwise explicitly and specifically limited.

[0056] Reference herein to "embodiments" means that the particular features, structures, or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The appearance of the phrase in various places in the specification does not necessarily all refer to the same embodiment, nor is it necessarily independent or alternative to other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0057] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent the three cases of A alone, A and B together, and B alone. In addition, the character " / " in this paper generally represents that the front and rear associated objects are a "or" relationship.

[0058] In the description of the embodiments of the present application, the term "a plurality of" means more than two (including two), and similarly, "a plurality of groups" means more than two groups (including two groups), and "a plurality of pieces" means more than two pieces (including two pieces).

[0059] In the description of the embodiments of the present application, unless otherwise explicitly specified and limited, the technical terms "mounting", "connecting", "connecting", "fixing" and the like should be understood in a broad sense, for example, it can be fixedly connected, or it can be detachably connected, or it can be integrated; it can be mechanical connection, or it can be electrical connection; it can be directly connected, or it can be indirectly connected through an intermediate medium; it can be the internal communication of two elements or the interaction relationship between two elements. For those skilled in the art, the specific meaning of the above terms in the embodiments of the present application can be understood according to the specific circumstances.

[0060] The existing natural language query system still has the following deficiencies in the power field: on the one hand, most systems adopt a single round of interaction architecture, which cannot combine historical context for semantic disambiguation, resulting in that the progressive query intention of the user in the multi-round dialogue is difficult to be accurately identified; on the other hand, the power business involves a large number of professional terms, complex index links and cross-event causal relationships, and the existing methods mostly rely on static rules or keyword matching, which is difficult to support the complex query demand under the free expression of the user. In addition, in the power scene, the query often not only stays at the data retrieval level, but also contains potential causal reasoning between variables, and the existing technology often ignores the influence of the potential causal relationship when generating a structured query statement, so that the generated structured query statement often lacks logicality and accuracy, finally reducing the query result accuracy and explainability.

[0061] Please refer to Figure 1 To solve the problem of low power data query accuracy in the prior art in the power field, a natural language query method in the power field provided by an embodiment of the present application includes S101 to S104:

[0062] S101: receiving a natural language query sentence input by a user, performing semantic disambiguation on the natural language query sentence according to historical context of the natural language query sentence, and obtaining a target entity.

[0063] Preferably, in some embodiments of the present application, before S101 is performed, it further includes: constructing a power field semantic knowledge base; and maintaining a context state of a multi-round dialogue.

[0064] Preferably, in some embodiments of the present application, the power field semantic knowledge base is constructed, including: collecting power system operation and maintenance data, equipment archives, index logs and event records and other multi-source information, performing unified formatting processing, removing missing items and redundant fields, and converting into standard structured business data; uniformly normalizing naming of all entity class fields in the structured business data (such as “transformer”, “trip event”, “line number”), constructing a domain term label library, forming an entity dictionary, an attribute dictionary and their relationship set; constructing triples (h, r, t) based on the logical, spatial and causal relationships between entities, wherein h is an entity, t is a tail entity, and r is the relationship between h and r, for example, (“trip event”, “occurs in”, “transformer A”), (“line loss”, “measurement unit”, “percentage”); converting the triples into a directed graph form, storing in a graph database to form a queryable semantic knowledge base; designing a query interface based on SPARQL (SPARQL Protocol and RDF Query Language) and built-in fuzzy matching mechanism, and improving the alignment capability for natural language fuzzy keywords through entity vector embedding and semantic similarity sorting, wherein the entity vector embedding can use embedding methods such as TransE, DistMult, etc.

[0065] Preferably, in some embodiments of the present application, the context state of the multi-round dialogue is maintained, including: receiving a natural language query sentence input by a user, performing word segmentation, part-of-speech tagging and named entity recognition on the natural language query sentence to obtain preliminary semantic units; splicing the current user input natural language query sentence with the historical context to form a multi-round dialogue semantic chain, and constructing a representation vector of the historical context through a Transforme type model; establishing a user intent trajectory table and an entity interaction record table to record intent keywords, domain entities, time ranges and superordinate and subordinate reference relationships of each round, respectively, for supporting semantic inheritance, reference tracing and intermediate entity completion during multi-round reasoning; in a dialogue exceeding a predefined maximum number of rounds, a sliding window strategy is used to clip the early historical context, and a semantic compression network (such as a bidirectional gated recurrent unit) is used to abstractly compress the early historical context to extract an abstract vector with the most information to reduce noise interference.

[0066] Further, in some embodiments of the present application, the semantic disambiguation of the natural language query sentence according to the historical context of the natural language query sentence obtains a target entity, including:

[0067] calculating a first semantic similarity between the natural language query sentence and the historical context corresponding to the natural language query sentence;

[0068] extracting a plurality of candidate entities from the natural language query statement when the first semantic similarity exceeds a first threshold value;

[0069] calculating a second semantic similarity of each of the candidate entities with the natural language query statement, and taking the candidate entity with the highest second semantic similarity as the target entity.

[0070] Preferably, in some embodiments of the present application, before the calculating the first semantic similarity of the natural language query statement and the historical context, the natural language query statement and the historical context are further subjected to semantic encoding to obtain respective semantic vectors of the natural language query statement and the historical context, and ensure that the dimensions of the semantic vectors of the two are consistent. The model used for semantic encoding can be a context-aware language model such as BERT or RoBERTa, and the present application does not limit the model used.

[0071] Preferably, in some embodiments of the present application, the first semantic similarity of the natural language query statement and the historical context is calculated by the following formula:

[0072]

[0073] wherein, is the natural language query statement; is the historical context; is the first semantic similarity; is the semantic vector of the natural language query statement; is the semantic vector of the historical context; is the norm of the vector.

[0074] Preferably, in some embodiments of the present application, when the first semantic similarity exceeds the first threshold value, a plurality of candidate entities are extracted from the natural language query statement, including: when the first semantic similarity exceeds the first threshold value, it is considered that the natural language query statement and the historical context have the same intent, i.e., it is considered as a continuation of the historical intent, at this time a plurality of candidate entities are extracted from the natural language query statement, including entity objects (such as devices, regions), attribute fields (such as voltage, current) and query actions (such as trend change, anomaly detection). The extraction method of the candidate entities is: according to the lexical rules, the labels of each entity in the power field semantic knowledge base constructed before step S101, and the mapping table between the entity and the label, three verifications are performed to improve the accuracy of candidate entity recognition. The identified candidate entities are compared with the labels of the standard entities in the power field semantic knowledge base, and a graph embedding similarity matching mechanism is used for fuzzy entity alignment and ambiguity elimination.

[0075] Preferably, in some embodiments of the present application, the calculation of the second semantic similarity between each of the candidate entities and the natural language query sentence, and the candidate entity with the highest second semantic similarity is taken as the target entity, is calculated by the above-mentioned first semantic similarity calculation formula, which only needs to replace the semantic vector of the natural language query sentence with the embedding vector representation of the candidate entity. Wherein, the embedding vector representation of the candidate entity is generated from the power field semantic knowledge base by the entity embedding model.

[0076] The present application calculates the first semantic similarity between the natural language query statement and the historical context, determines whether the natural language query statement input by the current user is the intention continuation of the historical context according to the first semantic similarity, when it is determined that the natural language query statement input by the current user is the intention continuation of the historical context, further extracts and identifies each candidate entity from the natural language query statement, selects the candidate entity with the second semantic similarity as the target entity from the candidate entity by calculating the second semantic similarity between each candidate entity and the natural language query statement, thereby avoiding the noise influence of invalid candidate entities on the subsequent query statement generation, realizing semantic accurate disambiguation, and improving the target locking accuracy in the query process.

[0077] S102: According to the natural language query statement, the target entity and the preset task target, a prompt word is constructed, and the prompt word is input into a pre-trained large language model to obtain a first SQL statement.

[0078] Further, in some embodiments of the present application, the construction of the prompt word according to the natural language query statement, the target entity and the preset task target, and the input of the prompt word into the pre-trained large language model to obtain the first SQL statement, comprises:

[0079] When the first semantic similarity exceeds the first threshold value, the natural language query statement and the corresponding historical context are spliced to obtain a first splicing result, and the first splicing result is encoded by a pre-trained language representation model to obtain a query intention vector;

[0080] According to the embedding vector representation of the target entity and the preset task target, and the query intention vector, a prompt word guide vector is constructed;

[0081] The prompt word guide vector is decoded into a prompt word template, and the prompt word is generated according to the prompt word template;

[0082] The embedding vector representations corresponding to the prompt word, the natural language query statement and the historical context are spliced to obtain a second splicing result, and the second splicing result is input into the large language model to obtain the first SQL statement.

[0083] Preferably, in some embodiments of the present application, the splicing the natural language query sentence and the corresponding historical context to obtain a first splicing result, and encoding the first splicing result through a pre-trained language representation model to obtain a query intent vector, includes: the language representation model can be a BERT model, input the spliced natural language query sentence and the corresponding historical context into the pre-trained BERT model, and extract the query intent vector from the output vector representation of the last hidden layer of the BERT model.

[0084] Preferably, in some embodiments of the present application, the constructing a prompt word guide vector according to the embedding vector representation of the target entity and the preset task target, and the query intent vector, includes:

[0085] The prompt word guide vector is generated through a linear fusion mechanism, and the specific formula is as follows:

[0086]

[0087] Wherein, is the prompt word guide vector; is the query intent vector; is the embedding vector representation of the target entity; is the embedding vector of the preset task target, representing the overall target of the current query task; is a weight system, wherein, , and .

[0088] Preferably, in some embodiments of the present application, the decoding the prompt word guide vector into a prompt word template, and generating the prompt word according to the prompt word template, includes: decoding the prompt word guide vector into a natural language template, generating multiple prompt words with high semantic consistency and strong task relevance through interpolation filling, language variant conversion and other means; scoring the credibility of the generated multiple prompt word candidates, and preferentially selecting the one closest to the historical high feedback example as the final input prompt word to improve the recognition accuracy of the large language model for complex intent.

[0089] The application concatenates the historical context, the natural language sentence and the vector representation of the target entity, so that the system can better capture the real query intention of the user, and then generate a prompt word template with better semantic fit. Further, the prompt word is generated through the prompt word template. Since the prompt word template supports dynamic slot filling, multiple expression style generation and context binding, the generated prompt word can improve the understanding accuracy of the language model for the query scene and user intention. Finally, the embedding vectors corresponding to the prompt word, the natural language query sentence and the historical context are concatenated, which improves the comprehensiveness of the information input to the large language model, thereby improving the accuracy and comprehensiveness of the first SQL statement generation.

[0090] Further, in some embodiments of the application, the inputting the second concatenation result into the large language model to obtain the first SQL statement comprises:

[0091] inputting the second concatenation result into the large language model in a multi-modal embedding manner to pass to the forward layer of the large language model to obtain a plurality of candidate structured query semantic expressions;

[0092] constructing a corresponding third SQL statement for each of the candidate structured query semantic expressions;

[0093] selecting the third SQL statement with the highest business consistency and context relevance as the first SQL statement.

[0094] Preferably, in some embodiments of the application, the candidate structured query semantic expression output by the large language model includes query components such as table name, field, connection condition, filtering constraint and sorting rule. The candidate structured query semantic expression is output in natural language form.

[0095] Preferably, in some embodiments of the application, constructing a corresponding third SQL statement for each of the candidate structured query semantic expressions comprises: performing semantic analysis and syntax normalization on each of the candidate structured query semantic expressions to extract key elements such as fields, table names and filtering logic to obtain a corresponding query expression tree; combining the data table structure, field type and entity relationship of the power domain semantic knowledge base to perform completion processing on the query expression tree (for example, filling the default range for missing filtering conditions, judging the data type of ambiguous fields, and introducing context entities to supplement the connection relationship); and constructing a third SQL statement corresponding to the candidate structured query semantic according to the query expression tree.

[0096] Preferably, in some embodiments of the application, the third SQL statement with the highest business consistency and context relevance is selected as the first SQL statement, including: based on the business consistency and context relevance scoring function, selecting the third SQL statement with the highest score as the first SQL statement, and if it is a multi-round query, supporting inheritance of intermediate results or filtering conditions of previous round statements; pre-verification is performed on the obtained first SQL statement, including syntax verification, field legality check, and data source binding legality detection, if the first SQL statement does not meet the verification requirements, the prompt word is regenerated, and the first SQL statement is reconstructed according to the regenerated prompt word.

[0097] The application introduces a multi-modal embedding method, inputs the second splicing result into a large language model forward layer, generates a plurality of candidate structured query expressions, and filters them in combination with business consistency and context relevance, thereby establishing multiple alternative paths in the SQL generation process, thereby avoiding the error risk caused by a single candidate. At the same time, the context relevance and business logic consistency are used as screening criteria to ensure that the finally generated first SQL statement is not only grammatically correct, but also meets the real needs of the power scene in terms of business logic, effectively improving the fault tolerance and robustness of the system to complex natural language inputs, making the SQL generation result more stable and reliable, thereby significantly enhancing the accuracy and practicality of the query.

[0098] S103: executing the first SQL statement, obtaining structured business data, and constructing a first causal graph according to the structured business data.

[0099] Further, in some embodiments of the application, the execution of the first SQL statement, obtaining structured business data, and constructing a first causal graph according to the structured business data, includes:

[0100] constructing a causal node set according to the structured business data, and performing causal structure search on the causal node set through a preset algorithm to obtain a second causal graph;

[0101] According to the preset domain business rule, the causal edge constraint of the second causal graph is performed to obtain a third causal graph;

[0102] By evaluating the correlation between each two adjacent nodes in the third causal graph, the confidence weight of each causal edge in the second causal graph is set to obtain the first causal graph.

[0103] Preferably, in some embodiments of the application, the construction of the causal node set according to the structured business data includes: extracting a feature variable set from the structured business data queried by the first SQL statement to construct a causal node set.

[0104] Preferably, in some embodiments of the application, the step of performing a causal structure search on the causal node set using a preset algorithm to obtain a second causal graph includes: establishing an initial causal graph based on the causal node set using an intervention-based causal discovery algorithm; and performing a scoring search on the initial causal graph using the GIES (Greedy Interventional Equivalence Search) algorithm, selecting the graph structure with the highest score from the initial causal graph as the second causal graph. The scoring function in the initial causal graph scoring search process is as follows:

[0105]

[0106] in, Representation of cause-and-effect diagram The rating; Representation of cause-and-effect diagram The number of causal nodes in the data; Cause-and-effect diagram The Middle One causal node; for The set of parent nodes; In a given causal graph Below, in a given set of parent nodes hour, The conditional probability of occurrence.

[0107] Preferably, in some embodiments of the application, the step of constraining the second causal graph according to preset domain business rules to obtain a third causal graph includes: introducing domain business rules to constrain the causal edges and optimizing the second causal graph. For example, when the third causal graph contains the causal path "transformer tripping ← current surge ← human intervention", the system determines "human intervention → current surge" as an invalid edge through rules and forcibly removes it to avoid generating causal paths that violate industry common sense.

[0108] Preferably, in some embodiments of this application, the step of setting the confidence weight of each causal edge in the second causal graph by evaluating the correlation between each pair of adjacent nodes in the third causal graph includes:

[0109] The confidence weight of each causal edge is calculated using the following formula:

[0110]

[0111] in, Causal nodes and The confidence weight of the causal edges between them; For a given Down, Conditional probability of occurrence; For Probability of occurrence.

[0112] Preferably, in some embodiments, after obtaining the first causal graph, further comprising: performing semantic annotation on the constructed first causal graph, including assigning a directional label, a confidence weight and a time lag parameter to each edge, for subsequent logical path reasoning; embedding the first causal graph into a query structure construction module, and if it is found that there are intermediate variables that do not appear in the key causal path, the system automatically inserts an intermediate query clause to complete the causal chain, ensuring that the final obtained second SQL statement is consistent with the business causal mechanism at the logical level.

[0113] Based on the relatively comprehensive structured business data obtained by the initially generated first SQL statement, the causal nodes are constructed to ensure the comprehensiveness of the final generated first causal graph. Further, through domain rule constraints, the potential causal relationship between different business variables is revealed, so as to further optimize the structure of the second causal graph and improve the interpretability and logical consistency of the finally obtained first causal graph. Finally, by judging the correlation between nodes, the confidence weight of each causal edge is set to provide a basis for subsequent path screening, thereby improving the optimization efficiency and accuracy of the first SQL statement.

[0114] S104: optimizing the first SQL statement according to the causal graph to obtain a second SQL statement, executing the second SQL statement to obtain a query result.

[0115] Further, in some embodiments of the present application, the optimization of the first SQL statement according to the causal graph to obtain a second SQL statement comprises:

[0116] querying all causal paths to which the target field corresponding to the first SQL statement belongs in the first causal graph;

[0117] For each of the causal paths, evaluating an effectiveness score of the corresponding causal path according to the confidence weight of each causal edge in the causal path;

[0118] selecting a first causal path with the highest effective score from all the causal paths, and optimizing the first SQL statement according to the first causal path to obtain the second SQL statement.

[0119] Preferably, in some embodiments of the present application, the querying, in the first causal graph, all causal paths to which the target field corresponding to the first SQL statement belongs, comprises: analyzing each valid causal path to which the target field corresponding to the first SQL statement belongs in the first causal graph, and determining whether each causal path is explicitly embodied in the first SQL statement; if not, adding auxiliary fields or table join conditions to complete the path.

[0120] Further, in some embodiments of the present application, the evaluating, according to the confidence weight of each causal edge in the causal path, the effectiveness score of the causal path corresponding to the causal path, comprises:

[0121] The calculation formula of the effectiveness score is specifically:

[0122]

[0123] wherein, is the effectiveness score of the causal path; is the causal path; represents a causal edge between two connected causal nodes in the causal path, is the starting causal node of the causal edge, is the ending causal node of the causal edge; represents and the confidence weight of the causal edge between and ; represents or whether it has appeared in the historical context or the natural language query statement, if it appears, then , if it does not appear, then .

[0124] The present application judges the relevance of the causal edge to the user's target query intention by judging whether the nodes at both ends of the causal edge appear in the historical context or the natural language query statement, and uses this as the basis for statistically evaluating the effectiveness score of the entire causal path, so as to more reasonably evaluate the actual contribution degree of different causal paths and improve the effectiveness of the finally selected causal path.

[0125] Preferably, in some embodiments of the present application, the optimizing the first SQL statement according to the first causal path to obtain the second SQL statement comprises: reconstructing tables in a FROM clause in the first SQL statement according to an order of causal nodes involved in the first causal path, ensuring that an order of variable references in the first SQL statement is consistent with the order of the causal nodes in the first causal path, and adjusting JOIN conditions to increase field connection constraints with strong logical dependencies; for a scenario where feedback structures or redundant paths exist in the first causal path, simplifying Boolean factors of a logical expression of a WHERE clause in the first SQL statement, removing logically redundant fields, and reducing query complexity.

[0126] The present application searches all causal paths related to the query target, calculates an effectiveness score according to a confidence weight, and finally selects an optimal causal path to correct the first SQL statement, thereby eliminating low-relevance or noise paths in the causal graph, improving the execution efficiency of the SQL statement correction process, and ensuring that the second SQL statement generated finally is closer to the real business logic. The optimized first SQL statement can better reflect the real intention of the user, reduce the deviation between the query result and the expectation, thereby improving the accuracy and reliability of the query. In particular, in the complex dependence scenario of power data, the above method can guarantee that the query result has higher logical self-consistency and decision reference value.

[0127] Preferably, in some embodiments of the present application, after obtaining the second SQL statement, the method further comprises: submitting the second SQL statement to a backend database for syntax analysis and execution simulation, checking whether there are syntax errors, non-existent fields, table association errors, and the like in the statement, and if the detection fails, returning error information and starting a SQL repair process.

[0128] Preferably, in some embodiments of the present application, after executing the second SQL statement to obtain a query result, the method further comprises: performing semantic alignment verification on the query result, including automatically comparing the result type (single value / multiple values / time series), field meaning, and unit with the original intention of the user, scoring using a semantic consistency scoring model, and triggering the regeneration of the second SQL statement when the threshold value is lower than a set value.

[0129] Preferably, in some embodiments of this application, after outputting the query results, the method further includes: collecting the user's displayed feedback (such as "satisfied", "inaccurate", "need more information" etc.) and implicit behaviors (such as clicking on a record, browsing dwell time etc.) based on the query results, constructing a feedback vector, and updating the representation vector of the historical context maintained in the system; fine-tuning the decoder that generates prompt word templates based on the feedback vector, updating the priority weight of candidate templates, and adjusting the generation temperature and sampling strategy of the large language model to improve the robustness and intent fit of subsequent responses; when the user generates continuous negative feedback on a causal edge in the first causal graph, reducing its confidence weight; conversely, increasing the confidence weight of the causal edge after multiple rounds of positive verification, thereby realizing the dynamic evolution and credibility enhancement of the causal graph structure.

[0130] This application improves the model's ability to adapt to user needs and its self-evolution by introducing a semantic closed-loop feedback mechanism, thereby continuously optimizing the system's understanding effect and response quality during multiple rounds of queries, and improving the overall interactive experience and business satisfaction.

[0131] In summary, the natural language query method for the power industry provided in this application has the following advantages compared to existing technologies: By introducing historical context, semantic disambiguation is performed on the natural language query statement input by the current user, effectively solving problems such as ambiguous expressions, unclear referentials, and contextual dependencies that users encounter during continuous queries. This achieves accurate parsing of complex semantic structures and significantly improves the coverage and accuracy of intent recognition. Furthermore, by introducing adaptively dynamically generated prompts, the system can automatically generate the most semantically relevant query prompts based on the current dialogue state and target entity. This effectively guides the large language model to generate structurally complete and semantically consistent SQL expressions, improving the accuracy and consistency of business meaning of SQL statements generated in complex constraint and multi-variable interaction scenarios. Finally, by querying business data through the first SQL statement to construct a first causal graph, the implicit relationships and logical paths between variables in the query process are inferred, enabling the system to have causal reasoning capabilities. Based on the first causal graph, the first SQL statement is optimized to generate a second SQL statement that better conforms to business logic, further improving the accuracy and interpretability of the query results.

[0132] like Figure 2 As shown, based on the above-described method embodiments, this application provides an embodiment of a natural language query method apparatus in the power field, including: a semantic disambiguation module 201, a first SQL statement acquisition module 202, a first cause-effect graph construction module 203, and a first SQL statement optimization module 204.

[0133] Further, in some embodiments of the present application, the semantic disambiguation module 201 is configured to receive a natural language query sentence input by a user, perform semantic disambiguation on the natural language query sentence according to a historical context of the natural language query sentence, and obtain a target entity; the first SQL statement acquisition module 202 is configured to construct a prompt word according to the natural language query sentence, the target entity, and a preset task target, input the prompt word into a pre-trained large language model to obtain a first SQL statement; the first causal graph construction module 203 is configured to execute the first SQL statement, obtain structured business data, and construct a first causal graph according to the structured business data; and the first SQL statement optimization module 204 is configured to optimize the first SQL statement according to the causal graph, obtain a second SQL statement, execute the second SQL statement, and obtain a query result.

[0134] Further, in some embodiments of the present application, the semantic disambiguation module 201 includes a first semantic similarity calculation unit, a candidate entity extraction unit, and a target entity screening unit; the semantic disambiguation module 201 is configured to perform semantic disambiguation on a natural language query sentence according to a historical context of the natural language query sentence, and obtain a target entity, including: the first semantic similarity calculation unit is configured to calculate a first semantic similarity between the natural language query sentence and the historical context; the candidate entity extraction unit is configured to extract a plurality of candidate entities from the natural language query sentence when the first semantic similarity exceeds a first threshold; and the target entity screening unit is configured to calculate a second semantic similarity between each of the candidate entities and the natural language query sentence, and select the candidate entity with the highest second semantic similarity as the target entity.

[0135] Further, in some embodiments of the present application, the first SQL statement acquisition module 202 comprises: a query intention vector acquisition unit, a prompt word guide vector construction unit, a prompt word generation unit, and a large language model calling unit; the first SQL statement acquisition module 202 is configured to construct a prompt word according to the natural language query statement, the target entity, and a preset task target, and input the prompt word into a pre-trained large language model to obtain a first SQL statement, comprising: the query intention vector acquisition unit is configured to, when the first semantic similarity exceeds a first threshold, concatenate the natural language query statement and the corresponding historical context to obtain a first concatenation result, and encode the first concatenation result through a pre-trained language representation model to obtain a query intention vector; the prompt word guide vector construction unit is configured to construct a prompt word guide vector according to the embedding vector representation of the target entity and the preset task target, and the query intention vector; the prompt word generation unit is configured to decode the prompt word guide vector into a prompt word template, and generate the prompt word according to the prompt word template; the large language model calling unit is configured to concatenate the embedding vector representation corresponding to the prompt word, the natural language query statement, and the historical context respectively to obtain a second concatenation result, and input the second concatenation result into the large language model to obtain the first SQL statement.

[0136] Further, in some embodiments of the present application, the large language model calling unit is configured to input the second concatenation result into the large language model to obtain the first SQL statement, comprising: inputting the second concatenation result into the large language model in a multi-modal embedding manner to pass to the forward layer of the large language model to obtain a plurality of candidate structured query semantic expressions; for each candidate structured query semantic expression, constructing a corresponding third SQL statement; taking the third SQL statement with the highest business consistency and context relevance as the first SQL statement.

[0137] Further, in some embodiments of the present application, the first causal graph construction module 203 comprises a second causal graph construction unit, a third causal graph construction unit and a confidence weight calculation unit; the first causal graph construction module 203 is configured to execute the first SQL statement, obtain structured business data, and construct a first causal graph according to the structured business data, comprising: the second causal graph construction unit is configured to construct a causal node set according to the structured business data, and perform causal structure search on the causal node set through a preset algorithm to obtain a second causal graph; the third causal graph construction unit is configured to perform causal edge constraint on the second causal graph according to a preset domain business rule to obtain a third causal graph; and the confidence weight calculation unit is configured to set the confidence weight of each causal edge in the second causal graph by evaluating the correlation between each two adjacent nodes in the third causal graph, to obtain the first causal graph.

[0138] Further, in some embodiments of the present application, the first SQL statement optimization module 204 comprises a causal path query unit, a causal path evaluation unit and a second SQL statement acquisition unit; the first SQL statement optimization module 204 is configured to optimize the first SQL statement according to the causal graph to obtain a second SQL statement, comprising: the causal path query unit is configured to query all causal paths to which the query target field corresponding to the first SQL statement belongs in the first causal graph; the causal path evaluation unit is configured to evaluate the effectiveness score of the causal path corresponding to each causal path according to the confidence weight of each causal edge in the causal path; and the second SQL statement acquisition unit is configured to filter a first causal path with the highest effective score from all the causal paths, and optimize the first SQL statement according to the first causal path to obtain the second SQL statement.

[0139] Further, in some embodiments of the present application, the causal path evaluation unit is configured to evaluate the effectiveness score of the causal path corresponding to each causal path according to the confidence weight of each causal edge in the causal path, comprising:

[0140] The calculation formula of the effectiveness score is specifically:

[0141]

[0142] wherein, is the effectiveness score of the causal path; is the causal path; represents the causal edge between two connected causal nodes in the causal path, is the starting causal node of the causal edge, is the ending causal node of the causal edge; represent with confidence weight of the causal edge between represent or whether it has appeared in the historical context or the natural language query sentence, if it appears, then , if it does not appear, then .

[0143] It can be understood that the above device item embodiments correspond to the method item embodiments of the present application, and can realize the power field natural language query method provided by any one of the above method item embodiments.

[0144] In summary, the power field natural language query device provided by the embodiments of the present application has the following beneficial effects compared with the prior art: by introducing historical context, the semantic disambiguation of the natural language query sentence input by the current user is performed, effectively solving the problems of ambiguous expression, unclear reference and context dependence in the continuous query process of the user, realizing accurate analysis of complex semantic structure, and significantly improving the coverage and accuracy of intent recognition. Further, by introducing adaptively generated prompt words, the system can automatically generate the most semantically consistent query prompt according to the current dialogue state and target entity, effectively guiding the large language model to generate a complete structure and semantically consistent SQL expression, improving the accuracy of the generated SQL statement and the consistency of the business meaning in the complex constraint and multi-variable interaction scene. Finally, the business data is obtained by querying the first SQL statement to construct the first causal graph, thereby reasoning out the logical path between the relationships and variables implied in the query process, so that the system has causal reasoning capability, and the first SQL statement is optimized based on the first causal graph to generate a second SQL statement that is more consistent with the business logic, further improving the accuracy and explainability of the query result.

[0145] It should be noted that the device embodiments described above are only illustrative, and part or all of the modules can be selected to achieve the purpose of the embodiment scheme according to actual needs. In addition, in the device embodiment drawings provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which can be realized as one or more communication buses or signal lines. Those skilled in the art can understand and implement without creative labor.

[0146] On the basis of the above-mentioned embodiments of the power field natural language query method, another embodiment of the present application provides a terminal device, which comprises a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, and when the processor executes the computer program, the power field natural language query method of any one embodiment of the present application is realized.

[0147] For example, in this embodiment, the computer program can be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present application. The one or more modules can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program in the terminal device.

[0148] The terminal device can be a desktop computer, a notebook computer, a palm computer, a cloud server and other computing devices. The terminal device can include, but is not limited to, a processor and a memory.

[0149] The processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc. The processor is the control center of the terminal device, and connects all parts of the terminal device through various interfaces and lines.

[0150] On the basis of the above-mentioned method embodiment, another embodiment of the present application provides a computer readable storage medium, including a stored computer program, wherein when the computer program runs, the device where the computer readable storage medium is located executes the power field natural language query method described in any one of the above-mentioned method embodiments of the present application.

[0151] The modules / units integrated in the device / terminal equipment, if realized in the form of software function units and sold or used as independent products, can be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the above-mentioned embodiments can also be completed by a computer program instructing related hardware, and the computer program can be stored in a computer readable storage medium. When the computer program is executed by a processor, the steps of each method embodiment described above can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or some intermediate forms. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc.

Claims

1. A natural language query method in the power industry, characterized in that, include: Receive a natural language query statement input by a user, perform semantic disambiguation on the natural language query statement based on its historical context, and obtain the target entity; Based on the natural language query statement, the target entity, and the preset task objective, prompt words are constructed, and the prompt words are input into the pre-trained large language model to obtain the first SQL statement; Execute the first SQL statement to obtain structured business data, and construct a first cause-effect graph based on the structured business data; Based on the cause-effect graph, the first SQL statement is optimized to obtain a second SQL statement, and the second SQL statement is executed to obtain the query result. The step of executing the first SQL statement to obtain structured business data, and constructing a first cause-effect graph based on the structured business data, includes: Based on the structured business data, a causal node set is constructed, and a causal structure search is performed on the causal node set using a preset algorithm to obtain a second causal graph; The second causal graph is constrained by causal edges according to the preset domain business rules to obtain the third causal graph; The first causal graph is obtained by evaluating the correlation between each pair of adjacent nodes in the third causal graph and setting the confidence weight of each causal edge in the second causal graph.

2. The natural language query method in the power field as described in claim 1, characterized in that, The step of constructing prompt words based on the natural language query statement, the target entity, and the preset task objective, and inputting the prompt words into a pre-trained large language model to obtain a first SQL statement includes: Calculate the first semantic similarity between the natural language query and the corresponding historical context; When the first semantic similarity exceeds the first threshold, the natural language query statement and the corresponding historical context are concatenated to obtain the first concatenation result, and the first concatenation result is encoded by the pre-trained language representation model to obtain the query intent vector; Based on the embedding vector representation of the target entity and the preset task target, and the query intent vector, a prompt word guidance vector is constructed; The prompt word guidance vector is decoded into a prompt word template, and the prompt word is generated based on the prompt word template; The second concatenation result is obtained by concatenating the prompt word, the natural language query statement, and the embedding vector representation corresponding to the historical context, and then inputting the second concatenation result into the large language model to obtain the first SQL statement.

3. The natural language query method in the power field as described in claim 2, characterized in that, The step of inputting the second concatenation result into the large language model to obtain the first SQL statement includes: The second concatenation result is input into the large language model and passed to the forward layer of the large language model in a multimodal embedding manner to obtain several candidate structured query semantic expressions; For each candidate structured query semantic expression, construct the corresponding third SQL statement; The third SQL statement, which has the highest business consistency and context relevance, is used as the first SQL statement.

4. The natural language query method in the power field as described in claim 1, characterized in that, The step of optimizing the first SQL statement based on the cause-effect graph to obtain the second SQL statement includes: In the first cause-effect graph, query all causal paths to which the target field of the first SQL statement belongs; For each causal path, the validity score of the corresponding causal path is evaluated based on the confidence weight of each causal edge in the causal path. The first causal path with the highest validity score is selected from all the causal paths, and the first SQL statement is optimized based on the first causal path to obtain the second SQL statement.

5. A natural language query method in the power field as described in claim 4, characterized in that, The step of evaluating the validity score of the corresponding causal path based on the confidence weight of each causal edge in the causal path includes: The specific formula for calculating the validity score is as follows: in, The validity score of the causal path; For causal path; This represents the causal edge between two connected causal nodes in a causal path. Let be the starting causal node of this causal edge. This is the ending causal node of the causal edge; represent and The confidence weight of the causal edges between them; represent or Does it already appear in the historical context or natural language query? If so, then... If it does not appear, then .

6. A natural language query device for the power industry, characterized in that, include: The module includes a semantic disambiguation module, a first SQL statement acquisition module, a first cause-effect graph construction module, and a first SQL statement optimization module. The semantic disambiguation module is used to receive a natural language query statement input by the user, perform semantic disambiguation on the natural language query statement according to the historical context of the natural language query statement, and obtain the target entity. The first SQL statement acquisition module is used to construct prompt words based on the natural language query statement, the target entity, and the preset task objective, and input the prompt words into the pre-trained large language model to obtain the first SQL statement; The first cause-effect graph construction module is used to execute the first SQL statement, obtain structured business data, and construct a first cause-effect graph based on the structured business data; The first SQL statement optimization module is used to optimize the first SQL statement according to the cause-effect graph to obtain a second SQL statement, execute the second SQL statement, and obtain query results; The first causal graph construction module includes: a second causal graph construction unit, a third causal graph construction unit, and a confidence weight calculation unit; the first causal graph construction module is used to execute the first SQL statement to obtain structured business data, and construct a first causal graph based on the structured business data, including: The second causal graph construction unit is used to construct a set of causal nodes based on the structured business data, and to perform a causal structure search on the set of causal nodes using a preset algorithm to obtain a second causal graph. The third causal graph construction unit is used to perform causal edge constraints on the second causal graph according to preset domain business rules to obtain a third causal graph; The confidence weight calculation unit is used to set the confidence weight of each causal edge in the second causal graph by evaluating the correlation between each two adjacent nodes in the third causal graph, thereby obtaining the first causal graph.

7. A terminal device, characterized in that, The device 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 a natural language query method for the power sector as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform a natural language query method in the power field as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, system and device for converting natural language to SQL (Structured Query Language) query statement and medium

    CN118779342A

  • SQL (Structured Query Language) statement generation method and device based on natural language and medium

    CN120560649A