A global optimization method for decomposition and execution of complex data query tasks

Through the task decomposition and execution method based on tree structure, the problems of complex syntax, complex operations and fuzzy intentions in complex database query tasks are solved, and efficient and accurate text-to-SQL code effect is achieved.

CN118689899BActive Publication Date: 2025-02-07SOUTHWESTERN UNIV OF FINANCE & ECONOMICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410838088.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2025-02-07
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

The prior art faces the problems of complex syntax, complex operations and fuzzy intentions when dealing with lengthy and complex database query tasks, making it difficult to generate accurate SQL code.

Method used

Using a tree-based structure-based task decomposition and execution method, a database query code that meets complex needs is generated through global, traceable tree task decomposition. This method includes building a task tree, a self-correction module and a local database knowledge graph module, and using a large language model to achieve the decomposition and execution of complex tasks.

Benefits of technology

It significantly improves the processing efficiency and accuracy of complex database query tasks, can effectively handle tasks with lengthy, syntax complex and multiple intentions, and ensures the continuity and accuracy of the SQL code generation process.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The present invention discloses a global optimization method for decomposing and executing complex data query tasks, which is based on a tree structure and is implemented using a large language model, including constructing a task decomposition and execution module based on a tree structure: the task tree adopts a tree structure, the root node represents the overall data query task, each child node represents a subtask decomposed from a parent node, and the state of each branch corresponds to the execution state of the corresponding subtask; constructing a task execution self-correction module based on a tree structure: when a subtask fails to execute, quickly locate the faulty child node and the corresponding parent node, and re-execute the faulty node; a lightweight local database knowledge graph module based on a local database and oriented to the basic attributes of the database: extract key information from the table structure of the database, and convert it into a knowledge graph through information combination; the present invention has significant effects and superior performance in processing complex database queries.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of large language models, and in particular to a global optimization method for decomposing and executing complex data query tasks. Background Art

[0002] With the development of large language models (LLMs), traditional databases have evolved from simple information storage and query to more intelligent ones. Currently, researchers are working on enhancing the ability of databases to understand human language (unstructured natural language expressions) instead of structured SQL commands. In addition, they are even expected to infer implicit intentions beyond user speech.

[0003] This research can be traced back to the work of Nitarshan Rajkumar, who proposed a one-step reasoning method to evaluate the ability of LLM to generate SQL query statements from text. His research laid the foundation for further development in this field. Subsequently, the SQL-PaLM and DB-GPT models utilized a small number of hint methods and model fine-tuning, which greatly improved the performance of LLM in generating SQL query statements from text compared to the one-step reasoning method. It is worth noting that industry giants such as Microsoft and OpenAI have also made significant contributions in this field, launching influential products such as Microsoft Copilot and GPT-4.0 Excel table analysis plug-in. Although these studies and products mainly focus on the task of generating SQL query statements from text, they actually pave the way for the development of database intelligence.

[0004] In fact, although Nitarshan Rajkumar's research has proven that LLM is superior to NLP (traditional natural language processing methods) in the task of generating SQL query statements from text, and the above research has made commendable progress in advancing database intelligence, a noteworthy challenge still exists. LLM faces limitations when processing lengthy and complex tasks. The complexity of the task includes three major challenges:

[0005] (1) The input query statement itself may be grammatically complex and difficult to parse:

[0006] First, the sentence "I want to see the average math scores of Chinese girls in Class 2, Grade 3 who are not sick, and only count the part of those aged 9 or above" reflects the above grammatical complexity. The combination of lengthy sentence structure, nested information (A and B and C and D, E, F, G), and multiple qualifiers (average score, math, China, girls, Class 2, Grade 3, not sick, age>9) creates the complexity of this query. It is difficult to handle this problem using one-time prompts or chained task planning methods.

[0007] (2) Even if the syntax of the query statement itself seems simple, the operations behind it may be complex:

