SQL (Structured Query Language) statement generation method and device, equipment and program product

By leveraging intent recognition and expert experience in multi-way query and multi-turn chat modes, the problem of low accuracy in SQL statement generation from large language models is solved, achieving higher accuracy and reliability of SQL statements.

CN121833740APending Publication Date: 2026-04-10BEIJING CENTURY TAL EDUCATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING CENTURY TAL EDUCATION TECH CO LTD
Filing Date
2025-12-29
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

In existing technologies, the "illusion" problem of large language models leads to low accuracy in the generated SQL statements, making it difficult to meet the user's query intent.

Method used

By using an intent recognition agent to perform multi-way queries on user query information, the initial SQL query intent is obtained, and the intent is adjusted in a multi-round chat mode. Finally, an SQL statement is generated based on the standard SQL query intent, and the accuracy is improved by combining expert experience and slot templates.

Benefits of technology

It improves the matching degree between the generated SQL statement and the user's query intent, reduces the risk of misjudgment by the large language model, and enhances the accuracy and reliability of the SQL statement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121833740A_ABST
    Figure CN121833740A_ABST
Patent Text Reader

Abstract

The invention provides an SQL (Structured Query Language) statement generation method, device, equipment and program product, in the scheme, on one hand, intention recognition is performed on user query information and a first matching result obtained through multi-path query to obtain a more accurate SQL standard query intention, so that it is ensured that a finally generated SQL statement is matched with the user query intention; and the accuracy of the generated SQL statement is improved. On the other hand, the SQL standard query intention meeting the user expectation is determined according to the multi-round chat content obtained in the multi-round chat mode, the SQL statement is generated based on the SQL standard query intention, and the accuracy of the generated SQL statement is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device and program product for generating SQL statements. Background Technology

[0002] Structured Query Language (SQL) is a database query and programming language used to access, query, update, and manage data. Querying a database typically requires users to have some SQL knowledge, which can be challenging for non-technical users. To improve database accessibility and user experience, user queries can be automatically converted into SQL statements, thereby lowering the barrier to entry for users interacting with the database.

[0003] Currently, most methods involve adding suggestions to a large language model based on the user's query request and related knowledge, and then using the large language model to convert natural language into SQL statements. However, due to the "illusion" problem inherent in large language models, the accuracy of the generated SQL statements is relatively low. Summary of the Invention

[0004] This application provides a method for generating SQL statements, comprising: obtaining an initial SQL query intent by performing intent recognition on user query information and a first matching result that matches the user query information; the first matching result is the result that matches the user query information obtained through multi-way query; when it is detected that the user has adjusted the initial SQL query intent, entering a multi-round chat mode to determine the standard SQL query intent that meets the user's expectations based on the content of the multi-round chat; and determining the SQL statement based on the standard SQL query intent and a second matching result that matches the standard SQL query intent.

[0005] This application provides an SQL statement generation apparatus, comprising: an identification module configured to identify intent by analyzing user query information and a first matching result that matches the user query information to obtain a standard SQL query intent; the first matching result is a result obtained through multi-way query that matches the user query information; a monitoring module configured to enter a multi-round chat mode when it detects that the user has adjusted the standard SQL query intent, so as to determine the standard SQL query intent that meets the user's expectations based on the content of the multi-round chat; and a determination module configured to determine an SQL statement based on the standard SQL query intent and a second matching result that matches the standard SQL query intent.

[0006] This application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described SQL statement generation method.

[0007] This application provides a server, including: a processor and a machine-readable storage medium, the machine-readable storage medium storing machine-executable instructions that can be executed by the processor; wherein, the processor is used to execute the machine-executable instructions to implement the above-described SQL statement generation method.

[0008] This application provides a machine-readable storage medium storing machine-executable instructions that can be executed by a processor; wherein the processor executes the machine-executable instructions to implement the above-described SQL statement generation method.

[0009] As can be seen from the above technical solutions, this application provides a method for generating SQL statements. In this method, on the one hand, intent recognition is performed on the user's query information and the first matching result obtained through multi-way queries to obtain a more accurate standard SQL query intent, thereby ensuring that the final generated SQL statement matches the user's query intent and improving the accuracy of the generated SQL statement. On the other hand, the standard SQL query intent that meets the user's expectations is determined based on the multi-round chat content obtained from the multi-round chat mode, and SQL statements are generated based on the standard SQL query intent, further improving the accuracy of the generated SQL statement. Attached Figure Description

