Low-sample chained NL2SQL generation method and system based on clause dependency

Through the low-sample chain NL2SQL generation method based on clause dependency, the business samples are expanded using intent clarification and dynamic templates, and the adapter group is built, which solves the problem of low NL2SQL generation accuracy in the case of low samples in the existing technology, and achieves high accuracy generation with very few samples.

CN119646023APending Publication Date: 2025-03-18SHANGHAI NETIS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411781029.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

The existing NL2SQL technology is difficult to achieve high accuracy under low sample conditions, resulting in the model generation results relying on a large number of labeled samples, increasing labor costs and time costs.

Method used

A low-sample chained NL2SQL generation method based on clause dependency is adopted to expand business samples through intent clarification and dynamic templates, and to build intent clarification adapters and SQL clauses to generate adapter groups, realizing chain generation from natural language to SQL.

Benefits of technology

Achieve high-accuracy NL2SQL generation with very few samples reduces dependence on the number of labeled samples and reduces labor and time costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646023A_ABST
    Figure CN119646023A_ABST
Patent Text Reader

Abstract

The invention provides a low-sample chained NL2SQL generation method and system based on clause dependency, and the method comprises the steps: S1, obtaining business samples from a natural language to an SQL, carrying out the intention clarification of the natural language, obtaining an intention clarification sample, and expanding the number of the business samples through a dynamic template; s2, constructing an intention clarification adapter by using the intention clarification sample, and constructing an SQL clause generation adapter group; and S3, performing'intention clarification 'on the input natural language question by using an intention clarification adapter, and performing SQL chain generation on the clarified language by using an SQL clause generation adapter group. According to the method provided by the invention, NL2SQL (Natural Language Generation Structured Query Language) with extremely high accuracy on given samples is realized through automatic data generation under the condition that extremely few samples are given, and the problem that a model generation result completely depends on the number of the samples in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of language recognition technology, and in particular to a low-sample chained NL2SQL generation method and system based on clause dependency. Background Art

[0002] NL2SQL is the abbreviation of the task of "converting natural language to SQL". This task converts natural language into SQL through artificial intelligence and other methods, making it easier for people without SQL knowledge to query the database. However, when implementing NL2SQL, a large number of labeled samples (such as "language" to "SQL" sample pairs) are often needed to train the model in order to achieve high accuracy. However, "a large number of labeled samples" has caused huge labor costs and time costs, which has seriously delayed the implementation of NL2SQL functions.

[0003] In the Chinese patent document with publication number CN117971861A, a feature decoupled and configurable NL2SQL method is disclosed. The document uses regular matching and transfer learning to extract the corresponding features of the scene, intent, time and business dimensions and then generates the corresponding SQL. The document emphasizes how to generate high-accuracy SQL through chained adapters in the case of small samples.

[0004] In a Chinese patent document with publication number CN116776893A, a NL2SQL method and system based on hierarchical feature decoupling is disclosed. The document uses the NL2SQL data set and then calculates the decoupled feature representation of morphemes in different SQLs. When used, appropriate morphemes are selected according to user input to construct high-quality SQL. Summary of the invention

[0005] In view of the defects in the prior art, the object of the present invention is to provide a low-sample chained NL2SQL generation method and system based on clause dependency.

[0006] According to the present invention, a low-sample chained NL2SQL generation method based on clause dependency is provided, comprising:

[0007] Step S1: Obtain business samples from "natural language" to "SQL", clarify the intent of the "natural language", obtain intent clarification samples, and use dynamic templates to expand the number of the business samples;

[0008] Step S2: construct an intent clarification adapter using the intent clarification sample, and construct an SQL clause to generate an adapter group;

[0009] Step S3: Use the intent clarification adapter to perform "intent clarification" on the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

[0010] Preferably, the step S1 comprises:

[0011] Step S1.1: Obtain a set of business samples, where the business sample is a two-tuple (natural language, SQL), where the natural language represents the meaning of the required operation and SQL is the corresponding database query language;

[0012] Step S1.2: Prompt the big model to generate corresponding clarified questions for the SQL in the business sample through the clarification template, and combine the natural language generation intent to clarify the sample;

[0013] Step S1.3: Extract individual samples from the business sample set one by one, and use a prompt word template to prompt the large model to generate SQL similar to the sample, wherein the prompt word template includes an operation list, and the operation list is randomly extracted from the operation set; then use a clarification template to prompt the large model to generate corresponding formal questions according to the generated SQL;

[0014] Step S1.4: Randomly select N samples from the business sample set, use the prompt word template to prompt the large model to refer to the N samples, generate similar SQL, and use the clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL.

[0015] Preferably, the step S2 comprises:

[0016] Step S2.1: train a large language model using the intent clarification template to obtain an intent clarification adapter;

[0017] Step S2.2: Train the SQL clause generation adapter group, which includes four adapters: Select adapter, From / Where adapter, Having / Group adapter and Order / Limit adapter.