[0008] One typical category of this type of task is: tasks with multiple intentions. Although the syntax of the description of these tasks seems simple, their connotations often require the database to perform multiple operations at the same time. For example: "I want to know Xiao Ming's average math scores before and after the third grade." Although this sentence has simple syntax, in order to meet its requirements, the database must perform a series of complex operations as follows:

[0009] 1. Calculate Xiao Ming’s GPA before the third grade;

[0010] 2. Calculate Xiao Ming’s GPA after the third grade;

[0011] 3. Combine the results of the previous two steps into a unified table.

[0012] (3) The input query may be ambiguous and requires more context to infer its true intent:

[0013] Understanding vague or ambiguous statements is a major challenge in natural language processing, especially in database querying. Database query interfaces must be able to discern the user's ambiguous intent and provide the most relevant results based on the provided context.

[0014] For example, the query "I want to see Xiao Ming's highest score in all first-year classes" obviously lacks basic information, that is, which classes Xiao Ming took in the first grade, so GPT cannot generate an accurate response. If you don't know which courses Xiao Ming took in the first grade, it will be difficult for the language model to generate appropriate SQL commands. However, when it is known that Xiao Ming only took math courses in the first grade, the language model can generate accurate SQL commands. Faced with this problem, other projects may require users to provide additional information in order to achieve correct code generation, but this behavior will undoubtedly affect the continuity of the code generation process and reduce the user experience. Ideally, the intelligent database project itself should have the ability to autonomously understand and query database information. If this can be achieved, when the user enters a query request with ambiguous intent again, it can not only simplify the code generation process, but also ensure the continuity of the process and improve the accuracy of the generated SQL code. Summary of the invention

[0015] In order to solve the problems existing in the prior art, the purpose of the present invention is to provide a global optimization method for decomposing and executing complex data query tasks. The present invention has significant effects and superior performance in processing complex database queries.

[0016] To achieve the above purpose, the technical solution adopted by the present invention is: a global optimization method for decomposing and executing complex data query tasks, for complex data query tasks in natural language form, by performing global and traceable tree-like task decomposition on them, a complex database query code that meets the corresponding requirements is obtained; based on the tree structure and using a large language model, it specifically includes the following steps:

[0017] Step 1: Construct a task decomposition and execution module based on a tree structure: The task tree adopts a tree structure. The root node represents the overall data query task, and each child node represents a subtask decomposed from the parent node. The state of each branch corresponds to the execution state of the corresponding subtask.

[0018] Step 2: Build a task execution self-correction module based on a tree structure: When a subtask fails to execute, quickly locate the faulty subnode and the corresponding parent node, and re-execute the faulty node. If a node fails for the second time, its parent task node is re-decomposed to generate new subtask nodes, and the newly generated subtask nodes are executed in sequence without restarting the entire tree-based task execution process;

[0019] Step 3: A lightweight local database knowledge graph module based on the local database and oriented to the basic attributes of the database: extract key information including table name, column name, column data type, primary key, foreign key, etc. from the table structure of the database, and convert it into a knowledge graph through information combination; by providing the knowledge graph information layer by layer to the generative language model, the generative language model is used to obtain accurate database background information.

[0020] As a further improvement of the present invention, in step 1, the process of constructing the task tree specifically includes the following steps:

[0021] Step 1.1: Given a task T1, this module will evaluate its complexity and decide whether to decompose it;

[0022] Step 1.2: If decomposition is not required, declare the current task T1 as a leaf node, denoted as L1;

[0023] Step 1.3: If decomposition is required, this module will decompose T1 into multiple subtasks, which are represented as T according to the order of tasks. 1-1 , T 1-2 , ..., T 1-n ;

[0024] Step 1.4: Subtask T 1-1 , T 1-2 , ..., T 1-n Declare as child nodes, represented by C 1-1 , C 1-2 , ..., C1-n ;

[0025] Step 1.5: For each child node C 1-n , recursively execute steps 1.1 to 1.4 until each subtask tree no longer generates new leaf nodes.

