Method, system and device for converting natural language to SQL (Structured Query Language) query statement and medium

By combining the method of general large language model and knowledge graph, the problem of low efficiency and insufficient accuracy in natural language to SQL query conversion in the existing technology is solved, the accurate understanding of user intentions and the generation of SQL query statements are achieved, and the query efficiency is improved. Efficiency and accuracy, suitable for multi-dimensional analysis of complex and large data volumes.

CN118779342APending Publication Date: 2024-10-15UNICOM (HENAN) IND INTERNET CO LTD
View PDF 0 Cites 24 Cited by

Patent Information

Application Number
CN202410870942.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-10-15

AI Technical Summary

Technical Problem

Existing natural language to SQL query conversion technology is inefficient and inaccurate when processing complex queries, especially multi-table related queries. It is difficult to accurately understand user intentions, resulting in generated SQL query statements that have logical errors or cannot be executed, and require A lot of manual intervention, increasing costs and query time.

Method used

Using a method based on a general large language model and knowledge graph, it identifies metadata information, forms SQL query semantics, and uses the thinking chain model of the SQL industry large model to convert the semantics into SQL query statements, combined with multiple rounds of dialogue and cosine similarity algorithms. Accurately identify and transform entity information and generate accurate SQL query statements.

Benefits of technology

It improves the accuracy and efficiency of queries and reduces errors. Users can complete complex data queries without professional SQL knowledge, meet the needs of large data volumes and multi-dimensional analysis, and have good versatility and scalability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118779342A_ABST
    Figure CN118779342A_ABST
Patent Text Reader

Abstract

The invention provides a method, system and device for converting a natural language into an SQL query statement and a medium, relates to the technical field of artificial intelligence, and is particularly suitable for improving the efficiency and accuracy of interaction between non-technical users and a database. According to the method, a natural language query instruction of a user is analyzed through a general large language model, a target table is accurately matched through a knowledge graph and a neural network technology, SQL query semantics are formed, then the SQL query semantics are intelligently converted into SQL query statements through an SQL industry large model and a thinking chain mode, and finally query results are executed and returned. According to the method, the problems of low efficiency and inaccurate result in the process of processing complex queries in the prior art can be solved, so that a user can conveniently describe query requirements through a natural language, and quick and accurate data retrieval is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, system, device and medium for converting natural language into SQL query statements. Background Art

[0002] With the rapid development of artificial intelligence technology, natural language processing (NLP) has become a hot topic of research, with the goal of enabling computers to understand, interpret and generate human language. In the field of database query, traditional query methods usually require users to have a certain technical background and be able to write structured query language (SQL) to retrieve information from the database. However, this limits the use of non-technical users, who prefer to use natural language to express query requirements.

[0003] Existing technologies mostly use rule matching, templating or statistical learning methods to achieve the conversion from natural language to SQL, but these methods are inefficient and have inaccurate results when processing complex queries, especially those involving multi-table associations. For example, some systems may not be able to accurately understand the user's intentions, resulting in logical errors or inability to execute the generated SQL query statements; or in multi-table association queries, it is difficult to accurately match tables and fields, resulting in inaccurate query results or missing important information. In addition, when processing large amounts of data and complex logical relationships, existing technologies often require a lot of manual intervention, which not only increases costs but also affects query efficiency. Summary of the invention

[0004] The present application provides a natural language to SQL query statement conversion method, system, device and medium, which can automatically convert the query requirements described by users in natural language into accurate SQL query statements, improve query efficiency and reduce errors.

[0005] A method for converting natural language to SQL query statements includes: obtaining a query instruction expressed in natural language input by a user; parsing the query instruction based on a general large language model to identify metadata information, the metadata information including: a target table name, a query field, and a query condition; using a knowledge graph and a neural network model to form SQL query semantics according to the metadata information; using a thinking chain mode based on an SQL industry large model to convert SQL query semantics into SQL query statements; executing the SQL query statement and returning the query result.