[0010] Figure 1 This is a flowchart of an SQL statement generation method in one embodiment of this application; Figure 2 This is an example architecture diagram of an SQL statement generation system in one embodiment of this application; Figure 3 This is a multi-way retrieval process in one embodiment of this application; Figure 4 This is a flowchart illustrating the process of obtaining a standard query intent in one embodiment of this application; Figure 5 This is an example architecture diagram of an SQL statement generation agent in one embodiment of this application; Figure 6 This is a flowchart illustrating the generation of SQL statements in one embodiment of this application; Figure 7 This is a schematic diagram of the structure of an SQL statement generation device in one embodiment of this application; Figure 8 This is a hardware structure diagram of an SQL statement generation device according to one embodiment of this application. Detailed Implementation

[0011] Embodiments of this application will now be described in more detail with reference to the accompanying drawings. While some embodiments of this application are shown in the drawings, it should be understood that this application can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this application. It should be understood that the drawings and embodiments of this application are for illustrative purposes only and are not intended to limit the scope of protection of this application.

[0012] It should be noted that the headings of any section / subsection provided herein are not limiting. Various embodiments are described throughout this document, and embodiments of any type may be included under any section / subsection. Furthermore, embodiments described in any section / subsection may be combined in any way with any other embodiments described in the same section / subsection and / or different sections / subsections.

[0013] In the description of embodiments of this application, the term "comprising" and similar terms should be understood as open-ended inclusion, i.e., "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may also be included below. The terms "first", "second", etc., may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0014] As used in this paper, the term "model" refers to a system that learns the relationship between inputs and outputs from training data, enabling it to generate corresponding outputs for a given input after training. Model generation can be based on machine learning techniques. Deep learning is a machine learning algorithm that uses multiple layers of processing units to process inputs and provide corresponding outputs. In this paper, "model" may also be referred to as a "machine learning model," a "machine learning network," or simply a "network," and these terms are used interchangeably. A model can also include different types of processing units or networks.

[0015] As mentioned above, user queries and related knowledge are typically added to the prompts of machine learning models to convert natural language into SQL statements, which are then used to manipulate the database. However, due to the "illusion" problem inherent in machine learning models, the generated SQL statements may not match the user's query or may contain syntax errors, resulting in low accuracy.

[0016] Specific embodiments are provided to illustrate the SQL statement generation method of this application. Figure 1This is a flowchart illustrating an SQL statement generation method in one embodiment of this application. Figure 1 The SQL statement generation method shown can be implemented or included in a server. In this application, a user can interact with a model or agent used to generate SQL statements through an application running on a terminal device to provide the user's query question to the machine learning model. The user can obtain the SQL statement generated by the machine learning model, the query question, and the SAL query intent generated during historical interactions through the application.

[0017] Figure 2 This is an example architecture diagram of an SQL statement generation system according to one embodiment of this application. Figure 2 As shown, the SQL statement generation system includes an intent recognition agent 210 and an SQL generation agent 220, which are used to perform intent recognition tasks and SQL statement generation tasks, respectively. The intent recognition agent 210 and the SQL generation agent 220 can be implemented based on a large language model.

[0018] like Figure 1 As shown, the method may include: in box 110, obtaining a standard SQL query intent by performing intent recognition on user query information and a first matching result that matches the user query information. The first matching result is the result obtained through a multi-way query that matches the user query information.

[0019] User query information can be a query question expressed in natural language input by the user. For example, a user query question could be "Query the sales volume of product A in the past 6 months". In some embodiments, the user query question can be a question generated by the preceding functional modules of a machine learning model. For example, the corresponding user query question can be generated using the user's selection operation on a certain type of data in the database or a question determined by pre-determined data query rules.

[0020] like Figure 2As shown, the intent recognition agent 210 performs a similarity question multi-way retrieval task 211 to obtain a first matching result that matches the user query information. Multi-way query indicates finding results that match the user query information by invoking multiple retrieval algorithms in parallel or sequentially. For example, the first matching result can be found from multiple different knowledge bases, or by using different keywords. In some embodiments, K1 results matching the user query information can be queried from an SQL experience knowledge base, and K2 first matching results matching the user query information can be queried from a pre-built database table creation statement. Subsequently, all the retrieved first matching results (K1+K2) are used as the first matching result matching the user query information.

[0021] In some embodiments, the intent recognition agent 210 combines all the obtained first matching results to obtain intent recognition expert experience. Intent recognition expert experience may include database table knowledge related to database table names, table creation statements, etc., and experience related to historical query questions.