[0026] As a further improvement of the present invention, in step 1, the execution process of the task tree specifically includes the following steps:

[0027] Step 1.6: Get the list of all leaf nodes L of the current task tree, the list of executed leaf nodes F, and the obtained execution results Result tmp (Generated SQL code);

[0028] Step 1.7, according to step 1.6, obtain the list UnL of all unexecuted leaf nodes of the current task tree;

[0029] Step 1.7: According to the current result tmp , execute the first leaf node task UnL1 in UnL;

[0030] Step 1.8: If the execution is successful, execute 1.8.1 to 1.8.3;

[0031] Step 1.8.1, delete UnL1 from UnL;

[0032] Step 1.8.2, add UnL1 to the end of F;

[0033] Step 1.8.3: Overwrite the original Result with the current execution result tmp , and passed to the first leaf node of the current UnL for the execution of the leaf task;

[0034] Step 1.9: If the execution fails, execute the self-correction module of step 2;

[0035] Step 1.10: Recursively execute steps 1.6 to 1.9 until UnL contains no nodes. tmp As the final output, the SQL code generation process is completed;

[0036] As a further improvement of the present invention, the step 2 specifically comprises the following steps:

[0037] Step 2.1: When a subtask fails, locate the current subtask and its parent node and sibling node positions and information;

[0038] Step 2.2, pass the fault information M and the current fault subtask goal into the generative language model, and re-execute the current subtask;

[0039] Step 2.3: If the execution is successful, the execution result of the current node is passed to the next leaf node for the execution of the next leaf task, and the current correction process ends;

[0040] Step 2.4: If the execution fails, execute steps 2.4.1 to 2.4.3;

[0041] Step 2.4.1, transfer the current fault information M to the parent node;

[0042] Step 2.4.2, clear the subtree corresponding to the parent node, including the current node;

[0043] Step 2.4.3: When M is supplemented, execute steps 1.1 to 1.5 of the task decomposition module for the parent node.

[0044] As a further improvement of the present invention, in step 3, the local database knowledge graph construction process is specifically as follows:

[0045] Step 3.1, obtain all table creation commands of the local database, also known as table structure information (Schema);

[0046] Step 3.2, store the table structure information of each table in a local text file in the form of a separate paragraph, denoted as F;

[0047] Step 3.3, use regular expressions to extract all table names from F, and store the table names in list form, denoted as T;

[0048] Step 3.4, traverse each element Tn in T, and repeat steps 3.4.1 to 3.4.3;

[0049] Step 3.4.1, extract the complete table structure information corresponding to Tn from F;

[0050] Step 3.4.2: Use regular expressions to extract the column name, column data type, primary key, and foreign key information corresponding to the table from the table structure information;

[0051] Step 3.4.3, combining the information in step 3.4.2 into triplets according to different categories;

[0052] Step 3.5: Store the triples obtained in step 3.4 in a local text file in the form of text. Completing the local database is just the construction of the graph.

[0053] As a further improvement of the present invention, in step 3, the reasoning process of the database background information is specifically as follows:

[0054] Step 3.6: Extract all table names in the current knowledge graph;

[0055] Step 3.7: Based on the table name, the generative language model selects a list of possible data table names, denoted as T.

[0056] Step 3.8: Extract the column names corresponding to each table in T from the knowledge graph, and use the generative language model to select the columns required to complete the task;

[0057] Step 3.9: Based on the columns selected in step 3.8 and the table selected in step 3.7, combine specific detailed information from the knowledge graph;

[0058] Step 3.10: Send the detailed task-related database information obtained in step 3.9 to the corresponding subtask node, ending the reasoning process of this round of database background information.

[0059] The beneficial effects of the present invention are:

[0060] The present invention adopts a tree-structure-based method and uses a generative large language model to decompose and reorganize complex data query tasks, achieving efficient and accurate text-to-SQL code conversion effects. Extensive experiments on real financial databases have verified the effectiveness and robustness of the present invention in processing complex database query tasks. DETAILED DESCRIPTION

