SQL (Structured Query Language) generation method, system and equipment based on large language model and medium

By analyzing the database query log and user input query statements, and combining the large language model to generate the ultimate executable SQL statement, the problem of inaccurate complex SQL generation is solved, the accuracy and efficiency of SQL generation is improved, the threshold for use is reduced, and the improvement of improvement of the threshold for use is improved. User experience.

CN119226311APending Publication Date: 2024-12-31湖北省信产通信服务有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411190970.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

When generating complex SQL queries in the prior art, it is difficult to generate language models correctly, the generated queries are not efficient enough, and the metadata information of the table may not be enough to express the relationships and constraints between the data, resulting in the generated SQL queries not meeting actual needs. .

Method used

By obtaining the database query log, determine the SQL template and query statement, form an associated statement, and input the query statement input by the user into the large language model, generate the final executable SQL statement, using LoRA, QLoRA, P-tuning or Prompt- Tuning technology fine-tunes large language models to improve the accuracy of SQL generation.

Benefits of technology

It improves the accuracy of SQL generation, reduces the threshold for users to use SQL, improves the efficiency of writing SQL statements, can quickly find the data users want, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226311A_ABST
    Figure CN119226311A_ABST
Patent Text Reader

Abstract

The invention discloses an SQL generation method, system and device based on a large language model and a medium, and relates to the technical field of business data processing, the method comprises the following steps: obtaining a query log of a to-be-processed business, and determining a plurality of SQL templates and a corresponding associated statement formed by each SQL template; determining N target first association statements from all the first association statements according to a second query statement input by the user; forming a long text by all the target first associated statements, and inputting the long text into a large language model to obtain a first SQL statement; when a filtering condition exists in the first SQL statement, inputting the second query statement into a large language model to obtain a first filtering field; and determining a final executable SQL statement of the to-be-processed service according to the first SQL statement and the first filtering field. According to the method and the device, the problem of dependence on the relationship between data table metadata information and data is solved, the SQL use threshold of a user is reduced, and the SQL statement writing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Background Art

[0002] Structured Query Language (SQL) is a special-purpose programming language, a database query and programming language used to access data and query, update, and manage relational database systems. Traditionally, writing SQL queries requires proficiency in SQL syntax and database schemas. Therefore, when querying business data, most non-technical personnel need to rely on the assistance of technical personnel if they want to analyze the raw data information in the database.

[0003] At present, natural language can generate SQL by the user inputting query statements on the client, and the natural language to SQL engine will generate the corresponding SQL, then input the SQL statement into the database to execute and generate the corresponding results, and finally return the results to the client. The natural language SQL generation method based on the metadata information of the table usually relies on the Chinese and English comparison information of the table fields and the understanding ability of the large language model to achieve SQL generation.

[0004] However, for complex queries (such as those involving multi-table joins, nested subqueries, complex aggregate functions, etc.), the language model may be difficult to generate correctly, and the generated queries may not be efficient enough and cannot be executed correctly. At the same time, the metadata information of the table may not be sufficient to fully express the relationship and constraints between the data. The model may infer incorrect logic based on limited information, resulting in the generated SQL queries not meeting actual needs, and thus being unable to quickly search the database for the data that the user wants to search. Summary of the invention

[0005] The technical problem to be solved by the present invention is to address the deficiencies of the prior art, specifically the difficulties in using SQL and the inability of the model to generate SQL in accordance with the requirements, and specifically provide a SQL generation method, system, device and medium based on a large language model, as follows:

[0006] 1) In the first aspect, the present invention provides a SQL generation method based on a large language model, and the specific technical solution is as follows:

[0007] Obtain a query log of a database of the business to be processed, determine multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combine any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template;

[0008] Obtain a second query statement input by a user, and determine N target first associated statements that meet a preset condition from all first associated statements according to the second query statement; determine a long text according to texts corresponding to all target first associated statements, and input the long text into a large language model to obtain a first SQL statement;

[0009] When there is a filtering condition in the first SQL statement, the second query statement is input into the large language model to obtain a first filtering field; based on the first SQL statement and the first filtering field, a final executable SQL statement of the business to be processed is determined to search for data in a database of the business to be processed based on the final executable SQL statement.

