Text conversion query statement generation method and system, medium and equipment

Through the Text-to-SQL method of multi-process collaboration and two-level prediction mechanism, the problem of inaccurate entity selection and inconsistent SQL keyword correspondence is solved, and the execution accuracy of SQL statements is improved.

CN120371853AActive Publication Date: 2025-07-25SHANDONG EVAYINFO TECH CO LTD

Patent Information

Application Number
CN202510857263.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-07-25
Estimated Expiration
2045-06-25

AI Technical Summary

Technical Problem

In the existing Text-to-SQL technology, inaccurate entity selection is inconsistent with the correspondence between SQL keywords, resulting in the generated SQL query statements that cannot accurately express user intentions.

Method used

A multi-process collaboration method is adopted to solve Text-to-SQL tasks in stages, using database value completion mode links, design a two-level prediction mechanism, predict SQL keywords and corresponding problem fragments, and conduct context learning and self-correction through a large language model.

Benefits of technology

Improve the execution accuracy of SQL statements, ensure the accuracy of the corresponding information of SQL keywords in user problems, and reduce the problem of inconsistent predicates and database values.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371853A_ABST
    Figure CN120371853A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of computer systems, and provides a text conversion query statement generation method and system, a medium and equipment, and the method comprises the steps: generating an initial structured query statement and a prediction mode link based on a user question, database mode information and external knowledge related to the user question; extracting database key value information of predicates in the initial structured query statement, and fusing the database key value information with the prediction mode link to obtain a key mode link; classifying the user questions based on the user questions, and performing structure prediction on the classified user questions to obtain aligned structured query keywords; generating a candidate structured query statement based on the user question, the database mode information, the external knowledge related to the user question, the key mode link, the aligned structured query keyword and the sample prompt, and performing self-correction and execution on the candidate structured query statement to obtain a correct structured query statement. Mode links are enriched, and the problem that problem values do not correspond to actual database storage values is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of computer systems, and particularly relates to a method, system, medium and device for generating text conversion query statements. Background Art

[0002] The statements in this part only provide background technical information related to the present invention, and do not necessarily constitute prior art.

[0003] As the core data carrier of modern information systems, databases play a very crucial role in the digital information age. With the continuous expansion of data scale and the increasing complexity of business requirements, the traditional query method based on SQL syntax has a relatively high technical threshold, bringing unprecedented pressure to professionals. To reduce the technical barriers of database queries, ordinary users can obtain the required information in the database through natural language questions, reducing the dependence on professional knowledge. The Text-to-SQL technology has emerged as the times require and has become an important bridge connecting people and structured data. Text-to-SQL, that is, the conversion technology from natural language to structured query language, is an important subtask of semantic analysis in the field of natural language processing. Its core function is to generate standard SQL statements that can accurately reflect the user's query intention and can be efficiently executed on the target database on the premise of a given natural language question and a database schema (DB Schema), achieving the goal of "breaking the barrier between people and structured data", enabling ordinary users to complete complex database queries through natural language descriptions without mastering complex SQL syntax and quickly obtaining the required results. In recent years, large language models (LLMs) have demonstrated their powerful performance in various fields. LLMs are trained with a large amount of data, covering knowledge in various fields, and can capture the complexity of language, including grammar, semantics, context, as well as the cultural and social knowledge therein. They are particularly outstanding in the field of natural language. At the same time, the research field of Text-to-SQL has generally shifted to the exploration of methods based on LLMs, leveraging the generalization ability and context understanding advantages of LLMs to improve the performance of Text-to-SQL systems.

[0004] However, in the existing methods for converting natural language questions into SQL query statements, incorrect phenomena are likely to occur when selecting the tables and fields corresponding to entities, and there are also inconsistencies between the selected entities and the values in the database, and the conditional information corresponding to SQL keywords is inaccurate, resulting in the final generated SQL query statement being unable to accurately express the key information of the question. Summary of the Invention