[0022] In box 120, when the intent recognition agent 210 detects that the user has adjusted the initial SQL query intent, it enters a multi-turn chat mode to determine the standard SQL query intent that meets the user's expectations based on the content of the multi-turn chat.

[0023] In each round of the multi-turn chat mode, the intent recognition agent 210 can present the initial query intent determined in the previous round to the user through an interactive page. For example, the intent recognition agent 210 can present the initial SQL query intent and adjustment controls for the initial SQL query intent in different areas of the user interface. The adjustment controls can be buttons for initiating adjustment operations or text input fields for obtaining adjustment requests.

[0024] If the user triggers an adjustment control, the intent recognition agent 210 can obtain the user's adjustment request for the initial SQL query intent through the interactive page. The adjustment request indicates a modification request for at least a part of the initial SQL query intent. The intent recognition agent 210 can obtain the user's adjustment request for the standard SQL query intent obtained in previous rounds. Based on the standard SQL query intent obtained in previous rounds, the adjustment request, and the chat content of previous rounds, a prompt word is generated. Based on the prompt word, the standard SQL query intent corresponding to the current round is generated. If the user's confirmation of the standard SQL query intent corresponding to the current round is detected, the standard SQL query intent corresponding to the current round is determined as the standard SQL query intent that meets the user's expectations.

[0025] In some embodiments, the intent recognition agent 210 can present the initial SQL query intent and the standard SQL query intent to the user based on the data results of a predetermined query intent, so that the user can view them. For example, the data results of the query intent can be {"User Question":"","Query Field":"","Special Logic":"","Filter Conditions":"","Association Logic":""}.

[0026] In multi-turn chat mode, the intent recognition agent 210 generates the query intent for each turn based on the chat content and the initial SQL query intent during the multi-turn conversation. If the user's query intent changes during the chat, the final generated standard SQL query intent may not match the user's query information.

[0027] In box 130, SQL statement generation agent 220 can determine the SQL statement based on the standard SQL query intent and a second matching result that matches the standard SQL query intent.

[0028] After determining the standard SQL query intent, the SQL statement generation agent 220 can retrieve a second matching result from the SQL experience knowledge base that matches the standard SQL query intent. Subsequently, an SQL statement is generated based on the second matching result and the standard SQL query intent. In this way, expert experience used to generate the SQL statement can be determined based on the standard SQL query intent, thereby improving the reliability of the determined expert experience and further improving the accuracy of the generated SQL code.

[0029] The second matching result can be the result obtained through multi-way query that matches the SQL standard query intent. In some embodiments, the SQL statement generation agent 220 can first determine the dense feature vector and sparse feature vector corresponding to the SQL standard query intent. Subsequently, based on the determined dense and sparse feature vectors, the SQL statement generation agent 220 searches for K3 results that match the SQL standard query intent in the SQL experience knowledge base, and searches for K4 results that match the SQL standard query intent in the constructed database table creation statements. The SQL statement generation agent 220 can combine all the obtained second matching results to obtain the database table knowledge chain and the expert knowledge chain.

[0030] SQL statement generation agent 220 can generate SQL statements using the determined database table knowledge chain and expert knowledge chain. In some embodiments, SQL statement generation agent 220 can put the obtained second matching result into the prompt word template of the SQL generation agent to guide the LLM to generate SQL. In some embodiments, multiple SQL slot templates can be predetermined. The SQL statement generation agent can generate prompt words for SQL generation agent 220 using the second matching result, the SQL standard query intent, and the SQL slot template corresponding to the SQL flag query intent. The SQL slot template includes multiple SQL keyword slots, such as "WHERE", "GROUP BY", or "HAVING".

[0031] SQL statement generation agent 220 can generate multiple slot values ​​in an SQL slot template. These multiple slot values ​​are then combined to generate an SQL statement. In this way, the SQL statement generation task can be broken down into multiple sub-generation tasks, thereby improving the accuracy and reliability of the generated SQL statements.

[0032] In some embodiments, after determining the SQL statement, the SQL statement generation agent 220 can execute the SQL statement to obtain an execution result. Subsequently, based on the execution result of the SQL statement, it is determined whether the SQL statement matches the user's query information. If the SQL statement does not match the user's query information, prompt words are generated based on the SQL statement, the execution result of the SQL statement, and the standard SQL query intent to adjust the SQL statement.

