Method for reducing natural language to generate complex SQL (Structured Query Language) by constructing table mode and converting SQL

By building table schema and SQL conversion methods, the difficulties of NL2SQL technology in understanding database schema and generating complex SQL are solved, and more accurate, lower cost and faster SQL generation is achieved, simplifying database schema description and SQL operations.

CN119271697AActive Publication Date: 2025-01-07GUANGZHOU HUAWEI TOMORROW SOFTWARE TECH

Patent Information

Application Number
CN202411797712.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-01-07
Estimated Expiration
2044-12-09

AI Technical Summary

Technical Problem

The existing NL2SQL technology has difficulties in understanding database schema and generating complex SQL, especially the large language model lacks understanding of database schema, which leads to the generated SQL complex and inaccurate, high maintenance costs and long-term time.

Method used

By building table schema and SQL conversion methods, pre-configuring the database schema, using vector search and full-text search to mix search table schema and SQL examples, building pseudo-table schema and simplifying SQL operations, reducing SQL complexity, and describing table schema based on CSV format for easier use Model learning and maintenance.

Benefits of technology

Improve the accuracy of complex queries, reduce maintenance costs and time-consuming, simplify the SQL generation process, and reduce the probability of generating errors and the number of tokens.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119271697A_ABST
    Figure CN119271697A_ABST
Patent Text Reader

Abstract

The invention discloses a method for reducing natural language generation complex SQL through table mode construction and SQL conversion. The method comprises the steps that a database mode is configured in advance, and a request of a user is processed; a database mode is pre-configured. The method comprises the following configuration steps: 1.1, a user configures connection information of a database to obtain a read permission of a target database in the database; and 1.2, reading table mode information from the target database according to the information configured by the user in the step 1.1, randomly reading two records at the same time, naming the two records as data 1 and data 2 respectively, and storing the data 1 and the data 2 in the database as a table mode. The method for processing Query of a user by the system comprises the following steps of: 2.1, retrieving a database mode related to the Query, and retrieving a related table mode from a database; 2.2, retrieving an SQL (Structured Query Language) example related to Query; 2.3, prompt word construction; 2.4, generating an SQL (structured query language) through the LLM model; 2.5, rewriting the SQL; and 2.6, executing the SQL. The method has the characteristics of more accurate complex query, lower maintenance cost and shorter time consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of converting natural language into structured query language of database, and in particular to a method for reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion. Background Art

[0002] The task of natural language to structured query language (NL2SQL) is to convert natural language into the database's structured query language (SQL). This technology enables users to interact with the database through natural language without knowing SQL. Due to the diversity of user question expressions, the complexity of database table structure and SQL, generating accurate SQL from natural language questions is a challenging task.

[0003] Traditional NL2SQL systems are usually based on rules and deep learning network methods. Although they have achieved good performance, rule-based methods rely on manual work and are therefore expensive. Traditional neural network-based methods require continuous fine-tuning of models based on business areas, which is very inflexible as databases become increasingly complex.

[0004] In recent years, with the popularity of Large Language Models (LLM), NL2SQL based on LLM has become a widely-watched research direction. With its powerful language understanding ability, LLM can achieve good results with only prompt words without fine-tuning. Although NL2SQL based on large models has made breakthroughs compared to previous methods, it still has the following problems: 1. LLM has a weak understanding of database schema: LLM understands the table names, column names and the relationships between various tables in the database, which is the basis for accurately generating SQL queries. However, database schemas are often complex and do not always conform to the most ideal design specifications, and they also vary greatly in different fields. How to accurately represent database schemas is a challenging task.

[0005] 2. The generated complex SQL does not meet expectations: In order to complete the user's query, you may need to use operations such as outer joins, subqueries, and window functions. These types of SQL are usually longer and involve more tables and operation types, so it is more difficult for LLM to accurately generate SQL. At the same time, the number of SQLs containing these types of operations in the data set used by the mainstream large model during the training phase is small, so the mainstream large model is not good at generating complex SQL.

[0006] Therefore, in view of the shortcomings of the prior art, it is necessary to provide a method for reducing the generation of complex SQL from natural language by constructing table schema and SQL conversion to overcome the shortcomings of the prior art. Summary of the invention

[0007] The purpose of the present invention is to avoid the shortcomings of the prior art and provide a method for reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion, which has the characteristics of more accurate complex queries, lower maintenance costs and shorter time consumption.