[0010] The beneficial effects of the SQL generation method based on a large language model provided by the present invention are as follows:

[0011] By analyzing the query logs of the database, the SQL template and the corresponding query statements were determined. By inputting the long text consisting of the SQL template and the query statement into the large language model, the problem of relying on the metadata information of the data table and the relationship between the data was overcome; by inputting the user's query statement into the large language model, the SQL filtering conditions were made more precise, and the accuracy of SQL generation was improved. At the same time, by generating SQL based on the large language model, people who are not proficient in SQL syntax can also query the database through natural language, which lowers the threshold for users to use SQL, improves the efficiency of writing SQL statements, and is easy to implement; and based on the SQL statement, the data that the user wants to search can be determined more quickly, improving the user experience.

[0012] Based on the above solution, the present invention can also be improved as follows.

[0013] Furthermore, it also includes:

[0014] When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement of the service to be processed.

[0015] Further, after determining the plurality of SQL templates and the first query statement corresponding to each SQL template according to the query log, the method further includes: determining a plurality of second filter fields;

[0016] A plurality of second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set.

[0017] Further, the technique of fine-tuning the large language model according to the data set includes:

[0018] Any of LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology.

[0019] 2) In the second aspect, the present invention also provides a SQL generation system based on a large language model, and the specific technical solution is as follows:

[0020] Log module, query module and splicing module;

[0021] The log module is used to obtain a query log of a database of a to-be-processed business, determine multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combine any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template;

[0022] The query module is used to obtain a second query statement input by a user, determine N target first associated statements that meet a preset condition from all first associated statements according to the second query statement; determine a long text according to the texts corresponding to all the target first associated statements, input the long text into the large language model, and obtain a first SQL statement;

[0023] The splicing module is used to input the second query statement into the large language model to obtain a first filter field when a filter condition exists in the first SQL statement; determine the final executable SQL statement of the business to be processed based on the first SQL statement and the first filter field, so as to search for data in the database of the business to be processed based on the final executable SQL statement.

[0024] Based on the above solution, the present invention can also be improved as follows.

[0025] Furthermore, it also includes:

[0026] When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement of the service to be processed.

[0027] Further, after determining the plurality of SQL templates and the first query statement corresponding to each SQL template according to the query log, the method further includes: determining a plurality of second filter fields;

[0028] A plurality of second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set.

[0029] Further, the technique of fine-tuning the large language model according to the data set includes:

[0030] Any of LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology.

[0031] 3) In a third aspect, the present invention further provides a computer device, comprising a processor, wherein the processor is coupled to a memory, wherein the memory stores at least one computer program, and wherein the at least one computer program is loaded and executed by the processor so that the computer device implements any of the above methods.

[0032] 4) In a fourth aspect, the present invention further provides a computer-readable storage medium, wherein at least one computer program is stored in the computer-readable storage medium, and the at least one computer program is loaded and executed by a processor so that a computer implements any of the above methods.

[0033] It should be noted that the beneficial effects achieved by the technical solutions of the second to fourth aspects of the present invention and the corresponding possible implementation methods can be found in the above-mentioned technical effects of the first aspect and its corresponding possible implementation methods, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0035] Figure 1 A flowchart of a SQL generation method based on a large language model according to an embodiment of the present invention;

[0036] Figure 2 The figure is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.

[0038] like Figure 1 As shown, a SQL generation method based on a large language model in an embodiment of the present invention includes the following steps:

[0039] S1, obtaining a query log of a database of a service to be processed, determining multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combining any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template;

[0040] S2, obtaining a second query statement input by a user, and determining N target first associated statements that meet a preset condition from all first associated statements according to the second query statement; determining a long text according to the texts corresponding to all the target first associated statements, and inputting the long text into a large language model to obtain a first SQL statement;

[0041] S3, when there is a filtering condition in the first SQL statement, the second query statement is input into the large language model to obtain the first filtering field; according to the first SQL statement and the first filtering field, the final executable SQL statement of the business to be processed is determined to search for data in the database of the business to be processed based on the final executable SQL statement.

[0042] The beneficial effects of the SQL generation method based on a large language model provided by the present invention are as follows:

[0043] By analyzing the query logs of the database, the SQL template and the corresponding query statements were determined. By inputting the long text consisting of the SQL template and the query statement into the large language model, the problem of relying on the metadata information of the data table and the relationship between the data was overcome; by inputting the user's query statement into the large language model, the SQL filtering conditions were made more precise, and the accuracy of SQL generation was improved. At the same time, by generating SQL based on the large language model, people who are not proficient in SQL syntax can also query the database through natural language, which lowers the threshold for users to use SQL, improves the efficiency of writing SQL statements, and is easy to implement.

[0044] S1, obtaining a query log of a database of a business to be processed, determining multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combining any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template.

[0045] After determining multiple SQL templates and the first query statement corresponding to each SQL template according to the query log, it also includes: determining multiple second filter fields; forming the multiple second filter fields into a data set, and fine-tuning the large language model according to the data set.

[0046] The technologies for fine-tuning the large language model according to the data set include: LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology. Among them:

[0047] The pending business refers to the business that needs to be analyzed based on the original data in the database or the business with large and complex data volume. For example, the merchant order business in the e-commerce website, the broadband processing business in a certain area, the telecommunications convergence business, etc.

[0048] Database refers to: a relational database that can use SQL to retrieve data.

[0049] Query log refers to the log generated by the system when SQL is used to query the database, including query SQL, query results, query time and other information.

[0050] SQL template refers to a template composed of query indicators and query methods (such as single-table query, multi-table joint query, nested subquery, and complex aggregate function query, etc.) of a data table. For example: select filed1, filed2, filed3 from table where condition1 and condition2.

[0051] The first query statement refers to: a query statement in natural language. For example: querying the data filed1, filed2, filed3 in the table table when the conditions are condition1 and condition2.

[0052] The first associative statement refers to: for example: select filed1, filed2, filed3 from table where condition1 and condition2 and query the filed1, filed2, filed3 data in the table when the conditions are condition1 and condition2.

[0053] The second filter field refers to the filter field in the where condition in the SQL statement. For example: {"condition1":"A place"}, {"condition2":"a time"}.

[0054] In this embodiment, the large language model is selected as the open source Yi-34B-Chat large model with 34 billion parameters. The fine-tuning of the Yi-34B-Chat large language model can be performed by using LoRA, QLoRA, P-tuning or Prompt-tuning. Since the several fine-tuning technologies mentioned here are existing technologies, only a brief introduction is given as follows.

[0055] LoRA means: LoRA (Label-Only Rehearsal with Attention) fine-tuning is a technique for continuous learning, especially widely used in the field of natural language processing. Its main goal is to update the existing model by minimizing the impact on the performance of old tasks when receiving new data, so that it can effectively learn new tasks or new domains while maintaining the memory of old tasks.

[0056] QLoRA means: QLoRA (Query-Label Rehearsal with Attention) is a further improvement based on LoRA, aiming to further improve the performance and stability of the model in continuous learning. Unlike traditional label replay only, QLoRA introduces a combination of query-label replay and attention mechanism to better manage the balance between new and old tasks and information reuse. QLoRA fine-tuning provides a more flexible and effective strategy for model updating and knowledge accumulation in continuous learning by introducing query-label replay and optimized attention mechanism.

[0057] P-tuning refers to: P-tuning (Pattern-based Tuning) is a fine-tuning method for natural language processing (NLP) tasks, which aims to improve the performance of the model on specific tasks. Its core idea is to use the language patterns learned by the language model in the pre-training stage to help fine-tune the model to adapt to the needs of specific tasks. P-tuning uses the language patterns learned in the pre-trained language model and combines them with task-specific patterns for fine-tuning. It is an effective method to improve model performance, especially for application scenarios that require efficient use of pre-trained model knowledge.

[0058] Prompt-tuning refers to: Prompt-tuning large model fine-tuning is a prompt-based method that adjusts the output of the model by modifying the prompt words in the input sequence; this method has achieved remarkable success in the field of natural language processing (NLP). It adjusts the model behavior by fine-tuning the prompt words. The prompt-tuning method has the advantages of flexibility and scalability, and can quickly adapt to various new tasks and fields.