[0033] As can be seen, the solution provided in this application uses an intent recognition agent and an SQL statement generation agent to collaboratively execute the SQL statement generation task. This ensures that the agent can be specialized and trained based on the tasks it performs, improving its performance and preventing the influence of model "illusion." The query intent generated by the intent recognition agent is adjusted based on multiple rounds of chat content to obtain a standard query intent. This allows for a more accurate determination of user intent and its conversion into a standard SQL query intent, preventing the impact of large model "illusion" on the reliability of SQL statements. Simultaneously, after determining the standard SQL generation intent, expert experience used to generate SQL statements is retrieved based on this intent, providing more accurate expert experience for the large model and improving the accuracy of the generated SQL statements.

[0034] In addition, SQL statements are generated based on pre-determined SQL slot templates to break down the SQL statement generation task into multiple sub-tasks, thereby further improving the accuracy and efficiency of the generated SQL statements.

[0035] The implementation process of this specification will be described in detail below with reference to specific embodiments.

[0036] I. Determining the first matching result using multi-way queries Figure 3 This is a flowchart of a multi-way retrieval method according to one embodiment of this application. For example... Figure 3 As shown, after obtaining user query information 310, the intent recognition agent 210 can use a combination of dense vectors and the Best Matching 25 (BM25) algorithm for hybrid retrieval to obtain a first matching result. In some embodiments, an embedding model can be used to encode the user query information 310 to obtain a dense vector corresponding to the user query information. During the retrieval process, the cosine similarity between the obtained dense vector and the content in the SQL experience knowledge base can be calculated. Simultaneously, combined with BM25 sparse retrieval technology, the user query information and the content in the SQL experience knowledge base are matched for similarity to obtain multiple reference knowledge items whose similarity meets preset conditions. The SQL experience knowledge base is compiled from user historical query records and analyst common SQL query records. The SQL experience knowledge base may include background knowledge, historical query information, table names corresponding to historical query information, table creation statements, and historical query intents corresponding to historical query information. The historical query intents in the SQL experience knowledge base are determined through large language models or manual annotation. Background knowledge supplements the original database table information, including regular field enumeration values, abbreviated enumeration values, colloquial expressions, and examples of industry jargon, representing the questioning habits of different user groups, which can improve the coverage and accuracy of intent recognition.

[0037] Table names and creation statements provide rich database table knowledge for SQL statement generation, thereby reducing the possibility of LLM creating fictitious table names and fields. In this embodiment, by performing multi-path retrieval of table names and creation statements, it supplements existing user query-retrieved table names and creation statements. Furthermore, when the experienced table names and creation statements are empty, it acts as a fallback, ensuring that database table information always constrains the intent recognition process, thus reducing the possibility of fictitious table names and fields. In addition, displaying table relationships in system prompts reduces the illusion of related fields in multi-table join queries, preventing LLM from randomly selecting table join fields and causing SQL generation syntax or logical errors.

[0038] like Figure 3 As shown in box 330, the intent recognition agent 210 retrieves historical query information similar to the user's query information from the SQL experience knowledge base by matching the user's query information with the "historical query information" field in the SQL experience knowledge base. Subsequently, it obtains K1 results 340 corresponding to the obtained historical query information. The K1 results 340 may include experience candidate table names, experience table creation statements, and experience SQL standard query intents.

[0039] In box 331, the intent recognition agent 210 retrieves K2 first matching results 350 from the SQL experience knowledge base by matching the user query information with the "database table creation statement" field in the SQL experience knowledge base. The K2 second matching results 350 may include candidate table names, table creation statements, table join instructions, and other information corresponding to the user query information. For example, if the user query information is "query the order volume of city A", the intent recognition agent 210 may use "city order volume table" as a candidate table name corresponding to the user query information. Table 1 shows an example of a historical query information matched with the user query information in the SQL experience knowledge base.

[0040] Table 1 As shown in Table 1, after identifying historical query information that matches the user's query information, the standard query intent, table name, and SQL slot template corresponding to that historical query information can be determined. Table 2 shows an example of a database table creation statement that matches the user's query information from the SQL experience knowledge base.

[0041] Table 2 In box 360, the intent recognition agent 210 can combine the K1 results 340 and K2 results 350 obtained through multi-way queries to obtain intent recognition expert experience. For example, intent recognition expert experience can include a database table knowledge chain and an experience knowledge chain. The intent recognition agent 210 can assemble a database table knowledge chain from candidate table names, table creation statements, table relationships, and background knowledge, providing sufficient database table background information and business language expression habits for intent recognition. It can also assemble an experience knowledge chain from historical query information similar to user query information and standard SQL query intent, providing user intent preferences and metric calculation logic for intent recognition. Table 3 shows an example of a database table knowledge chain and an experience knowledge chain.