[0006] Optionally, query instruction parsing is performed based on a general large language model, and identifying metadata information also includes: the backend service receives the query instruction transmitted from the front end through an interface; combining the user's historical question information and the currently input text to summarize and understand the context information through multiple rounds of dialogue; based on the context information, a prompt prompt project is created and input into the general large language model to identify user intent and entity information.

[0007] Optionally, based on the context information, a prompt project is created and input into a general large language model to identify user intent and entity information, including: determining the model role, task and execution method, and combining the context information and few-shot examples to guide the general large language model to generate results.

[0008] Optionally, query instruction parsing is performed based on a general large language model, and identifying metadata information also includes: using a cosine similarity algorithm to perform similarity analysis, and combining multiple rounds of clarification steps to convert the identified entity information into a standard entity that can be directly used; combining the standard entity to determine whether it conforms to the logic of the SQL query.

[0009] Optionally, using the knowledge graph and the neural network model to form SQL query semantics based on metadata information also includes: receiving parsed entity information; building a target table relationship sequence using the knowledge graph; and generating SQL query semantics by combining the SQL semantic template, the target table relationship sequence, the query fields, and the query conditions.

[0010] Optionally, using the knowledge graph to construct a target table relationship sequence includes: constructing a table relationship diagram for all tables in the database; obtaining a table name sequence related to the target table from the table relationship diagram; vectorizing the table name sequence through a neural network model; using a cosine similarity algorithm to match the table name sequence to obtain the optimal matching table sequence; and obtaining the target table relationship sequence based on the optimal matching table sequence.

[0011] Optionally, based on the SQL industry big model, the thinking chain mode is used to convert SQL query semantics into SQL query statements, including: preparing training corpus and creating a prompt project in combination with the thinking chain mode; fine-tuning the SQL-Coder industry big model through the prompt project; inputting the SQL query semantics into the fine-tuned SQL-Coder industry big model to generate SQL query statements; and performing logical verification on the SQL query statements.

[0012] On the other hand, a natural language to SQL query statement conversion system includes: an instruction receiving module, which is used to obtain query instructions expressed in natural language input by a user; an instruction parsing module, which is used to parse query instructions based on a general large language model and identify metadata information, and the metadata information includes: target table name, query field, query condition; a semantic generation module, which is used to use a knowledge graph and a neural network model to form SQL query semantics according to metadata information; a statement conversion module, which is used to convert SQL query semantics into SQL query statements based on a thinking chain mode based on an SQL industry large model; and an execution module, which is used to execute SQL query statements and return query results.

[0013] In addition, a computer device includes at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the above-mentioned conversion method.

[0014] Furthermore, a computer-readable storage medium stores computer instructions, which are used to enable a computer to execute the above-mentioned method for converting natural language to SQL query statements.

[0015] In addition, a computer program product includes a computer program / instruction, which, when executed by a processor, implements the steps of any of the above-mentioned methods for converting natural language into SQL query statements.

[0016] Through the technical solution of this application, when users interact with the database through natural language, they can accurately understand the user's query intention and generate correct SQL query statements. Complex data query tasks can be completed without professional SQL knowledge, which greatly improves the accuracy and efficiency of queries. At the same time, by using knowledge graphs and neural network technology, complex queries such as multi-table associations can be processed to meet users' needs for large data volumes and multi-dimensional analysis. In addition, the implementation of this application is not limited to a specific type of database or application scenario, and has good versatility and scalability.

[0017] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the following preferred embodiments are specifically cited and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0019] Figure 1 A flowchart of a conversion method provided by an embodiment of the present disclosure;

[0020] Figure 2 A diagram of a front-end query entry page provided by an embodiment of the present disclosure;

[0021] Figure 3 A flowchart of user instruction parsing based on a general large language model provided in an embodiment of the present disclosure;

[0022] Figure 4 A flow chart of SQL semantic generation based on knowledge graph and neural network provided in the embodiment of the present disclosure;

[0023] Figure 5 A flowchart of the relationship between target tables provided in the embodiment of the present disclosure;