[0005] To solve the above problems, the present invention proposes a method, system, medium and device for generating text conversion query statements. The present invention adopts a multi-process collaboration method to solve the Text-to-SQL task in stages. The database values are used to complete the schema linking task, enriching the schema linking and solving the problem that the problem value does not correspond to the actual stored value in the database. At the same time, a two-level prediction mechanism is designed to predict SQL keywords and corresponding problem segments.

[0006] According to some embodiments, the first solution of the present invention provides a method for generating text conversion query statements, adopting the following technical solutions: A method for generating text conversion query statements, comprising: Based on the user's question, database schema information, and external knowledge related to the user's question, generating an initial structured query statement and a predicted schema link, extracting the database key value information of the predicates in the initial structured query statement, and then fusing it with the predicted schema link to obtain a key schema link; Classifying the user's question, and performing structure prediction on the classified user's question to obtain aligned structured query keywords; Based on the user's question, database schema information, external knowledge related to the user's question, key schema link, aligned structured query keywords, and sample prompts, generating a candidate structured query statement, self-correcting and executing the candidate structured query statement to obtain a correct structured query statement.

[0007] Further, extracting the database key value information of the predicates in the initial structured query statement specifically includes: Extracting the relevant predicates in the initial structured query statement and the problem entities in the user's question, filtering based on the vector similarity between the relevant predicates and the problem entities to obtain filtered predicates; Using a locality-sensitive hashing function to hash the predicates, retrieving based on the hashed predicate information in the database hash mapping table to determine the predicate database hash value information; Based on the cosine similarity between all the predicate database hash value information and the corresponding predicate database value information, screening to obtain the key predicate database hash value information, and using a large language model to filter the key predicate database hash value information, the user's question, and the external knowledge related to the user's question to obtain the database key value information.

[0008] Further, based on the user's question, database schema information, external knowledge related to the user's question, and sample prompts, using a large language model for context learning to predict the relevance between the user's question and the tables and columns in the database to obtain a predicted schema link.

[0009] Further, classify based on the user's question, perform structure prediction on the classified user's question, and obtain the aligned structured query keywords, specifically as follows: Classify based on whether the user's question contains nested statements. If the user's question contains nested statements, it is a difficult question; otherwise, it is a simple question. Generate simple structured query keywords based on structure prediction of simple questions. After determining sub-questions for difficult questions, first perform sub-structure prediction and then outer-structure prediction to generate overall difficult structured query keywords. Align information between the simple structured query keywords or the overall difficult structured query keywords and the user's question slices to obtain the aligned structured query keywords.

[0010] Further, after determining sub-questions for difficult questions, first perform sub-structure prediction and then outer-structure prediction to generate overall difficult structured query keywords, specifically as follows: If it is classified as a difficult question, split based on the nested statements in the user's question, perform intent recognition on each split nested statement, and determine the sub-questions corresponding to the nested statements. Use a large language model to perform structure prediction on each sub-question to generate the keywords required for the sub-query statements. Use a large language model to perform structure prediction on the keywords required for all sub-query statements to generate overall difficult structured query keywords.

[0011] Further, generate candidate structured query statements based on the user's question, database schema information, external knowledge related to the user's question, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statements to obtain the correct structured query statements, specifically as follows: Use a large language model to generate candidate structured query statements based on the user's question, database schema information, external information related to the user's question, key pattern links, aligned structured query keywords, and sample prompts. Self-correct the candidate structured query statements based on the user's question, external knowledge related to the user's question, key pattern links, and aligned structured query keywords to obtain the structured query statements to be executed. Execute based on the structured query statements to be executed in the database. If the query execution fails, input the error information and the user's question into the large language model, correct the structured query statements to be executed and then execute to obtain the correct structured query statements.