[0042] Table 3 II. Determine the query intent that satisfies the user's expectations. Figure 4 This is a flowchart illustrating the process of obtaining a standard query intent in one embodiment of this application. For example... Figure 4As shown, in box 410, the intent recognition agent 210 can obtain user query information. In box 420, the intent recognition agent 210 can generate intent recognition prompts for the large language model based on the determined intent recognition expert experience (i.e., the database table knowledge chain and experience knowledge chain), the SQL standard query data structure, and the intent recognition prompt template. In box 430, the intent recognition agent 210 can provide the intent recognition prompts to the large language model. The large language module can determine whether the user query information is a data query requirement based on the intent recognition prompts. If it is a data query requirement, it proceeds to box 440, where the large language model generates the initial SQL query intent. If it is not a data query requirement, it proceeds to box 450, where the large language model provides a casual reply to the user. Thus, by combining intent recognition expert experience to determine user intent, the possibility of intent classification misjudgment can be effectively reduced.

[0043] Table 4 shows an example of intent recognition prompts. As shown in Table 4, the database knowledge chain can be assigned to the "db_info_chain" variable in the intent recognition prompt, and the experience knowledge chain can be assigned to the "experience_chain" variable in the intent recognition prompt to form a complete intent recognition prompt.

[0044] Table 4 After providing the intent recognition prompts to the large language model, the large language model generates an initial SQL query intent based on the prompts. If the user confirms the initial SQL query intent, it is determined as the standard SQL query intent, and the intent recognition process ends. If a user's request to adjust the initial SQL query intent is detected, a multi-turn dialogue mode can be entered. In each turn of the multi-turn dialogue, the intent recognition agent 210 presents the user with the standard query intent generated in the previous turn. Table 5 shows an example of generating an initial query intent. As shown in Table 5, the user's query is "Which users have the highest order volume in first-tier cities?" The intent recognition agent 210, based on a pre-determined data structure, uses the large language model to generate a query intent including {"User Question":"","Query Fields":"","Special Logic":"","Filtering Conditions":"","Association Logic":""} and presents it to the user. In addition, the output of the intent recognition agent 210 also includes the guiding information "Please confirm whether the above information is correct. If there are any modifications, please continue to supplement it" to guide the user to adjust the generated SQL query intent.

[0045] Table 5 In some embodiments, the intent recognition agent 210 can provide guidance to the user regarding missing information. For example, the intent recognition agent 210 can present "Please supplement the filter conditions." If the user determines that the generated query intent differs from their expectations, they can continue to send adjustment requests to the intent recognition agent 210 to adjust the SQL query intent. Through multiple rounds of chat interaction, the intent recognition agent 210 will identify the SQL standard query intent that best matches the user's query needs. In some embodiments, each time the intent recognition agent 210 generates a casual reply or SQL standard query intent using the large language model, it dynamically updates the session memory module and explicitly adds system prompts as context for the next generation, ensuring that the memory of the large language model is more controllable.

[0046] III. Generating SQL Statements Based on SQL Standard Query Intent In some embodiments, after the intent recognition agent 210 determines the SQL standard query intent, the SQL statement generation agent 220 can generate an SQL statement that meets the user's expectations based on the determined SQL standard query intent. Figure 5 This is an example architecture diagram of an SQL statement generation agent in one embodiment of this application. For example... Figure 5 As shown, in box 510, the SQL statement generation agent 220 obtains the standard SQL query intent. In box 520, the standard SQL query intent is encoded using a vector model to obtain a dense vector corresponding to the standard SQL query intent. In box 510, the BM25 algorithm is used to determine a sparse vector corresponding to the standard SQL query intent. In box 530, the SQL experience knowledge base is retrieved based on the determined dense and sparse vectors to obtain a second matching result 540 corresponding to the standard SQL query intent. The second matching result 540 includes the table name, SQL slot template, and the table creation statement and table relationships corresponding to the table name. Compared to the first matching result, the amount of expert experience data obtained by the second matching result is significantly reduced. In this way, the search scope of data tables and fields during the SQL statement generation process can be narrowed, improving the efficiency of SQL statement generation. At the same time, expert experience that does not match the standard SQL query intent can be filtered out, improving the accuracy and reliability of the SQL statement.

[0047] SQL slot templates are extracted from historical SQL code and used as the context of the LLM. This allows the complex SQL generation process to be broken down into multiple SQL keyword slot generation subtasks, further reducing the probability of SQL generation errors. This solution effectively reduces the SQL generation illusion in scenarios involving multi-table joins and complex logical calculations. The SQL slot template data structure can include {"WITH":"", "SELECT": "", "FROM": "", "INNER JOIN": "", "LEFTJOIN": "", "WHERE": "", "GROUP BY": "" ,"HAVING": "", "ORDER BY": "", "LIMIT": ""}.