[0008] The purpose of the present invention is achieved through the following technical measures.

[0009] A method is provided for reducing complex SQL generated by natural language by constructing table schema and SQL conversion, including: pre-configuring database schema and processing user requests; Pre-configure the database mode. The specific configuration steps are as follows: 1.1 The user configures the database connection information to obtain the read permission of the target database in the database; 1.2 According to the information configured by the user in step 1.1, the table schema information is read from the target database, and two records are randomly read and named as data 1 and data 2 respectively. The read table schema information and the read records are stored in the database as table schemas in units of tables; the set of stored table schemas constitutes the database schema; The system processes the user's query request in the following steps: 2.1 Retrieve the database schema related to the query, specifically by combining vector search and full-text search to retrieve the relevant table schema from the database; 2.2 Retrieve SQL examples related to the query, specifically by combining vector search and full-text search to retrieve relevant SQL examples from the database; 2.3 Prompt word construction, specifically filling in the query, table mode, and SQL example into the prompt template; 2.4 Generate SQL through LLM model; 2.5 Rewrite SQL to simplify the original complex SQL operations into single-table operation SQL; 2.6 SQL execution.

[0010] Preferably, in the above method of reducing the generation of complex SQL from natural language by constructing table schema and SQL conversion, the table schema information in step 1.2 is table name, table description, schema name, field name, field type, and field description.

[0011] Preferably, the above method for reducing complex SQL generated from natural language by constructing table schema and SQL conversion further includes step 1.3 of modifying the read database schema to obtain a modified database schema and a corresponding table schema.

[0012] Preferably, in the above method of reducing complex SQL generated from natural language by constructing table schema and SQL conversion, in step 1.3, the read database schema is modified, specifically, the table schema that will not be used in NL2SQL is deleted and the fields that are not used in the table schema are deleted.

[0013] Preferably, in the above method of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion, the table of the database mode contains a table name, a table description and a field declaration in csv format; the field declaration in csv format contains 5 fields, namely field name, data type, description, data 1 and data 2.

[0014] Preferably, the above method of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion builds a pseudo table on a database mode based on the CSV format, and simplifies the query operation originally involving multiple tables into a single table operation through the pseudo table.

[0015] Preferably, the above method of reducing complex SQL generated from natural language by constructing table schema and SQL conversion obtains a pseudo table by logically merging fields of two tables, and the schema of the logically merged tables is called a pseudo table schema.

[0016] Preferably, in the above method of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion, the pseudo table mode is used in the SQL generated by the large model according to the user's Query, and the SQL is rewritten into the SQL for operating the original table according to the rules.

[0017] Preferably, in the above method of reducing the generation of complex SQL from natural language by constructing table schema and SQL conversion, in step 1.3, the read database schema is modified according to actual business needs to obtain a modified standard database schema and a corresponding standard table schema.

[0018] The method of reducing the generation of complex SQL by natural language through constructing table mode and SQL conversion of the present invention comprises: pre-configuring database mode and processing user's request; pre-configuring database mode, the specific configuration steps are as follows: 1.1 user configures database connection information to obtain the read permission of the target database in the database; 1.2 according to the information configured by the user in step 1.1, reads table mode information from the target database, and randomly reads two records and names them as data 1 and data 2 respectively, and stores the read table mode information and the read records in the database as table mode in units of tables; the set of stored table modes constitutes the database mode; the system processes the user's request Query, the specific steps are as follows: 2.1 retrieves the database mode related to the Query, specifically through the combination of vector retrieval and full-text retrieval, retrieves the relevant table mode from the database; 2.2 retrieves the SQL example related to the Query, specifically through the combination of vector retrieval and full-text retrieval, retrieves the relevant SQL example from the database; 2.3 prompt word construction, specifically filling the Query, table mode, and SQL example into the prompt template; 2.4 Generate SQL through LLM model; 2.5 Rewrite SQL to simplify the original complex SQL operation into single table operation SQL; 2.6 SQL execution.

[0019] Compared with other existing technical solutions, the present invention has the following advantages: 1. Complex queries are more accurate. The pseudo-table mode and SQL rewriting technology pioneered by the present invention can effectively reduce the complexity of the SQL that LLM needs to generate for complex queries, reduce the probability that the generated SQL cannot be executed, and reduce the time required for complete SQL generation. On the other hand, the present invention describes the table mode based on csv, so that in addition to the field name, field type, and field remarks that can also be included in other work, the table mode can also contain additional table records, so that the model can learn the specific storage format of the records in the table.