[0012] Further, based on the user question, external knowledge related to the user question, key pattern links, and aligned structured query keywords, self-correct the candidate structured query statement to obtain the structured query statement to be executed, specifically: Take the user question, external knowledge related to the user question, key pattern links, aligned structured query keywords, and the candidate structured query statement as inputs, and use a large language model to check whether the candidate structured query statement conforms to the information of the key pattern links and aligned structured query keywords. If it conforms, output the candidate structured query statement as the structured query statement to be executed; If it does not conform, based on the user question, external knowledge related to the user question, key pattern links, and aligned structured query keywords, use a large language model to generate a corrected structured query statement as the structured query statement to be executed.

[0013] According to some embodiments, the second solution of the present invention provides a text conversion query statement generation system, which adopts the following technical solutions: A text conversion query statement generation system, comprising: A key pattern link construction module, configured to generate an initial structured query statement and a predicted pattern link based on the user question, database schema information, and external knowledge related to the user question, extract the database key value information of the predicates in the initial structured query statement, and then fuse it with the predicted pattern link to obtain the key pattern link; A structure prediction module, configured to classify the user question based on the user question, and perform structure prediction on the classified user question to obtain aligned structured query keywords; A statement correction module, configured to generate a candidate structured query statement based on the user question, database schema information, external knowledge related to the user question, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statement to obtain a correct structured query statement.

[0014] According to some embodiments, the third solution of the present invention provides a computer-readable storage medium.

[0015] A computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the steps in a text conversion query statement generation method as described in the first aspect above.

[0016] According to some embodiments, the fourth solution of the present invention provides a computer device.

[0017] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in a method for generating a text conversion query statement as described in the first aspect above.

[0018] Compared with the prior art, the beneficial effects of the present invention are as follows: By constructing a Text-to-SQL generation architecture with multi-functional collaboration, the present invention gives full play to the reasoning ability of the LLM, uses the values actually stored in the database, reduces the problem of inconsistency between the conditional predicates in the SQL statements generated by the LLM and the values stored in the database, and at the same time reduces the problem of inaccuracy of the fields and tables where the values corresponding to the conditional predicates in the SQL statements are located in the database; and the two-level prediction mechanism ensures the accuracy of the information corresponding to the keywords in the SQL statements in the user questions, and improves the execution accuracy of the SQL statements to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings forming a part of this specification are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention.

[0020] Figure 1 It is an architecture diagram of a method for generating a text conversion query statement in an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0021] The present invention will be further described below with reference to the drawings and embodiments.

[0022] It should be noted that the following detailed description is illustrative and is intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.

[0023] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments of the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0024] In the case of no conflict, the embodiments in the present invention and the features in the embodiments may be combined with each other.

[0025] Embodiment 1 As Figure 1As shown in the figure, this embodiment provides a method for generating a text conversion query statement. This embodiment takes the application of this method to a server as an example. It can be understood that this method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, web servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, and this application does not make any restrictions here. In this embodiment, the method includes the following steps: Step S1: Based on the user's question, database schema information, and external knowledge related to the user's question, generate an initial structured query statement and a predicted pattern link. After extracting the database key value information of the predicates in the initial structured query statement, fuse it with the predicted pattern link to obtain a key pattern link; Step S2: Classify the user's question, and perform structure prediction on the classified user's question to obtain the aligned structured query keywords; Step S3: Based on the user's question, database schema information, external knowledge related to the user's question, key pattern link, aligned structured query keywords, and sample prompts, generate a candidate structured query statement, self-correct and execute the candidate structured query statement to obtain a correct structured query statement.

[0026] This embodiment proposes a Text-to-SQL generation method with multi-functional collaboration, which adopts multi-process collaboration to solve the Text-to-SQL task in stages. Using database values to complete the pattern link task enriches the pattern link and solves the problem that the problem value does not correspond to the actual stored value in the database. At the same time, a two-level prediction mechanism is designed to predict SQL keywords and corresponding problem segments; it is mainly divided into the following three aspects, specifically: Schema linking: Schema linking refers to associating the meaning of a natural language query with a database schema to achieve interaction between the problem and the database. Ensure that the words or phrases in the query accurately match the relevant database elements (such as tables, columns, or values). Correct schema linking means being able to accurately retrieve all database components related to the natural language query.