[0048] SQL expert experience 550 is generated by assembling the second matching result 540. SQL expert experience 550 includes a database table knowledge chain consisting of candidate table names, table creation statements, and table relationships, and an experience knowledge chain consisting of SQL standard query intent and SQL slot template.

[0049] Figure 6 This is a flowchart illustrating the generation of SQL statements in one embodiment of this application. For example... Figure 6 As shown, SQL expert experience can be used as a dynamic variable and incorporated into the SQL generation prompts to guide the generation of SQL statements in large languages.

[0050] In box 610, the SQL generation agent 220 obtains the standard SQL query intent and determines a second matching result for generating the SQL statement through a multi-way retrieval query. In box 620, the SQL generation agent 220 can compose an SQL generation prompt based on the second matching result corresponding to the standard SQL query intent, the SQL slot template structure, and the SQL generation prompt word template, and append the standard SQL query intent as a user message to the end of the prompt word. Table 6 is an example of an SQL generation prompt word template.

[0051] Table 6 In some embodiments, the database knowledge chain from the second matching result can be assigned to the "db_info_chain" variable in Table 6, and the experience knowledge chain can be assigned to the "experience_chain" variable in Table 6. After the SQL slot is successfully generated, the SQL code will be executed, and the SQL verification log will be obtained. The SQL slot data structure is assigned to the "sql_slot" variable to standardize the SQL slot output structure. After generating the SQL slot values, they can be directly concatenated in order to obtain the executable SQL statement. The "db_type" variable is used to generate SQL code in different dialects, such as MySQL, Hive, etc.

[0052] In some embodiments, the generated SQL statement can be submitted to the database for syntax validation. If the SQL syntax validation passes, the complete result data is returned to the user. If the SQL validation fails, the error message is updated in the SQL validation log, and the SQL validation log is assigned to the "sql_check_log" variable to reconstruct the system prompt. Subsequently, the SQL slot is regenerated based on the reconstructed system prompt, until the maximum number of retries is reached or the SQL syntax validation passes.

[0053] Based on the same concept as the above method, this application proposes an SQL statement generation device, see [link to relevant documentation]. Figure 7 The diagram shows the structure of an SQL statement generation device. The device may include: an identification module configured to identify the user's query information and a first matching result that matches the user's query information to obtain a standard SQL query intent; the first matching result is the result obtained through multi-way queries that matches the user's query information; a monitoring module configured to enter a multi-round chat mode when it detects that the user has adjusted their standard SQL query intent, in order to determine a standard SQL query intent that meets the user's expectations based on the content of the multi-round chat; and a determination module configured to determine the SQL statement based on the standard SQL query intent and a second matching result that matches the standard SQL query intent.

[0054] Optionally, obtaining the first matching result through multi-way query includes: finding K1 results that match the user query information in the SQL experience knowledge base based on the dense feature vector and the sparse feature vector corresponding to the user query information; and finding K2 results that match the user query information in the table creation statements of the constructed database table based on the dense feature vector and the sparse feature vector.

[0055] Optionally, detecting user adjustments to the initial SQL query intent includes: displaying the initial SQL query intent and adjustment controls for the initial SQL query intent in different areas of the user interface; if a trigger on the adjustment controls is detected, obtaining the user's adjustment request for the initial SQL query intent; the adjustment request indicates a modification request for at least a portion of the initial SQL query intent.

[0056] Optionally, determining the SQL standard query intent that meets the user's expectations based on the multi-round chat content includes: in each round of the multi-round chat mode, obtaining the user's adjustment request for the SQL standard query intent obtained in the previous round; generating prompt words based on the SQL standard query intent obtained in the previous round, the adjustment request, and the chat content of the previous round; generating the SQL standard query intent corresponding to the current round based on the prompt words; and if the user's confirmation of the SQL standard query intent corresponding to the current round is detected, determining the SQL standard query intent corresponding to the current round as the SQL standard query intent that meets the user's expectations.

[0057] Optionally, the second matching result is determined in the following way: based on the dense feature vector and the sparse feature vector corresponding to the SQL standard query intent, K3 results matching the SQL standard query intent are found in the SQL experience knowledge base; based on the dense feature vector and the sparse feature vector, K4 results matching the SQL standard query intent are found in the table creation statements of the constructed database tables.