[0024] Figure 6 A flow chart for generating SQL statements based on the SQL-Coder industry model provided in an embodiment of the present disclosure;

[0025] Figure 7 A diagram of the SQL execution results provided by the embodiment of the present disclosure;

[0026] Figure 8 The SQL result graphics provided by the embodiment of the present disclosure;

[0027] Fig. 9 A principle block diagram of a conversion system provided by an embodiment of the present disclosure;

[0028] Fig.10 A schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0029] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.

[0030] It should be clear that the following embodiments of the present disclosure are described by specific specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other in the absence of conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.

[0031] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.

[0032] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The drawings only show components related to the present disclosure rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0033] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.

[0034] In this embodiment, if Figure 1 As shown, a method for converting a natural language to a SQL query statement is described in detail, including the following steps:

[0035] S101: Obtain a query instruction expressed in natural language input by a user.

[0036] For example, Figure 2As shown, non-technical personnel input query instructions expressed in natural language through the front-end page entrance of the corresponding business system (such as the business analysis system), such as "What is the number of mobile business users nationwide in May 2023?", and click the "Send" button to send the query instruction to the back-end server to initiate a query request.

[0037] S102: Parse the query instruction based on the general large language model to identify metadata information, where the metadata information includes the target table name, query field, and query condition.

[0038] This step ensures that the user's query intent can be accurately understood and key metadata information can be extracted from it. Figure 3 As shown in the figure, first, the backend server receives the query request from the frontend page through the interface, summarizes and understands the context information through multiple rounds of dialogue based on the user's historical question information and the current input text, and then creates a prompt project based on the context information and inputs it into the general language model to identify the user's intention and metadata information (target table name, query field, query condition), and structures it to obtain the output 1 (As shown in Table 1-1), the query fields parsed by the model are then mapped using the cosine similarity algorithm based on the standard name library to generate standard query fields. 1 Adjustments are made and, if necessary, multiple rounds of clarification are performed to ensure accurate understanding of the query fields. Then, the adjusted output is verified. 1 Whether the query fields and query conditions in the query meet the query logic rules, and finally, output after passing 1 (As shown in Table 1-1).

[0039]

[0040] S103: Using the knowledge graph and neural network model, SQL query semantics is formed according to the metadata information.

[0041] For example, Figure 4 and Figure 5 As shown, first, the result output by step S102 is received, and then the knowledge graph is used to understand the table entities and table relationships in the result to form multiple table sequences, and then the table sequence is converted into a vector representation through a neural network model (such as word2vector), and the cosine similarity algorithm is used for matching to obtain the most relevant table sequence, and then the most relevant table sequence is converted into a table relationship graph based on the knowledge graph to obtain the relationship between the table entities, and finally, SQL query semantics is generated in combination with the SQL semantic template for subsequent generation of SQL query statements.

[0042] S104: Based on the SQL industry big model, use the thinking chain mode to convert SQL query semantics into SQL query statements.

[0043] The above steps can ensure that the generated SQL query statement not only complies with SQL syntax rules, but also accurately reflects the user's query requirements. Figure 6 As shown, in order to improve the accuracy of generating SQL query statements, first, prepare training corpus according to the SQL semantic template and create a prompt prompt project in combination with the thinking chain model. Then, fine-tune the large model based on the open source SQL generation to form a fine-tuned SQL-Coder industry large model. Then, the SQL query semantics generated according to step S103 and combined with the prompt prompt project to form context semantics are input into the fine-tuned SQL-Coder industry large model to generate SQL query statements. Finally, perform logic verification on the SQL query statements, execute and return the results.

[0044] S105: Execute the SQL query statement and return the query result.

[0045] For example, Figure 7 As shown, the back-end server obtains and executes the generated SQL query statement, queries the corresponding results and returns them to the front-end page.

[0046] Optionally, the method for converting natural language to SQL query statements may further include the following steps: graphical display of results: Figure 8 As shown, the page is graphically displayed based on the query results to help data analysts quickly analyze and generate reports.