[0027] Structure prediction: Predict the keywords required to generate an SQL statement for the problem through a large language model to ensure structural stability.

[0028] SQL Correction: Execute the candidate SQL in the database. If an error occurs, input the user's question and error information into the large language model for correction.

[0029] Step S1: Based on the user's question, database schema information, and external knowledge related to the user's question, generate an initial structured query statement and a predicted pattern link. After extracting the database key value information of the predicates in the initial structured query statement, fuse it with the predicted pattern link to obtain a key pattern link.

[0030] Step S1.1: Utilize the user's question, database schema information, and external knowledge related to the user's question, and use Chain of Thought (COT) prompting to generate an initial structured query statement (initial SQL statement) based on the inference of the large language model.

[0031] First, utilize the inference ability of the large language model. Under the premise of the given user question information, database schema information, and external knowledge related to the user's question, use Chain of Thought (COT) prompting. The model infers and generates an initial SQL statement. Among them, the external knowledge related to the user's question refers to the common knowledge related to the user's question, that is, the explanation of the special entities in the user's question. For example, for the explanation of mathematical calculations and special fields (such as medical terms) existing in the question. For example, for the sample user question: "How much is 400 US dollars equivalent to in RMB on May 6, 2022", then the external knowledge related to the user's question: "The exchange rate of US dollars to RMB from May to June 2022 is: 6.77", which will not be elaborated here.

[0032] Database schema information defines the structure and organization method of data, including tables, columns, data storage types, sequences, views, primary keys, and foreign keys.

[0033] Step S1.2: Extract the relevant predicates in the initial SQL statement and the problem entities in the user's question, and filter them based on the vector similarity between the relevant predicates and the problem entities to obtain the filtered predicates.

[0034] Extract the relevant predicates in the initial SQL statement and the problem entities in the user's question, that is, extract the relevant predicates in the initial SQL statement (i.e., the actual values of the database used in the SQL statement). At the same time, decompose the user's question and extract the problem entities in the user's question.

[0035] Calculate the vector similarity between each relevant predicate and each problem entity. If it exceeds the set vector similarity threshold, select the problem entity as the filtered predicate; otherwise, select the relevant predicate as the filtered predicate.

[0036] That is to say, the filtering in this step is to check whether the extracted relevant predicate is only a part of the entire question entity. For example, for the question "Please list the zip codes of all charter schools in the Fresno County Office of Education.", the relevant predicate extracted by the initial SQL is "Fresno County", and the extracted question entity is "Fresno County Office of Education", then "Fresno County Office of Education" is selected as the filtered predicate.

[0037] Step S1.3: Hash the predicate using a locality-sensitive hashing function, and retrieve in the database hash mapping table based on the hashed predicate information to determine the predicate database hash value information.

[0038] Among them, the generation of the database hash mapping table is specifically as follows: Read the values in the database, use the table and field where the database value is located as the index, filter out the same values within the same table and field to ensure the uniqueness of the values, and obtain the filtered database values; Perform hash mapping on the filtered database values through a locality-sensitive hashing (LSH) function to obtain the database hash mapping table. Based on the filtering of the same values within the same table and field as above, it can solve problems such as incorrect selection of the corresponding table and field of the entity in the conversion of natural language to SQL and inconsistent selection of the entity and the values in the database in the pattern link.

[0039] Among them, the predicate database hash value information is the table and column in the filtered database where the corresponding predicate is located.

[0040] Step S1.4: Based on the cosine similarity between all the predicate database hash value information and the corresponding predicate database value information, perform screening to obtain the key predicate database hash value information, and use a large language model to filter the key predicate database hash value information, the user question, and the external knowledge related to the user question to obtain the database key value information.

[0041] Calculate the cosine similarity between all the predicate database hash value information and the corresponding predicate database value information; Retain the predicate database hash value information that exceeds the set cosine similarity threshold as the key predicate database hash value information; Use a large language model to filter the key predicate database hash value information, the user question, and the external knowledge related to the user question, and select the key predicate database hash value information associated with the user question as the database key value information.