[0018] Preferably, the step S3 comprises:

[0019] Step S3.1: clarifying the intent of the input natural language question according to the intent clarification adapter to obtain a clarified question;

[0020] Step S3.2: Use the SQL clause generation adapter group to perform SQL chain generation for the clarified questions.

[0021] Preferably, the step S2.2 comprises:

[0022] The Select adapter input is the clarified question, and the output is the Select part of the SQL statement;

[0023] The From / Where adapter inputs the clarified question and the Select part of the SQL statement, and outputs the From and Where parts of the SQL statement;

[0024] The Having / Group adapter inputs are the clarified question, the Select part, and the Where part, and outputs the Having and Group parts of the SQL statement;

[0025] The input of the Order / Limit adapter is the clarified question, the Select part, and the Group part, and the output is the Order and Limit parts of the SQL statement.

[0026] According to the present invention, a low-sample chained NL2SQL generation system based on clause dependency is provided, comprising:

[0027] Module M1: Obtain business samples from "natural language" to "SQL", clarify the intent of the "natural language", obtain intent clarification samples, and use dynamic templates to expand the number of the business samples;

[0028] Module M2: Use the intent clarification sample to build an intent clarification adapter and construct an SQL clause to generate an adapter group;

[0029] Module M3: Use the intent clarification adapter to "clarify the intent" of the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

[0030] Preferably, the module M1 comprises:

[0031] Module M1.1: Obtain a set of business samples, where the business sample is a tuple (natural language, SQL), where the natural language represents the meaning of the required operation and SQL is the corresponding database query language;

[0032] Module M1.2: Use the clarification template to prompt the big model to generate corresponding clarified questions for the SQL in the business sample, and combine the natural language generation intent to clarify the sample;

[0033] Module M1.3: Extract individual samples from the business sample set one by one, and use the prompt word template to prompt the large model to generate SQL similar to the sample, wherein the prompt word template includes an operation list, and the operation list is randomly selected from the operation set; then use the clarification template to generate corresponding formal questions according to the generated SQL;

[0034] Module M1.4: Randomly select N samples from the business sample set, use the prompt word template to prompt the large model to refer to the N samples, generate similar SQL, and use the clarification template to generate corresponding formal questions based on the generated SQL.

[0035] Preferably, the module M2 comprises:

[0036] Module M2.1: Use the intent clarification template to train the large language model and obtain the intent clarification adapter;

[0037] Module M2.2: Training SQL clause generation adapter group, the SQL clause generation adapter group includes 4 adapters: Select adapter, From / Where adapter, Having / Group adapter and Order / Limit adapter.

[0038] Preferably, the module M3 comprises:

[0039] Module M3.1: Clarify the intent of the input natural language question according to the intent clarification adapter to obtain the clarified question;

[0040] Module M3.2: Use the SQL clause generation adapter group to perform SQL chain generation for clarified questions.

[0041] Preferably, the module M2.2 comprises:

[0042] The Select adapter input is the clarified question, and the output is the Select part of the SQL statement;

[0043] The From / Where adapter inputs the clarified question and the Select part of the SQL statement, and outputs the From and Where parts of the SQL statement;

[0044] The Having / Group adapter inputs are the clarified question, the Select part, and the Where part, and outputs the Having and Group parts of the SQL statement;

[0045] The input of the Order / Limit adapter is the clarified question, the Select part, and the Group part, and the output is the Order and Limit parts of the SQL statement.

[0046] Compared with the prior art, the present invention has the following beneficial effects:

[0047] 1. The method provided by the present invention supports automatic data generation under the condition of very few samples, and realizes NL2SQL (natural language generated SQL) with extremely high accuracy on given samples, which solves the problem that the model generation results in the prior art are completely dependent on the number of samples.

[0048] 2. The present invention only needs a small amount of samples as startup data; SQL sample generation technology based on dynamic prompt templates; SQL generation technology that uses SQL context dependencies to implement adapter chain calls based on the COT principle of large models. The large model "adapter" here refers to the weight training module that is added to the original structure of the model when the Lora related technology trains the large model. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] 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:

[0050] Figure 1 A flow chart of sample generation using dynamic templates in the present invention;

[0051] Figure 2 An adapter flow chart for constructing intent clarification and SQL clause generation in the present invention;

[0052] Figure 3 A flowchart for realizing SQL generation by chain call adapter in the present invention;

[0053] Figure 4 This is a workflow diagram of the adapter from "problem" to SQL in the present invention. DETAILED DESCRIPTION

[0054] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.

[0055] The present invention discloses a low-sample chained NL2SQL generation method based on clause dependency, referring to Figures 1 to 4 As shown, the following steps are included:

[0056] Step S1: Obtain business samples from "natural language" to "SQL", clarify the intent of the "natural language", obtain intent clarification samples, and use dynamic templates to expand the number of business samples;