[0020] 2. Lower maintenance cost. The present invention is based on csv to organize the table mode. Compared with other NL2SQL methods that describe the table mode based on database table creation statements, the present invention is easier to be maintained by non-technical personnel.

[0021] 3. Shorter time consumption: The time consumption of NL2SQL mainly lies in the number of tokens required to generate for large models. SQL rewriting technology makes it possible to complete operations that originally required the generation of long SQL statements by generating shorter SQL statements, thus greatly reducing time consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] The present invention is further described with reference to the accompanying drawings, but the contents in the accompanying drawings do not constitute any limitation to the present invention.

[0023] Figure 1 It is a flow chart of a method of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion according to the present invention. DETAILED DESCRIPTION

[0024] The present invention will be further described with reference to the following examples.

[0025] Example 1 A method for reducing complex SQL generated by natural language by building table mode and SQL conversion includes: pre-configuring database mode and processing user requests.

[0026] Pre-configure the database mode. The specific configuration steps are as follows: 1.1 The user configures the database connection information to obtain the read permission of the target database in the database; 1.2 According to the information configured by the user in step 1.1, the table schema information is read from the target database, and two records are randomly read and named as data 1 and data 2 respectively. The read table schema information and the read records are stored in the database as table schemas in units of tables; the collection of stored table schemas constitutes the database schema.

[0027] The table schema information includes table name, table description, schema name, field name, field type, and field description.

[0028] The system processes the user's query request, such as Figure 1 As shown, the specific steps are as follows: 2.1 Retrieve the database schema related to the query, specifically by combining vector search and full-text search to retrieve the relevant table schema from the database; 2.2 Retrieve SQL examples related to the query, specifically by combining vector search and full-text search to retrieve relevant SQL examples from the database; 2.3 Prompt word construction, specifically filling in the query, table mode, and SQL example into the prompt template; 2.4 Generate SQL through LLM model; 2.5 Rewrite SQL to simplify the original complex SQL operations into single-table operation SQL; 2.6 SQL execution.

[0029] Database schema description is a key issue for NL2SQL. Only after the database schema is accurately described can LLM generate accurate SQL. In the past, table schemas were represented by table creation statements, such as "CREATE TABLE V_ATN_Record (name nvarchar(255), employee_id int, attendance_date date, show_temperature varchar(255), attendance_time time, organ_name varchar(255));". Although this method helps the model understand the table structure, it has three obvious disadvantages: First: The format of the data stored in the table cannot be represented. This makes it difficult for LLM to generate SQL statements based on the specific data storage format. For example, for a field storing the name of an administrative district, the actual stored value may be "Guangzhou" or "Guangzhou City". For a field storing "date", the actual stored value may be "2024-08-20" or "2024 / 08 / 20 / 000000".

[0030] Second: LLM may not understand the purpose and usage of the table. In previous work, the usage of the table was prompted to LLM through SQL examples, but this method may cause the table and SQL examples to not correspond.

[0031] Third: High maintenance cost. The table creation statement is not suitable for non-professionals to maintain.

[0032] In order to overcome the above problems, this application decomposes the representation of the database model into three parts: table name, table description and field declaration in csv format. The field declaration in csv format contains 5 fields, namely field name, data type, description, data 1 and data 2, where data 1 and data 2 are records randomly sampled from the table, used to indicate the storage format of the large model data.

[0033] This technology reduces the generation of complex SQL from natural language by building table models and SQL conversion. On a database model based on the CSV format, a pseudo table is built to simplify query operations that originally involved multiple tables into single-table operations.

[0034] Preferably, the above method of reducing complex SQL generated from natural language by constructing table schema and SQL conversion obtains a pseudo table by logically merging fields of two tables, and the schema of the logically merged tables is called a pseudo table schema.

[0035] A pseudo table is an artificially constructed table proposed on a database model based on the CSV format, which is designed to help simplify query operations that originally involve multiple tables into single-table operations. For example, a pseudo table model can be created based on the employee table and the supplementary punch-in table.