[0042] The filtering here refers to using the above-mentioned key predicate database hash value information retrieved, user questions, and external knowledge related to user questions as inputs to the large language model, and letting the large language model output value information with high relevance to the user questions. For example: User question: "How much is 400 US dollars equivalent to in RMB on May 6, 2022". The value of May 6, 2022 may be in the "time column" of the "user table" or in the "time column" of the "expense table". What is relevant to the user question is the "time column" in the "user table". In this embodiment, the large language model performs filtering by selecting May 6, 2022 in the "time column" of the "user table".

[0043] Among them, it can be understood that the predicate database value information is the table and column in the database where the predicate is located.

[0044] Perform cosine similarity and LLM filtering on all the retrieved predicate database hash value information in sequence, which ensures that the value exists in the database, the value is written correctly, and the selected table and fields are correct.

[0045] Step S1.5: Based on the user question, database schema information, external knowledge related to the user question, and sample prompts, use the large language model for context learning to predict the relevance between the user question and the tables and columns in the database, and obtain the predicted pattern link.

[0046] Use the user question, database schema information, and external knowledge related to the user question as LLM inputs, adopt sample prompts, and enable the LLM to perform context learning to predict the relevance between the question and the tables and columns in the database. Predict the pattern link.

[0047] Step S1.6: Combine the predicted pattern link with the database key value information to form the final key pattern link.

[0048] The pattern link prompt word template is as follows: Role: You are an experienced database administrator.

[0049] Task description: Your task is to determine the relevant tables and columns required to generate SQL statements from the database schema by deeply analyzing the question and prompts.

[0050] Database structure introduction: Table: Table name.

[0051] Column: Column_name (Column_type), column description -> column description, example: (example of the value stored in this column).

[0052] Goal: Determine the relevant tables and columns required to generate SQL statements for a given problem in the database.

[0053] Example: Sample prompt.

[0054] Database structure: {DB Schema}.

[0055] Output: Tables and columns.

[0056] Step S2: Classify based on the user's question, perform structure prediction on the classified user question, and obtain the aligned structured query keywords. This step mainly solves the problem that the conditional information corresponding to the SQL keywords in the conversion of natural language to SQL is incorrect.

[0057] Step S2.1: Classify based on whether the user's question contains nested statements. If the user's question contains nested statements, it is a difficult problem; otherwise, it is a simple problem.

[0058] Take the user's question as input and first classify the question into two categories: simple and difficult. A simple question is a statement without nesting, and a difficult question is a statement with nesting. Reducing the classification of tasks alleviates model hallucinations to a certain extent. That is, the basis for classifying simple and difficult questions is whether the question requires the results generated by subqueries to complete the overall query.

[0059] Step S2.2: Generate simple structured query keywords based on structure prediction for simple questions. After determining the sub-questions for difficult questions, perform sub-structure prediction first and then outer-structure prediction to generate overall difficult structured query keywords.

[0060] Perform structure prediction on the classified user question, that is, generate the keywords required to generate SQL statements based on the user question. Specifically as follows: If it is classified as a simple question, directly use the large language module for structure prediction to generate simple structured query keywords, such as "select", "join", "group by".

[0061] If it is classified as a difficult question, split based on the nested statements in the user question, perform intent recognition on each split nested statement, and determine the sub-questions corresponding to the nested statements; Use the large language model to perform structure prediction on each sub-question to generate the keywords required for the subquery statement; Use the large language model to perform structure prediction on the keywords required for all subquery statements to generate overall difficult structured query keywords.

[0062] Step S2.3: Align the simple structured query keywords or the overall difficult structured query keywords with the user question slices to obtain the aligned structured query keywords.

[0063] Among them, the aligned structured query keywords include the aligned simple structured query keywords and the aligned overall difficult structured query keywords.