[0047] Optionally, query instruction parsing is performed based on a general large language model, and metadata information is identified including:

[0048] 1. The back-end server receives user query instructions from the front-end page through its interface module to ensure that the natural language query instructions entered by the user can be captured and processed;

[0049] 2. Combining the user's historical question information and the current input text, the multi-round dialogue mechanism is used to summarize and understand the context information, so as to more accurately grasp the user's query intention;

[0050] 3. Create a prompt project based on the context information and input it into a general language model (such as llama) to identify user intent and entity information. By designing specific prompt information, it can guide the general language model to correctly identify and parse the user intent and entity information contained in the user's query instructions.

[0051] In this embodiment, the user's interaction history is recorded and learned through multi-round dialogue summary technology and a hybrid memory mechanism. When a user enters a short query command, it can provide accurate feedback data based on historical interaction information and context integration. For example, if a user has historically queried sales data for a specific region, when the user only enters "sales data" without specifying a region, it can infer the user's possible query intention based on historical interactions and provide feedback on sales data for the corresponding region.

[0052] In the Prompt project, design specific prompt information to clarify the model's role, tasks, and execution methods. For example, set a big data expert role and guide the model to understand the user's query intent through a few-shot example. If the user enters a query question, the required target table name, query field, and query condition can be parsed and output according to the preset json format; if the input is not a query question, prompt the user to enter a valid query content.

[0053] A few-shot example is as follows:

[0054] You are a big data expert. Please parse a paragraph of user input according to the following JSON format. If the user's data is not a query problem, return to the user "Sorry, please enter the content you want to query", otherwise parse the user's input as required.

[0055] {

[0056] "Input": "What is Shandong's main business income in March 2023?"

[0057] "output": "{

[0058] "Table Name": [dwd_user_info,],

[0059] "Query Field": ["Main Business Income",],

[0060] “Query Condition”: [“Account Period”: “March 2023”, “Region”: “Shandong Province”]

[0061] }”,

[0062] },

[0063] {

[0064] "Input": "So boring"

[0065] "output": "Sorry, please enter the content you want to query!"

[0066] }

[0067] Optionally, query instruction parsing based on a universal large language model and identifying metadata information also includes: using a cosine similarity algorithm to perform similarity analysis, and combining multiple rounds of clarification to convert the identified entity information into a standard entity that can be directly used; combining the standard entity to determine whether it conforms to the logic of the SQL query. For example, when the similarity reaches a preset threshold of 0.80 or more, if there is only one standard entity with the highest similarity, the standard entity is directly used; if there are multiple standard entities with high similarity, multiple rounds of clarification are performed to further confirm the user's intention.

[0068] The cosine similarity algorithm mentioned above in this application is as follows:

[0069] The above multiple rounds of clarification ensure that when there are multiple similar standard entities, the final standard entity is clarified through interaction with the user. For example, "What is the number of mobile network business development users nationwide in May 2023?" The query field is "number of mobile network business development users." When the similarity of "number of mobile network business development users" and "number of mobile development users" exceeds the set threshold during similarity calculation, it needs to be returned to the user for clarification and confirmation.

[0070] In addition, this embodiment can also perform query logic verification to ensure that the logical relationship between the query conditions and the query fields complies with the SQL query rules and avoid conflicts between query items.

[0071] Through the above steps, the method in this embodiment enhances the ability to understand the user's query intention, improves the accuracy of entity recognition, and ensures the correctness of the query statement through logical verification, thereby improving the reliability and effectiveness of the entire query conversion process.

[0072] Optionally, the steps of using the knowledge graph and the neural network model to form SQL query semantics according to the metadata information specifically include:

[0073] 1. Receive the parsed entity information, which includes the target table name, query fields, and query conditions involved in the user query;

[0074] 2. Use the knowledge graph to build a target table relationship sequence. By retrieving the table name sequence related to the target table in the knowledge graph, the complex relationship between the tables in the database is constructed;

[0075] 3. Combine the SQL query semantic template, target table relationship sequence, query fields and query conditions to generate SQL query semantics. This step quickly forms the basic structure of SQL query through template method.