[0061] Example

[0062] A global optimization method for decomposing and executing complex data query tasks is implemented based on a tree structure and using a large language model. Specifically, it includes the following steps:

[0063] Step 1: Construct a task decomposition and execution module based on a tree structure: The task tree adopts a tree structure. The root node represents the overall data query task, and each child node represents a subtask decomposed from the parent node. The state of each branch corresponds to the execution state of the corresponding subtask.

[0064] Step 2: Build a task execution self-correction module based on a tree structure: When a subtask fails to execute, quickly locate the faulty subnode and the corresponding parent node, and re-execute the faulty node. If a node fails for the second time, its parent task node is re-decomposed to generate new subtask nodes, and the newly generated subtask nodes are executed in sequence without restarting the entire tree-based task execution process;

[0065] Step 3: A lightweight local database knowledge graph module based on the local database and oriented to the basic attributes of the database: extract key information including table name, column name, column data type, primary key, foreign key, etc. from the table structure of the database, and convert it into a knowledge graph through information combination; by providing the knowledge graph information layer by layer to the generative language model, the generative language model is used to obtain accurate database background information.

[0066] In step 1, the task tree construction process specifically includes the following steps:

[0067] Step 1.1: Given a task T1, this module will evaluate its complexity and decide whether to decompose it;

[0068] Step 1.2: If decomposition is not required, declare the current task T1 as a leaf node, denoted as L1;

[0069] Step 1.3: If decomposition is required, this module will decompose T1 into multiple subtasks, which are represented as T according to the order of tasks. 1-1 , T 1-2 , ..., T 1-n ;

[0070] Step 1.4: Subtask T 1-1 , T 1-2 , ..., T 1-n Declare as child nodes, represented by C 1-1 , C 1-2 , ..., C 1-n ;

[0071] Step 1.5: For each child node C 1-n , recursively execute steps 1.1 to 1.4 until each subtask tree no longer generates new leaf nodes;

[0072] In step 1, the execution process of the task tree specifically includes the following steps:

[0073] Step 1.6: Get the list of all leaf nodes L of the current task tree, the list of executed leaf nodes F, and the obtained execution results Result tmp (Generated SQL code);

[0074] Step 1.7, according to step 1.6, obtain the list UnL of all unexecuted leaf nodes of the current task tree;

[0075] Step 1.7: According to the current result tmp , execute the first leaf node task UnL1 in UnL;

[0076] Step 1.8: If the execution is successful, execute 1.8.1 to 1.8.3;

[0077] Step 1.8.1, delete UnL1 from UnL;

[0078] Step 1.8.2, add UnL1 to the end of F;

[0079] Step 1.8.3: Overwrite the original Result with the current execution result tmp , and passed to the first leaf node of the current UnL for the execution of the leaf task;

[0080] Step 1.9: If the execution fails, execute the self-correction module of step 2;

[0081] Step 1.10: Recursively execute steps 1.6 to 1.9 until UnL contains no nodes. tmp As the final output, the SQL code generation process is completed;

[0082] The step 2 specifically includes the following steps:

[0083] Step 2.1: When a subtask fails, locate the current subtask and its parent node and sibling node positions and information;

[0084] Step 2.2, pass the fault information M and the current fault subtask goal into the generative language model, and re-execute the current subtask;

[0085] Step 2.3: If the execution is successful, the execution result of the current node is passed to the next leaf node for the execution of the next leaf task, and the current correction process ends;

[0086] Step 2.4: If the execution fails, execute steps 2.4.1 to 2.4.3

[0087] Step 2.4.1, transfer the current fault information M to the parent node;

[0088] Step 2.4.2, clear the subtree corresponding to the parent node, including the current node;

[0089] Step 2.4.3: When M is added, for the parent node, execute steps 1.1 to 1.5 of the task decomposition module;

[0090] In step 3, the local database knowledge graph construction process is as follows:

[0091] Step 3.1, obtain all table creation commands of the local database, also known as table structure information (Schema);

[0092] Step 3.2, store the table structure information of each table in a local text file in the form of a separate paragraph, denoted as F;

[0093] Step 3.3, use regular expressions to extract all table names from F, and store the table names in list form, denoted as T;

[0094] Step 3.4, traverse each element Tn in T, and repeat steps 3.4.1 to 3.4.3;

[0095] Step 3.4.1, extract the complete table structure information corresponding to Tn from F;

[0096] Step 3.4.2: Use regular expressions to extract the column name, column data type, primary key, and foreign key information corresponding to the table from the table structure information;

[0097] Step 3.4.3, combining the information in step 3.4.2 into triplets according to different categories;

[0098] Step 3.5: Store the triples obtained in step 3.4 in a local text file in the form of text. Completing the local database is just the construction of the graph.

[0099] In step 3, the reasoning process of the database background information is as follows:

[0100] Step 3.6: Extract all table names in the current knowledge graph;

[0101] Step 3.7: Based on the table name, the generative language model selects a list of possible data table names, denoted as T.

[0102] Step 3.8: Extract the column names corresponding to each table in T from the knowledge graph, and use the generative language model to select the columns required to complete the task;

[0103] Step 3.9: Based on the columns selected in step 3.8 and the table selected in step 3.7, combine specific detailed information from the knowledge graph;

[0104] Step 3.10: Send the detailed task-related database information obtained in step 3.9 to the corresponding subtask node, ending the reasoning process of this round of database background information;

[0105] The present embodiment is further described below by experiments:

[0106] 1. Experimental setup:

[0107] OpenAI's gpt-3.5-1106-16k API is used to complete various processes in the framework. In addition, a local database containing 26 tables is built (MySQL database is used as an example here). The database contains three types of data: macroeconomic data, microeconomic data, and commodity data. For more details, please see the appendix: The database, table creation command file, test data set, and project code of this embodiment will be open source on GitHub for interested researchers to use:

[0108] 2. Dataset:

[0109] Although this embodiment aims to complete the task of text to SQL, which is also one of the most familiar NLP tasks, it still has many differences from traditional text to SQL research.

[0110] The study of this embodiment prioritizes the needs of ordinary users rather than the needs of SQL engineers. For these users, it is important to obtain data that meets their requirements rather than focusing on elegant or standardized SQL syntax. In addition, it is based on real-world database usage scenarios, where correct syntax is crucial and there may be multiple SQL implementations for the same requirement. Therefore, it is considered more important to evaluate the ability of SQL code to meet user needs than to compare its similarity to standard answers.

[0111] Therefore, in order to evaluate the extent to which the retrieved data meets the user's requirements, a SQL query task dataset was developed. The dataset has four difficulty levels, including elementary, intermediate, advanced, and extra, and each level includes 10 specific data requirements. These difficulty levels have both traditional evaluation criteria (such as the number of data tables involved in a single task) and high-level criteria (such as the clarity of data requirements).

[0112] 3. Evaluation indicators:

[0113] Based on the above reasons, a corresponding necessary and sufficient data framework (N\&S data) is provided for each task. In addition, three indicators are established to evaluate the models and methods from different perspectives. The executable rate evaluates the ability of the model to generate executable code. The pass rate evaluates the ability of the model to solve general problems. The satisfaction rate measures the accuracy of the model in completing the task.

[0114] (1) Executable Rate (ER): This refers to the proportion of executable code in the generated SQL code. It evaluates the model's ability to generate executable code and shows the robustness of the model.

[0115] (2) Pass rate (PR): This metric is used to test whether the generated code can meet the data requirements of the task. It evaluates the comprehensive ability of the model, including understanding the task and generating complex code that meets the requirements. The higher the pass rate, the better the performance of this dimension.

[0116] (3) Cost rate (CR): This is an indicator of how much additional work a test model takes to complete tasks that require the model to generate accurate SQL code. The larger the value, the better the model.