[0058] Optionally, determining the SQL statement based on the SQL standard query intent and the second matching result includes: generating prompt words based on the second matching result, the SQL standard query intent, and the SQL slot template corresponding to the SQL standard query intent; the SQL slot template includes multiple SQL keyword slots; determining multiple slot values ​​corresponding to the multiple SQL keyword slots based on the prompt words; and determining the SQL statement based on the SQL slot template and the multiple slot values.

[0059] Optionally, determining the SQL statement based on the SQL standard query intent and the second matching result further includes: determining whether the SQL statement matches the user query information based on the execution result of the SQL statement; if the SQL statement does not match the user query information, generating prompt words based on the SQL statement, the execution result of the SQL statement, and the SQL standard query intent to adjust the SQL statement.

[0060] Based on the same concept as the methods described above, this application proposes an SQL statement generation device, see [link to relevant documentation]. Figure 8As shown, the SQL statement generation device includes a processor 81 and a machine-readable storage medium 82, wherein the machine-readable storage medium 82 stores machine-executable instructions that can be executed by the processor 81; the processor 81 is used to execute the machine-executable instructions to implement the steps of the above-described SQL statement generation method.

[0061] Based on the same application concept as the above method, this application embodiment also provides a machine-readable storage medium storing a plurality of computer instructions, which, when executed by a processor, can implement the parameter configuration method of the above example application of this application.

[0062] The aforementioned machine-readable storage medium can be any electronic, magnetic, optical, or other physical storage device that can contain or store information, such as executable instructions, data, etc. For example, machine-readable storage media can be: RAM (Random Access Memory), volatile memory, non-volatile memory, flash memory, storage drives (such as hard disk drives), solid-state drives, any type of storage disk (such as optical discs, DVDs, etc.), or similar storage media, or combinations thereof.

[0063] Based on the same application concept as the above method, this application embodiment also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described SQL statement generation method.

[0064] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0065] The above description is merely an embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of this application should be included within the scope of the claims of this application.

Claims

1. A method for generating SQL statements, characterized in that, The method includes: The initial SQL query intent is obtained by performing intent recognition on user query information and a first matching result that matches the user query information; the first matching result is the result that matches the user query information obtained through multi-way query. When the system detects that the user has adjusted the initial query intent of the SQL, it enters a multi-round chat mode to determine the standard SQL query intent that meets the user's expectations based on the content of the multi-round chat. The SQL statement is determined based on the SQL standard query intent and the second matching result that matches the SQL standard query intent.

2. The method according to claim 1, characterized in that, The first matching result obtained through the multi-way query includes: Based on the dense feature vector and the sparse feature vector corresponding to the user query information, K1 results matching the dense feature vector and the sparse feature vector are found in the historical query information of the SQL experience knowledge base; Based on the dense feature vector and the sparse feature vector, K2 results matching the user query information are found in the table creation statements of the constructed SQL experience knowledge base; Based on the K1 results and the K2 results, the first matching result is obtained.

3. The method according to claim 1, characterized in that, Before detecting any adjustment made by the user to the initial SQL query intent, the process further includes: The initial SQL query intent is displayed via a user interface; the user interface also includes adjustment controls. The detection of user adjustment of the initial SQL query intent includes: determining that the user has adjusted the initial SQL query intent when the adjustment control is detected to be triggered.

4. The method according to claim 1, characterized in that, The step of determining the SQL standard query intent that meets the user's expectations based on the multi-round chat content includes: For any given round of chat, that round of chat is taken as the current round of chat; If the current chat round is not the first chat round, when the user adjusts the SQL query intent obtained from the previous chat round, a prompt word is generated based on the SQL query intent, the user's adjustment request for the SQL query intent, and the context of the previous chat rounds. A large language model is then used to generate the SQL query intent corresponding to the current chat round based on the prompt word. Upon detecting the user's confirmation of the SQL query intent corresponding to the current chat round, the SQL query intent corresponding to the current chat round is determined to be the standard SQL query intent that meets the user's expectations. Otherwise, the next chat round is treated as the current chat round, and the operation performed when the user adjusted the SQL query intent obtained from the previous chat round is returned.

5. The method according to claim 1, characterized in that, The second matching result was determined in the following way: Based on the dense feature vector and the sparse feature vector corresponding to the SQL standard query intent, K3 results matching the dense feature vector and the sparse feature vector are found in the historical query intents of the SQL experience knowledge base; Based on the dense feature vector and the sparse feature vector, K4 results matching the dense feature vector and the sparse feature vector are found in the table creation statements of the constructed SQL experience knowledge base; Based on the K3 results and the K4 results, the second matching result is obtained.