[0064] Correspond the obtained simple structured query keywords or difficult structured query keywords with the user question slices, that is, align the keywords with the information in the question. For example, for the question "Which football player is the shortest? (Simple)", the predicted alignment is "select (the shortest player in height)". This reduces the divergent thinking of the model when generating SQL statements and allows the large language model to re-understand the question and its correspondence with the keywords.

[0065] The structure prediction prompt template is as follows: Role: You are an experienced SQL language expert.

[0066] Task description: Given a question and related hints, pattern links, database schema information, descriptions of columns in the database table, and examples of values stored in the columns.

[0067] Hint: The hint helps to better understand the question.

[0068] Information explanation: Table: Table name.

[0069] Column: Column_name (Column_type), column description -> column description, example: (example of values stored in this column).

[0070] Goal: Determine the SQL keywords and functions that may be used in the SQL query generated for the given question. Do not generate SQL statements.

[0071] Output: SQL keywords and functions.

[0072] Step S3: Generate candidate structured query statements based on the user question, database schema information, external knowledge related to the user question, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statements to obtain the correct structured query statements.

[0073] Step S3.1: Use the large language model to generate candidate structured query statements based on the user question, database schema information, external information related to the user question, key pattern links, aligned structured query keywords, and sample prompts.

[0074] Input the user question, database schema information, external information related to the user question, key schema links, aligned structured query keywords, and sample prompts into the LLM, and let the model think step by step based on the input sample prompts to generate candidate structured query statements (candidate SQL statements).

[0075] Step S3.2: Based on the user question, external knowledge related to the user question, key schema links, and aligned structured query keywords, self-correct the candidate structured query statements to obtain the structured query statements to be executed, specifically: Take the user question, external knowledge related to the user question, key schema links, aligned structured query keywords, and candidate structured query statements as input, and use the large language model to check whether the candidate structured query statements conform to the information of the key schema links and aligned structured query keywords. If they conform, output the candidate structured query statements as the structured query statements to be executed; If they do not conform, based on the user question, external knowledge related to the user question, key schema links, and aligned structured query keywords, use the large language model to generate corrected structured query statements as the structured query statements to be executed.

[0076] Input the user question, external knowledge related to the user question, key schema links, and aligned structured query keywords to let the LLM self-correct the candidate SQL statements, ensuring that the previous information can be fully utilized and preventing the generation of SQL statements directly based on the question and external knowledge without using the key schema links and aligned structured query keywords.

[0077] Step S3.3: Execute based on the structured query statements to be executed in the database. If the query execution fails, input the error information and the user question into the large language model, correct the structured query statements to be executed, and then execute to obtain the correct structured query statements.

[0078] Execute the SQL statements to be executed obtained after self-correction in the database. If the result is empty or an error occurs, input the error information and the user question into the large language model, correct the structured query statements to be executed, and then execute to obtain the correct structured query statements (correct SQL statements).

[0079] The error correction prompt words are as follows: Role: You are an expert in SQLite error correction.

[0080] Task description: You will be given a question, a hint, database schema information, an incorrect SQL statement, and information related to the SQL execution error. Analyze the error information and make corrections.

[0081] Introduce the database schema information: Table: Table name.

[0082] Column: Column_name (Column_type), column description -> column description, example: (example of the value stored in this column).

[0083] First step: Requirement check; Confirm whether the SQL query meets the requirements specified in the question.

[0084] Please pay close attention to "external knowledge" to obtain reference information for checking the SQL. Verify whether the SQL query correctly understands and applies relevant concepts or constraints.

[0085] If there is no "external knowledge", focus on the question itself.

[0086] Second step: Result rationality; If the SQL involves arithmetic operations, check whether the data types in the arithmetic operation part are correct and write the analysis in a descriptive manner.

[0087] Guidelines: If it does not meet the requirements, modify the SQL query to ensure that it meets all requirements and generates a logically reasonable result.

[0088] Just output the corrected SQL statement without any explanation.

[0089] Overturn the previous SQL if appropriate and rewrite the new SQL statement.

[0090] Output: The corrected SQL statement.