[0057] Step S2: construct an intent clarification adapter using the intent clarification sample, and construct an SQL clause to generate an adapter group;

[0058] Step S3: Use the intent clarification adapter to perform "intent clarification" on the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

[0059] Step S1 includes the following steps:

[0060] Step S1.1: Collect a set of business samples. Each business sample in the set is a two-tuple (natural language, SQL). The natural language is used to express the meaning of the required operation, and SQL is the corresponding database query language.

[0061] For example:

[0062] Natural language: Statistics on the trends of major network indicators between 00:1e:67:5b:79:57 and 00:1e:67:9b:60:0f.

[0063] SQL: select MACNumToString(`@client_mac`)as client_mac,

[0064] MACNumToString(`@server_mac`)as server_mac,

[0065] sum(`@pkt_len_c2s`) / 1024 / 1024 / 1024as gigabytes_c2s,sum(`@pkt_len_s2c`)

[0066] / 1024 / 1024 / 1024as gigabytes_s2c,

[0067] sum(`@conn_open_cnt`)as estb_conn,

[0068] sum(`@attach_succ`) / sum(`@attach_succ`+`@attach_fail`)as estb_succ_rate,

[0069] sum(`@pkt_cnt_c2s`+`@pkt_cnt_s2c`)as packets,

[0070] sum(`@tcp_segment_lost_c2s`+`@tcp_segment_lost_s2c`+`@capture_lost_c2s`+

[0071] `@capture_lost_s2c`) / sum(`@tcp_segment_lost_c2s`+

[0072] `@tcp_segment_lost_s2c`+`@capture_lost_c2s`+`@capture_lost_s2c`+

[0073] `@pkt_cnt_c2s`+`@pkt_cnt_s2c`)as packets_loss_rate,

[0074] sum(`@retransmission_c2s`+`@retransmission_s2c`) / sum(`@pkt_cnt_c2s`+

[0075] `@pkt_cnt_s2c`)as retransmission_rate,( sum(`@network_delay_sum_c2s`) /

[0076] sum(`@network_delay_cnt_c2s`) + sum(`@network_delay_sum_s2c`) /

[0077] sum(`@network_delay_cnt_s2c`)) / 1000000as network_delay_ms

[0078] from npm_conv.rollup_main

[0079] where MACNumToString(`@client_mac`)in('00:1E:67:5B:79:5D','00:1E:67:9B:60:14')

[0080] and MACNumToString(`@server_mac`)in('00:1E:67:5B:79:5D','00:1E:67:9B:60:14')

[0081] group by client_mac,server_mac

[0082] Step S1.2: Generate intent clarification samples. Intent clarification is to restate the business problem into clear and formal language. Each intent clarification sample is a tuple in the form of (business problem, clarified problem). The present invention prompts the large model to generate a "clarified problem" by using a "clarification template"; and forms an "intent clarification sample" by combining "business problem" and "clarified problem". For example, a clarification template is:

[0083] Below are the Standard-Examples of queries and the corresponding questions

[0084] Example-Query: SELECT MACNumToString(`@client_mac`)as mac,

[0085] sum(if(`@ether_type`='IPv4',`@pkt_cnt_c2s`+`@pkt_cnt_s2c`,0))asipv4_pkt_cnt,sum(if(`@ether_type`!='IPv4',`@pkt_cnt_c2s`+`@pkt_cnt_s2c`,0))as ipv6_pkt_cnt,sum(`@pkt_len_c2s`+`@pkt_len_s2c`)as pkt_len,sum(`@pkt_cnt_c2s`+

[0086] `@pkt_cnt_s2c`)as pkt_cnt FROM npm_conv.rollup_main WHERE sp_addr in

[0087] ('10.6.11.144')AND nic in('nic0')GROUP BY mac

[0088] Example-Question: Filtering conditions: probe address is 10.6.11.144, nic is nic0; aggregation condition: mac (client); aggregation filtering conditions: unlimited; output columns: mac (client), number of ipv4 packets, number of ipv6 packets, packet length;

[0089] Sorting method: unlimited; Number of returned items: unlimited.

[0090] Now consider the following query.

[0091] Query: <Business SQL>

[0092] Write a question for the Query in the style of Example-Question.

[0093] Format your response as a JSON object,ie

[0094] {"explanation":str,"question":str}

[0095] First write an explanation in about 3-5sentences,then write a onesentence question instyle of Example-Question,must describe all outputfields.

[0096] Use the "clarification template" to prompt the big model. By filling the SQL in all business samples of S1.1 into the <business SQL> part of the template, the big language model outputs the clarified question corresponding to the SQL. Using the above clarification template, the output of the model is a string in the form of Json. Extract the question part in the output Json. This part is the clarified question corresponding to the input SQL. Based on the "clarification question", and the "natural language question" together constitute the "intention clarification" sample. The sample is for example (ORIGINAL_QUESTION is a business question, REWRITE_AS is a clarified question), where ORIGINAL_QUESTION comes from the "natural language" part of the "business sample" mentioned in S1.1, and REWRITE_AS comes from the "SQL" of the "business sample" using the clarification template. The constructed "intention clarification sample" is for example:

[0097] {"ORIGINAL_QUESTION":"Statistics of the main network indicator trends between 00:1e:67:5b:79:57 and 00:1e:67:9b:60:0f recently.","REWRITE_AS":"Filtering conditions: client mac is data between 00:1E:67:5B:79:57 and 00:1E:67:9B:60:0f; aggregation conditions: client mac, service mac; aggregation filtering conditions: unlimited; output columns: client mac, service mac, client transmission GBytes, server transmission GBytes, number of established connections, attachment success rate, total number of packets, packet loss rate, network delay ms; sorting method: unlimited; number of returned items: unlimited."}.

[0098] Step S1.3: Generate SQL samples using a single-sample dynamic template. The specific operation is to extract individual samples from the business sample set one by one, and use the prompt word template to prompt the large model to generate SQL similar to the sample. The prompt word template contains an operation list, which consists of operations randomly extracted from an operation set. Prompt the large language model to generate SQL based on the operation list. After generating the SQL, use the "clarification template" mentioned in "Step S1.2" to prompt the large model again, and fill in the newly generated SQL into the "<Business SQL>" part of the template to write a formalized question. Taking the above steps as an example, the "operation list" mentioned above is for example:

[0099] a)Change the condition in WHERE clause.

[0100] b) For the LIMIT clause, adjust the limit number, remove the LIMIT clause, or add a LIMIT clause.

[0101] operation, add limit operation)

[0102] c) For the ORDER BY clause, adjust the fields, remove the ORDER BY clause, or add a ORDER BY clause. (For the contents of the ORDER BY clause, adjust the names of the columns to be sorted, remove the ORDER BY operation, and add an ORDER BY operation)

[0103] d) Make adjustments to the fields in the SELECT statement: remove fields, apply aliases, or change the order of fields.

[0104] e)If a GROUP BY clause exists, modify the field in the GROUP BY clause.

[0105] f)Use timeSlice to aggregrate by different time granularity. (Use the timeSlice function to aggregate data into different time granularities)

[0106] Randomly select three and arrange them to form an operation list:

[0107] a) Make adjustments to the fields in the SELECT statement:removefields,apply aliases,or change the order of fields.

[0108] b)Change the condition in WHERE clause.

[0109] c)If a GROUP BY clause exists, modify the field in the GROUP BY clause.

[0110] The prompt word template for generating SQL:

[0111] Write two different queries that are similar to the given example formodel training.

[0112] Example:

[0113] Question:<Question part of the business sample>

[0114] Query: <SQL part of the business sample>

[0115] Please do the every operation below to modify the example: / / af is randomly sampled from the set

[0116] a) Make adjustments to the fields in the SELECT statement:removefields,apply aliases,or change the order of fields.

[0117] b) Change the condition in the WHERE clause.

[0118] c) If a GROUP BY clause exists, modify the field in the GROUP BY clause.

[0119] Ensure the accuracy of the sql syntax.

[0120] Never write the fields that do not exist in the example.

[0121] Never use functions that are not mentioned in the example, except for standard SQL functions like SUM, AVG, etc.

[0122] Format the queries as a JSON object, i.e.

[0123] {"explanation": str, "sql_query_1": str, "sql_query_2": str}.

[0124] First write an explanation of why you decided to write these new queries in about 3 - 5 sentences, then write valid SQL queries for each of the 2 new queries.

[0125] Sample of the finally generated SQL and the corresponding formalized questions (clarified questions):

[0126] {"Question": "Filtering condition: network card is eth0; Aggregation condition: probe address, time slice of 30 minutes; Aggregation filtering condition: not limited; Output columns: probe address, time slice, bps, number of packets; Sorting method: descending order of the number of packets; Number of returned rows: 10.", "Query": "SELECT `sp_addr`, timeslice('30m') as ts, sum(`@pkt_len_c2s` + `@pkt_len_s2c`) * 8 / 60 / 60 as bps, count(*) as num_flows from npm_conv.rollup_main where `nic` = 'eth0' group by `sp_addr`, ts order by `sp_addr`, ts limit 10;"}.

[0127] Step S1.4: Use a multi-sample dynamic template to generate SQL samples. The specific operation is to randomly select N samples from the business sample set, use the prompt template to prompt the large model to generate N reference samples, and generate similar SQL. After generating the SQL, use the "clarification template" mentioned in "Step 1.2" to prompt the large model to write a formal question based on the generated sql. An example of the above steps, a prompt template containing N (N takes 3) reference examples:

[0128] Write two different queries that are similar to the given examples for model training.

[0129] Examples: / / The following three samples are obtained by random sampling

