SQL (Structured Query Language) statement generation method and system based on large model and storage medium
Through the SQL statement generation method based on the big model, problem prompts are generated dynamically and slot value optimization is performed, which solves the problem of low accuracy in SQL statement generation in the existing technology, and achieves a higher accuracy of SQL output statements.
Patent Information
- Application Number
- CN202411754361.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-03-07
AI Technical Summary
The accuracy of SQL statement generation in the prior art is low, mainly because the same prompt data is used for different query problems, resulting in the generated SQL statements being inaccurate enough.
The SQL statement generation method based on the big model is adopted. By obtaining query problems and determining related table information and related problems, a problem prompt is generated dynamically, and inputting them into the big model for statement generation, and finally obtaining an accurate SQL output statement through slot value optimization.
Improve the accuracy of SQL output statements, avoid the problem of low generation accuracy caused by the same prompt data, and ensure that the corresponding problem prompts of different query questions are different, thereby generating more accurate SQL statements.
Smart Images

Figure CN119576972A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a SQL statement generation method, system and storage medium based on a large model. Background Art
[0002] SQL (Structured Query Language) is a standard programming language for managing relational databases. SQL allows users to define, query, update, and manage data in relational databases. SQL is widely used in various database management systems. SQL statement generation is an important part of data analysis and database management. Therefore, the issue of SQL statement generation is receiving more and more attention.
[0003] In the existing SQL statement generation process, the same prompt data is used for different query questions, which leads to low accuracy of SQL statement generation. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a method, system and storage medium for generating SQL statements based on a large model, so as to solve the problem of low accuracy of generating SQL statements in the prior art.
[0005] The embodiment of the present invention is implemented as follows: a method for generating SQL statements based on a large model, the method comprising:
[0006] Obtaining a query question, and determining relevant table information and relevant questions according to the query question;
[0007] Determine relevant dynamic examples according to the relevant questions, and determine industry background and query constraints according to the business scenario of the query question;
[0008] Generate a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question;
[0009] The question prompt is input into the big model for statement generation to obtain SQL candidate statements, and the slot value of the SQL candidate statements is optimized to obtain SQL output statements.
[0010] Preferably, the SQL candidate statement is optimized for slot values to obtain an SQL output statement, including:
[0011] Obtaining a query condition slot value in the SQL candidate statement, and determining a target data column parameter according to the query condition slot value;
[0012] Acquire the data corresponding to the target data column parameter in the relevant table information, obtain relevant column data, and perform deduplication processing on the relevant column data;
[0013] Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database;
[0014] A similar condition slot value in the vector database is determined according to the query condition slot value, and in the SQL candidate statement, the query condition slot value is replaced by the similar condition slot value to obtain the SQL output statement.
[0015] Preferably, before determining the relevant table information and the relevant questions according to the query question, the method further includes:
[0016] Acquire a local table and a local question, and annotate table columns in the local table to obtain a table description;
[0017] The table description and the local problem are vectorized to obtain a table vector and a local problem vector, and the table vector and the local problem vector are stored in a vector database.
[0018] Preferably, determining relevant table information and relevant questions according to the query question includes:
[0019] Performing vector conversion on the query question to obtain a query vector, and calculating the similarity between the query vector and the table vector to obtain a first similarity;
[0020] Sorting the table descriptions according to the first similarity to obtain a table sorting, and determining the table descriptions before a first preset sequence number in the table sorting as the relevant table information;
[0021] Calculating the similarity between the query vector and the local question vector to obtain a second similarity, and sorting the local questions according to the second similarity to obtain a question sorting;
[0022] The local question before the second preset sequence number in the question sorting is determined as the relevant question.
[0023] Preferably, determining the relevant dynamic examples according to the relevant issues includes:
[0024] Obtain relevant SQL statements corresponding to the relevant questions, and determine relevant data tables, relevant fields, and relevant query conditions according to the relevant questions and the relevant SQL statements;
[0025] A statement thinking process is generated according to the relevant data table, the relevant fields and the relevant query conditions, and the relevant questions, the statement thinking process and the relevant SQL statements are combined to obtain the relevant dynamic examples.
[0026] Preferably, generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question includes:
[0027] Obtain a prompt template, and fill in the form information, background information and constraint information in the prompt template according to the relevant form information, the industry background and the query constraint to obtain a candidate prompt;
[0028] According to the inverse order of the order of the related questions corresponding to the related dynamic examples in the question order, the related dynamic examples are added to the candidate prompts in sequence;
[0029] After the relevant dynamic examples are added, the query question is added to the candidate prompt to obtain the question prompt.
[0030] Preferably, after obtaining the query condition slot value in the SQL candidate statement, the method further includes:
[0031] Matching the query condition slot value with the condition optimization table;
[0032] If the query condition slot value fails to match the condition optimization table, the SQL candidate statement is set as the SQL output statement.
[0033] Another object of an embodiment of the present invention is to provide a SQL statement generation system based on a large model, the system comprising:
[0034] A question determination module, used to obtain a query question and determine relevant table information and relevant questions according to the query question;
[0035] An example determination module, used to determine relevant dynamic examples according to the relevant questions, and determine industry background and query constraints according to the business scenario of the query question;
[0036] A prompt generating module, used for generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question;
[0037] The slot value optimization module is used to input the problem prompt into the big model for statement generation to obtain SQL candidate statements, and perform slot value optimization on the SQL candidate statements to obtain SQL output statements.
[0038] Preferably, the slot value optimization module is also used for:
[0039] Obtaining a query condition slot value in the SQL candidate statement, and determining a target data column parameter according to the query condition slot value;
[0040] Acquire the data corresponding to the target data column parameter in the relevant table information, obtain relevant column data, and perform deduplication processing on the relevant column data;
[0041] Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database;
[0042] A similar condition slot value in the vector database is determined according to the query condition slot value, and in the SQL candidate statement, the query condition slot value is replaced by the similar condition slot value to obtain the SQL output statement.
[0043] The embodiments of the present invention can effectively determine relevant dynamic examples by determining relevant table information and relevant questions corresponding to query questions, and can effectively generate question prompts corresponding to query questions based on relevant table information, industry background, query constraints, relevant dynamic examples and query questions. SQL candidate statements can be effectively generated based on the question prompts, and the accuracy of SQL output statements is effectively improved by optimizing slot values for SQL candidate statements. Different query questions correspond to different question prompts, thereby preventing the phenomenon of low accuracy in SQL statement generation due to the use of the same prompt data. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 is a flowchart of a method for generating SQL statements based on a large model provided by a first embodiment of the present invention;
[0045] Figure 2 It is a structural diagram of a SQL statement generation system based on a large model provided by a second embodiment of the present invention;
[0046] Figure 3 It is a specific implementation diagram of the SQL statement generation system based on the big model provided by the second embodiment of the present invention;
[0047] Figure 4 It is a schematic diagram of the structure of a terminal device provided in the third embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0049] In order to illustrate the technical solution of the present invention, a specific embodiment is provided below for illustration.
[0050] Embodiment 1
[0051] See also Figure 1 , is a flowchart of a method for generating SQL statements based on a large model provided in a first embodiment of the present invention. The method for generating SQL statements based on a large model can be applied to any device or system. The method for generating SQL statements based on a large model comprises the following steps:
[0052] Step S10, obtaining a query question, and determining relevant table information and relevant questions according to the query question;
[0053] The query question is matched with the ChromaDB vector database, and according to the matching result, the table description most relevant to the query question is determined as the relevant table information, and the local question most similar to the query question is determined as the relevant question.
[0054] Optionally, before determining relevant table information and relevant questions according to the query question, the method further includes:
[0055] A local table and a local question are obtained, and table columns in the local table are annotated to obtain a table description; wherein the local table and the local question can be set according to requirements, and the format of table annotation for table columns in the local table is as follows:
[0056] The table comment corresponding to the table {table name} is {table comment}, and the corresponding column name and column name comment are {column name 1} (column name 1 comment), {column name 2} {column name 2 comment}..., fill in the specific table name in {table name}, fill in the specific table comment in {table comment}, fill in the specific column name of the first column of the table in {column name 1}, fill in the specific column name comment of the first column of the table in {column name 1 comment}, and so on, to get the table description.
[0057] The table description and the local question are vectorized to obtain a table vector and a local question vector, and the table vector and the local question vector are stored in a vector database; wherein each table description and local question is converted into a 1024-dimensional vector through a Chinese-lert-large model with a 24-layer transformer structure and stored in a ChromaDB vector database. When a user asks a query question, the five table descriptions most relevant to the query question are retrieved through the ChromaDB vector database to obtain relevant table information. As the user's query question changes, the relevant table information will also change dynamically, thus reducing the interference of irrelevant table information on the large model, allowing the large model to focus more on table information that may be related to the problem, thereby facilitating the large model to filter out the relevant tables that are really needed for the problem from the refined table information according to the user's question. The large model can adopt a text2sql model.
[0058] Further, determining relevant table information and relevant questions according to the query question includes:
[0059] Performing vector conversion on the query question to obtain a query vector, and calculating the similarity between the query vector and the table vector to obtain a first similarity;
[0060] Sorting the table descriptions according to the first similarity to obtain a table sorting, and determining the table descriptions before a first preset sequence number in the table sorting as the relevant table information;
[0061] Calculating the similarity between the query vector and the local question vector to obtain a second similarity, and sorting the local questions according to the second similarity to obtain a question sorting;
[0062] Determine the local question before the second preset sequence number in the question sorting as the relevant question;
[0063] Among them, the first preset serial number and the second preset serial number can be set according to needs. The lower the ranking of the table description in the table sorting, the lower the correlation between it and the query question; the lower the ranking of the local question in the question sorting, the lower the similarity between it and the query question.
[0064] Step S20, determining relevant dynamic examples according to the relevant questions, and determining industry background and query constraints according to the business scenario of the query question;
[0065] Among them, the question identifier of the query question is obtained, and the question identifier is matched with the scenario query table to obtain the industry background and query constraints. The scenario query table stores the correspondence between different question identifiers and the corresponding industry background and query constraints. The question identifier can be a scenario vocabulary, that is, by performing a lexical analysis on the query question, the scenario vocabulary in the query question is obtained to obtain the question identifier. The scenario vocabulary is used to represent the business scenario corresponding to the query question.
[0066] Optionally, determining relevant dynamic examples according to the relevant issues includes:
[0067] Obtain the relevant SQL statements corresponding to the relevant questions, and determine the relevant data tables, relevant fields and relevant query conditions according to the relevant questions and the relevant SQL; wherein, the relevant questions are matched with the SQL query table to obtain the relevant SQL statements, and the SQL query table stores the correspondence between different relevant questions and the corresponding relevant SQL statements. By calling the big model between each relevant question and the relevant SQL statement, the thinking process of deriving SQL according to the question is automatically generated to obtain the relevant data tables, relevant fields and relevant query conditions, for example: user question: {question}; SQL: {SQL}; please analyze the relevant tables, relevant fields and query conditions used in the above SQL according to the above user question. Return in the format of 1, relevant tables 2, relevant fields 3, query conditions...
[0068] A statement thinking process is generated according to the relevant data table, the relevant fields and the relevant query conditions, and the relevant questions, the statement thinking process and the relevant SQL statements are combined to obtain the relevant dynamic examples; wherein, the relevant questions-statement thinking process-related SQL statements are combined in the order of relevant questions-statement thinking process-related SQL statements to obtain relevant dynamic examples, so that the big model can better understand the query requirements. As the most relevant related questions retrieved by the ChromaDB vector database change with different user query questions, the corresponding relevant dynamic examples can be dynamically changed instead of being fixed, which is conducive to the big model to find the key points related to the questions in different query questions.
[0069] Step S30, generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question;
[0070] Optionally, generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question includes:
[0071] Obtain a prompt template, and fill in the table information, background information and constraint information in the prompt template according to the relevant table information, the industry background and the query constraints to obtain a candidate prompt; wherein the prompt template can be set according to the needs, and based on the relevant table information, the table information related to the query question can be effectively filled in the prompt template, and based on the industry background and query constraints, the background and constraints of the business scenario corresponding to the prompt question can be effectively filled in the prompt template;
[0072] According to the inverse order of the related questions corresponding to the related dynamic examples in the question ranking, the related dynamic examples are sequentially added to the candidate prompts; wherein, based on the inverse order of the question ranking, the related dynamic examples that are more similar to the query question are placed at the end, thereby effectively filling the prompt template with example information related to the query question;
[0073] After the relevant dynamic examples are added, the query question is added to the candidate prompt to obtain the question prompt.
[0074] Step S40, inputting the question prompt into the big model to generate a statement to obtain a SQL candidate statement, and performing slot value optimization on the SQL candidate statement to obtain a SQL output statement;
[0075] Among them, the large model can adopt the pre-trained text2sql model. The pre-trained text2sql model can effectively generate corresponding SQL candidate statements based on question prompts. By optimizing the slot values of the SQL candidate statements, the synonyms or abbreviations of the query conditions in the SQL statements can be automatically rewritten into the values actually stored in the database, avoiding the situation where the generated SQL statements cannot find data in the actual database due to the synonyms or abbreviations used in the user's query questions.
[0076] Optionally, slot value optimization is performed on the SQL candidate statement to obtain an SQL output statement, including:
[0077] Obtaining the query condition slot value in the SQL candidate statement, and determining the target data column parameter according to the query condition slot value; for example, when the query condition slot value is city = "Aba Prefecture", the determined target data column parameter is city;
[0078] Acquire the data corresponding to the target data column parameter in the relevant table information to obtain the relevant column data, and perform deduplication processing on the relevant column data; for example, when the determined target data column parameter is city, acquire the data corresponding to the city column in the relevant table information to obtain the relevant column data, and perform deduplication processing on the relevant column data to effectively improve the accuracy of the relevant column data;
[0079] Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database; wherein the relevant column data after deduplication processing is converted into a 1024-dimensional vector through a Chinese-lert-large model with a 24-layer transformer structure and stored in a ChromaDB vector database;
[0080] Determine the similar condition slot value in the vector database according to the query condition slot value, and replace the query condition slot value with the similar condition slot value in the SQL candidate statement to obtain the SQL output statement; wherein, retrieve the word closest to the query condition slot value through the ChromaDB vector database to obtain the similar word, input the similar condition slot value and the similar word into the big model for semantic analysis, and determine the similar word with the closest semantics as the similar condition slot value. For example, the big model believes that Aba Tibetan and Qiang Autonomous Prefecture and Aba Prefecture are semantically closest, then change the query condition city="Aba Prefecture" to city="Aba Tibetan and Qiang Autonomous Prefecture" in the SQL candidate statement to obtain the SQL output statement, thereby ensuring that the query condition slot value actually exists in the database. Under the premise that the SQL statement logic is correct, the query condition slot value optimization can ensure that the SQL statement can query the result as much as possible.
[0081] Furthermore, after obtaining the query condition slot value in the SQL candidate statement, the following is further included:
[0082] Matching the query condition slot value with the condition optimization table; wherein the condition optimization table can be set according to demand, and the condition optimization table is used to set the query condition that needs to be optimized. For example, when the query condition slot value is city = "Aba Prefecture" and "Aba Prefecture" matches the condition optimization table, it is determined that the SQL candidate statement needs to be slot optimized;
[0083] If the query condition slot value fails to match the condition optimization table, the SQL candidate statement is set as the SQL output statement; wherein, if the query condition slot value fails to match the condition optimization table, it is determined that there is no need to optimize the slot value of the SQL candidate statement.
[0084] This embodiment implements dynamic question prompts and SQL query condition slot value optimization. It is no longer necessary to organize a large amount of training set corpus to fine-tune the large model. Instead, it is only necessary to organize a small amount of (question, SQL) corpus pairs in advance and store them in the ChromaDB vector database, which greatly reduces labor costs and computing resources.
[0085] In this embodiment, the relevant tables and examples are dynamically retrieved according to different query questions, and the thought chain process in each example is automatically generated, and then the detected information is filled into the question prompt to form a dynamic question prompt. On the one hand, the dynamic question prompt avoids the problem that the question prompt content is too bloated or even exceeds the maximum text length that the large model can handle due to writing all tables and all examples into the question prompt at one time. On the other hand, it allows the large model to focus on the table information and examples related to the query question according to different query questions, which is more conducive to the large model's understanding of the query question.
[0086] In this embodiment, by determining the relevant table information and relevant questions corresponding to the query question, the relevant dynamic examples can be effectively determined. Based on the relevant table information, industry background, query constraints, relevant dynamic examples and query questions, question prompts corresponding to the query questions can be effectively generated. Based on the question prompts, SQL candidate statements can be effectively generated. By optimizing the slot values of the SQL candidate statements, the accuracy of the SQL output statements is effectively improved. Different query questions correspond to different question prompts, which prevents the phenomenon of low SQL statement generation accuracy due to the use of the same prompt data.
[0087] Embodiment 2
[0088] See also Figure 2 , is a schematic diagram of the structure of a SQL statement generation system 100 based on a large model provided in a second embodiment of the present invention, including:
[0089] The question determination module 10 is used to obtain a query question and determine relevant table information and relevant questions according to the query question.
[0090] Optionally, the problem determination module 10 is further used to: obtain a local table and a local problem, and annotate a table column in the local table to obtain a table description;
[0091] The table description and the local problem are vectorized to obtain a table vector and a local problem vector, and the table vector and the local problem vector are stored in a vector database.
[0092] Furthermore, the question determination module 10 is further used to: perform vector conversion on the query question to obtain a query vector, and calculate the similarity between the query vector and the table vector to obtain a first similarity;
[0093] Sorting the table descriptions according to the first similarity to obtain a table sorting, and determining the table descriptions before a first preset sequence number in the table sorting as the relevant table information;
[0094] Calculating the similarity between the query vector and the local question vector to obtain a second similarity, and sorting the local questions according to the second similarity to obtain a question sorting;
[0095] The local question before the second preset sequence number in the question sorting is determined as the relevant question.
[0096] The example determination module 11 is used to determine relevant dynamic examples according to the relevant questions, and to determine the industry background and query constraints according to the business scenario of the query question.
[0097] Optionally, the example determination module 11 is further used to: obtain a relevant SQL statement corresponding to the relevant question, and determine a relevant data table, relevant fields and relevant query conditions according to the relevant question and the relevant SQL;
[0098] A statement thinking process is generated according to the relevant data table, the relevant fields and the relevant query conditions, and the relevant questions, the statement thinking process and the relevant SQL statements are combined to obtain the relevant dynamic examples.
[0099] The prompt generating module 12 is used to generate a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question.
[0100] Optionally, the prompt generating module 12 is further used to: obtain a prompt template, and fill in the form information, background information and constraint information in the prompt template according to the relevant form information, the industry background and the query constraint to obtain a candidate prompt;
[0101] According to the inverse order of the order of the related questions corresponding to the related dynamic examples in the question order, the related dynamic examples are added to the candidate prompts in sequence;
[0102] After the relevant dynamic examples are added, the query question is added to the candidate prompt to obtain the question prompt.
[0103] The slot value optimization module 13 is used to input the problem prompt into the large model for statement generation to obtain SQL candidate statements, and perform slot value optimization on the SQL candidate statements to obtain SQL output statements.
[0104] Optionally, the slot value optimization module 13 is further used to: obtain the query condition slot value in the SQL candidate statement, and determine the target data column parameter according to the query condition slot value;
[0105] Acquire the data corresponding to the target data column parameter in the relevant table information, obtain relevant column data, and perform deduplication processing on the relevant column data;
[0106] Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database;
[0107] A similar condition slot value in the vector database is determined according to the query condition slot value, and in the SQL candidate statement, the query condition slot value is replaced by the similar condition slot value to obtain the SQL output statement.
[0108] Furthermore, the slot value optimization module 13 is also used to: match the query condition slot value with the condition optimization table; if the query condition slot value fails to match the condition optimization table, set the SQL candidate statement as the SQL output statement.
[0109] See also Figure 3 First, perform relevant table detection based on the query question, dynamically select 5 relevant table information and add them to the question prompt, then customize the industry background, query constraints and other information in the question prompt according to different business scenarios, perform relevant example detection, and add 6 examples related to the query question to the question prompt. The order of the above 6 examples is based on the similarity with the query question. The examples that are more similar to the question are placed at the end. Finally, add the user query question to the question prompt, generate SQL candidate statements by calling the LLM model, optimize the slot values of the SQL candidate statements, and generate SQL output statements.
[0110] This embodiment implements dynamic question prompts and SQL query condition slot value optimization. It is no longer necessary to organize a large amount of training set corpus to fine-tune the LLM model. Instead, it is only necessary to organize a small amount of (question, SQL) corpus pairs in advance and store them in the ChromaDB vector database, which greatly reduces labor costs and computing resources.
[0111] In this embodiment, the relevant tables and relevant examples are dynamically retrieved according to different query questions of the user, and the thought chain process in each example is automatically generated, and then the detected information is filled into the question prompt to form a dynamic question prompt. This dynamic question prompt, on the one hand, avoids the problem that the question prompt content is too bloated or even exceeds the maximum text length that LLM can handle due to writing all tables and all examples into the question prompt at one time, and on the other hand, allows the LLM model to focus on the table information and examples related to the query question according to different query questions, which is more conducive to the LLM model's understanding of the query question.
[0112] In this embodiment, the synonyms or abbreviations of the query conditions in the SQL statement can be automatically rewritten into the values actually stored in the database, avoiding the situation where the generated SQL statement cannot find data in the actual database due to the synonyms or abbreviations used in the user's query question.
[0113] In this embodiment, by determining the relevant table information and relevant questions corresponding to the query question, the relevant dynamic examples can be effectively determined. Based on the relevant table information, industry background, query constraints, relevant dynamic examples and query questions, question prompts corresponding to the query questions can be effectively generated. Based on the question prompts, SQL candidate statements can be effectively generated. By optimizing the slot values of the SQL candidate statements, the accuracy of the SQL output statements is effectively improved. Different query questions correspond to different question prompts, which prevents the phenomenon of low SQL statement generation accuracy due to the use of the same prompt data.
[0114] Embodiment 3
[0115] Figure 4 2 is a block diagram of a terminal device 2 provided in the third embodiment of the present application. Figure 4 As shown, the terminal device 2 of this embodiment includes: a processor 20, a memory 21, and a computer program 22 stored in the memory 21 and executable on the processor 20, such as a program of a SQL statement generation method based on a large model. When the processor 20 executes the computer program 22, the steps in each embodiment of the above-mentioned SQL statement generation method based on a large model are implemented.
[0116] Exemplarily, the computer program 22 may be divided into one or more modules, which are stored in the memory 21 and executed by the processor 20 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 22 in the terminal device 2. The terminal device may include, but is not limited to, a processor 20 and a memory 21.
[0117] The processor 20 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0118] The memory 21 may be an internal storage unit of the terminal device 2, such as a hard disk or memory of the terminal device 2. The memory 21 may also be an external storage device of the terminal device 2, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 2. Further, the memory 21 may also include both an internal storage unit and an external storage device of the terminal device 2. The memory 21 is used to store the computer program and other programs and data required by the terminal device. The memory 21 may also be used to temporarily store data that has been output or is to be output.
[0119] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional unit.
[0120] If the integrated module is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Among them, the computer-readable storage medium can be non-volatile or volatile. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable storage medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in computer-readable storage media can be appropriately increased or decreased according to the requirements of legislation and patent practices in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practices, computer-readable storage media do not include electrical carrier signals and telecommunication signals.
[0121] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for generating SQL statements based on a large model, characterized in that: The method comprises: Obtaining a query question, and determining relevant table information and relevant questions according to the query question; Determine relevant dynamic examples according to the relevant questions, and determine industry background and query constraints according to the business scenario of the query question; Generate a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question; The question prompt is input into the big model for statement generation to obtain SQL candidate statements, and the slot value of the SQL candidate statements is optimized to obtain SQL output statements.
2. The method for generating SQL statements based on a large model according to claim 1, characterized in that: The SQL candidate statement is optimized for slot values to obtain an SQL output statement, including: Obtaining a query condition slot value in the SQL candidate statement, and determining a target data column parameter according to the query condition slot value; Acquire the data corresponding to the target data column parameter in the relevant table information, obtain relevant column data, and perform deduplication processing on the relevant column data; Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database; A similar condition slot value in the vector database is determined according to the query condition slot value, and in the SQL candidate statement, the query condition slot value is replaced by the similar condition slot value to obtain the SQL output statement.
3. The method for generating SQL statements based on a large model according to claim 1, characterized in that: Before determining relevant table information and relevant questions according to the query question, the method further includes: Acquire a local table and a local question, and annotate table columns in the local table to obtain a table description; The table description and the local problem are vectorized to obtain a table vector and a local problem vector, and the table vector and the local problem vector are stored in a vector database.
4. The method for generating SQL statements based on a large model as claimed in claim 3, characterized in that: Determine relevant table information and relevant questions based on the query question, including: Performing vector conversion on the query question to obtain a query vector, and calculating the similarity between the query vector and the table vector to obtain a first similarity; Sorting the table descriptions according to the first similarity to obtain a table sorting, and determining the table descriptions before a first preset sequence number in the table sorting as the relevant table information; Calculating the similarity between the query vector and the local question vector to obtain a second similarity, and sorting the local questions according to the second similarity to obtain a question sorting; The local question before the second preset sequence number in the question sorting is determined as the relevant question.
5. The method for generating SQL statements based on a large model according to claim 1, characterized in that: Relevant dynamic examples are determined based on the relevant issues, including: Obtain relevant SQL statements corresponding to the relevant questions, and determine relevant data tables, relevant fields, and relevant query conditions according to the relevant questions and the relevant SQL statements; A statement thinking process is generated according to the relevant data table, the relevant fields and the relevant query conditions, and the relevant questions, the statement thinking process and the relevant SQL statements are combined to obtain the relevant dynamic examples.
6. The method for generating SQL statements based on a large model as claimed in claim 4, characterized in that: Generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question includes: Obtain a prompt template, and fill in the form information, background information and constraint information in the prompt template according to the relevant form information, the industry background and the query constraint to obtain a candidate prompt; According to the inverse order of the order of the related questions corresponding to the related dynamic examples in the question order, the related dynamic examples are added to the candidate prompts in sequence; After the relevant dynamic examples are added, the query question is added to the candidate prompt to obtain the question prompt.
7. The method for generating SQL statements based on a large model as claimed in claim 2, characterized in that: After obtaining the query condition slot value in the SQL candidate statement, the following steps are also included: Matching the query condition slot value with the condition optimization table; If the query condition slot value fails to match the condition optimization table, the SQL candidate statement is set as the SQL output statement.
8. A SQL statement generation system based on a large model, characterized in that: The system comprises: A question determination module, used to obtain a query question and determine relevant table information and relevant questions according to the query question; An example determination module, used to determine relevant dynamic examples according to the relevant questions, and determine industry background and query constraints according to the business scenario of the query question; A prompt generating module, used for generating a question prompt according to the relevant table information, the industry background, the query constraint, the relevant dynamic example and the query question; The slot value optimization module is used to input the problem prompt into the big model for statement generation to obtain SQL candidate statements, and perform slot value optimization on the SQL candidate statements to obtain SQL output statements.
9. The SQL statement generation system based on the large model as claimed in claim 8, characterized in that: The slot value optimization module is also used for: Obtaining a query condition slot value in the SQL candidate statement, and determining a target data column parameter according to the query condition slot value; Acquire the data corresponding to the target data column parameter in the relevant table information, obtain relevant column data, and perform deduplication processing on the relevant column data; Performing vector conversion on the relevant column data after deduplication processing to obtain column data vectors, and storing the column data vectors in a vector database; A similar condition slot value in the vector database is determined according to the query condition slot value, and in the SQL candidate statement, the query condition slot value is replaced by the similar condition slot value to obtain the SQL output statement.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.