[0091] Example 2 This embodiment provides a text conversion query statement generation system, including: A key pattern link construction module, configured to generate an initial structured query statement and a predicted pattern link based on the user question, database schema information, and external knowledge related to the user question, extract the database key value information of the predicates in the initial structured query statement, and then fuse it with the predicted pattern link to obtain the key pattern link; A structure prediction module, configured to classify the user question and perform structure prediction on the classified user question to obtain the aligned structured query keywords; The statement correction module is configured to generate a candidate structured query statement based on the user question, database schema information, external knowledge related to the user question, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statement to obtain a correct structured query statement.

[0092] The examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the content disclosed in the first embodiment above. It should be noted that the above modules, as part of the system, can be executed in a computer system such as a set of computer-executable instructions.

[0093] In the above embodiments, the descriptions of each embodiment have their own focuses. For parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0094] The proposed system can be implemented in other ways. For example, the above-described system embodiments are merely illustrative. For example, the division of the above modules is only a logical function division. In actual implementation, there can be other division methods. For example, multiple modules can be combined or integrated into another system, or some features can be ignored or not executed.

[0095] Embodiment Three This embodiment provides a computer-readable storage medium with a computer program stored thereon. When the program is executed by a processor, it implements the steps in a method for generating a text conversion query statement as described in the first embodiment above.

[0096] Embodiment Four This embodiment provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, it implements the steps in a method for generating a text conversion query statement as described in the first embodiment above.

[0097] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories and optical memories, etc.) containing computer-usable program code.

[0098] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one flow Figure 1 one flow or more flows and / or blocks Figure 1 or means for implementing the functions specified in one block or more blocks.

[0099] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that implement the functions specified in one flow Figure 1 one flow or more flows and / or blocks Figure 1 or means for implementing the functions specified in one block or more blocks.

[0100] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or more flows and / or blocks Figure 1 or means for implementing the functions specified in one block or more blocks.

[0101] Those of ordinary skill in the art can understand that all or part of the processes in the above-described method embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-described method embodiments. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM), etc.

[0102] Although the specific embodiments of the present invention have been described above in conjunction with the accompanying drawings, it is not a limitation on the protection scope of the present invention. Those skilled in the art should understand that, based on the technical solutions of the present invention, various modifications or deformations that can be made by those skilled in the art without creative efforts are still within the protection scope of the present invention.

Claims

1. A method for generating a text conversion query statement, characterized in that, Including: Based on the user's question, database schema information, and external knowledge related to the user's question, generate an initial structured query statement and a predicted pattern link. After extracting the database key value information of the predicates in the initial structured query statement, fuse it with the predicted pattern link to obtain a key pattern link; Classify the user's question, perform structure prediction on the classified user's question, and obtain the aligned structured query keywords; Based on the user's question, database schema information, external knowledge related to the user's question, key pattern link, aligned structured query keywords, and sample prompts, generate candidate structured query statements, self-correct and execute the candidate structured query statements to obtain the correct structured query statements.

2. The method for generating a text conversion query statement according to claim 1, wherein Extract the database key value information of the predicates in the initial structured query statement, specifically: Extract the relevant predicates in the initial structured query statement and the problem entities in the user's question, filter based on the vector similarity between the relevant predicates and the problem entities to obtain the filtered predicates; Use the locality-sensitive hashing function to hash the predicates, retrieve based on the hashed predicate information in the database hash mapping table to determine the predicate database hash value information; Based on the cosine similarity between all the predicate database hash value information and the corresponding predicate database value information, perform screening to obtain the key predicate database hash value information, and use the large language model to filter the key predicate database hash value information, user's question, and external knowledge related to the user's question to obtain the database key value information.

3. A method for generating a text conversion query statement according to claim 1, characterized in that, Based on the user's question, database schema information, external knowledge related to the user's question, and sample prompts, use the large language model for context learning to predict the relevance between the user's question and the tables and columns in the database to obtain the predicted pattern link.

