Large model-based sql statement generation method and device
By obtaining user's original problem and database table structure information, decomposing complex problems and generating pattern structures, the accuracy problem of complex query requirements in the existing technology is solved, and the accurate generation and robustness of SQL statements are achieved.
Patent Information
- Application Number
- CN202411120633.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-12-06
AI Technical Summary
The prior art cannot effectively ensure the generation of accurate SQL statements for complex query requirements, rely on rule setting, pre-training knowledge or large amounts of data and computing resources, and may damage the original capabilities of the model.
By obtaining the original user's problem and database table structure information, we gradually query the structure information of the big model, decompose complex problems into simple queries, and use preset modes to generate pattern structures, including table name, field name, field value and foreign key information. And generate SQL query statements based on the problem category.
It realizes accurate generation of complex queries, improves the accuracy and robustness of SQL statements, reduces dependence on a large amount of data and computing resources, and avoids model capability damage.
Smart Images

Figure CN119088824A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information query technology, and in particular to a method and device for generating SQL statements based on a large model. Background Art
[0002] The conversion of natural language into SQL statements is a hotly used field at present. It saves researchers a lot of time in writing and correcting SQL statements, and can convert questions into SQL statements by asking questions directly.
[0003] The current methods for generating SQL statements from natural language mainly include the following: 1. Relying on preset rules for generation. 2. Directly using a large model to construct corresponding prompts to stimulate the emergence of the model and achieve the requirement of generating SQL with higher accuracy. 3. Pre-training the corresponding model with a large amount of data and generating SQL statements through the model. 4. Fine-tuning a certain amount of data to use the downstream task of generating SQL statements.
[0004] However, the first method strongly relies on the setting of rules, and there are currently various complex requirements, and it is difficult to have adapted rules, so it is impossible to guarantee the accurate generation of query statements. The second method relies on the knowledge obtained during the pre-training process, and the knowledge obtained is limited, so for complex query requests, it is also impossible to guarantee the generation of accurate query statements. The third method requires a large amount of task characteristic data and computing resources. If there is no guarantee of a large amount of task characteristic data and computing resources, the accuracy of the generated query statements cannot be guaranteed. The last method may damage the original capabilities of the model when fine-tuning and introducing corresponding knowledge, and thus cannot guarantee the generation of accurate query statements. Therefore, these existing methods perform poorly for more complex query requirements, that is, they cannot effectively guarantee the generation of accurate SQL statements. Summary of the invention
[0005] Based on the above-mentioned deficiencies of the prior art, the present application provides a method and device for generating SQL statements based on a large model to solve the problem that the prior art cannot effectively guarantee the generation of accurate SQL statements.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] The first aspect of the present application provides a method for generating SQL statements based on a large model, comprising:
[0008] Get the user's original question and the corresponding table structure information in the database;
[0009] Based on the original question and the table structure information, four structural information query questions are gradually queried on the large model to obtain the pattern link information of the original question; wherein the pattern link information includes the table name, field name, field value and foreign key information;
[0010] Analyze the category to which the original question belongs;
[0011] If the original question is a simple query, then according to a first preset mode, the pattern structure of the original question is generated by using the information of the database, the original question and its pattern link information; wherein the simple query is a query that operates only on a single table;
[0012] If the original question belongs to a non-nested complex query, then according to the second preset mode, the pattern structure of the original question is generated by using the information of the database, the original temperature and its corresponding pattern link information, and the intermediate information; wherein the intermediate information is the information generated by the large model and guides the connection of multiple tables; the non-nested complex query is a query that connects multiple tables but does not contain a subquery;
[0013] If the original question is a nested complex query, then according to the third preset mode, the pattern structure of the original question is generated by using the information of the database, the original question and its corresponding pattern link information, intermediate information, each sub-question and its answer; wherein each sub-question is constructed based on the original question; the answer to each sub-question is obtained by processing the large model; the nested complex query is a query containing sub-queries or set operations;
[0014] By analyzing the pattern structure of the large model based on the original question, the SQL query statement of the original question is obtained.
[0015] Optionally, in the above-mentioned SQL statement generation method based on the big model, based on the original question and the table structure information, four structural information query questions are gradually queried on the big model to obtain the pattern link information of the original question, including:
[0016] Based on the original question, the table structure information and the information inquiry prompt, the name of the table queried by the large model is inquired to obtain the table name corresponding to the original question; wherein the information inquiry prompt is a prompt generated by multiple question inquiry sample data;
[0017] Based on the table structure information, the original question and its corresponding table name, and the information query prompt, the name of the field queried by the large model is inquired to obtain the field name corresponding to the original question;
[0018] Based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, the value of the field queried by the large model is inquired to obtain the field value corresponding to the original question;
[0019] Based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, the foreign key relationship between the tables queried by the large model is inquired to obtain the foreign key information corresponding to the original question.
[0020] Optionally, in the above-mentioned SQL statement generation method based on the large model, it also includes:
[0021] Construct multiple information inquiry prompts that include questions, model thinking processes, and sample answers;
[0022] Scramble each step node in the model thinking process in each of the information query prompts to obtain a new information query prompt;
[0023] According to the preset probability, the step nodes in the model thinking process in the new information query prompt are randomly discarded to obtain the final information query prompt.
[0024] Optionally, in the above-mentioned SQL statement generation method based on a large model, the step of generating a pattern structure of the original question by using information of the database, the original question and its pattern link information according to the first preset pattern includes:
[0025] The information of the database is sequentially concatenated with a plurality of simple query sample data to obtain a prompt of the simple query; wherein one of the simple query sample data includes a sample question, pattern link information of the sample question, and a SQL query statement of the sample question;
[0026] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the simple query to obtain the pattern structure of the original question.
[0027] Optionally, in the above-mentioned SQL statement generation method based on the large model, the second preset mode is used to generate the model structure of the original question by using the information of the database, the original temperature and its corresponding model link information and intermediate information, including:
[0028] The information of the database is sequentially concatenated with a plurality of non-nested complex query sample data to obtain a prompt of the non-nested complex query; wherein one non-nested complex query sample data includes a sample question, pattern link information of the sample question, intermediate information of the sample question, and a SQL query statement of the sample question;
[0029] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the non-nested complex query;
[0030] The large model analyzes the intermediate information of the original question based on the prompt of the non-nested complex query, and splices the intermediate information of the original question into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0031] Optionally, in the above-mentioned SQL statement generation method based on the big model, the pattern structure of the original question is generated according to the third preset pattern by using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer, including:
[0032] The information of the database and a plurality of nested complex query sample data are sequentially spliced to obtain the prompt of the nested complex query; wherein one nested complex query sample data includes a sample question, pattern link information of the sample question, each sub-question of the sample question and the answer to the sub-question, intermediate information of the sample question, and a SQL query statement of the sample question;
[0033] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the nested complex query;
[0034] By using the large model to split the original question into multiple sub-questions based on the nested complex query prompt, the large model is queried to obtain answers to the sub-questions of the original question, and intermediate information of the original question is analyzed;
[0035] The multiple sub-questions of the original question and their answers, and the intermediate information of the original question are spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0036] Optionally, in the above-mentioned SQL statement generation method based on a large model, before sequentially concatenating the database information with a plurality of nested complex query sample data to obtain the prompt of the nested complex query, the method further includes:
[0037] Constructing a plurality of initial nested complex query sample data;
[0038] Randomly selecting a plurality of the nested complex query sample data from each of the initial nested complex query sample data, and selecting a plurality of the nested complex query sample data that are most similar to the original question;
[0039] The selected nested complex query sample data are shuffled to obtain the final nested complex query sample data.
[0040] Optionally, in the above-mentioned method for generating SQL statements based on a large model, after obtaining the SQL query statement of the original question by analyzing the pattern structure of the large model based on the original question, the method further includes:
[0041] Generate a first correction prompt using the original question, the data table structure, the SQL query statement of the original question, and a question modification requirement; wherein the question modification requirement is used to require modification of all questions in the SQL query statement;
[0042] The large model is used to obtain a calibrated SQL query statement for the original question based on the first correction prompt.
[0043] Optionally, in the above-mentioned method for generating SQL statements based on a large model, after obtaining the SQL query statement of the original question by analyzing the pattern structure of the large model based on the original question, the method further includes:
[0044] Generate a second correction prompt using the original question, the data table structure, the SQL query statement of the original question, and the modification suggestion;
[0045] Based on the second correction prompt, the large model is used to obtain a calibrated SQL query statement for the original question.
[0046] The second aspect of the present application provides a SQL statement generation device based on a large model, comprising:
[0047] An acquisition unit, used to obtain the user's original question and the corresponding table structure information in the database;
[0048] A step-by-step matching unit, configured to query the large model with four structural information query questions step by step based on the original question and the table structure information, and obtain the pattern link information of the original question; wherein the pattern link information includes the table name, field name, field value and foreign key information;
[0049] A classification unit, used for analyzing the category to which the original question belongs;
[0050] A first generating unit is used to generate a pattern structure of the original question according to a first preset pattern by using information of the database, the original question and pattern link information thereof when the original question belongs to a simple query; wherein the simple query is a query that operates only on a single table;
[0051] A second generating unit is used to generate a pattern structure of the original question according to a second preset mode by using the information of the database, the original temperature and its corresponding pattern link information, and intermediate information when the original question belongs to a non-nested complex query; wherein the intermediate information is information generated by the large model to guide multi-table connection; the non-nested complex query is a query that connects multiple tables but does not contain a subquery;
[0052] A third generating unit is used to generate a pattern structure of the original question according to a third preset mode by using information of the database, the original question and its corresponding pattern link information, intermediate information, each sub-question and its answer when the original question is a nested complex query; wherein each sub-question is constructed based on the original question; the answer to each sub-question is obtained by processing the large model; and the nested complex query is a query containing a sub-query or a set operation;
[0053] The analyzing unit is used to analyze the large model based on the pattern structure of the original question to obtain the SQL query statement of the original question.
[0054] Optionally, in the above-mentioned SQL statement generation device based on the large model, the step-by-step matching unit includes:
[0055] A first matching unit is used to inquire the table name queried by the large model based on the original question, the table structure information and the information inquiry prompt, and obtain the table name corresponding to the original question; wherein the information inquiry prompt is a prompt generated by multiple question inquiry sample data;
[0056] A second matching unit is used to inquire the field name queried by the large model based on the table structure information, the original question and its corresponding table name, and the information query prompt, to obtain the field name corresponding to the original question;
[0057] A third matching unit is used to inquire about the value of the field queried by the large model based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information inquiry prompt, so as to obtain the field value corresponding to the original question;
[0058] The fourth matching unit is used to inquire about the foreign key relationship between the tables queried by the large model based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, so as to obtain the foreign key information corresponding to the original question.
[0059] Optionally, in the above-mentioned SQL statement generation device based on the large model, it also includes:
[0060] A first construction unit is used to construct a plurality of information inquiry prompts including questions, model thinking processes and sample answers;
[0061] A first scrambling unit is used to scramble each step node in the model thinking process in each of the information query prompts to obtain a new information query prompt;
[0062] The discarding unit is used to randomly discard the step nodes in the model thinking process in the new information query prompt according to a preset probability to obtain the final information query prompt.
[0063] Optionally, in the above-mentioned SQL statement generation device based on the big model, when the first generation unit executes the step of generating the pattern structure of the original question according to the first preset pattern by using the information of the database, the original question and its pattern link information, it is used to:
[0064] The information of the database is sequentially concatenated with a plurality of simple query sample data to obtain a prompt of the simple query; wherein one of the simple query sample data includes a sample question, pattern link information of the sample question, and a SQL query statement of the sample question;
[0065] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the simple query to obtain the pattern structure of the original question.
[0066] Optionally, in the above-mentioned SQL statement generation device based on the large model, when the second generation unit executes the step of generating the pattern structure of the original question according to the second preset mode by using the information of the database, the original temperature and its corresponding pattern link information and intermediate information, it is used to:
[0067] The information of the database is sequentially concatenated with a plurality of non-nested complex query sample data to obtain a prompt of the non-nested complex query; wherein one non-nested complex query sample data includes a sample question, pattern link information of the sample question, intermediate information of the sample question, and a SQL query statement of the sample question;
[0068] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the non-nested complex query;
[0069] The large model analyzes the intermediate information of the original question based on the prompt of the non-nested complex query, and splices the intermediate information of the original question into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0070] Optionally, in the above-mentioned SQL statement generation device based on the big model, when the third generation unit executes the step of generating the pattern structure of the original question according to the third preset pattern by using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer, it is used to:
[0071] The information of the database and a plurality of nested complex query sample data are sequentially spliced to obtain the prompt of the nested complex query; wherein one nested complex query sample data includes a sample question, pattern link information of the sample question, each sub-question of the sample question and the answer to the sub-question, intermediate information of the sample question, and a SQL query statement of the sample question;
[0072] The original question and its pattern link information are sequentially concatenated at the end of the prompt of the nested complex query;
[0073] By using the large model to split the original question into multiple sub-questions based on the nested complex query prompt, the large model is queried to obtain answers to the sub-questions of the original question, and intermediate information of the original question is analyzed;
[0074] The multiple sub-questions of the original question and their answers, and the intermediate information of the original question are spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0075] Optionally, in the above-mentioned SQL statement generation device based on the large model, it also includes:
[0076] A second construction unit is used to construct a plurality of initial nested complex query sample data;
[0077] A first selection unit is used to randomly select a plurality of the nested complex query sample data from each of the initial nested complex query sample data, and select a plurality of the nested complex query sample data that are most similar to the original question;
[0078] The second selection unit is used to shuffle the selected nested complex query sample data to obtain the final nested complex query sample data.
[0079] Optionally, in the above-mentioned SQL statement generation device based on the large model, it also includes:
[0080] A first correction prompt generating unit is used to generate a first correction prompt by using the original question, the data table structure, the SQL query statement of the original question and the question modification requirement; wherein the question modification requirement is used to require modification of all questions in the SQL query statement;
[0081] The first correction unit is used to obtain a calibrated SQL query statement for the original question based on the first correction prompt through the large model.
[0082] Optionally, in the above-mentioned SQL statement generation device based on the large model, it also includes:
[0083] A second correction prompt generating unit, configured to generate a second correction prompt by using the original question, the data table structure, the SQL query statement of the original question and the modification suggestion;
[0084] The second correction unit is used to obtain a calibrated SQL query statement for the original question based on the second correction prompt through the large model.
[0085] The present application provides a method for generating SQL statements based on a large model, which obtains the original question of the user and the corresponding table structure information in the database, and based on the original question and the table structure information, gradually inquires the large model about four structural information query questions to obtain the pattern link information of the original question. Among them, the pattern link information includes table name, field name, field value and foreign key information, so as to decompose the complex question into multiple simple query questions, and then accurately obtain the relevant information of the complex question, so that the SQL statement can be generated more accurately based on this information. Then analyze the category to which the original question belongs, so as to be able to analyze the category to which the original question belongs in a targeted manner, so as to be able to generate the corresponding SQL query statement more accurately. Specifically, if the original question belongs to a simple query, then according to the first preset mode, the pattern structure of the original question is generated using the information of the database, the original question and its pattern link information. Among them, the simple query is a query that only operates on a single table. If the original question belongs to a non-nested complex query, then according to the second preset mode, the pattern structure of the original question is generated using the information of the database, the original temperature and its corresponding pattern link information, and the intermediate information. Among them, the intermediate information is the information generated by the large model to guide the connection of multiple tables. A non-nested complex query is a query that connects multiple tables but does not contain a subquery. If the original question is a nested complex query, the pattern structure of the original question is generated according to the third preset mode using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer. Among them, each sub-question is constructed based on the original question. The answer to each sub-question is obtained by processing the large model. A nested complex query is a query that contains subqueries or set operations. Finally, by analyzing the pattern structure of the large model based on the original question, the sql query statement of the original question is obtained, thereby realizing a method for accurately generating sql query statements based on the large model. BRIEF DESCRIPTION OF THE DRAWINGS
[0086] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0087] Figure 1 A flowchart of a method for generating SQL statements based on a large model provided in an embodiment of the present application;
[0088] Figure 2 A flowchart of a method for gradually performing four structural information query questions on a large model based on the original question and table structure information provided in an embodiment of the present application;
[0089] Figure 3 A flowchart of a method for generating an information query prompt provided in an embodiment of the present application;
[0090] Figure 4 A flowchart of a method for generating a pattern of a simple query question provided in an embodiment of the present application;
[0091] Figure 5 A flowchart of a method for generating a pattern of a non-nested complex query question provided in an embodiment of the present application;
[0092] Figure 6 A flowchart of a method for generating a pattern of nested complex query questions provided in an embodiment of the present application;
[0093] Figure 7 A flowchart of a method for screening prompt information provided in an embodiment of the present application;
[0094] Figure 8 A schematic diagram of the architecture of a large model-based SQL statement generation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0095] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0096] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0097] The present application embodiment provides a method for generating SQL statements based on a large model, such as Figure 1 As shown, including:
[0098] S101. Obtain the user's original question and the corresponding table structure information in the database.
[0099] The database is the database where the data to be queried by the user's original question is located. The corresponding table structure in the obtained database includes the name of each table, the name of each field in the table, the field type, and primary and foreign key information, so that the next step is to obtain the model link information of the original question from this information.
[0100] S102. Based on the original question and the table structure information, four structural information query questions are gradually queried on the large model to obtain the pattern link information of the original question.
[0101] The schema link information includes table name, field name, field value, and foreign key information. The field name is the name of a certain type of field, and the field value is a specific field. For example, "name" is a field name, and "Zhang San" is a value under the field. Through these two, you can further query the relevant information about Zhang San, and get the answer to the original question.
[0102] It should be noted that, considering that the original question may be relatively complex, the accuracy of the query statement of the large model generated directly through the large model is low. Therefore, in the embodiment of the present application, the original question is first split into multiple smaller simple questions, so that the relevant information of the table structure to be queried in the process of querying the original question can be accurately obtained through each smaller simple question, and then based on these relevant information, the query statement of the entire original question is further generated.
[0103] Specifically, we decompose four structural information questions and ask the big model, which then answers the four structural information questions to obtain the table name, field name, field value, and foreign key information. Since the fields are in the table, we need to determine the table name before we can more accurately determine the field name, and after determining the field name, we can get the corresponding field value and foreign key information. Therefore, these four questions need to be gradually decomposed into one question, and after the big model answers the question, we can further construct the next question and ask it based on the content of the answer, so as to finally obtain various information.
[0104] Optionally, in the embodiment of the present application, a specific implementation of step S102 is as follows: Figure 2 As shown, including:
[0105] S201. Based on the original question, table structure information and information query prompts, the name of the table queried by the large model is inquired to obtain the table name corresponding to the original question.
[0106] The information inquiry prompt is a prompt generated by asking multiple questions about sample data.
[0107] It should be noted that in order to allow the large model to know how to determine the corresponding question based on the original question, and determine the answer to the question from the table structure information, that is, to obtain the table name, field name, field value and foreign key information. Therefore, in the embodiment of the present application, it is necessary to construct a series of sample data as prompts to stimulate the ability of the large model to disassemble the problem. Among them, each sample data constructed requires to take the user question as the starting point, the information to be generated as the final goal, and the intermediate thinking process must be fully output. That is, each sample data needs to include user questions and model thinking processes, so that the large model can split the original question according to the thinking process according to the prompts of these sample data and reply to it, and obtain the answers to each question. Therefore, in the embodiment of the present application, steps S201 to S204 are all implemented by corresponding prompts, but the sample of each prompt needs to include the entire complete thinking process from input to output.
[0108] Optionally, in another embodiment of the present application, a method for generating an information query prompt is improved, such as Figure 3 As shown, including:
[0109] S301, construct multiple information inquiry prompts including questions, model thinking processes and answer samples.
[0110] S302: Scramble the various step nodes in the model thinking process in each information query prompt to obtain a new information query prompt.
[0111] It should be noted that, considering that the information inquiry prompt constructed directly, that is, the prompt constructed in step S301 is static, there is a problem that when completing the same task, such as asking for the table name involved in the question, the prompt constructed for different questions is the same. In this way, the model may be relatively rigid, and the things learned are relatively simple and not robust enough.
[0112] Therefore, in the embodiment of the present application, a "COT ensemble" strategy is adopted to shuffle the step nodes of the thinking process in the chain of thought (COT) in the prompt. Specifically, a container set containing each step node of the COT is constructed, and each time the evolution data or model answer is generated, each step node in the container set is randomly shuffled and a new prompt is regenerated, so that the generated prompt is guaranteed to be inconsistent, thereby increasing the stability of the model.
[0113] S303: randomly discard the step nodes in the model thinking process in the new information query prompt according to the preset probability to obtain the final information query prompt.
[0114] Similarly, in order to further increase the robustness of the model, "COTdropout" is also used in the embodiment of the present application. Specifically, the thinking process after the disruption of step S202 is randomly discarded with a certain probability p, or a part of the thinking process is retained with a certain probability (1-p). Among them, the larger the probability value p is designed to be, the greater the probability of discarding the thinking process. The smaller the design, the greater the probability of retaining the thinking process. In the extreme case, when p is 1, the entire thinking process is discarded, and prompt becomes a sample without cot (few-shot). When p=0, it degenerates to the result of step S302, that is, no processing is performed on the result in step S302.
[0115] S202. Based on the table structure information, the original question and its corresponding table name, and the information query prompt, the field name queried by the large model is inquired to obtain the field name corresponding to the original question.
[0116] S203. Based on the table structure information, the original question and its corresponding table name and field name, and the information query prompt, the value of the field queried by the large model is inquired to obtain the field value corresponding to the original question.
[0117] S204. Based on the table structure information, the original question and its corresponding table name and corresponding field name, and information query prompt, inquire about the foreign key relationship between the tables queried by the large model to obtain the foreign key information corresponding to the original question.
[0118] It should be noted that the specific implementation method of steps S202 to 204 is consistent with that of step S201 , and thus will not be described in detail.
[0119] S103. Analyze the category to which the original question belongs.
[0120] It should be noted that since different types of questions have different difficulty levels and different analysis ideas, if the pattern link information of the original question is obtained and directly used to generate SQL statements for the big model, the big model will analyze in a related way, so the accuracy of the generated statements cannot be guaranteed. Therefore, in the embodiment of the present application, the category to which the original question belongs is first analyzed, and then the SQL statement of the original question is generated in a targeted manner according to the category of the original question.
[0121] Specifically, in the embodiments of the present application, the categories of questions include: simple query, non-nested complex query and nested complex query. Among them, a simple query is a query that operates only on a single table, that is, the corresponding result can be queried from only one table. A non-nested complex query is a query that connects multiple tables but does not contain a subquery, that is, the query process involves multiple tables, but only includes one query. A nested complex query is a query that contains subqueries or set operations.
[0122] Optionally, the category to which the original question belongs can also be analyzed by using a series of corresponding prompts containing COT samples (few-show) constructed based on the large model. In addition, the prompt generation method can also be completed by using the "COT ensemble" strategy and "COT dropout" strategy mentioned in the above method embodiment.
[0123] S104: Determine whether the original question is a simple query.
[0124] If the original question is a simple query, then step S105 is executed. If the original question is not a simple query, then step S106 is executed.
[0125] S105. According to the first preset mode, the model structure of the original question is generated by using the information of the database, the original question and its model link information.
[0126] The first preset mode is a mode composed of table structure information, question and mode link information. Since it is only a query involving a single table, only the table structure information, question and mode link information are needed to accurately obtain the SQL query statement of the original question.
[0127] Optionally, in another embodiment of the present application, a specific implementation of step S105 is as follows: Figure 4 As shown, including:
[0128] S401, sequentially concatenate the information in the database with a plurality of simple query sample data to obtain a prompt for a simple query.
[0129] A simple query sample data includes a sample question, pattern link information of the sample question and a SQL query statement of the sample question.
[0130] S402: The original question and its pattern link information are sequentially concatenated at the end of the prompt of the simple query to obtain the pattern structure of the original question.
[0131] It should be noted that in order to allow the big model to know how to generate the corresponding sql query statement based on the table structure information, the question and its pattern link, in the embodiment of the present application, when generating the sql query statement, it is also necessary to build the corresponding prompt based on multiple samples and provide it to the big model. Therefore, multiple simple query sample data are constructed, each simple query sample data includes a sample question, the pattern link information of the sample question and the sql query statement of the sample question, and each simple query sample data is spliced, and finally spliced with the original question and its pattern link information, so as to construct a pattern structure data, which is provided to the big model for analysis, so that the big model can analyze the sql statement of the original question according to the sample in the pattern. Therefore, in the embodiment of the present application, the first preset pattern can be expressed as: <D,Q j , S j , A j >. Where D is the information of the database to be queried, which can be the name of the database; Q j is the jth question; S j A is the pattern link information for the jth question; j is the SQL query statement for the jth question.
[0132] S106: Determine whether the original question belongs to a non-nested complex query.
[0133] If the original question is a non-nested complex query, step S107 is executed. If the original question is not a non-nested complex query, since it is not a simple query either, it is a nested complex query, so step S108 is executed at this time. That is, when the original question is a simple query, step S105 is executed, when the original question is a non-nested complex query, step S107 is executed, and when the original question is a nested complex query, step S108 is executed.
[0134] S107. According to the second preset mode, the model structure of the original question is generated by using the information of the database, the original temperature and its corresponding model link information and intermediate information.
[0135] The intermediate information is generated by the large model to guide the multi-table connection. Since non-nested complex queries need to involve the connection of multiple tables, and multi-table connection is a place where large models are prone to make mistakes, a central information is added accordingly to remind the model that this problem requires table connection.
[0136] Optionally, in another embodiment of the present application, a specific implementation of step S107 is as follows: Figure 5 As shown, the following steps are included:
[0137] S501: sequentially concatenate the information in the database with a plurality of non-nested complex query sample data to obtain a prompt of the non-nested complex query.
[0138] A non-nested complex query sample data includes a sample question, pattern link information of the sample question, intermediate information of the sample question and a SQL query statement of the sample question.
[0139] S502: The original question and its pattern link information are sequentially concatenated at the end of the prompt of the non-nested complex query.
[0140] S503. Analyze the intermediate information of the original question through the large model based on the prompt of the non-nested complex query, and splice the intermediate information of the original question into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0141] Specifically, the second preset mode is <D,Q j , S j , I j , A j >. Among them, I j is the intermediate information of the jth question. Therefore, compared with the simple query mode, it has one more intermediate information. This allows the model to obtain the final correct answer through the guidance of the intermediate steps. For example:
[0142] Q j : "Find the name and building of the department with the highest budget".
[0143] S j :[department.budget,department.dept_name,department.building].
[0144] I j : Let's think about it step by step. For the SQL of this problem, we need to join some tables. First, create an intermediate representation, and then use it to construct the SQL query.
[0145] Intermediate representation: select department.dept_name,department.building fromdepartment orderby department.budget desc limit 1.
[0146] A j: SELECT dept_name, building FROM department ORDER BY budget DESCLIMIT 1.
[0147] Optionally, the construction of the intermediate information can also be completed by constructing multiple series of few-show prompts containing cot through the strategy provided above.
[0148] S108. According to the third preset mode, the pattern structure of the original question is generated by using the information in the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer.
[0149] Each sub-question is constructed based on the original question, and the answer to each sub-question is processed by the big model.
[0150] Since nested complex query questions contain multiple sub-questions, it is necessary to first construct sub-questions based on the original question, and then respond to each sub-question through a large model to obtain the answer to each sub-question. In this way, the final answer to the original question can be analyzed based on the answers to each sub-question.
[0151] Optionally, in another embodiment of the present application, a specific implementation of step S108 is as follows: Figure 6 As shown, the following steps are included:
[0152] S601: sequentially concatenate the information in the database with a plurality of nested complex query sample data to obtain a prompt of the nested complex query.
[0153] A nested complex query sample data includes a sample question, pattern link information of the sample question, each sub-question of the sample question and the answer of the sub-question, intermediate information of the sample question, and SQL query statement of the sample question.
[0154] S602: The original question and its pattern link information are sequentially concatenated at the end of the prompt of the nested complex query.
[0155] S603, using the big model to query the prompt based on the nested complex query, split the original question into multiple sub-questions, obtain answers to the sub-questions of the original question, and analyze the intermediate information of the original question.
[0156] S604: Multiple sub-questions of the original question and their answers, and the intermediate information of the original question are spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0157] Specifically, in the embodiment of the present application, the third preset mode is <D,Qj , S j , j1 , A j1 , …, Q jn , A jn >I j , A j >. Among them, Q ji and A ji The ith sub-problem of the jth problem and the answer to the sub-problem, i.e., the SQL query statement of the sub-problem, is added compared to the second preset mode. Through this mode, simple sub-problems can be gradually solved, thereby solving the final complex problem.
[0158] Among them, each sub-question and its answer can be obtained by the above-mentioned step-by-step decomposition inquiry method. By constructing a prompt containing several examples of question decomposition to guide the large model to conduct self-questioning and learning, the large model can autonomously split the user's questions, autonomously answer the split questions, and finally obtain the correct answer.
[0159] Optionally, since these types of questions are too complex, in order to better generate the final SQL statement, the present invention also introduces a "shot sample" strategy in nested complex queries. When processing nested complex queries, it is necessary to construct several prompts from user questions to SQL query statements. Among them, each sample contains the thinking process of problem decomposition. The "shot sample" strategy is to determine whether each sample is presented in the final prompt, that is, to filter the samples. The initial prompt will have a batch of samples, and these matching samples are the same in each prompt, and these samples are not all related to the user's question, so these samples are actually not conducive to the model answer. For this reason, a method for screening prompt information is provided in an embodiment of the present application to screen out some samples to form the prompt of the nested complex query.
[0160] like Figure 7 As shown, a method for screening prompt information provided in an embodiment of the present application includes the following steps:
[0161] S701. Construct multiple initial nested complex query sample data.
[0162] S702: Randomly select multiple nested complex query sample data from each initial nested complex query sample data, and select multiple nested complex query sample data that are most similar to the original question.
[0163] That is to say, in the embodiment provided in the present application, rendering is performed by random sampling, which may be to create a list container, put a constructed sample set containing the thinking process of problem decomposition into the container, and when generating the final prompt, randomly select K samples based on the container for combination.
[0164] S703: shuffle the selected nested complex query sample data to obtain final nested complex query sample data.
[0165] Specifically, you can create a list container and put the constructed sample set containing the thought process of problem decomposition into the container. Then you need to introduce a vectorized large model based on vector embedding technology, transform each sample in the container into a vector, and construct a vector database. At the same time, you also need to vectorize the user's question, and finally retrieve the K samples that are most similar to the user's question based on the vector database.
[0166] S109. By analyzing the pattern structure of the large model based on the original question, the SQL query statement of the original question is obtained.
[0167] Optionally, since the SQL query statement of the original question is based on the self-decomposition learning answer of the large model, the final answer may have problems. The most common ones are missing or redundant keywords such as DESC, DISTINCT and aggregate functions.
[0168] Therefore, in another embodiment, when executing step S109, self-calibration is also required. Optionally, a calibration method provided in an embodiment of the present application includes:
[0169] The first correction prompt is generated by using the original question, the data table structure, the SQL query statement of the original question and the question modification requirements, and the SQL query statement of the original question is calibrated through the large model based on the first correction prompt to obtain the SQL query statement of the original question.
[0170] The question modification request is used to request modification of all questions in the SQL query statement. That is, in the embodiment of the present application, assuming that the SQL query statement of the original question obtained by the above method has problems, a prompt needs to be constructed to allow the large model to find and modify the problems therein, thereby achieving self-correction.
[0171] Optionally, another embodiment of the present application provides another calibration method, including:
[0172] The second correction prompt is generated by using the original question, data table structure, SQL query statement of the original question and modification suggestions, and the SQL query statement of the original question is calibrated through the large model based on the second correction prompt to obtain the SQL query statement of the original question.
[0173] That is to say, in the embodiment of the present application, the authenticity of the final SQL is not assumed, but some modification suggestions and guidance are given to guide the direction of model modification, which is also completed by constructing prompts. When constructing prompts, it is necessary to tell the big model some modification suggestions, such as: use the database values mentioned accurately in the question, pay attention to the correctness of the fields in the table connection, check keywords such as DESC and DISTINCT, check the fields in GROUP BY, check the fields in SELECT, etc.
[0174] The embodiment of the present application provides a method for generating SQL statements based on a large model, which obtains the original question of the user and the corresponding table structure information in the database, and based on the original question and the table structure information, gradually inquires the large model with four structural information query questions to obtain the pattern link information of the original question. Among them, the pattern link information includes table name, field name, field value and foreign key information, so as to decompose the complex question into multiple simple query questions, and then accurately obtain the relevant information of the complex question, so that the SQL statement can be generated more accurately based on this information. Then analyze the category to which the original question belongs, so as to be able to analyze the category to which the original question belongs in a targeted manner, so as to be able to generate the corresponding SQL query statement more accurately. Specifically, if the original question belongs to a simple query, then according to the first preset mode, the pattern structure of the original question is generated using the information of the database, the original question and its pattern link information. Among them, the simple query is a query that only operates on a single table. If the original question belongs to a non-nested complex query, then according to the second preset mode, the pattern structure of the original question is generated using the information of the database, the original temperature and its corresponding pattern link information, and the intermediate information. Among them, the intermediate information is the information generated by the large model to guide the connection of multiple tables. A non-nested complex query is a query that connects multiple tables but does not contain a subquery. If the original question is a nested complex query, the pattern structure of the original question is generated according to the third preset mode using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer. Among them, each sub-question is constructed based on the original question. The answer to each sub-question is obtained by processing the large model. A nested complex query is a query that contains subqueries or set operations. Finally, by analyzing the pattern structure of the large model based on the original question, the sql query statement of the original question is obtained, thereby realizing a method for accurately generating sql query statements based on the large model.
[0175] Another embodiment of the present application provides a sql statement generation device based on a large model, such as Figure 8 As shown, including:
[0176] The acquisition unit 801 is used to acquire the original question of the user and the corresponding table structure information in the database.
[0177] The step-by-step matching unit 802 is used to query the large model with four structural information query questions based on the original question and the table structure information, and obtain the pattern link information of the original question, wherein the pattern link information includes the table name, field name, field value and foreign key information.
[0178] The classification unit 803 is used to analyze the category to which the original question belongs.
[0179] The first generating unit 804 is used to generate the pattern structure of the original question according to the first preset pattern by using the information of the database, the original question and its pattern link information when the original question is a simple query. The simple query is a query that operates only on a single table.
[0180] The second generation unit 805 is used to generate the pattern structure of the original question according to the second preset mode by using the information of the database, the original temperature and its corresponding pattern link information and the intermediate information when the original question belongs to a non-nested complex query. The intermediate information is information generated by the large model to guide the connection of multiple tables. The non-nested complex query is a query that connects multiple tables but does not contain a subquery.
[0181] The third generating unit 806 is used to generate the pattern structure of the original question according to the third preset mode by using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer when the original question is a nested complex query. Each sub-question is constructed based on the original question. The answer to each sub-question is obtained by processing the large model. The nested complex query is a query containing sub-queries or set operations.
[0182] The analyzing unit 807 is used to obtain the SQL query statement of the original question by analyzing the pattern structure of the large model based on the original question.
[0183] Optionally, in the SQL statement generation device based on the large model provided in another embodiment of the present application, the step-by-step matching unit includes:
[0184] The first matching unit is used to inquire the table name queried by the large model based on the original question, the table structure information and the information inquiry prompt to obtain the table name corresponding to the original question. The information inquiry prompt is a prompt generated by multiple question inquiry sample data.
[0185] The second matching unit is used to inquire the field name queried by the large model based on the table structure information, the original question and its corresponding table name, and the information query prompt to obtain the field name corresponding to the original question.
[0186] The third matching unit is used to inquire the value of the field queried by the large model based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, so as to obtain the field value corresponding to the original question.
[0187] The fourth matching unit is used to inquire about the foreign key relationship between the tables queried by the large model based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, and obtain the foreign key information corresponding to the original question.
[0188] Optionally, in another embodiment of the present application, the SQL statement generation device based on the large model further includes:
[0189] The first construction unit is used to construct a plurality of information inquiry prompts including questions, model thinking processes and answer samples.
[0190] The first scrambling unit is used to scramble each step node in the model thinking process in each information query prompt to obtain a new information query prompt.
[0191] The discarding unit is used to randomly discard the step nodes in the model thinking process in the new information query prompt according to a preset probability to obtain the final information query prompt.
[0192] Optionally, in the SQL statement generation device based on the big model provided in another embodiment of the present application, when the first generation unit generates the pattern structure of the original question according to the first preset pattern by using the information of the database, the original question and its pattern link information, it is used to:
[0193] The information of the database is sequentially concatenated with a plurality of simple query sample data to obtain a simple query prompt, wherein a simple query sample data includes a sample question, pattern link information of the sample question, and a SQL query statement of the sample question.
[0194] The original question and its pattern link information are sequentially concatenated at the end of the simple query prompt to obtain the pattern structure of the original question.
[0195] Optionally, in the SQL statement generation device based on the large model provided in another embodiment of the present application, when the second generation unit generates the pattern structure of the original question according to the second preset mode, using the information of the database, the original temperature and its corresponding pattern link information and intermediate information, it is used to:
[0196] The database information and multiple non-nested complex query sample data are sequentially spliced to obtain the prompt of the non-nested complex query. Among them, a non-nested complex query sample data includes a sample question, pattern link information of the sample question, intermediate information of the sample question and SQL query statement of the sample question.
[0197] Concatenate the original question and its pattern link information at the end of the prompt of the non-nested complex query.
[0198] Through the large model, the intermediate information of the original question is analyzed from the prompt based on the non-nested complex query, and the intermediate information of the original question is spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0199] Optionally, in the SQL statement generation device based on the big model provided in another embodiment of the present application, when the third generation unit generates the pattern structure of the original question according to the third preset mode by using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer, it is used to:
[0200] The database information and multiple nested complex query sample data are sequentially spliced to obtain the nested complex query prompt, wherein a nested complex query sample data includes a sample question, pattern link information of the sample question, each sub-question of the sample question and the answer to the sub-question, intermediate information of the sample question, and SQL query statement of the sample question.
[0201] The original question and its pattern link information are concatenated at the end of the prompt of the nested complex query.
[0202] Through the large model, the prompt based on the nested complex query is split into multiple sub-questions to ask the large model, obtain the answers to the sub-questions of the original question, and analyze the intermediate information of the original question.
[0203] The multiple sub-questions of the original question and their answers, as well as the intermediate information of the original question, are spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
[0204] Optionally, in another embodiment of the present application, the SQL statement generation device based on the large model further includes:
[0205] The second construction unit is used to construct a plurality of initial nested complex query sample data.
[0206] The first selection unit is used to randomly select a plurality of nested complex query sample data from each initial nested complex query sample data, and select a plurality of nested complex query sample data that are most similar to the original question.
[0207] The second selection unit is used to shuffle the selected nested complex query sample data to obtain final nested complex query sample data.
[0208] Optionally, in another embodiment of the present application, the SQL statement generation device based on the large model further includes:
[0209] The first correction prompt generating unit is used to generate a first correction prompt using the original question, the data table structure, the SQL query statement of the original question and the question modification requirement, wherein the question modification requirement is used to require modification of all questions in the SQL query statement.
[0210] The first correction unit is used to obtain a calibrated SQL query statement for the original question based on the first correction prompt through the large model.
[0211] Optionally, in the above-mentioned SQL statement generation device based on the large model, it also includes:
[0212] The second correction prompt generating unit is used to generate a second correction prompt by using the original question, the data table structure, the SQL query statement of the original question and the modification suggestion.
[0213] The second correction unit is used to obtain a calibrated SQL query statement for the original question based on the second correction prompt through the large model.
[0214] It should be noted that the specific working process of each unit provided in the above embodiments of the present application can refer to the implementation process of the corresponding steps in the above method embodiments, and will not be repeated here.
[0215] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0216] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating SQL statements based on a large model, characterized in that: include: Get the user's original question and the corresponding table structure information in the database; Based on the original question and the table structure information, four structural information query questions are gradually queried on the large model to obtain the pattern link information of the original question; wherein the pattern link information includes the table name, field name, field value and foreign key information; Analyze the category to which the original question belongs; If the original question is a simple query, then according to a first preset mode, the pattern structure of the original question is generated by using the information of the database, the original question and its pattern link information; wherein the simple query is a query that operates only on a single table; If the original question belongs to a non-nested complex query, then according to the second preset mode, the pattern structure of the original question is generated by using the information of the database, the original temperature and its corresponding pattern link information, and the intermediate information; wherein the intermediate information is the information generated by the large model and guides the connection of multiple tables; the non-nested complex query is a query that connects multiple tables but does not contain a subquery; If the original question is a nested complex query, then according to the third preset mode, the pattern structure of the original question is generated by using the information of the database, the original question and its corresponding pattern link information, intermediate information, each sub-question and its answer; wherein each sub-question is constructed based on the original question; the answer to each sub-question is obtained by processing the large model; the nested complex query is a query containing sub-queries or set operations; By analyzing the pattern structure of the large model based on the original question, the SQL query statement of the original question is obtained.
2. The method according to claim 1, characterized in that Based on the original question and the table structure information, four structural information query questions are gradually queried on the large model to obtain the pattern link information of the original question, including: Based on the original question, the table structure information and the information inquiry prompt, the name of the table queried by the large model is inquired to obtain the table name corresponding to the original question; wherein the information inquiry prompt is a prompt generated by multiple question inquiry sample data; Based on the table structure information, the original question and its corresponding table name, and the information query prompt, the name of the field queried by the large model is inquired to obtain the field name corresponding to the original question; Based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, the value of the field queried by the large model is inquired to obtain the field value corresponding to the original question; Based on the table structure information, the original question and its corresponding table name and corresponding field name, and the information query prompt, the foreign key relationship between the tables queried by the large model is inquired to obtain the foreign key information corresponding to the original question.
3. The method according to claim 2, characterized in that Also includes: Construct multiple information inquiry prompts that include questions, model thinking processes, and sample answers; Scramble each step node in the model thinking process in each of the information query prompts to obtain a new information query prompt; According to the preset probability, the step nodes in the model thinking process in the new information query prompt are randomly discarded to obtain the final information query prompt.
4. The method according to claim 1, characterized in that: The method of generating a pattern structure of the original question by using the information of the database, the original question and its pattern link information according to the first preset pattern includes: The information of the database is sequentially concatenated with a plurality of simple query sample data to obtain a prompt of the simple query; wherein one of the simple query sample data includes a sample question, pattern link information of the sample question, and a SQL query statement of the sample question; The original question and its pattern link information are sequentially concatenated at the end of the prompt of the simple query to obtain the pattern structure of the original question.
5. The method according to claim 1, characterized in that The method of generating the pattern structure of the original question according to the second preset pattern by using the information of the database, the original temperature and its corresponding pattern link information and intermediate information includes: The information of the database is sequentially concatenated with a plurality of non-nested complex query sample data to obtain a prompt of the non-nested complex query; wherein one non-nested complex query sample data includes a sample question, pattern link information of the sample question, intermediate information of the sample question, and a SQL query statement of the sample question; The original question and its pattern link information are sequentially concatenated at the end of the prompt of the non-nested complex query; The large model analyzes the intermediate information of the original question based on the prompt of the non-nested complex query, and splices the intermediate information of the original question into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
6. The method according to claim 1, characterized in that According to the third preset mode, the pattern structure of the original question is generated by using the information of the database, the original question and its corresponding pattern link information, the intermediate information, each sub-question and its answer, including: The information of the database and a plurality of nested complex query sample data are sequentially spliced to obtain the prompt of the nested complex query; wherein one nested complex query sample data includes a sample question, pattern link information of the sample question, each sub-question of the sample question and the answer to the sub-question, intermediate information of the sample question, and a SQL query statement of the sample question; The original question and its pattern link information are sequentially concatenated at the end of the prompt of the nested complex query; By using the large model to split the original question into multiple sub-questions based on the nested complex query prompt, the large model is queried to obtain answers to the sub-questions of the original question, and intermediate information of the original question is analyzed; The multiple sub-questions of the original question and their answers, and the intermediate information of the original question are spliced into the prompt of the non-nested complex query to obtain the pattern structure of the original question.
7. The method according to claim 1, characterized in that Before sequentially concatenating the information of the database with a plurality of nested complex query sample data to obtain the prompt of the nested complex query, the method further includes: Constructing a plurality of initial nested complex query sample data; Randomly selecting a plurality of the nested complex query sample data from each of the initial nested complex query sample data, and selecting a plurality of the nested complex query sample data that are most similar to the original question; The selected nested complex query sample data are shuffled to obtain the final nested complex query sample data.
8. The method according to claim 1, characterized in that After the SQL query statement of the original question is obtained by analyzing the pattern structure of the large model based on the original question, the method further includes: Generate a first correction prompt using the original question, the data table structure, the SQL query statement of the original question, and a question modification requirement; wherein the question modification requirement is used to require modification of all questions in the SQL query statement; The large model is used to obtain a calibrated SQL query statement for the original question based on the first correction prompt.
9. The method according to claim 1, characterized in that: After the SQL query statement of the original question is obtained by analyzing the pattern structure of the large model based on the original question, the method further includes: Generate a second correction prompt using the original question, the data table structure, the SQL query statement of the original question, and the modification suggestion; Based on the second correction prompt, the large model is used to obtain a calibrated SQL query statement for the original question.
10. A SQL statement generation device based on a large model, characterized in that: include: An acquisition unit, used to obtain the user's original question and the corresponding table structure information in the database; A step-by-step matching unit, configured to query the large model with four structural information query questions step by step based on the original question and the table structure information, and obtain the pattern link information of the original question; wherein the pattern link information includes the table name, field name, field value and foreign key information; A classification unit, used for analyzing the category to which the original question belongs; A first generating unit is used to generate a pattern structure of the original question according to a first preset pattern by using information of the database, the original question and pattern link information thereof when the original question belongs to a simple query; wherein the simple query is a query that operates only on a single table; A second generating unit is used to generate a pattern structure of the original question according to a second preset mode by using the information of the database, the original temperature and its corresponding pattern link information, and intermediate information when the original question belongs to a non-nested complex query; wherein the intermediate information is information generated by the large model to guide multi-table connection; the non-nested complex query is a query that connects multiple tables but does not contain a subquery; A third generating unit is used to generate a pattern structure of the original question according to a third preset mode by using information of the database, the original question and its corresponding pattern link information, intermediate information, each sub-question and its answer when the original question is a nested complex query; wherein each sub-question is constructed based on the original question; the answer to each sub-question is obtained by processing the large model; and the nested complex query is a query containing a sub-query or a set operation; The analyzing unit is used to analyze the large model based on the pattern structure of the original question to obtain the SQL query statement of the original question.
Citation Information
Cited By
Text conversion query statement generation method and system, medium and equipment
CN120371853A
A text conversion query statement generation method, system, medium and device
CN120371853B