[0036] The characteristic of pseudo table mode is that the information density is higher, and there is no need to consider the corresponding relationship with the database table. For example, for the query requirement "Who is late this week", you can add a row "late, bool, indicating whether the employee is late on that day, 1 is late, 0 is not late" in the pseudo table, without considering whether the late field actually exists in the real database. When the SQL generated by LLM uses this field, you can clearly know the user's question intention, and extract and rewrite the SQL parameters.

[0037] The method of reducing the generation of complex SQL from natural language by building table mode and SQL conversion, the pseudo table mode is used in the SQL generated by the large model according to the user's query, and the SQL is rewritten into the SQL operating the original table according to the rules.

[0038] When LLM generates complex SQL, it is very easy to generate SQL that does not conform to the syntax, or conforms to the syntax but the query results are not what the user needs, due to insufficient model capabilities such as model hallucination. SQL rewriting aims to reduce the difficulty of LLM generating SQL and simplify operations that can only be completed by complex SQL into shorter single-table operation SQL.

[0039] After using SQL rewriting technology, LLM only needs to generate simple SQL, and the code logic will restore the SQL. Therefore, LLM needs fewer TOKENs to generate complete SQL, which speeds up the system's response and reduces the cost of TOKEN generation.

[0040] For example, the table schema of two tables is required to use the JOIN syntax, but if the fields of the two tables are logically merged in advance, the JOIN operation can be omitted. We call the schema of the logically merged tables a pseudo table schema.

[0041] If the pseudo table mode is used in the SQL generated by the large model based on the user's query, the SQL will be rewritten into SQL that operates the original table according to the rules.

[0042] Compared with other existing technical solutions, the method of this embodiment of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion has the following advantages: 1. Complex queries are more accurate. The pseudo-table mode and SQL rewriting technology pioneered by the present invention can effectively reduce the complexity of the SQL that LLM needs to generate for complex queries, reduce the probability that the generated SQL cannot be executed, and reduce the time required for complete SQL generation. On the other hand, the present invention describes the table mode based on csv, so that in addition to the field name, field type, and field remarks that can also be included in other work, the table mode can also contain additional table records, so that the model can learn the specific storage format of the records in the table.

[0043] 2. Lower maintenance cost. The present invention is based on csv to organize the table mode. Compared with other NL2SQL methods that describe the table mode based on database table creation statements, the present invention is easier to be maintained by non-technical personnel.

[0044] 3. Shorter time consumption: The time consumption of NL2SQL mainly lies in the number of tokens required to generate for large models. SQL rewriting technology makes it possible to complete operations that originally required the generation of long SQL statements by generating shorter SQL statements, thus greatly reducing time consumption.

[0045] Example 2 A method for reducing complex SQL generated by natural language by constructing table mode and SQL conversion, the other features are the same as those of embodiment 1, except that: it also has the following features.

[0046] The method of reducing complex SQL generated by natural language by constructing table schema and SQL conversion in this example also includes step 1.3 of modifying the read database schema to obtain a modified database schema and a corresponding table schema. In step 1.3, the read database schema is modified, specifically deleting the table schema that will not be used in NL2SQL and deleting the unused fields in the table schema.

[0047] Specifically, the read database schema can be modified according to actual business needs to obtain a modified standard database schema and a corresponding standard table schema.

[0048] Through step 1.3, a more suitable database model can be modified according to the user's specific query situation, which can further improve the accuracy of the query, reduce maintenance costs and time consumption.

[0049] Example 3 This embodiment proposes a solution based on LLM to solve the complex table NL2SQL, proposes a table model representation method that can provide richer information for large models, and proposes a pseudo table model and SQL rewriting solution based on this method to alleviate the problem that LLM is difficult to correctly generate SQL when performing complex queries on multiple tables.

[0050] This embodiment has the following functions: Database schema creation and SQL rewriting.

[0051] Database schema generation: describes the schema of the table in the database. The representation of the database schema is decomposed into three parts: table name, table description and field declaration in csv format. The field declaration in csv format contains 5 fields, namely field name, data type, description, data 1, and data 2. Data 1 and data 2 are records randomly sampled from the database, which are used to indicate the storage format of the large model data.

[0052] SQL rewriting: Convert the simple SQL output by LLM to query the pseudo table mode into SQL for querying the real table. Store the fields in multiple tables required for complex queries in a table that does not actually exist in the database. When LLM generates a query for the data in this table, it is rewritten to query the original table.