4. A method for generating a text conversion query statement according to claim 1, wherein, The above-mentioned classification based on the user's question, performing structure prediction on the classified user's question, and obtaining the aligned structured query keywords, specifically: Classify based on whether the user's question contains nested statements. If the user's question contains nested statements, it is a difficult question; otherwise, it is a simple question; Perform structure prediction on the simple question to generate simple structured query keywords. After determining the sub-questions according to the difficult question, first perform sub-structure prediction and then perform outer-structure prediction to generate the overall difficult structured query keywords; Align the information based on the simple structured query keywords or the overall difficult structured query keywords with the user's question slices to obtain the aligned structured query keywords.

5. The method for generating a text conversion query statement according to claim 4, wherein, After determining the sub-questions according to the difficult question, first perform sub-structure prediction and then perform outer-structure prediction to generate the overall difficult structured query keywords, specifically: If it is classified as a difficult question, split based on the nested statements in the user's question, perform intent recognition on each split nested statement to determine the sub-questions corresponding to the nested statements; Use the large language model to perform structure prediction on each sub-question to generate the keywords required for the sub-query statements; Use the large language model to perform structure prediction on the keywords required for all sub-query statements to generate the overall difficult structured query keywords.

6. The method for generating a text conversion query statement according to claim 1, wherein Generate candidate structured query statements based on user questions, database schema information, external knowledge related to user questions, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statements to obtain correct structured query statements. Specifically: Generate candidate structured query statements using a large language model based on user questions, database schema information, external information related to user questions, key pattern links, aligned structured query keywords, and sample prompts; Self-correct the candidate structured query statements based on user questions, external knowledge related to user questions, key pattern links, and aligned structured query keywords to obtain structured query statements to be executed; Execute based on the structured query statements to be executed in the database. If the query execution fails, input the error information and user questions into the large language model, correct the structured query statements to be executed and then execute them to obtain correct structured query statements.

7. The method for generating a text conversion query statement according to claim 6, wherein Self-correct the candidate structured query statements based on user questions, external knowledge related to user questions, key pattern links, and aligned structured query keywords to obtain structured query statements to be executed. Specifically: Use the user questions, external knowledge related to user questions, key pattern links, aligned structured query keywords, and candidate structured query statements as inputs, and use the large language model to check whether the candidate structured query statements conform to the information of the key pattern links and aligned structured query keywords. If they conform, output the candidate structured query statements as the structured query statements to be executed; If they do not conform, generate corrected structured query statements using the large language model based on user questions, external knowledge related to user questions, key pattern links, and aligned structured query keywords as the structured query statements to be executed.

8. A text conversion query statement generation system, characterized in that Include: A key pattern link construction module configured to generate an initial structured query statement and a predicted pattern link based on user questions, database schema information, and external knowledge related to user questions, extract the database key value information of the predicates in the initial structured query statement, and fuse it with the predicted pattern link to obtain a key pattern link; A structure prediction module configured to classify user questions and perform structure prediction on the classified user questions to obtain aligned structured query keywords; A statement correction module configured to generate candidate structured query statements based on user questions, database schema information, external knowledge related to user questions, key pattern links, aligned structured query keywords, and sample prompts, self-correct and execute the candidate structured query statements to obtain correct structured query statements.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps in a method for generating a text conversion query statement as described in any one of claims 1-7.

10. A computer device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in a method for generating a text conversion query statement as described in any one of claims 1-7.

Citation Information

Patent Citations

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

    CN117708297A

  • Large model-based sql statement generation method and device

    CN119088824A

  • Method, system and equipment for generating SQL (Structured Query Language) statement based on large model

    CN119127913A

  • Context learning-based database query generation method and system and storage medium

    CN119669265A

  • Query statement generation method and device, equipment and storage medium

    CN119719321A

Cited By

  • Large-scale language model enhanced table question and answer method based on thinking chain reasoning

    CN120654835A

  • Semantic constraint chain-based special equipment inspection complex query generation method

    CN122366414A

  • Method for generating complex query of special equipment inspection based on semantic constraint chain

    CN122366414B