[0130] Question: <The question part of Seed1>

[0131] Query: <The sql part of Seed1>

[0132] Question: <The question part of Seed2>

[0133] Query: <The sql part of Seed2>

[0134] Question: <The question part of Seed3>

[0135] Query: <The sql part of Seed3>

[0136] Ensure the accuracy of the sql syntax.

[0137] Never write the fields are not existed in the example.

[0138] Never use functions that are not mentioned in the example,except forstandardSQL functions like SUM,AVG,etc.

[0139] Format the queries as a JSON object,ie

[0140] {"explanation":str,"sql_query_1":str,"sql_query_2":str}.

[0141] First write an explanation of why you decided to write these newqueries inabout 3-5 sentences, then write valid SQL queries for each of the2newqueries.

[0142] The above prompt words are input into the big model, and sql_query_1 and sql_query_2 are extracted from the output Json to generate SQL. The final generated sample is similar to the form of step S1.3, and will not be repeated.

[0143] In the process of generating SQL using a single-sample dynamic template, the large model generates new SQL based on a single specified sample. It is expected that the generated SQL will be similar to the sample. The SQL of the sample is modified based on the operations mentioned in Section 1.3 to obtain a new sample. This process will obtain a new sample with a high degree of similarity to the specified sample. When the model trained with this data asks questions similar to those of the business sample, the model can ensure high-quality answers.

[0144] When using multi-sample dynamic templates to generate SQL, the large model will refer to multiple samples (greater than 1) to generate new SQL. At this time, the generated SQL will be generated by combining the appearance of multiple reference SQLs. The newly generated samples will have the characteristics of multiple SQLs, but they will also be quite different from each reference sample. This process will result in samples that are quite different from the business samples provided by the user. When the model trained with this data is asked by the user and is very different from the questions in the business samples, the model can also give a high-quality answer, that is, a model with high generalization ability is obtained.

[0145] Step S2 includes the following steps:

[0146] Step S2.1: Train the "Intent Clarification" adapter. Use the sample data generated in step 1.2 to train the large language model adapter. The input part of the training is the original question, and the output part is the formal description of the question. The "Intent Clarification" adapter is trained using the adapter technology of the large model. For example, the following sample, the input is the ORIGINAL_QUESTION part, and the output is the REWRITE_AS part:

[0147] {"ORIGINAL_QUESTION":"Statistics of the main network indicator trends between 00:1e:67:5b:79:57 and 00:1e:67:9b:60:0f.","REWRITE_AS":"Filtering conditions: client mac is data between 00:1E:67:5B:79:57 and 00:1E:67:9B:60:0f; aggregation conditions: client mac, service mac; aggregation filtering conditions: unlimited; output columns: client mac, service mac, client transmission GBytes, server transmission GBytes, number of established connections, attachment success rate, total number of packets, packet loss rate, network delay ms; sorting method: unlimited; number of returned items: unlimited."}

[0148] Step S2.2: Train the SQL clause generation adapter group. The SQL clause generation adapter group contains 4 adapters, namely "Select adapter", "From / Where adapter", "Having / Group adapter", and "Order / Limit adapter". The input of "Select adapter" is "formally described problem", and the output is "Select part of SQL statement"; the input of "From / Where adapter" is "formally described problem" and "Select part of SQL statement", and the output is "From, Where part of SQL statement"; the input of "Having / Group adapter" is "formally described problem", "Select part", "Where part", and the output is "Having, Group part of SQL statement"; the input of "Order / Limit adapter" is "formally described problem", "Select part", "Group part", and the output is "Order, Limit part of SQL statement". Based on the samples, each adapter is trained using the adapter technology of the large model. If there is no output for the corresponding part, it is filled with "no". The input and output samples of each part are as follows:

[0149] / / Samples used to train the Select adapter

[0150] enter:

[0151] Question: Filter condition: Client mac is '00:1E:67:5B:79:5D' or '00:1E:67:9B:60:14'...

[0152] Output:

[0153] {"Select_Clause":"MACNumToString(`@client_mac`)as client_mac,MACNumToString(`@server_mac`)as server_mac,…"}

[0154] / / Samples for training From / Where adapters

[0155] enter:

[0156] Question: Filter condition: Client mac is '00:1E:67:5B:79:5D' or '00:1E:67:9B:60:14'...

[0157] Select Clause:

[0158] MACNumToString(`@client_mac`)as client_mac,

[0159] MACNumToString(`@server_mac`)as server_mac,…

[0160] Output: {"From_Clause":"npm_log_table","Where_Clause":" MACNumToString(`@client_mac`) in ('00:1E:67:5B:79:5D','00:1E:67:9B:60:14') andMACNumToString(`@server_mac`) in('00:1E:67:5B:79:5D','00:1E:67:9B:60:14')"}

[0161] / / Samples used to train the Having / Group adapter

[0162] enter:

[0163] Question: Filter condition: Client mac is '00:1E:67:5B:79:5D' or '00:1E:67:9B:60:14'... Select Clause:

[0164] MACNumToString(`@client_mac`)as client_mac,

[0165] MACNumToString(`@server_mac`)as server_mac,…

[0166] Where Clause: MACNumToString(`@client_mac`)in('00:1E:67:5B:79:5D','00:1E:67:9B:60:14')and MACNumToString(`@server_mac`)in('00:1E:67:5B:79:5D','00:1E:67:9B:60:14')

[0167] Output: {"Group_Clause":"client_mac,server_mac","Having_Clause":"no"}

[0168] / / Samples for training Order / Limit adapter

[0169] enter:

[0170] Question: Filter condition: Client mac is '00:1E:67:5B:79:5D' or '00:1E:67:9B:60:14'... Select Clause:

[0171] MACNumToString(`@client_mac`)as client_mac,

[0172] MACNumToString(`@server_mac`)as server_mac,…

[0173] Group Clause: client_mac, server_mac

[0174] Output: {"Order_Clause":"no","Limit":"no"}

[0175] Step S3 includes the following steps:

[0176] Step S3.1: "Clarify the intent" of the input natural language question. Load the big model and the intent clarification adapter trained in step S2.1. If the current user's question is User_Question, submit the question to the big model based on the question template, obtain the clarified intent from the output of the big model, and set the clarified intent to Clarified_Question. For example, the question template is:

[0177] Below are the Standard-Examples of queries and the corresponding questionsExample-Query: SELECT MACNumToString(`@client_mac`)as mac,sum(if(`@ether_type`='IPv4',`@pkt_cnt_c2s`+`@pkt_cnt_s2c`,0))asipv4_pkt_cnt, sum(if(`@ether_type`!='IPv4',`@pkt_cnt_c2s`+

[0178] `@pkt_cnt_s2c`,0))as ipv6_pkt_cnt, sum(`@pkt_len_c2s`+

[0179] `@pkt_len_s2c`)as pkt_len, sum(`@pkt_cnt_c2s`+`@pkt_cnt_s2c`)aspkt_cnt FROM npm_conv.rollup_main WHERE sp_addr in('10.6.11.144')AND nicin('nic0')GROUP BY mac

[0180] Example-Question: Filtering conditions: Probe address is 10.6.11.144, nic is nic0; Aggregation conditions: mac (client); Aggregation filtering conditions: unlimited; Output columns: mac (client), number of ipv4 packets, number of ipv6 packets, packet length; Sorting method: unlimited; Number of returned items: unlimited.

[0181] Now consider the following query.

[0182] Query:<User_Question>

[0183] Write a question for the Query in the style of Example-Question.

[0184] Format your response as a JSON object,ie

[0185] {"explanation":str,"question":str}

[0186] First write an explanation in about 3-5sentences,then write a onesentencequestion in style of Example-Question,must describe all outputfields.

[0187] The question part of the Json output of the large model is Clarified_Question.

[0188] Step S3.2: Chain generation of SQL for the "clarified" language. Load the large model and the "Select adapter", input Clarified_Question into the adapter, and obtain the Select clause, recorded as Select_Clause; load the large model and the "From / Where adapter", input Clarified_Question and Select_Clause into the adapter, and obtain the From clause and Where clause, recorded as From_Clause and Where_Clause; load the large model and the "Group / Having adapter", input Clarified_Question, Select_Clause, Where_Clause into the adapter, and obtain the Group clause and Having clause, recorded as Group_Clause and Having_Clause; load the large model and the "Order / Limit adapter", input Clarified_Question, Select_Clause, Group_Clause into the adapter, and obtain the Order clause and Limit clause, recorded as Order_Clause and Limit_Clause. Assemble Select_Clause, From_Clause, Where_Clause, Group_Clause, Having_Clause, Order_Clause, and Limit_Clause into complete SQL. For the workflow, see Figure 4 The template examples for each part are as follows:

[0189] Template for Select adapter:

[0190] Now the User Question is as below:

[0191] <Clarified_Question>

[0192] Please write the select_clause for the question.

[0193] Format your response as a JSON object,ie

[0194] {"Select_Clause":str}

[0195] Template for From / Where adapter:

[0196] Now the User Question is as below:

[0197] <Clarified_Question>

[0198] The Select Clause:

[0199] <Select_Clause>

[0200] Please write the from_clause and where_clause for the question.

[0201] Format your response as a JSON object,i.e.

[0202] {"From_Clause":str,"Where_Clause":str}

[0203] Template for Group / Having adapter:

[0204] Now the User Question is as below:

[0205] <Clarified_Question>

[0206] The Select Clause:

[0207] <Select_Clause>

[0208] The Where Clause:

[0209] <Where_Clause>

[0210] Please write the group_clause and having_clause for the question.

[0211] Format your response as a JSON object,i.e.