[0117] 4. Baseline model selection:

[0118] In order to make a fair comparison, a set of representative methods are selected as baselines, and they are provided with necessary database information to facilitate the generation of SQL codes.

[0119] (1) The Chain-of-Thought method uses thought chain prompts (step-by-step thinking) to achieve step-by-step reasoning of the language model. It provides task-related database information as background knowledge to improve its performance.

[0120] (2) The ReAct method uses thought chain prompts to generate reasoning trajectories and action plans. To support the operation of this method, a knowledge graph module is integrated as an operation to search for database information.

[0121] (3) Reflexion gives dynamic agents the ability to reflect on themselves. Similar to ReAct, it provides a knowledge graph module to facilitate the search for relevant database information.

[0122] 5. Evaluation results:

[0123] To evaluate the performance of our invention and the baseline frameworks, we evaluate their text-to-data capabilities from three dimensions: robustness (executable rate), effectiveness (pass rate), and accuracy (cost rate). This comprehensive evaluation allows us to measure the effectiveness and efficiency of these frameworks in handling various tasks.

[0124] (1) High robustness

[0125] All methods showed commendable performance on "easy" and "medium" tasks. However, when the tasks became more challenging, other methods struggled to complete the tasks, often failing to generate executable SQL code, even when provided with the most relevant database information. The present invention stood out for its remarkable robustness, consistently generating executable SQL code for even the most difficult tasks.

[0126] (2) Outstanding task understanding and task execution capabilities

[0127] Task understanding and task execution are the key to a language model’s success in completing tasks. Across all difficulty levels, SmarterDB consistently achieves high scores in task understanding and solving skills (PR).

[0128] (3) Lower database costs

[0129] The CR indicator evaluates the additional database resources required by the model to complete the task. The higher the CR, the better the performance. As shown in Table x, compared with other methods, the data extracted by the present invention is very close to the necessary and sufficient data framework (N / &S data). This shows that the present invention can accurately understand the task and perform operations efficiently, thereby reducing database costs and improving data query efficiency.

[0130] 6. Ablation study:

[0131] We conducted an ablation analysis on the three major functional modules in this invention: the tree-based task decomposition framework, the tree bank, and the knowledge graph of the local database. We conducted an in-depth study on the impact of these design choices on SQL code generation in the local database environment. The results are shown in the table:

[0132] (1) The knowledge graph of the local database is crucial to the code generation progress.

[0133] Without the knowledge graph, the ER, PR and CR rates of the present invention will drop sharply in the tests of tasks of various difficulty levels, especially those of medium and high difficulty. This drop is attributed to the limitations of the language model's ability to understand and remember the context when faced with the complete information of all tables. The lack of the knowledge graph leads to the input of a large amount of redundant and useless information, further exacerbating the problems of forgetting and hallucination inherent in the generative language model, leading to errors in the code generation process.

[0134] (2) The tree-based task decomposition framework has shown impressive capabilities in handling difficult tasks.

[0135] Without the task decomposition module, the performance of the present invention only slightly degrades for simpler tasks that can be handled by a single language model. However, for more difficult tasks, the performance degrades significantly. The task decomposition framework solves this problem by decomposing complex tasks that exceed the capabilities of the language model into simpler subtasks, thereby effectively reducing the overall task difficulty.

[0136] (3) The tree traversal module focuses more on improving CR.

[0137] The tree traversal module mainly helps to improve the CR rate, and removing this module leads to a significant decrease in SR. The tree traversal module plays an important role in optimizing the code generation process and enhancing the comprehensive ability of the model.

[0138] In summary, the ablation study reveals the key role of the local database knowledge graph, the effectiveness of the tree-based task decomposition framework in handling complex tasks, and the significance of the tree traversal module in optimizing the code generation process and enhancing the model's task execution capability.

[0139] In this embodiment, a tree-based task decomposition framework is proposed, and the following three contributions are made:

[0140] (1) A tree-based task decomposition framework is introduced to address the limitations of existing methods in the task of generating SQL statements from text. First, as mentioned above, the purpose of mainstream methods such as "small hints" and "model fine-tuning" is to train the language model so that it can complete the SQL generation task in one go. However, when faced with complex tasks that exceed the processing capabilities of the language model, the performance of these methods is often proven to be insufficient. In contrast to traditional methods, the framework of this embodiment chooses to decompose complex tasks. This decomposition method reduces the complexity of the overall task, disperses the cognitive load, and improves the contribution of each agent. In addition, through the tree structure, the task nodes can be traversed (see the next paragraph) to evaluate the growth of each subtask tree. This recursive traversal can be optimized from a global perspective, minimizing the interference between subtasks and reducing overall costs.

[0141] (2) With the help of tree decomposition of complex tasks, the problem of self-correction of the language model can be solved through the tree traversal module. By utilizing the real error report information from the database and the tree structure, the framework can accurately locate the task node failure and rebuild the subtask tree. This self-supervision and self-correction method ensures the successful execution of the entire text-to-data task and enhances the robustness of the framework. Since the research is task-oriented, in the evaluation, unlike the previous comparison of the similarity between the generated SQL and the reference SQL in the field of natural language processing, we established our own test dataset and measurement criteria to evaluate the framework's ability to correctly extract the data required for the current task.

[0142] (3) Finally, the tree decomposition method separates task planning and execution, improving the scalability and flexibility of the framework. With this structure, additional modules can be easily added to the entire framework when necessary. A local database knowledge graph (KG) module is integrated, which can easily convert local database commands into a comprehensive and easy-to-maintain knowledge graph. This module helps to easily retrieve valuable database information from the database, provide necessary relevant information for the language model (LLM), and enhance the language model's understanding of user intent. The integration of the knowledge graph improves adaptability, system performance, and response accuracy, enabling the framework to more effectively handle complex tasks in various database environments.

[0143] Finally, experiments were conducted on a financial database to evaluate the performance of the proposed method. The results show that the proposed method outperforms the state-of-the-art research including Thought Chain Prompt, ReAct, and Reflexion, especially in dealing with complex queries. These findings demonstrate the effectiveness and superiority of the proposed framework in dealing with challenges associated with complex queries and demonstrate its potential for practical applications.

[0144] The above-mentioned embodiments only express the specific implementation of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the scope of the present invention. It should be pointed out that, for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.

Claims

1. A global optimization method for decomposing and executing complex data query tasks, for complex data query tasks in natural language form, by performing global, backtrackable tree-like task decomposition on them, to obtain complex database query codes that meet corresponding requirements; characterized in that: Based on the tree structure and using a large language model, it is implemented in the following steps: Step 1: Construct a task decomposition and execution module based on a tree structure: The task tree adopts a tree structure. The root node represents the overall data query task, and each child node represents a subtask decomposed from the parent node. The state of each branch corresponds to the execution state of the corresponding subtask. Step 2: Construct a task execution self-correction module based on a tree structure: When a subtask fails to execute, quickly locate the faulty child node and the corresponding parent node, and re-execute the faulty node; if a node fails for the second time, re-decompose its parent task node to generate new subtask nodes, and execute the newly generated subtask nodes in sequence without restarting the entire tree-type task execution process; Step 3: A lightweight local database knowledge graph module based on the local database and oriented to the basic attributes of the database: extract key information including table name, column name, column data type, primary key, and foreign key from the table structure of the database, and convert it into a knowledge graph by combining the information; provide the knowledge graph information layer by layer to the generative language model, so as to obtain accurate database background information using the generative language model; In step 3, the local database knowledge graph construction process is as follows: Step 3.1, obtain all table creation commands of the local database, also known as table structure information; Step 3.2, store the table structure information of each table in a local text file in the form of a separate paragraph, denoted as F; Step 3.3, use regular expressions to extract all table names from F, and store the table names in list form, denoted as T; Step 3.4, traverse each element Tn in T, and repeat steps 3.4.1 to 3.4.3; Step 3.4.1, extract the complete table structure information corresponding to Tn from F; Step 3.4.2: Use regular expressions to extract the column name, column data type, primary key, and foreign key information corresponding to the table from the table structure information; Step 3.4.3, combining the information in step 3.4.2 into triplets according to different categories; Step 3.5: Store the triples obtained in step 3.4 in a local text file in the form of text to complete the construction of the local database knowledge graph; In step 3, the reasoning process of the database background information is as follows: Step 3.6: Extract all table names in the current knowledge graph; Step 3.7: Based on the table name, the generative language model selects a list of possible data table names, denoted as S. Step 3.8: Extract the column names corresponding to each table in S from the knowledge graph, and use the generative language model to select the columns required to complete the task; Step 3.9: Based on the columns selected in step 3.8 and the table selected in step 3.7, combine specific detailed information from the knowledge graph; Step 3.10: Send the detailed task-related database information obtained in step 3.9 to the corresponding subtask node, ending the reasoning process of this round of database background information.