[0076] Optionally, the step of constructing a target table relationship sequence using a knowledge graph includes:

[0077] 1. Analyze all tables in the database and build a table relationship graph. The graph uses table names as nodes and relationships between tables as edges, forming a complex network structure.

[0078] 2. From the parsed table name sequence, select the target table as the starting point, traverse the sequence, and use the knowledge graph to obtain the table name sequences related to the target table in turn, and build a relationship network centered on the target table;

[0079] 3. Through the neural network model, the obtained table name sequence is vectorized and the table name is converted into a numerical vector for mathematical operations and similarity comparison;

[0080] 4. Use the cosine similarity algorithm to calculate the similarity between the vectorized table name sequences. According to the calculated cosine similarity value, select the table sequence with the highest similarity as the optimal match;

[0081] 5. The final target table relationship sequence is formed based on the optimal matching table sequence, and this sequence will be used for subsequent SQL query statement generation.

[0082] For example, using the knowledge graph to construct the target table relationship sequence includes: first, for all the tables in the database, a relationship graph is constructed with table names as nodes and relationships between tables as edges; then, output from step S102 is 1 The table name sequence TableList1 is obtained, specifically including: sorting and vectorizing the tables in the table sequence in ascending order, then traversing the table sequence TableList1, and combining the knowledge graph to obtain the table name sequence TableList_N related to the target table T1 in turn; then using the neural network model to vectorize the obtained table sequence TableList_N respectively; finally using the cosine similarity algorithm to calculate the similarity with the table sequence TableList1 to obtain the optimal matching table sequence TableList_1; according to the obtained optimal matching table sequence TableList_1, the target table relationship graph SubGraph is obtained, and finally a sequence output in the format of (table name 1, table name 2, relationship) is formed for generating SQL query semantics.

[0083] Optionally, the step of generating SQL query semantics by combining the SQL query semantic template, the target table relationship sequence, the query field and the query condition includes: generating the SQL query semantics by combining the table-table relationship sequence generated in the previous step and the output in step S102 according to the SQL semantic template 1Get the query conditions and query items to generate SQL query semantics, the style is as follows: """1. Data source table: ZBG_DWA.DWA_CUS_CB_USER_INFO A, ZBA_DWA.DWA__USER_INFO B, 2. Restriction conditions: ① Account period: A.month_id = '202305' ② Region: A.prov_id = "; ③ Whether it is in the network (yes): A.is_innet = '1' and B.is_this_innet = '1'; ④ Whether it is valid (yes): A.IS_STAT = '1'; ⑥ Whether it is moved to another network (yes): A.dev_user = '1'; 3. Metric field: A.user_id to remove duplicates, take count(user_id)"""

[0084] Optionally, based on the SQL industry big model, using the thought chain mode, converting SQL query semantics into SQL query statements includes:

[0085] 1. Prepare training corpus, which includes a series of SQL query statements and their corresponding natural language descriptions, for training and fine-tuning the SQL-Coder industry model;

[0086] 2. Create prompt projects based on the thought chain model. These prompt projects are used to guide the model on how to generate accurate SQL query statements based on given SQL query semantics.

[0087] 3. Fine-tune the SQL-Coder industry model through prompt engineering. This step optimizes the model's ability to generate specific types of SQL query statements.

[0088] 4. Input the generated SQL query semantics into the fine-tuned SQL-Coder industry model, and the model generates the corresponding SQL query statement based on the input semantics;

[0089] 5. Perform logical verification on the generated SQL query statements to ensure that the statements comply with SQL syntax rules, are logically correct, and can accurately reflect the user's query intent.

[0090] For example, through the prompt project, determine the role the model will play, what to do and how to do it, and combine context information, few-shot samples, and thought chains to guide the large model to generate results step by step. Common examples: You are a data analysis expert. Please parse a paragraph of user input in the following json format, and write SQL scripts step by step according to the following requirements. Requirements: 1. First determine the data source and understand the data structure, then determine the filtering conditions and select the aggregation function, then build the basic query, and finally generate the SQL query statement. 2. All data comes from the input. Don't make up query conditions, query items, and table names out of thin air.