[0053] This embodiment takes the SQL Service database storing attendance punch-in data as an example to introduce the NL2SQL function of this patent application. Before using the NL2SQL function, it is necessary to configure the database mode.

[0054] The configuration steps are as follows: The user configures the database connection information to obtain the read permission for the target database in the database.

[0055] According to the configuration provided by the user, the table name, table description, schema name, field name, field type, and field description are read from the target database. At the same time, two records are randomly read and this information is stored in the database as a table schema in units of tables.

[0056] According to actual business needs, modify the mapping of the read database schema, such as deleting table schemas that will not be used in NL2SQL and fields that are not used in the table schema. The modification can remove fields that users do not care about, such as the update time of the field. As for which fields users do not care about, it can be determined in combination with specific business.

[0057] The configured database mode is shown in Table 1 below:

[0058] Table 1 Table schema read from the target database

[0059] The system processes the user's query request as follows: Figure 1 As shown, the specific steps are as follows: 2.1 Retrieve the database schema related to the query, specifically by combining vector search and full-text search to retrieve the relevant table schema from the database; 2.2 Retrieve SQL examples related to the query, specifically by combining vector search and full-text search to retrieve relevant SQL examples from the database; 2.3 Prompt word construction, specifically filling in the query, table mode, and SQL example into the prompt template; 2.4 Generate SQL through LLM model; 2.5 Rewrite SQL to simplify the original complex SQL operations into single-table operation SQL; 2.6 SQL execution.

[0060] In this application, the representation of the database schema is decomposed into three parts: table name, table description and field declaration in csv format. The field declaration in csv format contains 5 fields, namely field name, data type, description, data 1 and data 2. Data 1 and data 2 are records randomly sampled from the table, which are used to indicate the storage format of the large model data.

[0061] A representative database pattern prompt is shown in Table 2:

[0062] Table 2. Table schema description in csv format

[0063] This technology reduces the generation of complex SQL from natural language by building table models and SQL conversion. On a database model based on the CSV format, a pseudo table is built to simplify query operations that originally involved multiple tables into single-table operations.

[0064] A method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion. Fields of two tables are logically merged to obtain a pseudo table. The schema of the logically merged tables is called a pseudo table schema.

[0065] For example, based on the employee table in Table 3 and the punch-in table in Table 4, a pseudo table schema such as Table 5 can be created.

[0066] Table 3 Schema of the employee table

[0067] Table 4: Table schema of the punch-in record table

[0068] Table 5 Pseudo table mode description

[0069] The characteristic of pseudo table mode is that the information density is higher, and there is no need to consider the corresponding relationship with the database table. For example, for the query requirement "Who is late this week", you can add a row "late, bool, indicating whether the employee is late on that day, 1 is late, 0 is not late" in the pseudo table, without considering whether the late field actually exists in the real database. When the SQL generated by LLM uses this field, you can clearly know the user's question intention, and extract and rewrite the SQL parameters.

[0070] When LLM generates complex SQL, it is very easy to generate SQL that does not conform to the syntax, or conforms to the syntax but the query results are not what the user needs, due to insufficient model capabilities such as model hallucination. SQL rewriting aims to reduce the difficulty of LLM generating SQL and simplify operations that can only be completed by complex SQL into shorter single-table operation SQL.

[0071] After using SQL rewriting technology, LLM only needs to generate simple SQL, and the code logic will restore the SQL. Therefore, LLM needs fewer TOKENs to generate complete SQL, which speeds up the system's response and reduces the cost of TOKEN generation.

[0072] For example, the table schema of two tables is required to use the JOIN syntax, but if the fields of the two tables are logically merged in advance, the JOIN operation can be omitted. The schema of the logically merged tables is called a pseudo table schema.

[0073] A common method to merge the fields of two tables to obtain a pseudo table schema is to collect the SQLs generated by the user's query, and then see which join operations are included in these SQLs. After knowing the common join operations, manually create a pseudo table after joining.

[0074] If the pseudo table mode is used in the SQL generated by the large model based on the user's query, the SQL will be rewritten into SQL that operates the original table according to the rules.

[0075] For example, when the following SQL query is performed on the pseudo table mode shown in Table 6, it will be converted into the original query shown in Table 7.

[0076] Table 6

[0077] Table 7