2. The global optimization method for decomposing and executing complex data query tasks according to claim 1, characterized in that: In step 1, the task tree construction process specifically includes the following steps: Step 1.1: Given a task T1, this module will evaluate its complexity and decide whether to decompose it; Step 1.2: If decomposition is not required, declare the current task T1 as a leaf node, denoted as L1; Step 1.3: If decomposition is required, this module will decompose T1 into multiple subtasks, which are represented as T according to the order of tasks. 1-1 , T 1-2 , ..., T 1-n ; Step 1.4: Subtask T 1-1 , T 1-2 , ..., T 1-n Declare as child nodes, represented by C 1-1 , C 1-2 , ..., C 1-n ; Step 1.5: For each child node, recursively execute steps 1.1 to 1.4 until each subtask tree no longer generates new leaf nodes.

3. The global optimization method for decomposing and executing complex data query tasks according to claim 2, characterized in that: In step 1, the execution process of the task tree specifically includes the following steps: Step 1.6: Get the list of all leaf nodes L of the current task tree, the list of executed leaf nodes F, and the obtained execution results Result tmp ; Step 1.7, according to step 1.6, obtain the list UnL of all unexecuted leaf nodes of the current task tree; Step 1.7: According to the current result tmp , execute the first leaf node task UnL1 in UnL; Step 1.8: If the execution is successful, execute 1.8.1 to 1.8.3; Step 1.8.1, delete UnL1 from UnL; Step 1.8.2, add UnL1 to the end of F; Step 1.8.3: Overwrite the original Result with the current execution result tmp , and passed to the first leaf node of the current UnL for the execution of the leaf node task; Step 1.9: If the execution fails, execute the self-correction module of step 2; Step 1.10: Recursively execute steps 1.6 to 1.9 until UnL contains no nodes. tmp As the final output, the SQL code generation process is completed.

4. The global optimization method for decomposing and executing complex data query tasks according to claim 3, characterized in that: The step 2 specifically includes the following steps: Step 2.1: When a subtask fails, locate the current subtask and its parent node and sibling node positions and information; Step 2.2, pass the fault information M and the current fault subtask goal into the generative language model, and re-execute the current subtask; Step 2.3: If the execution is successful, the execution result of the current node is passed to the next leaf node for the execution of the next leaf task, and the current correction process ends; Step 2.4: If the execution fails, execute steps 2.4.1 to 2.4.3; Step 2.4.1, transfer the current fault information M to the parent node; Step 2.4.2, clear the subtree corresponding to the parent node, including the current node; Step 2.4.3: When M is supplemented, execute steps 1.1 to 1.5 of the task decomposition module for the parent node.

Citation Information

Patent Citations

  • Method and system for optimizing knowledge graph based on large language model

    CN117271791A

  • Knowledge graph and personalized learning path construction method and system

    CN117952200A