[0212] {"Group_Clause":str,"Having_Clause":str}

[0213] Template for Order / Limit adapter:

[0214] Now the User Question is as below:

[0215] <Clarified_Question>

[0216] The Select Clause:

[0217] <Select_Clause>

[0218] The Group Clause:

[0219] <Group_Clause>

[0220] Please write the order_clause and limit_clause for the question.

[0221] Format your response as a JSON object,ie

[0222] {"Order_Clause":str,"Limit_Clause":str}

[0223] Sample output is:

[0224] / / Select adapter output

[0225] {"Select_Clause":"client_ip,client_mac,sum(c2s_pkt_len)asc2s_pkt_size"}

[0226] / / From / Where adapter output

[0227] {"From_Clause":"npm_table","Where_Clause":"server_site in('app1')"}

[0228] / / Group / Having adapter output

[0229] {"Group_Clause":"client_ip,client_mac","Having_Clause":"no"}

[0230] / / Order / Limit adapter output

[0231] {"Order_Clause":"client_ip","Limit_Clause":"50"}

[0232] Combined into SQL:

[0233] select client_ip,client_mac,sum(c2s_pkt_len)as c2s_pkt_size

[0234] from npm_table

[0235] where server_site in('app1')

[0236] group by client_ip,client_mac

[0237] order by client_ip

[0238] limit 50

[0239] The present invention also provides a low-sample chained NL2SQL generation system based on clause dependency. The low-sample chained NL2SQL generation system based on clause dependency can be implemented by executing the process steps of the low-sample chained NL2SQL generation method based on clause dependency, that is, those skilled in the art can understand the low-sample chained NL2SQL generation method based on clause dependency as a preferred implementation of the low-sample chained NL2SQL generation system based on clause dependency.

[0240] The present invention provides a low-sample chained NL2SQL generation system based on clause dependency, comprising:

[0241] Module M1: Obtain business samples from "natural language" to "SQL", clarify the intent of the "natural language", obtain intent clarification samples, and use dynamic templates to expand the number of business samples.

[0242] In a specific embodiment, the module M1 includes:

[0243] Module M1.1: Obtain a set of business samples. The business sample is a two-tuple (natural language, SQL), where the natural language represents the meaning of the required operation and SQL is the corresponding database query language;

[0244] Module M1.2: Use the clarification template to prompt the big model to generate corresponding clarified questions for the SQL in the business sample, and combine the natural language generation intent to clarify the sample;

[0245] Module M1.3: Extract individual samples from the business sample set one by one, and use the prompt word template to prompt the large model to generate SQL similar to the sample. The prompt word template includes an operation list, and the operation list is randomly selected from the operation set; then use the clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL;

[0246] Module M1.4: Randomly select N samples from the business sample set, use the prompt word template to prompt the large model to refer to the N samples, generate similar SQL, and use the clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL.

[0247] Module M2: Use the intent clarification sample to build the intent clarification adapter and construct the SQL clause generation adapter group.

[0248] In a specific embodiment, the module M2 includes:

[0249] Module M2.1: Use the intent clarification template to train the large language model and obtain the intent clarification adapter;

[0250] Module M2.2: Training the SQL clause generation adapter group. The SQL clause generation adapter group includes four adapters: Select adapter, From / Where adapter, Having / Group adapter and Order / Limit adapter.

[0251] The input of the Select adapter is the clarified question, and the output is the Select part of the SQL statement;

[0252] The From / Where adapter takes as input the clarified question and the Select part of the SQL statement, and outputs the From and Where parts of the SQL statement.

[0253] The input of the Having / Group adapter is the clarified question, the Select part, and the Where part, and the output is the Having and Group parts of the SQL statement;

[0254] The input of the Order / Limit adapter is the clarified question, the Select part, and the Group part, and the output is the Order and Limit parts of the SQL statement.

[0255] Module M3: Use the intent clarification adapter to "clarify the intent" of the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

[0256] In a specific embodiment, the module M3 includes:

[0257] Module M3.1: Clarify the intent of the input natural language question according to the intent clarification adapter to obtain the clarified question;

[0258] Module M3.2: Use the SQL clause generation adapter group to perform SQL chain generation for clarified questions.

[0259] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.

[0260] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.

Claims

1. A low-sample chained NL2SQL generation method based on clause dependency, characterized in that: include: Step S1: obtaining a business sample from "natural language" to "SQL", clarifying the intent of the "natural language", obtaining a sample of clarified intent, and using a dynamic template to expand the number of the business samples; Step S2: construct an intent clarification adapter using the intent clarification sample, and construct an SQL clause to generate an adapter group; Step S3: Use the intent clarification adapter to "clarify the intent" of the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