[0078] The prefix "E_" stands for "Employee.", "R_" stands for "Record.", and "R_E" stands for "from Recordjoin Employee". This way of writing simplifies the original "table name.field name" expression into field names, preventing the model from mistaking the relationship between tables and fields, and restoring it when rewriting SQL.

[0079] The method of reducing the generation of complex SQL from natural language by constructing table mode and SQL conversion in this implementation has the following advantages compared with other existing technical solutions: 1. Complex queries are more accurate. The pseudo-table mode and SQL rewriting technology pioneered by the present invention can effectively reduce the complexity of the SQL that LLM needs to generate for complex queries, reduce the probability that the generated SQL cannot be executed, and reduce the time required for complete SQL generation. On the other hand, the present invention describes the table mode based on csv, so that in addition to the field name, field type, and field remarks that can also be included in other work, the table mode can also contain additional table records, so that the model can learn the specific storage format of the records in the table.

[0080] 2. Lower maintenance cost. The present invention is based on csv to organize the table mode. Compared with other NL2SQL methods that describe the table mode based on database table creation statements, the present invention is easier to be maintained by non-technical personnel.

[0081] 3. Shorter time consumption: The time consumption of NL2SQL mainly lies in the number of tokens required to generate for large models. SQL rewriting technology makes it possible to complete operations that originally required the generation of long SQL statements by generating shorter SQL statements, thus greatly reducing time consumption.

[0082] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit the scope of protection of the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the essence and scope of the technical solution of the present invention.

Claims

1. A method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion, characterized by comprising: pre-configuring database schema and processing user requests; Pre-configure the database mode. The specific configuration steps are as follows: 1.1 The user configures the database connection information to obtain the read permission of the target database in the database; 1.2 According to the information configured by the user in step 1.1, the table schema information is read from the target database, and two records are randomly read and named as data 1 and data 2 respectively. The read table schema information and the read records are stored in the database as table schemas in units of tables; the set of stored table schemas constitutes the database schema; The system processes the user's query request in the following steps: 2.1 Retrieve the database schema related to the query, specifically by combining vector search and full-text search to retrieve the relevant table schema from the database; 2.2 Retrieve SQL examples related to the query, specifically by combining vector search and full-text search to retrieve relevant SQL examples from the database; 2.3 Prompt word construction, specifically filling in the query, table mode, and SQL example into the prompt template; 2.4 Generate SQL through LLM model; 2.5 Rewrite SQL to simplify the original complex SQL operations into single-table operation SQL; 2.6 SQL execution.

2. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 1, characterized in that: The table schema information in step 1.2 is table name, table description, schema name, field name, field type, and field description.

3. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 1, characterized in that: It also includes step 1.3 of modifying the read database schema to obtain a modified database schema and a corresponding table schema.

4. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 3, characterized in that: In step 1.3, modify the read database schema, specifically delete the table schema that will not be used in NL2SQL and delete the fields that are not used in the table schema.

5. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 1, characterized in that: The table of the database schema contains a table name, a table description and a field declaration in csv format; the field declaration in csv format contains 5 fields, namely field name, data type, description, data 1 and data 2.

6. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 5, characterized in that: Based on the CSV format, a pseudo table is constructed to simplify the query operations that originally involved multiple tables into single-table operations.

7. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 6, characterized in that: A pseudo table is obtained by logically merging the fields of two tables. The mode of the logically merged tables is called a pseudo table mode.

8. The method for reducing complex SQL generated from natural language by constructing table schema and SQL conversion according to any one of claims 1 to 7, characterized in that: If the pseudo table mode is used in the SQL generated by the large model based on the user's query, the SQL is rewritten into the SQL that operates the original table according to the rules.

9. The method for reducing complex SQL generated by natural language by constructing table schema and SQL conversion according to claim 4, characterized in that: In step 1.3, the read database schema is modified according to actual business needs to obtain a modified standard database schema and a corresponding standard table schema.

Citation Information

Patent Citations

  • NL2SQL method based on LLM multi-table adaptive selection

    CN117112732A

  • Method and system for automatically generating sql and replying questions

    CN118093634A

  • Data analysis method and system based on natural language, electronic equipment and storage medium

    CN118132587A

  • NL2SQL method and system combining LLM and BERT

    CN118296034A

  • Database question and answer method, system and equipment based on large language model and medium

    CN118733747A

Cited By

  • Fine tuning and Prompt combined natural language to SQL (Structured Query Language) task method

    CN119988420A