CN-122019578-A - Large language model TEXT2SQL method and system based on user clarification and problem enhancement
Abstract
The invention discloses a large language model TEXT2SQL method and system based on user clarification and problem enhancement, according to the method, firstly, a question-answer data pair of a corresponding natural language question and a corresponding SQL sentence is generated by aiming at a target database through a question-answer data pair large language model. And secondly, identifying ambiguity in natural language questions in the question-answering data pair through a candidate SQL big language model, and continuously communicating with a user to clarify the questions to generate a candidate SQL. And then, extracting candidate predicates and clarifying predicates according to the execution result of the candidate SQL, and generating a final candidate predicate list. And finally, enhancing the context of the natural language problem by using a problem enhancement large language model through clarifying evidence and a final candidate predicate list, and generating a corresponding SQL (structured query language) for database query. The invention realizes the enhancement of the large language model on the user intention recognition and improves the accuracy of generating SQL sentences through natural language.
Inventors
- Wang Hezhidong
- SONG YANG
- QIN ZHIWEI
Assignees
- 杭州电子科技大学
Dates
- Publication Date
- 20260512
- Application Date
- 20260128
Claims (9)
- 1. The large language model TEXT2SQL method based on user clarification and problem enhancement is characterized by comprising the following steps: S1, aiming at a target database through a big language model of the question-answer data pair, generating a question-answer data pair of a corresponding natural language question and a corresponding SQL sentence; S2, identifying ambiguity in natural language questions in the question-answer data pair through a candidate SQL big language model, continuously communicating with a user to clarify the questions, and eliminating the ambiguity to generate a candidate SQL; s3, extracting candidate predicates and clarifying predicates according to the execution result of the candidate SQL, and generating a final candidate predicate list; S4, enhancing the context of the natural language problem by using the problem enhancement large language model through clarifying evidence and a final candidate predicate list, generating a corresponding SQL (structured query language) for database query, and finally responding to the user.
- 2. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 1, wherein said step S1 specifically comprises the following procedures: s11, acquiring a structure of a corresponding database table and desensitized data; s12, inputting the acquired desensitized data and the database table structure into a large language model of the question-answer data pair to obtain a question-answer data pair of a natural language question and a corresponding SQL sentence; s13, checking the format, accuracy and validity of the question-answer data pair.
- 3. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 2, wherein said step S13 specifically comprises the following procedures: S131, storing the question-answer data pairs; s132, inquiring a database through the SQL sentence generated by the big language model by the question-answer data, comparing the SQL sentence with the expected inquiring result, and rewriting SQL or removing the question-answer data pair for the question data pair with inconsistent comparison result.
- 4. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 3, wherein said step S2 specifically comprises the following procedures: s21, after receiving a natural language problem input by a user, the candidate SQL big language model identifies ambiguity in the natural language problem through a prompt word; S22, generating a structured clarification problem and a clarification result for the identified ambiguity through a clarification large language model, and providing the structured clarification problem and the clarification result for a user for selection; S23, after receiving the clarification result selected by the user, verifying whether the result can be disambiguated by the large language model, and determining whether to carry out the second round of clarification; s24, the final clarified result of the user is arranged into disambiguation data, and the disambiguation data are transmitted to a candidate SQL big language model for generating the candidate SQL.
- 5. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 3, wherein said step S3 specifically comprises the following procedures: S31, extracting characteristics formed by operation and values of candidate predicates from the initial candidate SQL; S32, querying a database through a similar LIKE operator, matching potential correct values, and combining the potential correct values into a complete candidate predicate list; s33, clarifying ambiguity existing in the candidate predicate list, generating clarified evidence, and integrating to obtain a final candidate predicate list for subsequent problem enhancement generation.
- 6. The large language model TEXT2SQL method based on user clarification and question enhancement according to claim 5, wherein the ambiguity existing in the candidate predicate list in step S33 specifically includes: the table connecting JOIN is ambiguous; The columns of the conditions WHERE and JOIN are ambiguous; The value of the predicate is ambiguous.
- 7. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 6, wherein said step S4 specifically comprises the following procedures: s41, integrating all evidence encapsulation prompt word contexts to carry out enhancement and rewriting on the original natural language problem, and generating a final SQL; S42, inquiring according to the final SQL, and returning the final inquiring result to the user.
- 8. The large language model TEXT2SQL method based on user clarification and problem enhancement according to claim 7, wherein said step S41 specifically comprises the following procedures: S411, adding clear evidence expansion context into the prompt word; S412, adding the final candidate predicate list expansion context to the prompt.
- 9. A large language model TEXT2SQL system based on user clarification and problem enhancement for implementing the large language model TEXT2SQL method of any one of claims 1 to 8, comprising the following modules: The question-answer data pair generation module is used for generating a question-answer data pair of a corresponding natural language question and a corresponding SQL sentence aiming at the target database through a question-answer data pair large language model; The candidate SQL generating module is used for identifying ambiguity in natural language questions in the question-answer data pair through a candidate SQL big language model, continuously communicating with a user to clarify the questions, and eliminating the ambiguity to generate a candidate SQL; The final candidate predicate list generation module is used for extracting candidate predicates and clarifying predicates according to the execution result of the candidate SQL to generate a final candidate predicate list; and the final SQL generating module is used for enhancing the context of the natural language problem by using the problem enhancement large language model through clarifying evidence and a final candidate predicate list, generating a corresponding SQL for database query and finally responding to the user.
Description
Large language model TEXT2SQL method and system based on user clarification and problem enhancement Technical Field The invention relates to the technical field of artificial intelligence and industry, in particular to a large language model TEXT2SQL method based on user clarification and problem enhancement. Background In the current age, the information development is very rapid, and the database is used as a core tool for data storage and management and is widely applied to various industries. Traditional database query methods rely mainly on Structured Query Language (SQL), which requires users to have some programming skills and database knowledge, which increases the difficulty of non-technical users to operate the database. Especially when dealing with complex queries, users need to write complex SQL statements, which are time consuming and also prone to error. The following two problems are faced by a conversion method of encapsulating a table structure and a problem into a hint word by a large language model. First, natural language questions entered by users often have ambiguous expressions such as ambiguous time ranges, ambiguous terms, ambiguous computational logic, etc., which are difficult to automatically identify without training, resulting in the generated SQL being easily deviated from the user's true mind. Secondly, the quality of training data is difficult to guarantee, although a large language model can automatically generate question-answer data pairs, various problems such as format non-standardization, SQL grammar errors, mismatching of semantics and results exist in the generated results, the capability of relying on the large model only can not meet a plurality of specific scene requirements, and the cost is too high through manual standards. Aiming at the problems, the invention provides a natural language interaction scheme for realizing accurate SQL generation through man-machine interaction clarification and based on high-quality problems, thereby solving the problems of understanding deviation of user intention and insufficient quality of the generated problems in the prior art and reducing the operation difficulty of common staff. Disclosure of Invention The invention aims to solve the problems that the understanding deviation of a large language model on natural language problems of users is insufficient in problem quality and the operation difficulty of common staff is low. In order to solve the problems, the technical scheme of the invention discloses a natural language interaction method and a natural language interaction system for user clarification and problem enhancement based on a large language model. The technical scheme is as follows: in one aspect of the present invention, a method for user clarification and problem enhancement natural language interaction based on a large language model is provided, which is implemented by a user clarification and problem enhancement natural language interaction system based on a large language model, the method comprising the steps of: S1, aiming at a target database through a big language model of the question-answer data pair, generating a question-answer data pair of a corresponding natural language question and a corresponding SQL sentence. S2, identifying ambiguity in natural language questions in the question-answer data pair through a candidate SQL big language model, continuously communicating with a user to clarify the questions, eliminating the ambiguity, and generating a candidate SQL. S3, extracting candidate predicates and clarifying predicates according to the execution result of the candidate SQL, and generating a final candidate predicate list. S4, enhancing the context of the natural language problem by using the problem enhancement large language model through clarifying evidence and a final candidate predicate list, generating a corresponding SQL (structured query language) for database query, and finally responding to the user. In one possible implementation, generating the question-answer data pair of the corresponding natural language question and the corresponding SQL sentence for the target database through the question-answer data pair large language model in S1 includes: s11, acquiring the structure of the corresponding database table and the desensitized data. S12, inputting the acquired desensitized data and the database table structure into a large language model of the question-answer data pair to obtain a question-answer data pair of the natural language question and the corresponding SQL sentence. S13, checking the format, accuracy and validity of the question-answer data pair. In one possible embodiment, S13 verifies the format, accuracy and validity of the question-answer data pairs, including; s131, storing the question and answer data pairs. S132, inquiring a database through the SQL sentence generated by the big language model by the question-answer data, comparing the SQL sentence with the