[0091] """

[0092] {

[0093] "Input": "1. Data source table: ZBG_DWA.DWA_CUS_CB_USER_INFO A, ZBA_DWA.DWA__USER_INFO B, 2. Restriction conditions: ① Account period: A.month_id = '202305' ② Region: A.prov_id = "; ③ Whether in the network (yes): A.is_innet = '1' and B.is_this_innet = '1'; ④ Whether valid (yes): A.IS_STAT = '1'; ⑥ Whether to move the network (yes): A.dev_user = '1'; 3. Metric field: A.user_id to remove duplicates, take count(user_id)"

[0094] "output": "{

[0095] 1. Understand data requirements: The requirement is to obtain the number of users under specific conditions, including account period, region, online status, validity, and mobile network status.

[0096] 2. Determine the data source: The data comes from two tables: ZBG_DWA.DWA_CUS_CB_USER_INFO (Table A) and ZBA_DWA.DWA__USER_INFO (Table B).

[0097] 3. Clarify the restrictions:

[0098] ①Account period: A.month_id = '202305'

[0099] ②Region: A.prov_id=” (Region condition is not specified here, further information may be required)

[0100] ③ Is it in the network (yes): A.is_innet = '1' AND B.is_this_innet = '1'

[0101] ④Is it valid (yes): A.IS_STAT='1'

[0102] ⑥Whether to move the network (yes): A.dev_user = '1' (the condition number skips ⑤, assuming that ⑤ is not necessary).

[0103] 4. Determine the metric field: You need to calculate the number of unique users: COUNT(DISTINCT A.user_id).

[0104] 5. Write SQL query statements: The SQL query statements are as follows:

[0105]

[0106]

[0107] The SQL-Coder industry big model, which is formed by preparing training corpus according to SQL semantic templates and fine-tuning based on open source SQL generation big models (such as llama-code big models) and open source fine-tuning technologies (such as Lora, QLora), can further improve the accuracy of generating SQL query statements based on SQL query semantics.

[0108] Verify whether the SQL query statement complies with the grammatical rules, such as whether the keywords are correct and whether the brackets match. For queries using aggregate functions (such as SUM, AVG, COUNT, etc.), it can help determine how the aggregate logic is processed.

[0109] Through the technical solution of this application, when users interact with the database through natural language, they can accurately understand the user's query intention and generate correct SQL query statements. Complex data query tasks can be completed without professional SQL knowledge, which greatly improves the accuracy and efficiency of queries. At the same time, by using knowledge graphs and neural network technology, complex queries such as multi-table associations can be processed to meet users' needs for large data volumes and multi-dimensional analysis. In addition, the implementation of this application is not limited to a specific type of database or application scenario, and has good versatility and scalability.

[0110] This embodiment also provides a natural language to SQL query statement conversion system, such as Fig. 9 As shown, specifically including:

[0111] An instruction receiving module is used to obtain a query instruction expressed in a natural language input by a user;

[0112] The instruction parsing module is used to parse query instructions based on the general large language model and identify metadata information, which includes: target table name, query field, and query condition;

[0113] The semantic generation module is used to use the knowledge graph and neural network model to form SQL query semantics based on metadata information;

[0114] The statement conversion module is used to convert SQL query semantics into SQL query statements using the thinking chain mode based on the SQL industry big model;

[0115] The execution module is used to execute SQL query statements and return the query results.

[0116] These modules work together to ensure that the conversion process from natural language to SQL query statements is efficient and accurate, allowing users to conveniently perform database queries without having professional SQL knowledge. The specific details of the above natural language to SQL query statement conversion method are applicable to the corresponding modules in the natural language to SQL query statement conversion system and will not be repeated here.

[0117] In addition, this embodiment also provides a computer device, including at least one processor and a memory connected to the processor. The memory stores executable instructions so that the processor can execute the method steps of the above system. At the same time, a computer readable storage medium is also provided, in which computer instructions for causing a computer to execute the above conversion method are stored.

[0118] The computer device according to the embodiment of the present disclosure includes a memory and a processor. The memory is used to store non-temporary computer-readable instructions. Specifically, the memory may include one or more computer program products, and the computer program product may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may, for example, include a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may, for example, include a read-only memory (ROM), a hard disk, a flash memory, etc.

[0119] The processor may be a central processing unit (CPU) or other forms of processing units with data processing capabilities and / or instruction execution capabilities, and may control other components in the computer device to perform desired functions. In one embodiment of the present disclosure, the processor is used to run the computer-readable instructions stored in the memory, so that the computer device performs all or part of the steps of the natural language to SQL query statement conversion method of each embodiment of the present disclosure.

[0120] Those skilled in the art should be able to understand that in order to solve the technical problem of how to obtain a good user experience, the present embodiment may also include well-known structures such as a communication bus and an interface, and these well-known structures should also be included in the protection scope of the present disclosure.

[0121] like Fig.10 A schematic diagram of the structure of a computer device provided in an embodiment of the present disclosure is shown, which is a schematic diagram of the structure of a computer device suitable for implementing the embodiment of the present disclosure. Fig.10 The computer device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0122] like Fig.10 As shown, the computer device may include a processor (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the computer device are also stored. The processor, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.

[0123] Typically, the following devices can be connected to the I / O interface: input devices such as sensors or visual information acquisition devices; output devices such as display screens; storage devices such as tapes, hard disks, etc.; and communication devices. The communication device can allow the computer device to communicate with other devices (such as edge computing devices) wirelessly or by wire to exchange data. Fig.10 A computer device having various devices is shown, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.

[0124] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processor, all or part of the steps of the natural language to SQL query statement conversion method of the embodiment of the present disclosure are executed.

[0125] For detailed description of this embodiment, reference may be made to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.

[0126] According to the computer-readable storage medium of the embodiment of the present disclosure, non-transitory computer-readable instructions are stored thereon. When the non-transitory computer-readable instructions are executed by a processor, all or part of the steps of the natural language to SQL query statement conversion method of each embodiment of the present disclosure are executed.

[0127] The above-mentioned computer-readable storage media include, but are not limited to: optical storage media (e.g., CD-ROM and DVD), magneto-optical storage media (e.g., MO), magnetic storage media (e.g., magnetic tape or mobile hard disk), media with built-in rewritable non-volatile memory (e.g., memory card) and media with built-in ROM (e.g., ROM box).

[0128] For detailed description of this embodiment, reference may be made to the corresponding descriptions in the aforementioned embodiments, which will not be repeated here.

[0129] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.

[0130] In the present disclosure, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. The block diagrams of the devices, devices, equipment, and systems involved in the present disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagram. As will be appreciated by those skilled in the art, these devices, devices, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including", "comprising", "having", etc. are open words, referring to "including but not limited to", and can be used interchangeably with them. The words "or" and "and" used here refer to the words "and / or" and can be used interchangeably with them, unless the context clearly indicates otherwise. The words "such as" used here refer to the phrase "such as but not limited to", and can be used interchangeably with them.

[0131] Additionally, as used herein, "or" used in a list of items beginning with "at least one" indicates a separate list, so that, for example, a list of "at least one of A, B, or C" means A or B or C, or AB or AC or BC, or ABC (i.e., A and B and C). Furthermore, the word "exemplary" does not mean that the example described is preferred or better than other examples.

[0132] It should also be noted that in the system and method of the present disclosure, each component or each step can be decomposed and / or recombined. Such decomposition and / or recombination should be regarded as equivalent solutions of the present disclosure.

[0133] Various changes, substitutions, and modifications of the techniques described herein may be made without departing from the teachings defined by the appended claims. Furthermore, the scope of the claims of the present disclosure is not limited to the specific aspects of the processes, machines, manufactures, compositions of events, means, methods, and actions described above. Currently existing or later to be developed processes, machines, manufactures, compositions of events, means, methods, or actions that perform substantially the same functions or achieve substantially the same results as the corresponding aspects described herein may be utilized. Thus, the appended claims include such processes, machines, manufactures, compositions of events, means, methods, or actions within their scope.

[0134] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of the present disclosure. Therefore, the present disclosure is not intended to be limited to the aspects shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

[0135] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit the embodiments of the present disclosure to the forms disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.

Claims

1. A method for converting natural language to SQL query statements, characterized in that: The following steps are involved: Obtaining a query instruction expressed in a natural language input by a user; Parse query instructions based on a universal large language model and identify metadata information, including target table name, query field, and query condition; Using knowledge graphs and neural network models, SQL query semantics are formed based on metadata information; Based on the SQL industry big model, use the thinking chain mode to convert SQL query semantics into SQL query statements; Execute SQL query statements and return the query results.

2. The method according to claim 1, characterized in that Parse query instructions based on a general language model and identify metadata information including: The backend service receives query instructions from the frontend through the interface; Combine the user's historical question information and the current input text to summarize and understand the context information through multiple rounds of dialogue; Based on the context information, a prompt project is created and input into a general large language model to identify user intent and entity information.

3. The method according to claim 2, characterized in that Based on the context information, a prompt project is created and input into a general language model to identify user intent and entity information, including: Determine the model roles, tasks, and execution methods, and use contextual information and few-shot examples to guide the general large language model to generate results.

4. The method according to claim 2, characterized in that: Parsing query instructions based on a general language model, identifying metadata information also includes: Use the cosine similarity algorithm to perform similarity analysis, and combine multiple rounds of clarification to transform the identified entity information into standard entities that can be directly used; Combined with standard entities, determine whether it conforms to the logic of SQL query.

5. The method according to claim 1, characterized in that Using knowledge graph and neural network models, SQL query semantics are formed based on metadata information, including: Receive the parsed entity information; Use the knowledge graph to construct the target table relationship sequence; Generate SQL query semantics by combining SQL semantic template, target table relation sequence, query fields and query conditions.

6. The method according to claim 5, characterized in that Using the knowledge graph to construct the target table relationship sequence includes: Construct table relationship diagrams for all tables in the database; Get the table name sequence related to the target table from the table relationship diagram; Vectorize the table name sequence through the neural network model; Use the cosine similarity algorithm to match the table name sequence to obtain the optimal matching table sequence; Obtain the target table relationship sequence based on the optimal matching table sequence.

7. The method according to claim 1, characterized in that Based on the SQL industry big model, the thinking chain mode is used to convert SQL query semantics into SQL query statements including: Prepare training corpus and create prompt project by combining thought chain mode; Fine-tune the SQL-Coder industry model through prompt engineering; Input SQL query semantics into the fine-tuned SQL-Coder industry model to generate SQL query statements; Perform logical verification on SQL query statements.

8. A natural language to SQL query statement conversion system, characterized in that: include: An instruction receiving module is used to obtain a query instruction expressed in a natural language input by a user; The instruction parsing module is used to parse query instructions based on the general large language model and identify metadata information, which includes: target table name, query field, and query condition; The semantic generation module is used to use the knowledge graph and neural network model to form SQL query semantics based on metadata information; The statement conversion module is used to convert SQL query semantics into SQL query statements using the thinking chain mode based on the SQL industry big model; The execution module is used to execute SQL query statements and return the query results.

9. A computer device, characterized in that: The computer device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the conversion method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the conversion method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Power field SQL intelligent agent construction method based on KMDI chain

    CN119166662A

  • DSL-based intelligent dialogue implementation method, device and equipment for generating SQL (Structured Query Language)

    CN119293068A

  • Large model-based data query and interaction method and program product

    CN119322821A

  • Method and device for generating SQL (Structured Query Language) based on semantic alignment and hierarchical Agent

    CN119377255A

  • Query statement model fine tuning method, device and equipment based on large model

    CN119599131A