[0059] Multiple second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set so that the large model can learn the correspondence between the query statement and the filter field information in the where condition of the SQL statement, and obtain a fine-tuned large language model that can generate the filter field information in the where condition of the corresponding SQL statement through the query statement. The fine-tuned large language model is used for subsequent steps to make SQL generation more accurate and improve the accuracy of SQL queries.

[0060] S2, obtaining the second query statement input by the user, determining N target first associated statements that meet the preset conditions from all the first associated statements according to the second query statement; determining a long text according to the texts corresponding to all the target first associated statements, inputting the long text into the large language model, and obtaining the first SQL statement. Wherein:

[0061] The second query statement refers to a natural language query statement input by the user, for example, querying the performance of a certain region within a certain period of time. The abbreviations of the keywords of the new question and the commonly used synonyms are rewritten in combination with the user's usage habits and the synonym dictionary, and the query statement is processed into a standard query.

[0062] The target first associated sentences refer to: N first associated sentences that meet the preset conditions.

[0063] The first SQL statement is a statement that is close to an executable SQL statement, for example, select filed1, filed2 from table where condition1 or select filed1, filed2 from table. It should be noted that at this time, the where condition in the first SQL statement may not exist. If it does exist, it may be incorrect, which will be processed in S3.

[0064] During use, according to the second query statement input by the user, the 10 target first-related statements with the highest correlation with the second query statement are matched according to the preset matching conditions, the SQL templates corresponding to the 10 target first-related statements and the corresponding first query statements are spliced ​​into a long text, the long text is input into the large language model, and the corresponding first SQL statement is generated. For example, in the telecommunications convergence business scenario, the keyword "end-to-end mismatch" is rewritten as "end without business".

[0065] S3, when there is a filtering condition in the first SQL statement, the second query statement is input into the large language model to obtain the first filtering field; according to the first SQL statement and the first filtering field, the final executable SQL statement of the business to be processed is determined to search for data in the database of the business to be processed based on the final executable SQL statement.

[0066] When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement for the service to be processed.

[0067] The filtering condition refers to whether it contains where and subsequent classification conditions.

[0068] The first filter field refers to an accurate filter field obtained by inputting the second query statement into the large language model.

[0069] When there is a filtering condition in the first SQL statement, the first SQL statement and the first filtering field are concatenated to obtain the final executable SQL statement for the business to be processed. This process can also be seen as combining the first SQL statement with accurate query indicators but inaccurate filtering conditions with the accurate first filtering field to obtain an executable SQL statement containing accurate query indicators and accurate filtering conditions.

[0070] When the first SQL statement does not have a filtering condition, the first SQL statement is an SQL statement including accurate query indicators and does not contain a where condition, and this SQL statement is executed as a final executable SQL statement.

[0071] In addition, this embodiment also includes: executing executable SQL statements in the database to generate corresponding query results, then returning the query results to the client, and the user scoring according to the answers, and finally manually correcting the returned query logs to obtain new training corpus. The newly collected training corpus is added to the fine-tuned large language model for incremental fine-tuning, improving the accuracy of the model in extracting the filtering field information in the where condition of the SQL statement, thereby improving the accuracy of the SQL query.

[0072] The beneficial effects of adopting the above scheme are as follows:

[0073] 1. The present invention generates an SQL statement that does not fill in the correct where condition by combining the first query statement and the SQL template question and answer corpus into a long text input into the large language model, and puts the query statement and the filter field information in the where condition of the SQL statement as a training data set into the large language model for fine-tuning, so that the model learns the filter field information in the where condition of the SQL statement corresponding to the query information. The second query statement is input into the fine-tuned large language model, and the filter field information in the where condition of the corresponding SQL statement can be generated. Then, the filter field in the where condition is put into the SQL statement that does not fill in the filter field in the correct where condition to obtain the final executable SQL, and then the SQL is put into the database for execution, and the corresponding answer can be generated, and the answer is finally returned to the question and answer client. This method reduces the threshold for users to use SQL, improves the efficiency of writing SQL statements, greatly improves the accuracy of complex SQL generation, and also reduces costs, is easy to implement and continuously optimized, and proposes a new solution for the interaction between users and databases.