6. The method according to claim 1, characterized in that, The SQL statement determined based on the SQL standard query intent and the second matching result includes: Based on the second matching result, the SQL standard query intent, and the SQL slot template corresponding to the SQL standard query intent, a prompt word is generated; the SQL slot template includes multiple SQL keyword slots; Using a large language model based on the prompt words, determine multiple slot values ​​corresponding to the multiple SQL keyword slots respectively; The SQL statement is determined based on the SQL slot template and the multiple slot values.

7. The method according to claim 1, characterized in that, Determining the SQL statement based on the SQL standard query intent and the second matching result further includes: The execution result of the SQL statement determines whether the SQL statement matches the user's query information. If the SQL statement does not match the user's query information, a prompt word is generated based on the SQL statement, the execution result of the SQL statement, and the standard query intent of the SQL statement to adjust the SQL statement.

8. An SQL statement generation device, characterized in that, include: The identification module is configured to identify the initial SQL query intent by performing intent identification on user query information and a first matching result that matches the user query information. The first matching result is the result obtained through multi-way query that matches the user's query information; The monitoring module is configured to enter a multi-round chat mode when it detects that the user has adjusted the initial query intent of the SQL, so as to determine the standard SQL query intent that meets the user's expectations based on the content of the multi-round chat. The determination module is configured to determine the SQL statement based on the SQL standard query intent and a second matching result that matches the SQL standard query intent.

9. The SQL statement generation apparatus according to claim 8, characterized in that, The first matching result obtained through the multi-way query includes: Based on the dense feature vector and the sparse feature vector corresponding to the user query information, K1 results matching the dense feature vector and the sparse feature vector are found in the historical query information of the SQL experience knowledge base; Based on the dense feature vector and the sparse feature vector, K2 results matching the user query information are found in the table creation statements of the constructed SQL experience knowledge base; Based on the K1 results and the K2 results, the first matching result is obtained; or, Before detecting any adjustment made by the user to the initial SQL query intent, the process further includes: The initial SQL query intent is displayed via a user interface; the user interface also includes adjustment controls. The detection of user adjustment to the initial SQL query intent includes: determining that the user has adjusted the initial SQL query intent upon detecting that the adjustment control has been triggered; or, The step of determining the SQL standard query intent that meets the user's expectations based on the multi-round chat content includes: For any given round of chat, that round of chat is taken as the current round of chat; If the current chat round is not the first chat round, then when the user adjusts the SQL query intent obtained from the previous chat round, a prompt word is generated based on the SQL query intent, the user's adjustment request for the SQL query intent, and the context of the previous chat rounds; a large language model is used to generate the SQL query intent corresponding to the current chat round based on the prompt word; when the user confirms the SQL query intent corresponding to the current chat round, it is determined that the SQL query intent corresponding to the current chat round is the standard SQL query intent that meets the user's expectations; otherwise, the next chat round is taken as the current chat round, and the operation when the user adjusted the SQL query intent obtained from the previous chat round is returned; or... The second matching result was determined in the following way: Based on the dense feature vector and the sparse feature vector corresponding to the SQL standard query intent, K3 results matching the dense feature vector and the sparse feature vector are found in the historical query intents of the SQL experience knowledge base; Based on the dense feature vector and the sparse feature vector, K4 results matching the dense feature vector and the sparse feature vector are found in the table creation statements of the constructed SQL experience knowledge base; Based on the K3 results and the K4 results, the second matching result is obtained; or, The SQL statement determined based on the SQL standard query intent and the second matching result includes: Based on the second matching result, the SQL standard query intent, and the SQL slot template corresponding to the SQL standard query intent, a prompt word is generated; the SQL slot template includes multiple SQL keyword slots; Using a large language model, multiple slot values ​​corresponding to the multiple SQL keyword slots are determined based on the prompt words; The SQL statement is determined based on the SQL slot template and the multiple slot values; or, Determining the SQL statement based on the SQL standard query intent and the second matching result further includes: The execution result of the SQL statement determines whether the SQL statement matches the user's query information. If the SQL statement does not match the user's query information, a prompt word is generated based on the SQL statement, the execution result of the SQL statement, and the standard query intent of the SQL statement to adjust the SQL statement.

10. An electronic device, characterized in that, include: A processor and a machine-readable storage medium, the machine-readable storage medium storing machine-executable instructions that can be executed by the processor; The processor is configured to execute machine-executable instructions to implement the method of any one of claims 1-7.