A method, device, equipment and medium for generating and interpreting SQL based on business rules
By decomposing and interpreting the SQL generation process based on business rules, building a business data flow diagram and outputting a natural language description, the problem of difficult SQL explanation in the prior art is solved, and the transparency and interpretability of SQL query statements are realized.
Patent Information
- Application Number
- CN202311244918.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2043-09-25
AI Technical Summary
The existing XAI methods can only be explained from a single technical dimension and cannot meet the understanding of SQL query statements by non-technical users, especially in complex business application scenarios, which lack the explanation of business processes and management rules.
Using a business rule-based method, the problem is broken down into subtasks, and the data flow chart and business flow chart are constructed using the subtask decomposition model and the business discriminant model. The business data flow chart is generated through node similarity matching, and a natural language description is output. SQL generation explanation that is easy to understand by users.
This enables non-professional users to evaluate the correctness of SQL query statements, and improves the transparency and interpretability of the SQL generation process.
Smart Images

Figure CN117271557B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of artificial intelligence technology, and in particular to a method, device, equipment and medium for generating and interpreting SQL based on business rules. Background Art
[0002] With the rapid development of artificial intelligence, database management technology and SQL programming language are also advancing. At present, a large amount of information is stored in structured and semi-structured knowledge bases. The analysis and acquisition of such data requires interactive operations with the database through programming languages such as SQL. However, the difficulty of using SQL limits non-technical users and brings a high threshold to data analysis and use. NL2SQL is a technology that converts natural language query statements into structured query language (SQL). It is an important research direction in the field of artificial intelligence, aiming to convert human queries expressed in natural language into SQL query statements that the database can understand and execute through machine learning and natural language processing technology.
[0003] As an implementation of deep learning models, the NL2SQL generative model is also a black box model with defects such as opacity and poor interpretability. XAI (Explainable AI) technology is divided into intrinsic interpretability methods and post-explainability methods according to the time of obtaining interpretability, and further divided into global interpretability methods and local interpretability methods according to the scope of interpretation; it can also be divided into deep learning model XAI methods, Bayesian model XAI methods, and reinforcement learning model XAI methods from the perspective of model type.
[0004] Current methods mainly focus on analyzing the factors that affect the model working process and model generation results from a single technical dimension, ignoring the interdisciplinary complexity of AI's actual application scenarios. In actual business application scenarios, there is a lack of definition, generation, selection, and evaluation of explanations from the perspectives of the application scenario's design specifications, business processes, and management rules that are most easily understood by users. Therefore, existing XAI methods cannot meet user needs. Summary of the invention
[0005] The present invention provides a business rule-based SQL generation and interpretation method, device, equipment and medium to solve the problem that the existing XAI method can only be interpreted from a single technical level, is difficult for users without professional knowledge to understand, and cannot meet user needs.
[0006] According to one aspect of the present invention, a method for generating an interpretation of SQL based on business rules is provided, comprising:
[0007] Use the learned subtask decomposition model to decompose the problem-solving process into multiple subtasks;
[0008] Use the learned business discrimination model to determine the business type of the problem based on the problem description;
[0009] Construct a data flow diagram and a business flow diagram based on the multiple subtasks, the pre-constructed business knowledge graph, and the business type to which the problem belongs;
[0010] Matching and merging the data flow graph and the business flow graph according to node similarity to generate a business data flow graph;
[0011] The business data flow graph is traversed, and a natural language description of node attributes and relationships between nodes in the business data flow graph is output.
[0012] According to another aspect of the present invention, there is provided a SQL generation and interpretation device based on business rules, comprising:
[0013] A decomposition module is used to decompose the problem-solving process into multiple subtasks using the learned subtask decomposition model;
[0014] A judgment module is used to use the learned business discrimination model to judge the business type of the problem according to the problem description;
[0015] A construction module, used to construct a data flow graph and a business flow graph based on the multiple subtasks, the pre-constructed business knowledge graph, and the business type to which the problem belongs;
[0016] A generation module, used to match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph;
[0017] The output module is used to traverse the business data flow graph and output a natural language description of the node attributes and the relationship between the nodes in the business data flow graph.
[0018] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0019] at least one processor;
[0020] and a memory communicatively coupled to the at least one processor;
[0021] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the business rule-based SQL generation and interpretation method described in any embodiment of the present invention.
[0022] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the business rule-based SQL generation and interpretation method described in any embodiment of the present invention when executed.
[0023] The technical solution of the embodiment of the present invention decomposes the problem-solving process into multiple subtasks by using a learned subtask decomposition model; uses a learned business discrimination model to determine the business type to which the problem belongs according to the problem description; constructs a data flow graph and a business flow graph based on the multiple subtasks, a pre-built business knowledge graph, and the business type to which the problem belongs; matches and merges the data flow graph and the business flow graph according to node similarity to generate a business data flow graph; traverses the business data flow graph and outputs a natural language description of the node attributes and the relationships between the nodes in the business data flow graph, thereby achieving the beneficial effect of enabling users who do not have professional SQL development knowledge to evaluate the correctness of SQL query statements.
[0024] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0026] Figure 1 A flowchart of a method for generating an SQL statement based on business rules provided in the first embodiment of the present invention;
[0027] Figure 2 A flowchart of a method for generating an SQL statement based on business rules provided in Embodiment 2 of the present invention;
[0028] Figure 3 A flowchart of a method for generating an SQL statement based on business rules provided in Embodiment 3 of the present invention;
[0029] Figure 4 A flowchart of a method for generating and interpreting SQL based on business rules provided in Embodiment 4 of the present invention;
[0030] Figure 5 A schematic diagram of the structure of a business rule-based SQL generation and interpretation device provided in Embodiment 5 of the present invention;
[0031] Figure 6 A schematic diagram of the structure of an electronic device for a method for generating and interpreting SQL based on business rules according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described embodiment is only an embodiment of a part of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work should belong to the scope of protection of the present invention. It should be understood that the various steps recorded in the method implementation of the present invention can be performed in different orders and / or in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0033] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.
[0034] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0035] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0036] The names of the messages or information exchanged between multiple devices in the embodiments of the present invention are only used for illustrative purposes, and are not used to limit the scope of these messages or information.
[0037] Embodiment 1
[0038] Figure 1 A flowchart of a business rule-based SQL generation and interpretation method provided in Embodiment 1 of the present invention is provided. The method can be applied to situations where a user understands the process logic of SQL generation. The method can be executed by a business rule-based SQL generation and interpretation device, wherein the device can be implemented by software and / or hardware and is generally integrated on an electronic device. In this embodiment, the electronic device includes but is not limited to: a computer.
[0039] like Figure 1 As shown, a method for generating and explaining SQL based on business rules provided in the first embodiment of the present invention includes the following steps:
[0040] S110. Decompose the problem-solving process into multiple subtasks using the learned subtask decomposition model.
[0041] The function of the subtask decomposition model is to output the steps required to complete the SQL query statement corresponding to the problem description based on the data table description and background knowledge, and each step corresponds to a subtask. The problem can be understood as the question that the user wants to query.
[0042] In this embodiment, the subtask decomposition model that has completed learning can be obtained by training the seq2seq model using training samples in the form of prompts and training sample labels. The description of the training sample includes the role description, problem description, data table description, background knowledge, and the steps for generating the SQL query statement corresponding to the problem description; the training sample label is the steps for generating the SQL query statement corresponding to the problem description. Inputting the training sample into the prompt template to build the model can output the training sample in the form of prompts.
[0043] In this embodiment, the task execution prompt word is input into the subtask decomposition model that has been learned, and the steps for generating SQL query statements corresponding to multiple subtasks, i.e., the problem description, can be output. Among them, the task execution prompt word is a prompt word in the form of Prompt, and its description includes the problem description, the data table description, and the background knowledge involved in the problem.
[0044] S120: Use the learned business discrimination model to determine the business type of the problem according to the problem description.
[0045] The function of the business discrimination model is to identify and determine the business type of the problem based on the input problem description.
[0046] In this embodiment, the learned business discrimination model can be obtained by training the classification model using training samples and training labels in the form of text sequences. The description of the training sample can include a role description, a problem description, a data table description, background knowledge, and the business category to which the problem description belongs; the training sample label can be the business category to which the problem description belongs.
[0047] In this embodiment, the problem description is input into the learned business discrimination model to output the business type to which the problem belongs.
[0048] It should be noted that the business type to which the question belongs is obtained using the learned business discrimination model, and then the corresponding business rules can be extracted according to the business type.
[0049] S130. Construct a data flow diagram and a business flow diagram based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs.
[0050] Among them, the pre-built business knowledge graph can change the query scope of the data flow graph and the business flow graph, thereby achieving coverage of more application scenarios. The pre-built business knowledge graph is stored in the graph database.
[0051] In this embodiment, for the steps of generating SQL query statements corresponding to the input multiple subtasks, i.e., problem descriptions, a data flow diagram is generated with the support of the business knowledge graph; for the input business type, the business knowledge graph is used to retrieve related business processes to construct a business flow diagram.
[0052] S140. Match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph.
[0053] Among them, the SQL query statement is usually only a link in the business process, so in theory the data flow diagram corresponding to the SQL statement is only a component of the business flow diagram.
[0054] In this embodiment, the input data flow graph and business flow graph can be matched and retained according to node similarity to generate a merged business data flow graph.
[0055] Specifically, the data flow graph and the business flow graph are matched and merged according to node similarity to generate a business data flow graph, including: calculating the similarity of the nodes in the data flow graph and the business flow graph; matching the nodes with similarity higher than a preset threshold; merging the successfully matched nodes and successfully matched edges in the business flow graph into the data flow graph to generate a business data flow graph.
[0056] S150, traverse the business data flow graph, and output a natural language description of node attributes and relationships between nodes in the business data flow graph.
[0057] This embodiment uses a description construction method based on large model generation, including designing a description prompt word template, outputting the description of each step based on the prompt word description in the order of sub-graphs of the business data flow diagram, and outputting the business step description of the context generated by SQL.
[0058] The first embodiment of the present invention provides a method for generating and interpreting SQL based on business rules. First, the problem-solving process is decomposed into multiple subtasks using a learned subtask decomposition model; secondly, the business discrimination model that has been learned is used to determine the business type to which the problem belongs according to the problem description; then, a data flow graph and a business flow graph are constructed based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs; then, the data flow graph and the business flow graph are matched and merged according to the node similarity to generate a business data flow graph; finally, the business data flow graph is traversed to output a natural language description of the node attributes and the relationship between the nodes in the business data flow graph. The above method generates a procedural explanation of SQL query statements based on business rules that is easy for users to understand, thereby providing an expression language at the business rule level that is familiar to users, allowing users to understand the process logic of SQL generation, so that users who do not have professional SQL research and development knowledge can evaluate the correctness of SQL query statements.
[0059] Based on the above embodiment, a variant embodiment of the above embodiment is proposed. It should be noted that in order to make the description concise, only the differences from the above embodiment are described in the variant embodiment.
[0060] Furthermore, the learning process of the subtask decomposition model includes: obtaining a subtask decomposition corpus, the subtask decomposition corpus at least including a problem description, a data table description, an SQL query statement related to the problem query, and the steps for generating the SQL query statement corresponding to the problem description; inputting training samples in the form of prompts and training sample labels into the seq2seq model for model training; wherein the description of the training sample includes a role description, the problem description, the data table description, background knowledge, and the steps for generating the SQL query statement corresponding to the problem description, and the training sample label is the steps for generating the SQL query statement corresponding to the problem description.
[0061] The questions used in the learning process of the subtask decomposition model can be pre-collected questions that users have previously queried, or can be questions directly obtained from a question library.
[0062] In this embodiment, the subtask decomposition corpus may include a problem description (i.e., Query), a data table description schema, an SQL query statement related to the problem query (i.e., SQL), and steps for generating the SQL query statement corresponding to the Query (i.e., subtask-CoTs), etc. The subtask decomposition corpus may generally be generated manually, by tools, or automatically.
[0063] In this embodiment, the subtask decomposition model can be a seq2seq model, and a model architecture such as BERT, GPT, etc. can be used. In this embodiment, the LLM model is used preferentially. The training sample input is in the form of a Prompt, and its description may include a role description, a query, a corresponding schema, necessary background knowledge, and the logic of generating the SQL corresponding to the query. The training sample label is subtask-CoTs. After the training samples are labeled, the training of the subtask decomposition model is completed through the training framework of the LLM model, such as deepspeed or PyTorch. The training mode can be full training or fine-tuning training, and there is no specific restriction here.
[0064] Furthermore, the learning process of the business discrimination model includes: obtaining business discrimination corpus, which at least includes a problem description and a business category to which the problem description belongs; inputting training samples in the form of text sequences and training sample labels into a classification model for model training; wherein the description of the training sample includes a role description, the problem description, a data table description, background knowledge, and the business category to which the problem description belongs, and the training sample label is the business category to which the problem description belongs.
[0065] The questions used in the business discrimination model learning process may be pre-collected questions that users have previously queried, or may be questions directly obtained from a question library.
[0066] In this embodiment, the service identification corpus may include a problem description (ie, Query), a service type to which the Query belongs (ie, service type), etc. The service identification corpus may generally be generated manually, by a tool, or automatically.
[0067] In this embodiment, the business discrimination model is a classification model, and a model architecture such as Xgboost or a neural network may be used, with the neural network model architecture being preferred; the training sample input is in the form of a text sequence, and its description may include a role description, a query, a corresponding schema, necessary background knowledge, and what business category the query corresponds to. The training sample label is service type; based on the training sample, the training of the business discrimination model is completed through a neural network training framework, such as TensorFlow or PyTorch.
[0068] Furthermore, the construction process of the business knowledge graph includes: obtaining business domain-related data, and preprocessing the business domain-related data to obtain target data; using natural language processing technology and pattern recognition algorithms to identify and extract entity objects from the target data; using natural language processing and machine learning technology to identify and extract data relationships; filling the entity objects, the data relationships and attribute information into the knowledge graph model to obtain a business knowledge graph.
[0069] In this embodiment, the table information and business process information of the database are stored in the form of a graph. Specifically: for table information, the nodes in the graph correspond to table or field information, and the edges in the graph correspond to the relationship between the fields; for business process information, the steps include objects and actions, the nodes in the graph correspond to the objects in the business process, and the edges in the graph correspond to the actions in the business process.
[0070] Specifically, the process of building a business knowledge graph is as follows: first, collect data related to the business field, including structured data, semi-structured data, and unstructured data, and pre-process these data, such as data cleaning, deduplication, and format conversion; then use natural language processing technology and pattern recognition algorithms to identify and extract entities from the collected data, conduct in-depth analysis of the data, and use natural language processing, machine learning and other technologies to identify and extract relationships; finally, fill the entity, relationship and attribute information into the knowledge graph model to generate a business knowledge graph. Among them, automated methods, such as rule-based or machine learning methods, can be used for automatic filling and supplementation.
[0071] This embodiment can change the query scope of the data flow graph and the business flow graph by customizing the business knowledge graph, thereby achieving coverage of more application scenarios.
[0072] Embodiment 2
[0073] Figure 2 This is a flow chart of a method for generating and interpreting SQL based on business rules provided in the second embodiment of the present invention. The second embodiment is optimized on the basis of the above embodiments. For details not yet provided in this embodiment, please refer to the first embodiment.
[0074] like Figure 2 As shown, a business rule-based SQL generation explanation provided by Embodiment 2 of the present invention includes the following steps:
[0075] S210, input the question description, data table description and background knowledge of the question to be queried by the user into the Prompt template to build a model and infer the task execution prompt words.
[0076] Among them, the problem description is the description of the problem that the user needs to query. SQL query generally involves one or more tables. Table selection can be achieved manually or through schema linking technology. After the table selection operation is completed, the description information of the corresponding table, that is, the data table description, can be obtained. According to the problem description, the corresponding background knowledge is extracted from the knowledge base. The background knowledge extraction can be achieved based on existing technologies such as database query, knowledge graph query, and vector database matching.
[0077] In this embodiment, the problem description, data table description and background knowledge are input into the Prompt template construction model, so that the task execution prompt words in the form of Prompt can be inferred.
[0078] S220: Input the task execution prompt words into the learned subtask decomposition model, perform subtask decomposition reasoning, and output a plurality of subtasks.
[0079] Among them, a subtask is a step in the step of generating an SQL query statement corresponding to the problem description.
[0080] S230 , input the question description of the question to be queried by the user into the learned business discrimination model, perform business discrimination reasoning, and output the business type to which the question belongs.
[0081] The input of the business discrimination model is the problem description of the user's query, and the business discrimination model performs reasoning to output the business discrimination result.
[0082] S240. Construct a data flow diagram and a business flow diagram based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs.
[0083] S250. Match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph.
[0084] S260, traverse the business data flow graph, and output a natural language description of node attributes and relationships between nodes in the business data flow graph.
[0085] The second embodiment of the present invention provides a method for generating and interpreting SQL based on business rules, which embodies the process of decomposing the problem-solving process into multiple subtasks using the learned subtask decomposition model and the process of using the learned business discrimination model to determine the business type to which the problem belongs based on the problem description. The method uses the subtask decomposition model to gradually decompose the problem into multiple subtasks, so that the model can provide good SQL generation results even when facing complex problems; the method uses the business discrimination model to classify the problem description into a specific business type based on its characteristics, thereby accurately matching the business process specifications and knowledge involved in the problem.
[0086] Embodiment 3
[0087] Figure 3 This is a flow chart of a method for generating and interpreting SQL based on business rules provided in the third embodiment of the present invention. The third embodiment is optimized on the basis of the above embodiments. For details not yet provided in this embodiment, please refer to the first and second embodiments.
[0088] like Figure 3 As shown, a business rule-based SQL generation explanation provided by Embodiment 3 of the present invention includes the following steps:
[0089] S310: Decompose the problem-solving process into multiple subtasks using the learned subtask decomposition model.
[0090] S320: Use the learned business discrimination model to determine the business type of the problem according to the problem description.
[0091] S330. Complete the construction of the data flow graph according to the multiple subtasks and the pre-constructed business knowledge graph.
[0092] Specifically, the data flow graph is constructed according to the multiple subtasks and the pre-built business knowledge graph, including: using a large model to extract tables and fields from the multiple subtasks through the Prompt method; using a word segmentation algorithm and a part-of-speech analysis algorithm to process the multiple subtasks to obtain data processing operations; using semantic similarity calculation to match table names and field names with nodes in the pre-built business knowledge graph; matching the data processing operations with edges in the pre-built business knowledge graph; and constructing successfully matched nodes and successfully matched edges into a data flow graph.
[0093] In this embodiment, the data objects and data processing operations to be processed in each step are parsed from the step of generating the SQL query statement. The data objects may include tables and fields. The step of extracting data objects is: using the big model, extracting information such as tables and columns from the multiple subtasks through the Prompt method. The big model used can be an untrained open source big model. If the extraction accuracy is not good, a table / field extraction training set can be prepared to improve the ability of the big model to extract table and field information from the step of generating the SQL query statement through fine-tuning. The training corpus sample format can be {subtask-CoTs->Tables, Columns}. The step of data processing operation is: using word segmentation and part-of-speech analysis algorithms to process multiple subtasks, and the analysis results are subject, object, predicate, etc., and the subject and object are predicates of tables / fields.
[0094] In this embodiment, the extracted table names and field names are matched with the nodes of the business knowledge graph. The matching method can use semantic similarity calculation. If the similarity is higher than the set threshold, the match is successful. Similarly, the data processing operation is calculated with the edge in the business knowledge graph. If the similarity is higher than the set threshold, the match is successful. All matched nodes and edges constitute a data flow graph. The difference from the ordinary flow graph is that the data flow graph dataflow-graph constructed in this embodiment is divided into subgraphs stage-graph with timing information according to the CoT steps, dataflow-graph = Graph{stage-1-graph, stage-2-graph, ..., stage-i-graph} = {[nodex-edge-nodey, ...]}, i is the subgraph number, corresponding to the CoT step number, nodex-op-nodey is the node and edge information (corresponding to the table / field and data processing operation information) matched by the CoT step corresponding to the subgraph.
[0095] S340. Use the business knowledge graph to retrieve the business process corresponding to the business type to which the question belongs to construct a business flow graph.
[0096] In this embodiment, the corresponding business process is retrieved from the business knowledge graph based on the business type to which the question belongs, and a business flow graph is constructed and output. The business process can be described in text or a flow chart and can be stored in a database system or a big data system. Preferably, the business process is stored in the form of a graph in the business knowledge graph system, and the corresponding business flow graph can be extracted according to the business type to which the question belongs.
[0097] Specifically, the use of the business knowledge graph to retrieve the business process corresponding to the business type to construct a business flow graph includes: retrieving the nodes and edges corresponding to the business process from the business knowledge graph according to the business type; treating all nodes and all edges as a superimposed graph; and expanding the graph into multiple subgraphs according to the steps in the business process to obtain a business flow graph.
[0098] Among them, the nodes and edges corresponding to the business process in the business knowledge graph are retrieved according to the business type to which the problem belongs. All nodes and edges are recorded as Graph_init. Because different steps may operate the same object multiple times, Graph_init can be regarded as a superimposed graph; Graph_init is expanded according to the steps of the business process, and expanded into multiple sub-graphs in the order of the steps, that is, the business flow graph serviceflow-graph, serviceflow-graph = Graph{step-1-graph, step-2-graph,…, step-i-graph} = {[nodex-edge-nodey,…]}, i is the sub-graph number, corresponding to the business step number; nodex-op-nodey is the node and edge information matching the business process step corresponding to the sub-graph (corresponding to the object and operation information in the step).
[0099] S350. Match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph.
[0100] In this embodiment, the similarity of the nodes in the data flow graph and the business flow graph is calculated, and the nodes with similarity higher than the set threshold are matched, and the matched nodes and edges in the business flow graph are merged into the data flow graph to obtain the business data flow graph SQL_Graph, SQL_Graph = {step-1-graph, step-2-graph, ..., step-i-graph}, and the graph of the business flow graph before and after the SQL_Graph execution sequence is used as the context of SQL_Graph, recorded as SQL_Graph_Context = {serviceflow-graph-pre, serviceflow-graph-follow}, serviceflow-graph-pre is the previous context of SQL_Graph, and serviceflow-graph-follow is the following context of SQL_Graph.
[0101] S360, traverse the business data flow graph, and output a natural language description of node attributes and relationships between nodes in the business data flow graph.
[0102] Specifically, the traversal of the business data flow graph and the output of a natural language description of node attributes and relationships between nodes in the business data flow graph include: designing a description prompt word template, the prompt word including how to generate a step description based on the description of nodes and edges; outputting the business step description of the business flow graph in the order of subgraphs of the business data flow graph based on a large model and the prompt word template; generating a business step description of the context of the business data flow graph and a business step description of the context of the business data flow graph, the context of the business data flow graph being a graph of the business flow graph before and after the execution order of the business data flow graph; and selectively outputting the business step description of the business flow graph, the business step description of the context of the business data flow graph and the business step description of the context of the business data flow graph according to the needs of upper-level business applications.
[0103] The prompt word includes instructions on how to generate a step description based on the description of nodes and edges. The business step description may include the description of the intention and specific operation of each step, which is recorded as Query2SQL_CoTs_Dsr. The business step description above the business data flow graph is recorded as Query2SQL_Pre_CoTs_Dsr, and the business step description below the business data flow graph is recorded as Query2SQL_Follow_CoTs_Dsr.
[0104] Among them, {Query2SQL_CoTs_Dsr, Query2SQL_Pre_CoTs_Dsr, Query2SQL_Follow_CoTs_Dsr} can be selectively output according to the needs of upper-level business applications, that is, a logical explanation of how the SQL query statement based on the business rules is generated that can be understood by the user.
[0105] The third embodiment of the present invention provides a method for generating and interpreting SQL based on business rules, which completes the logic consistency check based on the graph path matching method. By building a complete data flow graph and a business flow graph match, the internal consistency of the data processing logic and the business processing logic in the business process is determined based on the consistency between the data flow graph and the business flow graph.
[0106] Embodiment 4
[0107] The embodiment of the present invention provides a specific implementation method based on the technical solutions of the above embodiments.
[0108] As a specific implementation method of this embodiment, Figure 4 A flowchart of a method for generating an SQL statement based on business rules provided in Embodiment 4 of the present invention is shown in FIG. Figure 4 As shown, it includes the following three stages:
[0109] Phase 1: subtask decomposition and business type identification. It includes the following steps:
[0110] Step 100: learning subtask decomposition model and business discrimination model;
[0111] Step 101: Subtask decomposition;
[0112] This step is equivalent to using the learned subtask decomposition model to decompose the problem-solving process into multiple subtasks.
[0113] Step 102: Determine the service type.
[0114] This step is equivalent to using the learned business discrimination model to determine the business type of the problem based on the problem description.
[0115] Phase 2: Matching, aligning and merging data flow graphs and business flow graphs. This includes the following steps:
[0116] Step 200: constructing a business knowledge graph;
[0117] Step 201: data flow graph matching;
[0118] This step is equivalent to completing the construction of the data flow graph based on multiple subtasks and a pre-built business knowledge graph.
[0119] Step 202: Business flow graph matching;
[0120] This step is equivalent to using the business knowledge graph to retrieve the business process corresponding to the business type to which the question belongs to construct a business flow graph.
[0121] Step 203: Business data flow graph merging.
[0122] This step is equivalent to matching and merging the data flow graph and the business flow graph according to node similarity to generate a business data flow graph.
[0123] Phase 3: Query2SQL interpretation generation based on business rules. This includes the following steps:
[0124] Step 301: SQL_Graph flow chart description construction;
[0125] This step includes designing a description prompt word template to generate a business step description above the business data flow diagram and a business step description below the business data flow diagram.
[0126] Step 302: Query2SQL interprets the output.
[0127] This step is equivalent to selectively outputting the business step description of the business flow diagram, the business step description above the business data flow diagram, and the business step description below the business data flow diagram according to the needs of the upper-level business application.
[0128] As another specific implementation method of this implementation, this embodiment is an application scenario of e-commerce business status query based on NL2SQL technology. Traditional business status query can execute query tasks through a pre-developed query system, and business personnel can only query according to the query type provided by the interface, and the business query ability is relatively weak. NL2SQL can convert the natural language description of business personnel into query statements, thereby realizing an interactive query system with real-time input and real-time conversion, but the generation process of its SQL statements is a black box for users, with defects such as opacity. Compared with traditional query systems, there are certain problems with the correctness of its results. With the help of the SQL generation and interpretation method and system method based on business rules of the present invention, the above problems can be well solved. In the application scenario of this embodiment, through the method of SQL generation and interpretation based on business rules, a procedural and easy-to-understand explanation for ordinary users is provided according to the SQL query generated by NL2SQL, thereby realizing self-examination and self-correction of users, and solving the application landing problem of NL2SQL. The method of the present invention matches and integrates Query with business rules, and uses graph database technology and LLMs to generate business-based explanations.
[0129] In this embodiment, taking the transaction record table TRANSACTIONS as an example, the field information of the TRANSACTIONS table includes transaction ID transaction_id, trader ID customer_id, transaction type transaction_type, transaction date data_of_transaction, transaction number amount_of_transaction, and transaction amount transaction_amount. Now the business personnel ask the NL2SQL query system the question "Query all transaction dates with the transaction type of selling", and the SQL statement output by the system is "SELECT date_of_transaction FROM TRANSACTIONS WHERE transaction_type=\"SALE\"". In order to obtain the generated logic explanation of the SQL statement based on the business rules, the specific implementation details are as follows:
[0130] Phase 1: Subtask decomposition and business type identification.
[0131] Step 100: Learning subtask decomposition model and business discrimination model
[0132] Subtask decomposition model learning:
[0133] Step 1: Subtask decomposition corpus preparation. The subtask decomposition corpus comes from the common questions and corresponding SQL query statements of the e-commerce business consulting system. Through manual cleaning, high-quality corpus is selected. The corpus specifically includes Query, table schema related to the question, correct SQL query statements, and logical steps subtask-CoTs written in SQL. The following is a sample example from the original corpus:
[0134] {
[0135] "index":18,
[0136] "query":"Query the transaction ID of the user whose trader ID is 3574467",
[0137] "schema":"create table TRANSACTIONS(
[0138] transaction_id int(11)primary key,
[0139] customer_id int(11),
[0140] transaction_type varchar(255),
[0141] date_of_transaction date,
[0142] amount_of_transaction int(11),
[0143] transaction_amount decimal(10,2) );
[0145] "sql":"SELECT transaction_id FROM TRANSACTIONS WHERE customer_id=3574467",
[0146] "subtask-CoTs":"First, use the FROM clause to select the TRANSACTIONS table. Second, use the SELECT keyword to select transaction_id. Third, use the WHERE clause to filter the transaction records with customer_id 3574467.",
[0147] }
[0148] Step 2: Standardization of training samples. In this embodiment, the subtask decomposition model uses the LLM large model, and the training sample input is in the form of Prompt, which contains the role description of the e-commerce business personnel, Query, e-commerce related schema and background knowledge, and the logic of generating the SQL corresponding to the Query. The training sample label is the generation step of Query2SQL, that is, subtask-CoTs.
[0149] For example, for the query "Query the transaction ID of the user whose trader ID is 3574467", enter the prompt as follows:
[0150] Please play the role of task decomposer. You can decompose complex tasks into multiple subtasks. The decomposition method is: based on query, schema, SQL, output subtask step description subtask-CoTs. Known query is "query what is the transaction ID of the user with trader ID 3574467", the data table information is "create_table": "create tableTRANSACTIONS(
[0151] transaction_id int(11)primary key,
[0152] customer_id int(11),
[0153] transaction_type varchar(255),
[0154] date_of_transaction date,
[0155] amount_of_transaction int(11),
[0156] transaction_amount decimal(10,2)
[0157] );"Please describe how to generate the SQL query statement to solve the Query problem step by step "SELECT transaction_id FROM TRANSACTIONS WHERE customer_id=3574467"
[0158] The tag (i.e., subtask description) corresponding to Prompt is: "Step 1, use the FROM clause to select the TRANSACTIONS data table. Step 2, use the SELECT keyword to select transaction_id. Step 3, use the WHERE clause to filter the transaction records with customer_id 3574467."
[0159] Step 3: Subtask decomposition model training. After marking the training samples in step 2, use the DeepSpeed training framework to complete the training of the subtask decomposition model. In this embodiment, the training mode selects full-scale fine-tuning training.
[0160] Business discrimination model learning:
[0161] Step 1: Business discrimination corpus preparation. Business discrimination corpus is manually written, including e-commerce related queries and corresponding labels such as business categories. The following is a sample example of the original corpus:
[0162] {
[0163] "index":18,
[0164] "query":"Query the transaction ID of the user whose trader ID is 3574467",
[0165] "service type":"Transaction record query",
[0166] }
[0167] Step 2: Business discrimination model training. The subtask decomposition model is a classification model, using the DL model architecture. Based on the training samples in step 2, the business discrimination model training is completed using PyTorch.
[0168] Step 101: Subtask generation.
[0169] Subtask decomposition model input data preparation. Input the query "query all transaction dates with transaction type as sell" and the SQL query statement "SELECT date_of_transaction FROM TRANSACTIONSWHERE transaction_type=\"SALE\"" into the subtask decomposition model, use schema linking technology to select the TRANSACTIONS table, and obtain the description information of the table, i.e., the schema; at the same time, link to the Wikipedia external knowledge base to provide relevant background knowledge bg-kg.
[0170] Subtask decomposition model input prompt construction. Based on the query, schema, bg-kg and other information in the previous step, the task execution prompt words required for model reasoning are constructed according to the subtask decomposition model input prompt template.
[0171] Execute subtask decomposition reasoning and output the subtask decomposition results: Use the FROM clause to select the TRANSACTIONS data table; use the SELECT keyword to select date_of_transaction; use the WHERE clause to filter transaction records with transaction_type of SALE.
[0172] Step 102: Business type identification. Input the query "query all transaction dates with the transaction type of selling" into the business identification model. The business identification model performs business identification reasoning and outputs the business identification result service type as "transaction record query".
[0173] Phase 2: Matching, aligning and merging data flow graphs and business flow graphs
[0174] Step 200: Business knowledge graph construction. First, collect data related to the e-commerce transaction business field (including structured data, semi-structured data, and unstructured data) and pre-process these data manually. Then, with the help of the BERT pre-trained language model, identify and extract entities and relationships from the collected data. Finally, use TransE to fill the entity, relationship, and attribute information into the knowledge graph model RDF. Store the constructed knowledge graph in the graph database Neo4j.
[0175] Step 201: Data flow graph matching.
[0176] Subtask parsing. In this embodiment, the existing Solar data analysis model is used to parse the subtasks and extract data objects and data processing operations. Among them, the table TRANSACTIONS and the fields date_of_transaction and transaction_type are extracted from the subtask through the Prompt method;
[0177] The example is as follows: Please play the role of statement parsing. You can parse the subtask step description subtask-CoTs and extract tables and fields from it. The parsing method is: based on subtask-CoTs, output tables and fields. It is known that subtask-CoTs is "In the first step, use the FROM clause to select the TRANSACTIONS data table. In the second step, use the SELECT keyword to select date_of_transaction. In the third step, use the WHERE clause to filter the transaction records with transaction_type SALE." Please extract the table and field information in subtask-CoTs as follows:
[0178] Use word segmentation and this analysis algorithm to process the subtasks. The analysis results are objects, predicates, etc. The predicates whose objects are tables / fields are the data processing operations Ops.
[0179] The examples are as follows: Step 1: Predicate phrase: Select using the FROM clause; Object: TRANSACTIONS; The object is a table, and the predicate "Select using the FROM clause" is recorded as Ops1; Step 2: Predicate phrase: Select using the SELECT keyword; Object: date_of_transaction; The object is a field, and the predicate "Select using the SELECT keyword" is recorded as Ops2; Step 3: Predicate phrase: Filter using the WHERE clause; Object: Transaction records with transaction_type being SALE; The object is a field, and the predicate "Filter using the WHERE clause" is recorded as Ops3.
[0180] Data flow graph construction. First, the extracted table names and field names are matched with the nodes of the knowledge graph. The specific matching method can use the Jaccard similarity coefficient to calculate the semantic similarity. If the similarity is higher than the set threshold, the match is successful. Then, similarly, the data processing method Ops is calculated with the edges in the knowledge graph. If the similarity is higher than the set threshold, the match is successful. Finally, all the matched nodes and edges are the data flow graph. The result is: dataflow-graph = Graph{stage-1-graph, stage-2-graph, stage-3-graph} = {[NULL-Ops1-TRANSACTIONS], [NULL-Ops2-date_of_transaction], [transaction_type-Ops3-SALE]}.
[0181] Step 202: Business flow graph matching. Use the business knowledge graph system in step 200 to store the business process. First, retrieve the nodes and edges corresponding to the business process in the business knowledge graph according to the business type "transaction record query", and the Graph_init composed of all nodes and edges = {enter, transaction record query page, specify, query conditions, submit, query request, display, query results}; then, expand Graph_init according to the steps of the business process, and expand it into multiple subgraphs in the order of steps, that is, the business flow graph serviceflow-graph = Graph{step-1-graph, step-2-graph, step-3-graph, step-4-graph} = {[enter-transaction record query page], [specify-query conditions], [submit-query request], [display-query results]}.
[0182] Step 203: Merge the business data flow graph. Use the graph edit distance technology GED to detect the similarity of the nodes in the data flow graph in step 201 and the business flow graph in step 202; match the nodes whose similarity is higher than the set threshold, and merge the matched nodes and edges in the business flow graph into the data flow graph SQL_Graph = {stage-1-graph, stage-2-graph, stage-3-graph} = {[Ops1-TRANSACTIONS], [Ops2-date_of_transaction], [transaction_type-Ops3'-SALE]}, where Ops3' is the operation after matching "[Specified-Query Condition]" in the serviceflow-graph. The business flow graph before and after the SQL_Graph execution sequence is used as the context of SQL_Graph, that is, SQL_Graph_Context = {serviceflow-graph-pre, serviceflow-graph-follow}, where serviceflow-graph-pre = {[enter - transaction record query page]}, serviceflow-graph-follow = {[submit - query request], [display - query results]}.
[0183] Phase 3: Query2SQL interpretation generation based on business rules
[0184] Step 301: SQL_Graph and SQL_Graph_Context flow graph description construction. First, manually design the description prompt word template: "For xx node, perform xx operation" "Perform xx operation on xx node" to generate an instruction for step description. Then use the Solar large model and prompt word template to output the intention and specific operation description of each step {Query2SQL_CoTs_Dsr, Query2SQL_Pre_CoTs_Dsr, Query2SQL_Follow_CoTs_Dsr} in the subgraph order of SQL_Graph and SQL_Graph_Context, where Query2SQL_CoTs_Dsr = {[`SELECT date_of_transaction` indicates the fields to be returned in the query result, that is, select the transaction date (date_of_transaction) as the output from the query result. ], [`FROM TRANSACTIONS` indicates the source of the data table, that is, query from the data table named "TRANSACTIONS". ], [`WHERE transaction_type = "SALE"` is the filter condition, indicating that only data records with transaction type "SALE" are selected for query. ]}; Query2SQL_Pre_CoTs_Dsr = {[Enter the transaction record query interface to perform the next query operation. ]}; Query2SQL_Follow_CoTs_Dsr = {[Submit the query request to instruct the system to start the query. ], [Show the query results. The system will sort and process the queried transaction records and display them to the user in the form of a list or table. ]}.
[0185] Step 302: Query2SQL explanation output. Use the Solar large model to output the explanation: "Enter the transaction record query interface and start querying. This SQL query statement is used to query the transaction date (date_of_transaction) of the transaction type "SALE" from the data table named "TRANSACTIONS". Among them, `SELECT date_of_transaction` indicates the field to be returned in the query result, that is, the transaction date (date_of_transaction) is selected from the query result as the output. `FROM TRANSACTIONS` indicates the source of the data table, that is, the query is performed from the data table named "TRANSACTIONS". `WHEREtransaction_type="SALE"` is the filter condition, which means that only data records with the transaction type "SALE" are selected for query. Submit the query request to instruct the system to start querying. Display the query results, and the system will sort and process the queried transaction records and display them to the user in the form of a list or table. Therefore, the query will return the transaction date (date_of_transaction) of the transaction records that meet the transaction type "SALE"."
[0186] This embodiment provides a method for generating and explaining SQL based on business rules. In the actual application scenario of the NL2SQL large model, users can understand how the model makes decisions based on the generated explanations, and then evaluate the correctness of the SQL queries, thereby ensuring the transparency and explainability of the model.
[0187] Embodiment 5
[0188] Figure 5 A schematic diagram of the structure of a business rule-based SQL generation and interpretation device provided in Embodiment 5 of the present invention, which can be used to allow users to understand the process logic of SQL generation, wherein the device can be implemented by software and / or hardware and is generally integrated on an electronic device.
[0189] like Figure 5 As shown, the device includes: a decomposition module 110, a judgment module 120, a construction module 130, a generation module 140 and an output module 150.
[0190] A decomposition module 110, configured to decompose the problem solving process into a plurality of subtasks using the learned subtask decomposition model;
[0191] A judgment module 120, configured to use the learned business discrimination model to judge the business type to which the problem belongs according to the problem description;
[0192] A construction module 130, configured to construct a data flow graph and a business flow graph based on the multiple subtasks, the pre-constructed business knowledge graph, and the business type to which the problem belongs;
[0193] A generating module 140, configured to match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph;
[0194] The output module 150 is used to traverse the business data flow graph and output a natural language description of node attributes and relationships between nodes in the business data flow graph.
[0195] In this embodiment, the device first decomposes the problem-solving process into multiple subtasks using the learned subtask decomposition model through the decomposition module 110; secondly, uses the learned business discrimination model through the judgment module 120 to determine the business type to which the problem belongs according to the problem description; then, through the construction module 130, a data flow graph and a business flow graph are constructed based on the multiple subtasks, the pre-constructed business knowledge graph, and the business type to which the problem belongs; then, through the generation module 140, the data flow graph and the business flow graph are matched and merged according to node similarity to generate a business data flow graph; finally, the business data flow graph is traversed through the output module 150 to output a natural language description of the node attributes and the relationships between nodes in the business data flow graph.
[0196] This embodiment provides a business rule-based SQL generation and interpretation device, which can provide a user-familiar expression language at the business rule level, allowing the user to understand the process logic of SQL generation.
[0197] Furthermore, the learning process of the subtask decomposition model includes: obtaining a subtask decomposition corpus, the subtask decomposition corpus at least including a problem description, a data table description, an SQL query statement related to the problem query, and the steps for generating the SQL query statement corresponding to the problem description; inputting training samples in the form of prompts and training sample labels into the seq2seq model for model training; wherein the description of the training sample includes a role description, the problem description, the data table description, background knowledge, and the steps for generating the SQL query statement corresponding to the problem description, and the training sample label is the steps for generating the SQL query statement corresponding to the problem description.
[0198] Based on the above optimization, the decomposition module 110 is specifically used to: input the problem description, data table description and background knowledge of the user's query problem into the Prompt template to build a model to infer the task execution prompt words; input the task execution prompt words into the subtask decomposition model that has been learned, perform subtask decomposition reasoning, and output multiple subtasks; wherein a subtask is a step in the generation step of the SQL query statement corresponding to the problem description.
[0199] Furthermore, the learning process of the business discrimination model includes: obtaining business discrimination corpus, which at least includes a problem description and a business category to which the problem description belongs; inputting training samples in the form of text sequences and training sample labels into a classification model for model training; wherein the description of the training sample includes a role description, the problem description, a data table description, background knowledge, and the business category to which the problem description belongs, and the training sample label is the business category to which the problem description belongs.
[0200] Based on the above optimization, the judgment module 120 is specifically used to: input the question description of the question to be queried by the user into the learned business discrimination model, perform business discrimination reasoning, and output the business type to which the question belongs.
[0201] Furthermore, the building block 130 includes:
[0202] A first construction unit, used to complete the construction of a data flow graph according to the multiple subtasks and a pre-constructed business knowledge graph;
[0203] The second construction unit is used to use the business knowledge graph to retrieve the business process corresponding to the business type to which the question belongs to construct a business flow graph.
[0204] Furthermore, the construction process of the business knowledge graph includes: obtaining business domain-related data, and preprocessing the business domain-related data to obtain target data; using natural language processing technology and pattern recognition algorithms to identify and extract entity objects from the target data; using natural language processing and machine learning technology to identify and extract data relationships; filling the entity objects, the data relationships and attribute information into the knowledge graph model to obtain a business knowledge graph.
[0205] On the basis of the above scheme,
[0206] The first construction module is specifically used to: use the large model to extract tables and fields from the multiple subtasks through the Prompt method; use the word segmentation algorithm and the part-of-speech analysis algorithm to perform data processing operations on the multiple subtasks; use semantic similarity calculation to match the table name and field name with the nodes in the pre-built business knowledge graph; match the data processing operation with the edges in the pre-built business knowledge graph; and construct the successfully matched nodes and the successfully matched edges into a data flow graph.
[0207] The second construction module is specifically used to: retrieve the nodes and edges corresponding to the business process from the business knowledge graph according to the business type; regard all nodes and all edges as a superimposed graph; and expand the graph into multiple subgraphs according to the steps in the business process to obtain a business flow graph.
[0208] Furthermore, the generation module 140 is specifically used to: calculate the similarity of the nodes in the data flow graph and the business flow graph; match the nodes whose similarity is higher than a preset threshold; merge the successfully matched nodes and successfully matched edges in the business flow graph into the data flow graph to generate a business data flow graph.
[0209] Furthermore, the output module 150 is specifically used to: design a description prompt word template, the prompt word includes how to generate a step description based on the description of the nodes and edges; output the business step description of the business flow graph according to the subgraph order of the business data flow graph, based on the large model and the prompt word template, according to the subgraph order; generate the business step description of the business data flow graph above and the business step description of the business data flow graph below, the context of the business data flow graph being the graph of the business flow graph before and after the execution order of the business data flow graph; selectively output the business step description of the business flow graph, the business step description of the business data flow graph above and the business step description of the business data flow graph below according to the needs of the upper-level business application.
[0210] The above-mentioned SQL generation and interpretation device based on business rules can execute the SQL generation and interpretation method based on business rules provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0211] Embodiment 6
[0212] Figure 6A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0213] like Figure 6 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0214] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0215] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as the SQL generation interpretation method based on business rules.
[0216] In some embodiments, the SQL generation and interpretation method based on business rules may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps in the SQL generation and interpretation method based on business rules described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the SQL generation and interpretation method based on business rules in any other appropriate manner (e.g., by means of firmware).
[0217] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0218] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0219] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0220] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0221] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0222] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0223] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0224] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for generating and interpreting SQL based on business rules, characterized in that: The method comprises: Use the learned subtask decomposition model to decompose the problem-solving process into multiple subtasks; Use the learned business discrimination model to determine the business type of the problem based on the problem description; Constructing a data flow diagram and a business flow diagram based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs; Matching and merging the data flow graph and the business flow graph according to node similarity to generate a business data flow graph; Traversing the business data flow graph, and outputting a natural language description of node attributes and relationships between nodes in the business data flow graph; The subtask decomposition model is a model for outputting the steps required to complete the SQL query statement corresponding to the problem description based on the data table description and background knowledge, and each step corresponds to a subtask; The business discrimination model is a model used to identify and determine the business type of the problem based on the problem description; The step of constructing a data flow graph and a business flow graph based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs includes: Complete the construction of the data flow graph according to the multiple subtasks and the pre-built business knowledge graph; Use the business knowledge graph to retrieve the business process corresponding to the business type to which the question belongs to construct a business flow graph; The step of constructing a data flow graph based on the multiple subtasks and the pre-built business knowledge graph includes: Using the large model, extract tables and fields from the multiple subtasks through the Prompt method; Performing data processing operations on the multiple subtasks using a word segmentation algorithm and a part-of-speech analysis algorithm; Using semantic similarity calculation to match table names and field names with nodes in the pre-built business knowledge graph; Matching the data processing operations with edges in the pre-built business knowledge graph; Construct the successfully matched nodes and edges into a data flow graph; The step of using the business knowledge graph to retrieve the business process corresponding to the business type to which the question belongs and constructing a business flow graph includes: Retrieving nodes and edges corresponding to the business process from the business knowledge graph according to the business type; Think of all nodes and all edges as a graph stacked together; The graph is expanded into multiple subgraphs according to the steps in the business process to obtain a business flow graph.
2. The method according to claim 1, characterized in that The learning process of the subtask decomposition model includes: Obtaining subtask decomposition corpus, wherein the subtask decomposition corpus at least includes a problem description, a data table description, an SQL query statement related to the problem query, and a step of generating the SQL query statement corresponding to the problem description; Input the prompt format training samples and training sample labels into the seq2seq model for model training; The description of the training sample includes a role description, a problem description, a data table description, background knowledge, and the steps for generating an SQL query statement corresponding to the problem description. The training sample label is the steps for generating an SQL query statement corresponding to the problem description.
3. The method according to claim 1, characterized in that The learning process of the business discrimination model includes: Obtaining business discrimination corpus, wherein the business discrimination corpus at least includes a problem description and a business category to which the problem description belongs; Input the training samples in the form of text sequences and the training sample labels into the classification model for model training; The description of the training sample includes a role description, the problem description, a data table description, background knowledge, and the business category to which the problem description belongs, and the training sample label is the business category to which the problem description belongs.
4. The method according to claim 1 or 2, characterized in that The problem-solving process is decomposed into multiple subtasks using the learned subtask decomposition model, including: Input the user's query question description, data table description, and background knowledge into the prompt template to build a model and infer the task execution prompt words; Inputting the task execution prompt words into the learned subtask decomposition model, performing subtask decomposition reasoning, and outputting multiple subtasks; Among them, a subtask is a step in the generation of the SQL query statement corresponding to the problem description.
5. The method according to claim 1 or 3, characterized in that The method of using the learned business discrimination model to determine the business type of the problem according to the problem description includes: The question description of the user's query is input into the learned business discrimination model, business discrimination reasoning is performed, and the business type to which the question belongs is output.
6. The method according to claim 1, wherein The process of constructing the business knowledge graph includes: Acquire business domain related data, and pre-process the business domain related data to obtain target data; Identify and extract entity objects from the target data using natural language processing technology and pattern recognition algorithms; Use natural language processing and machine learning techniques to identify and extract data relationships; Fill the entity objects, the data relationships and the attribute information into the knowledge graph model to obtain the business knowledge graph.
7. The method according to claim 1, characterized in that The matching and merging of the data flow graph and the business flow graph according to node similarity to generate a business data flow graph includes: Calculating the similarity of nodes in the data flow graph and the business flow graph; Match nodes whose similarity is higher than a preset threshold; The successfully matched nodes and successfully matched edges in the business flow graph are merged into the data flow graph to generate a business data flow graph.
8. The method according to claim 1, characterized in that The traversing the business data flow graph and outputting a natural language description of node attributes and relationships between nodes in the business data flow graph includes: Designing a description prompt word template, wherein the prompt word includes how to generate a step description based on the description of the node and the edge; Outputting the business step description of the business flow diagram in the order of the sub-diagrams of the business data flow diagram based on the large model and the prompt word template in the order of the sub-diagrams; Generate a business step description above the business data flow diagram and a business step description below the business data flow diagram, wherein the context of the business data flow diagram is a diagram of the business flow diagram before and after the execution sequence of the business data flow diagram; The business step description of the business flow diagram, the business step description above the business data flow diagram, and the business step description below the business data flow diagram are selectively output according to the requirements of the upper-level business application.
9. A SQL generation and interpretation device based on business rules, characterized in that: The device comprises: A decomposition module is used to decompose the problem-solving process into multiple subtasks using the learned subtask decomposition model; The judgment module is used to use the learned business discrimination model to determine the business type of the problem based on the problem description; A construction module, configured to construct a data flow diagram and a business flow diagram based on the multiple subtasks, the pre-built business knowledge graph, and the business type to which the problem belongs; A generation module, configured to match and merge the data flow graph and the business flow graph according to node similarity to generate a business data flow graph; An output module, configured to traverse the business data flow graph and output a natural language description of node attributes and relationships between nodes in the business data flow graph; The subtask decomposition model is a model for outputting the steps required to complete the SQL query statement corresponding to the problem description based on the data table description and background knowledge, and each step corresponds to a subtask; The business discrimination model is a model used to identify and determine the business type of the problem based on the problem description; Wherein, the building blocks include: A first construction unit is configured to complete the construction of a data flow graph according to the plurality of subtasks and a pre-constructed business knowledge graph; The second construction unit is configured to use the business knowledge graph to retrieve a business process corresponding to the business type to which the question belongs and to construct a business flow graph; Wherein, the first building block is specifically used for: Using the large model, extract tables and fields from the multiple subtasks through the Prompt method; Performing data processing operations on the multiple subtasks using a word segmentation algorithm and a part-of-speech analysis algorithm; Using semantic similarity calculation to match table names and field names with nodes in the pre-built business knowledge graph; Matching the data processing operations with edges in the pre-built business knowledge graph; Construct the successfully matched nodes and edges into a data flow graph; Wherein, the second building block is specifically used for: Retrieving nodes and edges corresponding to the business process from the business knowledge graph according to the business type; Think of all nodes and all edges as a graph stacked together; The graph is expanded into multiple subgraphs according to the steps in the business process to obtain a business flow graph.
10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the business rule-based SQL generation and interpretation method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the business rule-based SQL generation and interpretation method according to any one of claims 1 to 8 when executed.
Citation Information
Patent Citations
Model training method and device, natural language processing method and device, equipment and storage medium
CN115905282A
Data query method and device, electronic equipment and storage medium
CN116303537A
Natural language-based domain-specific business knowledge retrieval method and retrieval device
CN116662582A
Semantic parsing of natural language query
US20220277005A1