[0074] 2. Improve query efficiency: Traditionally, writing SQL queries requires proficiency in SQL syntax and database schema. The big language model can directly convert natural language queries into SQL queries, saving users the time and effort of learning SQL syntax. This natural language to SQL conversion can greatly improve the query writing speed and execution efficiency.

[0075] 3. Reduce query error rate: Manually writing SQL queries is prone to syntax errors or logical errors, especially for users who are not familiar with SQL. Using a large language model for natural language to SQL conversion can reduce the occurrence of these errors because the model can understand the user's intention and generate SQL statements that are grammatically and logically correct.

[0076] 4. Enhanced user experience: For non-technical personnel or novice users, learning and using SQL is usually a high threshold. With the large language model, users can directly describe their query requirements in the natural language they are familiar with, without having to deeply understand the database structure and SQL syntax. This intuitive interaction method significantly improves the user experience and enables more people to use the database for complex queries and analysis.

[0077] 5. Support complex queries: The large language model can learn complex SQL queries through an external knowledge base and extract the filter field information in the where condition of the SQL statement through the large language model, thereby improving the accuracy of complex SQL queries.

[0078] 6. Automation and intelligence: With the further development and application of large language models, more advanced functions can be realized, such as automatic report generation, intelligent recommendation query optimization, semantic understanding and context awareness, etc. These functions will further enhance the intelligence level of database systems and improve the efficiency and quality of data analysis.

[0079] The method of converting natural language into SQL based on a large language model has broad application prospects in the field of database query and analysis. It can significantly improve work efficiency, reduce error rates, and improve user experience, thus bringing significant results.

[0080] In the above embodiments, although the steps are numbered S1, S2, etc., these are only specific embodiments given by the present invention. Those skilled in the art may adjust the execution order of S1, S2, etc. according to actual conditions, which is also within the protection scope of the present invention. It can be understood that in some embodiments, some or all of the above embodiments may be included.

[0081] The present invention also provides a SQL generation system based on a large language model, and the specific technical scheme is as follows: comprising: a log module, a query module and a splicing module;

[0082] A log module, used to obtain a query log of a database of a business to be processed, determine multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combine any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template;

[0083] A query module is used to obtain a second query statement input by a user, and determine N target first associated statements that meet preset conditions from all first associated statements according to the second query statement; determine a long text according to the texts corresponding to all the target first associated statements, and input the long text into the large language model to obtain a first SQL statement;

[0084] The splicing module is used to input the second query statement into the large language model to obtain the first filter field when there is a filter condition in the first SQL statement; determine the final executable SQL statement of the business to be processed based on the first SQL statement and the first filter field, so as to search for data in the database of the business to be processed based on the final executable SQL statement.

[0085] Furthermore, it also includes:

[0086] When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement of the service to be processed.

[0087] Further, after determining multiple SQL templates and the first query statement corresponding to each SQL template according to the query log, it also includes: determining multiple second filter fields;

[0088] The plurality of second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set.

[0089] Further, techniques for fine-tuning large language models based on datasets include:

[0090] Any of LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology.

[0091] It should be noted that the beneficial effects of the SQL generation system based on a large language model provided in the above embodiment are the same as the beneficial effects of the SQL generation method based on a large language model, which will not be repeated here. In addition, when the system provided in the above embodiment realizes its functions, it only takes the division of the above functional modules as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the system is divided into different functional modules according to actual conditions to complete all or part of the functions described above. In addition, the system and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0092] like Figure 2 As shown, a computer device 300 according to an embodiment of the present invention includes a processor 320, the processor 320 is coupled to a memory 310, and the memory 310 stores at least one computer program 330, and the at least one computer program 330 is loaded and executed by the processor 320, so that the computer device 300 implements any of the above methods, specifically:

[0093] The computer device 300 may have relatively large differences due to different configurations or performances, and may include one or more processors 320 (Central Processing Units, CPU) and one or more memories 310, wherein the one or more memories 310 store at least one computer program 330, and the at least one computer program 330 is loaded and executed by the one or more processors 320, so that the computer device 300 implements a SQL generation method based on a large language model provided in the above embodiment. Of course, the computer device 300 may also have components such as a wired or wireless network interface, a keyboard, and an input and output interface for input and output, and the computer device 300 may also include other components for implementing device functions, which will not be described in detail here.