2. The method for generating low-sample chained NL2SQL based on clause dependency according to claim 1, characterized in that: The step S1 comprises: Step S1.1: Obtain a set of business samples, where the business sample is a two-tuple (natural language, SQL), where the natural language represents the meaning of the required operation and SQL is the corresponding database query language; Step S1.2: Prompt the big model to generate corresponding clarified questions for the SQL in the business sample through the clarification template, and combine the natural language generation intent to clarify the sample; Step S1.3: Extract individual samples from the business sample set one by one, and use a prompt word template to prompt the large model to generate SQL similar to the sample, wherein the prompt word template includes an operation list, and the operation list is randomly extracted from the operation set; then use a clarification template to prompt the large model to generate corresponding formal questions according to the generated SQL; Step S1.4: Randomly select N samples from the business sample set, use the prompt word template to prompt the large model to refer to the N samples, generate similar SQL, and use the clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL.

3. The method for generating low-sample chained NL2SQL based on clause dependency according to claim 1, characterized in that: The step S2 comprises: Step S2.1: train a large language model using the intent clarification template to obtain an intent clarification adapter; Step S2.2: Train the SQL clause generation adapter group, which includes four adapters: Select adapter, From / Where adapter, Having / Group adapter and Order / Limit adapter.

4. The method for generating low-sample chained NL2SQL based on clause dependency according to claim 1, characterized in that: The step S3 comprises: Step S3.1: clarifying the intent of the input natural language question according to the intent clarification adapter to obtain a clarified question; Step S3.2: Use the SQL clause generation adapter group to perform SQL chain generation for the clarified questions.

5. The method for generating low-sample chained NL2SQL based on clause dependency according to claim 1, characterized in that: The step S2.2 comprises: The Select adapter input is the clarified question, and the output is the Select part of the SQL statement; The From / Where adapter inputs the clarified question and the Select part of the SQL statement, and outputs the From and Where parts of the SQL statement; The Having / Group adapter inputs are the clarified question, the Select part, and the Where part, and outputs the Having and Group parts of the SQL statement; The input of the Order / Limit adapter is the clarified question, the Select part, and the Group part, and the output is the Order and Limit parts of the SQL statement.

6. A low-sample chained NL2SQL generation system based on clause dependency, characterized in that: include: Module M1: obtain business samples from "natural language" to "SQL", clarify the intent of the "natural language", obtain intent clarification samples, and use dynamic templates to expand the number of the business samples; Module M2: Use the intent clarification sample to build an intent clarification adapter and construct an SQL clause to generate an adapter group; Module M3: Use the intent clarification adapter to "clarify the intent" of the input natural language question, and use the SQL clause generation adapter group to chain generate SQL for the "clarified" language.

7. The low-sample chained NL2SQL generation system based on clause dependency according to claim 6, characterized in that: The module M1 comprises: Module M1.1: Obtain a set of business samples, where the business sample is a tuple (natural language, SQL), where the natural language represents the meaning of the required operation and SQL is the corresponding database query language; Module M1.2: Use the clarification template to prompt the big model to generate corresponding clarified questions for the SQL in the business sample, and combine the natural language generation intent to clarify the sample; Module M1.3: Extract individual samples from the business sample set one by one, and use a prompt word template to prompt the large model to generate SQL similar to the sample, wherein the prompt word template includes an operation list, and the operation list is randomly selected from the operation set; then use a clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL; Module M1.4: Randomly select N samples from the business sample set, use the prompt word template to prompt the large model to refer to the N samples, generate similar SQL, and use the clarification template to prompt the large model to generate corresponding formal questions based on the generated SQL.

8. The clause dependency-based low-sample chained NL2SQL generation system according to claim 6, characterized in that: The module M2 comprises: Module M2.1: Use the intent clarification template to train the large language model and obtain the intent clarification adapter; Module M2.2: Training SQL clause generation adapter group, the SQL clause generation adapter group includes 4 adapters: Select adapter, From / Where adapter, Having / Group adapter and Order / Limit adapter.

9. The low-sample chained NL2SQL generation system based on clause dependency according to claim 6, characterized in that: The module M3 comprises: Module M3.1: Clarify the intent of the input natural language question according to the intent clarification adapter to obtain the clarified question; Module M3.2: Use the SQL clause generation adapter group to perform SQL chain generation for clarified questions.

10. The low-sample chained NL2SQL generation system based on clause dependency according to claim 6, characterized in that: The module M2.2 includes: The Select adapter input is the clarified question, and the output is the Select part of the SQL statement; The From / Where adapter inputs the clarified question and the Select part of the SQL statement, and outputs the From and Where parts of the SQL statement; The Having / Group adapter inputs are the clarified question, the Select part, and the Where part, and outputs the Having and Group parts of the SQL statement; The input of the Order / Limit adapter is the clarified question, the Select part, and the Group part, and the output is the Order and Limit parts of the SQL statement.

Citation Information

Patent Citations

  • NL2SQL method and system based on hierarchical feature decoupling

    CN116776893A

  • Feature decoupling configurable NL2SQL method

    CN117971861A