[0094] A computer-readable storage medium according to an embodiment of the present invention stores at least one computer program, and the at least one computer program is loaded and executed by a processor so that a computer implements any one of the above methods.

[0095] Optionally, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, and the like.

[0096] In an exemplary embodiment, a computer program product or a computer program is also provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes any of the above-mentioned SQL generation methods based on a large language model.

[0097] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects and represent the definition of a specific order or sequence. The order of use of similar objects can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than the order shown or described.

[0098] Those skilled in the art know that the present invention can be implemented as a system, method or computer program product. Therefore, the present disclosure can be specifically implemented in the following forms, namely: it can be complete hardware, it can be complete software (including firmware, resident software, microcode, etc.), or it can be a combination of hardware and software, which is generally referred to as "circuit", "module" or "system" herein. In addition, in some embodiments, the present invention can also be implemented in the form of a computer program product in one or more computer-readable media, and the computer-readable medium contains computer-readable program code.

[0099] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, device, or device.

[0100] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A SQL generation method based on a large language model, characterized in that: include: Obtain a query log of a database of the business to be processed, determine multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combine any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template; Obtain a second query statement input by a user, and determine N target first associated statements that meet a preset condition from all first associated statements according to the second query statement; determine a long text according to texts corresponding to all target first associated statements, and input the long text into a large language model to obtain a first SQL statement; When there is a filtering condition in the first SQL statement, the second query statement is input into the large language model to obtain a first filtering field; based on the first SQL statement and the first filtering field, a final executable SQL statement of the business to be processed is determined to search for data in a database of the business to be processed based on the final executable SQL statement.

2. The SQL generation method based on a large language model according to claim 1, characterized in that: Also includes: When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement of the service to be processed.

3. The SQL generation method based on a large language model according to claim 1, characterized in that: After determining the plurality of SQL templates and the first query statement corresponding to each SQL template according to the query log, the method further includes: determining a plurality of second filter fields; A plurality of second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set.

4. The SQL generation method based on a large language model according to claim 3, characterized in that: The technique of fine-tuning the large language model according to the data set includes: Any of LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology.

5. A SQL generation system based on a large language model, characterized in that: include: Log module, query module and splicing module; The log module is used to obtain a query log of a database of a to-be-processed business, determine multiple SQL templates and a first query statement corresponding to each SQL template according to the query log, and combine any SQL template and its corresponding first query statement into a first associated statement corresponding to the SQL template; The query module is used to obtain a second query statement input by a user, determine N target first associated statements that meet a preset condition from all first associated statements according to the second query statement; determine a long text according to the texts corresponding to all the target first associated statements, input the long text into the large language model, and obtain a first SQL statement; The splicing module is used to input the second query statement into the large language model to obtain a first filter field when a filter condition exists in the first SQL statement; determine the final executable SQL statement of the business to be processed based on the first SQL statement and the first filter field, so as to search for data in the database of the business to be processed based on the final executable SQL statement.

6. The SQL generation system based on a large language model according to claim 5, characterized in that: Also includes: When there is no filtering condition in the first SQL statement, the first SQL statement is used as the final executable SQL statement of the service to be processed.

7. The SQL generation system based on a large language model according to claim 5, characterized in that: After determining the plurality of SQL templates and the first query statement corresponding to each SQL template according to the query log, the method further includes: determining a plurality of second filter fields; A plurality of second filter fields are combined into a data set, and the large language model is fine-tuned according to the data set.

8. The SQL generation system based on a large language model according to claim 7, characterized in that: The technique of fine-tuning the large language model according to the data set includes: Any of LoRA technology, QLoRA technology, P-tuning technology and Prompt-tuning technology.

9. A computer device, characterized in that: The computer device comprises a processor, the processor is coupled to a memory, at least one computer program is stored in the memory, and the at least one computer program is loaded and executed by the processor so that the computer device implements the method according to any one of claims 1 to 4.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one computer program, and the at least one computer program is loaded and executed by a processor so that a computer implements the method according to any one of claims 1 to 4.

Citation Information

Cited By

  • SQL statement generation method and device, electronic equipment and storage medium

    CN120470021A