Structured query language generation method and device, electronic equipment and storage medium

By using pre-trained large language models and coding information recall technology in structured query language generation, SQL statements containing coding information are directly generated, solving the problems of low manual mapping efficiency and high error rate, and achieving efficient and accurate SQL generate.

CN119226318AActive Publication Date: 2024-12-31LONGSHINE TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411732736.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2024-12-31
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

In the prior art, the field mapping is inefficient and the error rate is high, resulting in inefficient generation of structured query languages.

Method used

By determining the target table and header information based on query problems, searching the encoding information in the target table, generating a structured query language using a pre-trained large language model, and directly generating SQL statements containing the encoding information to simplify post-processing operations.

Benefits of technology

It improves the efficiency and accuracy of structured query language generation, reduces the error rate, and generates SQL statements concisely and efficiently without manual encoding mapping.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226318A_ABST
    Figure CN119226318A_ABST
Patent Text Reader

Abstract

The invention provides a structured query language generation method and device, electronic equipment and a storage medium, and belongs to the technical field of data processing.The method comprises the steps that based on a query problem, a target table and corresponding header information are determined, the query problem is a natural language query problem, and the target table is a table related to the query problem; on the basis of the query question, encoding information of a target field in the target table is retrieved, related encoding information is obtained, the related encoding information is encoding information, related to the query question, in the encoding information of the target field, the target field is an encoding field related to the query question, and the encoding field is a field for storing data in an encoding mode; a structured query language is generated using a large language model based on header information and related coding information. According to the method, after the relevant coding information is retrieved, the coding information is input into the large model together, the SQL statement containing the coding information is directly generated, the SQL generation efficiency is improved, and the error rate is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a structured query language generation method, device, electronic device and storage medium. Background Art

[0002] Smart Questioning is designed to help users find data quickly and easily. The core module of a smart questioning system is the Text-to-SQL module, which uses an algorithm model to convert natural language into corresponding SQL (Structured Query Language) statements. In this way, users can directly query the underlying database without having professional SQL knowledge or manually writing complex SQL statements, which greatly reduces the threshold for data query.

[0003] At present, after the conventional Text-to-SQL method generates SQL statements using the algorithm model, it is necessary to manually map the coded fields in the generated SQL statements, convert the Chinese semantics into specific digital codes, and finally generate SQL query statements that can be directly executed by the database. This manual mapping process is not only inefficient, but also involves a lot of mapping rules, which is labor-intensive and error-prone.

[0004] Therefore, there is an urgent need for a structured query language generation method to solve the problems of low efficiency and high error rate caused by manually completing field mapping in the prior art. Summary of the invention

[0005] The present invention provides a structured query language generation method, device, electronic device and storage medium, which are used to solve the defects of low efficiency and high error rate in manually completing field mapping in the prior art.

[0006] The present invention provides a structured query language generation method, comprising the following steps: Determine a target table and table header information corresponding to the target table based on a query question, wherein the query question is a natural language query question, and the target table is a table related to the query question; Based on the query question, the coding information of the target field in the target table is retrieved to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; Based on the header information and the relevant encoding information, a structured query language is generated using a pre-trained large language model.

[0007] According to a structured query language generation method provided by the present invention, the header information includes coding identification information, and the coding identification information is used to identify whether each field in the target table is a coding field. Before determining the target table and the header information corresponding to the target table based on the query question, the method further includes: For any coding field in the target table, the coding information of the coding field is stored in a vector library corresponding to the coding field, and the coding information of the coding field is a text-coding comparison relationship of the coding field.

[0008] According to a structured query language generation method provided by the present invention, based on the query question, retrieving the coding information of the target field in the target table to obtain the relevant coding information includes: Each field in the target table is traversed, and if the current field is a coding field, a vector library corresponding to the current field is retrieved to obtain coding information related to the query question as the related coding information.

[0009] According to a structured query language generation method provided by the present invention, the retrieving a vector library corresponding to the current field to obtain encoding information related to the query question as the related encoding information includes: Based on a preset scoring standard, scoring the coded information in the vector library corresponding to the current field to obtain a relevance score of each coded information, where the relevance score of each coded information reflects the relevance of each coded information to the query question; The N pieces of coding information with the largest correlation scores are used as the relevant coding information, where N is a positive integer.

[0010] According to a structured query language generation method provided by the present invention, the table header information includes the table name, table comments and table field information of the target table.

[0011] According to a structured query language generation method provided by the present invention, the structured query language is generated based on the header information and the related encoding information using a pre-trained large language model, comprising: Based on the relevant coding information, updating the header information; Based on the query question and the updated header information, a query statement is generated using a preset prompt word prompt; The query statement is input into a pre-trained large language model to obtain a structured query language output by the large language model.

[0012] The present invention also provides a structured query language generation device, comprising the following modules: A table recall module is used to: determine a target table and table header information corresponding to the target table based on a query question, wherein the query question is a natural language query question, and the target table is a table related to the query question; A coding recall module is used to: retrieve the coding information of the target field in the target table based on the query question to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; The statement generation module is used to generate a structured query language based on the header information and the related encoding information using a pre-trained large language model.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the structured query language generation method described above is implemented.

[0014] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the structured query language generation method described in any one of the above is implemented.

[0015] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any one of the structured query language generation methods described above.

[0016] The structured query language generation method, device, electronic device and storage medium provided by the present invention determine the target table and the header information corresponding to the target table based on the query question, the query question is a natural language query question, and the target table is a table related to the query question; based on the query question, the encoding information of the target field in the target table is retrieved to obtain relevant encoding information, the relevant encoding information is the encoding information related to the query question in the encoding information of the target field, the target field is the encoding field related to the query question, and the encoding field is a field storing data in an encoded form; based on the header information and the relevant encoding information, a pre-trained large language model is used to generate a structured query language. After retrieving the target table related to the query question, the present invention further retrieves the encoding information related to the query question, and inputs the encoding information and the header information of the target table into the pre-trained large language model, so that the large language model can directly generate a standard SQL statement containing the encoding information based on the context information, which is concise and efficient, and no manual post-processing operation of encoding mapping is required for the generated SQL, thereby reducing the error rate of SQL statement generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 It is a flow chart of the structured query language generation method provided by the present invention; Figure 2 is the encoding information of the exemplary target field provided by the present invention; Figure 3 It is a schematic diagram of the structure of the structured query language generating device provided by the present invention.

[0019] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0020] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0021] It should be noted that in the description of the embodiments of the present invention, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "include one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements. The orientation or position relationship indicated by the terms "upper", "lower" and the like is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. Unless otherwise clearly specified and limited, the terms "installed", "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected, or indirectly connected through an intermediate medium, or it can be a connection between two elements. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0022] The terms "first", "second", etc. in the present invention are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present invention can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of the same type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" means at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0023] Combine the following Figure 1-Figure 4 The present invention describes a structured query language generation method, device, electronic device and storage medium provided in an embodiment of the present invention.

[0024] Figure 1 is a flow chart of the structured query language generation method provided by the present invention, such as Figure 1 As shown, the method includes the following: S110, determining a target table and table header information corresponding to the target table based on the query question; S120, based on the query question, retrieving the coding information of the target field in the target table to obtain relevant coding information; S130, generating a structured query language using a pre-trained large language model based on the header information and related encoding information.

[0025] It should be noted that the execution subject of the structured query language generation method provided in the embodiment of the present invention can be a server, a computer device, such as a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc.

[0026] For ease of understanding, the following embodiments take the "User Arrears Details List" as an example to illustrate the structured query language generation method provided by the present invention.

[0027] The information of the user arrears details table nl2sql_dw_zw_awe_det_day is as follows: CREATE TABLE `nl2sql_dw_zw_awe_det_day` ( `company_code` text COMMENT 'Power supply company', `cust_no` text COMMENT 'account number', `CUST_NAME` varchar(500) DEFAULT NULL COMMENT 'Account name', `ec_addr` text COMMENT 'address', `cust_cls` text COMMENT 'User type', `User Type` varchar(30) DEFAULT NULL COMMENT 'User Type', `rcvbl_ym` text COMMENT 'Year and month of receipt', `ec_qty` text COMMENT 'Battery', `t_bal` text COMMENT 'Account balance', `rcvbl_amt` text COMMENT 'Electricity charges receivable', `rcvd_amt` text COMMENT 'Actual electricity charges', `arer_bal` text COMMENT 'arrears', `rcvbl_lqd_damg` text COMMENT 'Liquidated damages receivable', `rcvd_lqd_damg` text COMMENT 'Actual payment of liquidated damages', `arer_lqd_damg` text COMMENT 'arrears penalty', `mobile` text COMMENT 'Contact number', `cur_stop_rcvr_stat` text COMMENT 'Current status', `Current user status` varchar(30) DEFAULT NULL COMMENT 'Current user status', `to_date` date DEFAULT NULL COMMENT 'Statistical date', `city_name` text COMMENT 'Company name in the city', `county_name` text COMMENT 'County company name', `station_name` text COMMENT 'Name of the power supply station', `mgt_org_name` text COMMENT 'Management unit name' ) ENGINE=InnoDB DEFAULT CHARSET=utf8.

[0028] As mentioned above, the first half of each sentence `XXXX` is the field name, and the second half text COMMENT 'XXXXX' is the explanation corresponding to the field. For example, the field company_code represents the code of the power supply company.

[0029] Figure 2 is the encoding information of the exemplary target field provided by the present invention, such as Figure 2 As shown, the exemplary coding information of the field company_code includes the name of each power supply company and its corresponding code.

[0030] In the specific implementation process, in the database, the data stored in the field company_code is dim_value, which is the code of the corresponding power supply company.

[0031] In the prior art, when a user asks: "Query the actual electricity charges of Power Supply Company B in May 2023", the user asks the Text-to-SQL algorithm model, and the algorithm model may generate a reply SQL: "select rcvd_amt as actual electricity charges from nl2sql_dw_zw_awe_det_day where company_code = 'B Power Supply Company' and rcvbl_ym = '202305'"; That is, query the actual electricity fee "rcvd_amt" of "B Power Supply Company" in the receivable year and month "rcvbl_ym=202305" from the target table "nl2sql_dw_zw_awe_det_day"; like Figure 2 As shown in the figure, the unit code corresponding to "B Power Supply Company" is 11112. Therefore, when actually executing the query task, it is necessary to convert some Chinese semantics in the SQL generated by the algorithm model into specific digital codes. The condition in the SQL should be "company_code= '11112'" instead of "company_code = 'B Power Supply Company'"; Therefore, the final standard SQL is: "select rcvd_amt as actual electricity charges from nl2sql_dw_zw_awe_det_day where company_code = '11112' and rcvbl_ym = '202305'".

[0032] In S110, the query question is a natural language query question, and the target table is a table related to the query question. Specifically, the query question is a question raised by the user that needs to be queried. For example, "Query the actual electricity charges of Power Supply Company B in May 2023" raised by the user is a query question. According to the query question, the most relevant table, that is, the target table, is retrieved and returned in the database. In response to the above query question, the detailed table of users in arrears (nl2sql_dw_zw_awe_det_day) and related header information are retrieved and returned, wherein the header information includes relevant information of the table, such as the table name, the field names contained in the table, the data types of each field, comments on the table, and other information.

[0033] It should be noted that the criteria for judging the relevance of a table to a query question and the method used to retrieve the most relevant table are not limited here.

[0034] In S120, the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field that stores data in a coded form.

[0035] Still taking "query the actual electricity charges of power supply company B in May 2023" as an example, the target field is the company_code field in the user details table (nl2sql_dw_zw_awe_det_day), such as Figure 2 As shown, the coding information of the company_code field includes multiple pieces of coding information, and the coding information "B Power Supply Company: 11112" related to the query question is retrieved from the multiple pieces of coding information, which is the relevant coding information.

[0036] In some embodiments, the coding fields related to the query question are first determined, and then the coding information most related to the query question in each coding field related to the query question is further retrieved as the related coding information.

[0037] In other embodiments, each field of the target table is traversed, and a search is performed for each coding field to obtain coding information related to the query question in each coding field, and these coding information are combined as relevant coding information.

[0038] The structured query language generation method provided by the embodiment of the present invention determines the target table and the header information corresponding to the target table based on the query question, the query question is a natural language query question, and the target table is a table related to the query question; based on the query question, the encoding information of the target field in the target table is retrieved to obtain relevant encoding information, the relevant encoding information is the encoding information related to the query question in the encoding information of the target field, the target field is the encoding field related to the query question, and the encoding field is a field that stores data in an encoded form; based on the header information and the relevant encoding information, a pre-trained large language model is used to generate a structured query language. After retrieving the target table related to the query question, the present invention further retrieves the encoding information related to the query question, and inputs the encoding information and the header information of the target table into the pre-trained large language model, so that the large language model can directly generate a standard SQL statement containing the encoding information based on the context information, which is concise and efficient, and no manual post-processing operation of encoding mapping is required for the generated SQL, thereby reducing the error rate of SQL statement generation.

[0039] In an optional embodiment, the header information includes coding identification information, and the coding identification information is used to identify whether each field in the target table is a coding field. Before determining the target table and the header information corresponding to the target table based on the query question, it also includes: For any coding field in the target table, the coding information of the coding field is stored in a vector library corresponding to the coding field, and the coding information of the coding field is a text-coding comparison relationship of the coding field.

[0040] Specifically, the coding identification information has two values, which can be a number, a string, or a combination of a number and a string. One value indicates that the field is a coding field, and the other value indicates that the field is not a coding field. For example, the coding identification information is is_code, which has two values ​​1 and 0. If is_code=1 for a field, it means that the field is a coding field, and if is_code=0 for a field, it means that the field is a non-coding field.

[0041] In the embodiment of the present invention, for each coding field, its Chinese name and digital code are stored in the vector library corresponding to the coding field. The name of the vector library is named after the name of the coding field, and each data in the vector library represents a piece of coding information. For example, the name of the vector library corresponding to the field company_code is also company_code, and the vector library contains multiple pieces of coding information, such as: A Province Power Company: 11111, B Power Supply Company: 11112, C Power Supply Company: 11113, D Power Supply Company: 11114, E Power Supply Company: 11115, F Power Supply Company: 11116, G Power Supply Company: 11117, H Power Supply Company: 11118.

[0042] It should be noted that in the embodiment of the present invention, for example, in each coded information, the text and the coded number are connected with a colon “:”. In the specific implementation process, the storage format of the coded information can be set according to actual usage requirements, for example, connected with a connector “-” or a separator “|”.

[0043] The structured query language generation method provided in the embodiment of the present invention distinguishes coded fields from non-coded fields through coded identification information, thereby facilitating rapid identification of coded fields; the coded information of each coded field is stored in its corresponding vector library, thereby achieving unified management of the coded information and providing a reliable data basis for subsequent retrieval of the coded information.

[0044] In an optional embodiment, the retrieving the encoding information of the target field in the target table based on the query question to obtain the relevant encoding information includes: Each field in the target table is traversed, and if the current field is a coding field, a vector library corresponding to the current field is retrieved to obtain coding information related to the query question as the related coding information.

[0045] Specifically, according to the query question, each field in the target table is traversed. In this example, each field in the user detail table nl2sql_dw_zw_awe_det_day is traversed. If the coding identification information is_code = 0, it means that the current field is a non-coding field, and the next field is processed; if the coding identification information is_code = 1, it means that the current field is a coding field. At this time, the vector library corresponding to the field name is retrieved to obtain the coding information most relevant to the query question, that is, the relevant coding information. It can be understood that some coding fields are not relevant to the query question. For these coding fields, the coding information related to the query question cannot be retrieved when searching the vector library.

[0046] Preferably, only the target field is searched for its corresponding vector library, and the encoding information most relevant to the query question is returned.

[0047] The structured query language generation method provided by the embodiment of the present invention retrieves, for each coding field, only the coding information related to the query question from its corresponding vector library, thereby reducing the amount of data calculation and improving data query efficiency.

[0048] In an optional embodiment, the retrieving a vector library corresponding to the current field to obtain encoding information related to the query question as the related encoding information includes: Based on a preset scoring standard, scoring the coded information in the vector library corresponding to the current field to obtain a relevance score of each coded information, where the relevance score of each coded information reflects the relevance of each coded information to the query question; The N pieces of coding information with the largest correlation scores are used as the relevant coding information, where N is a positive integer.

[0049] In the embodiment of the present invention, the N most relevant coded information to the query question is queried from the vector library and returned, where N is a positive integer and the specific value can be set according to actual usage requirements. For example, for the query question "Please query the details of users in arrears in city B in the past three months", N=3, then the top 3 coded information that may be recalled is: B Power Supply Company: 11112, A Province Power Company: 11111, C Power Supply Company: 11113.

[0050] The structured query language generation method provided by the embodiment of the present invention recalls the most relevant multiple encoding information from the vector library, provides sufficient data basis for the subsequent generation of SQL statements, avoids SQL statement generation errors caused by the fact that the most relevant piece of encoding information calculated is not the encoding information that is ultimately required to be used, and improves the fault tolerance rate of SQL statement generation.

[0051] In an optional embodiment, the retrieving a vector library corresponding to the current field to obtain encoding information related to the query question as the related encoding information includes: Based on a preset scoring standard, scoring the coded information in the vector library corresponding to the current field to obtain a relevance score of each coded information, where the relevance score of each coded information reflects the relevance of each coded information to the query question; The coding information whose correlation score is greater than a preset threshold is used as the relevant coding information.

[0052] In an optional embodiment, the table header information includes the table name, table comments and table field information of the target table.

[0053] Here, the table name is the name of the table. Taking the user arrears details table as an example, the table name is "nl2sql_dw_zw_awe_det_day"; the table comment is the comment information of the table, such as "Electricity bill arrears user details table, used to record the relevant detailed information of the arrears users, counted on a daily basis"; the table field information is the relevant information of the fields in the table, including the above-mentioned "`company_code` text COMMENT "power supply unit, `cust_no` text COMMENT 'account number'" and other information.

[0054] In an optional embodiment, the generating structured query language based on the header information and the related encoding information using a pre-trained large language model includes: Based on the relevant coding information, updating the header information; Based on the query question and the updated header information, a query statement is generated using a preset prompt word prompt; The query statement is input into a pre-trained large language model to obtain a structured query language output by the large language model.

[0055] In the embodiment of the present invention, the header information is updated according to the relevant coding information, that is, the retrieved relevant coding information is assembled into the corresponding field of the header information to form new header information. For example: The relevant code information retrieved and recalled is: Power Supply Company B: 11112, Power Supply Company A: 11111, Power Supply Company C: 11113. The relevant code information is assembled into the company_code field to form the following header information: "Table name: nl2sql_dw_zw_awe_det_day Table Notes: Detailed table of users in arrears of electricity bills, used to record relevant detailed information of users in arrears, with daily statistics The table fields are as follows: `company_code` text COMMENT "Power supply company, enumeration value such as: - Power Supply Company B: 11112 - Electricity Company of Province A: 11111 - C Power Supply Company: 11113", `cust_no` text COMMENT 'account number', `CUST_NAME` varchar(500) DEFAULT NULL COMMENT 'Account name', `ec_addr` text COMMENT 'address', `cust_cls` text COMMENT 'User type', `User Type` varchar(30) DEFAULT NULL COMMENT 'User Type', `rcvbl_ym` text COMMENT 'Year and month of receipt', `ec_qty` text COMMENT 'Battery', `t_bal` text COMMENT 'Account balance', `rcvbl_amt` text COMMENT 'Electricity charges receivable', `rcvd_amt` text COMMENT 'Actual electricity charges', `arer_bal` text COMMENT 'arrears', `rcvbl_lqd_damg` text COMMENT 'Liquidated damages receivable', `rcvd_lqd_damg` text COMMENT 'Actual payment of liquidated damages', `arer_lqd_damg` text COMMENT 'arrears penalty', `mobile` text COMMENT 'Contact number', `cur_stop_rcvr_stat` text COMMENT 'Current status', `Current user status` varchar(30) DEFAULT NULL COMMENT 'Current user status', `to_date` date DEFAULT NULL COMMENT 'Statistical date', `city_name` text COMMENT 'Company name in the city', `county_name` text COMMENT 'County company name', `station_name` text COMMENT 'Name of the power supply station', `mgt_org_name` text COMMENT 'Name of the management organization'".

[0056] In the embodiment of the present invention, the query question and the header information are recombined according to the preset prompt template to generate a complete query statement, and the complete context is input into the pre-trained large language model. The large language model generates a corresponding SQL statement based on the query question and the header information to query the database. For example, the following query statement is generated: As a text-to-sql model, it generates accurate sql statements based on the provided table information and user questions, supporting complex nested queries and advanced mysql functions.

[0057] Table name: nl2sql_dw_zw_awe_det_day Table Notes: Detailed table of users in arrears of electricity bills, used to record relevant detailed information of users in arrears, with daily statistics The table fields are as follows: `company_code` text COMMENT "Power supply company, enumeration value such as: - Power Supply Company B: 11112 - Electricity Company of Province A: 11111 - C Power Supply Company: 11113", `cust_no` text COMMENT 'account number', `CUST_NAME` varchar(500) DEFAULT NULL COMMENT 'Account name', `ec_addr` text COMMENT 'address', `cust_cls` text COMMENT 'User type', `User Type` varchar(30) DEFAULT NULL COMMENT 'User Type', `rcvbl_ym` text COMMENT 'Year and month of receipt', `ec_qty` text COMMENT 'Battery', `t_bal` text COMMENT 'Account balance', `rcvbl_amt` text COMMENT 'Electricity charges receivable', `rcvd_amt` text COMMENT 'Actual electricity charges', `arer_bal` text COMMENT 'arrears', `rcvbl_lqd_damg` text COMMENT 'Liquidated damages receivable', `rcvd_lqd_damg` text COMMENT 'Actual payment of liquidated damages', `arer_lqd_damg` text COMMENT 'arrears penalty', `mobile` text COMMENT 'Contact number', `cur_stop_rcvr_stat` text COMMENT 'Current status', `Current user status` varchar(30) DEFAULT NULL COMMENT 'Current user status', `to_date` date DEFAULT NULL COMMENT 'Statistical date', `city_name` text COMMENT 'Company name in the city', `county_name` text COMMENT 'County company name', `station_name` text COMMENT 'Name of the power supply station', `mgt_org_name` text COMMENT 'Name of management unit' "arer_bal" text COMMENT "Amount of outstanding fees (yuan)" User question: Check the actual electricity charges collected by Power Supply Company B in May 2023."

[0058] The structured query language generation method provided by the embodiment of the present invention updates the relevant encoding information retrieved and recalled into the header information, and assembles the query question and the updated header information into a preset input prompt, thereby accurately controlling the large language model to generate the desired output.

[0059] In summary, in the prior art, in the process of converting Chinese semantics into specific digital codes, a corresponding mapping relationship is required. If it is constructed manually by matching key characters, due to the large number of codes, the workload may be very large, and a complete match of the string is required. Once the field condition value involved in the user's question has a slight change, the key string code cannot be matched. For example, for the comparison relationship between the code and Chinese constructed by the dictionary, when the user asks a question, the query question may have various changes. For example, for "B Power Supply Company", the user may ask "B Power Company", "B City Power Supply Company", etc. Even if there is a slight difference with the key value of the dictionary, it cannot be successfully converted, lacking flexibility and usability; in addition, some fields may have a lot of codes (such as thousands of codes). If all the codes are written into the context and handed over to the large model for generation, the accuracy of the generated SQL will be reduced and the generation efficiency will be too low. The structured query language generation method provided by the present invention recalls the relevant coding information and assembles it into the context in the pre-processing link of the large language model to generate SQL, so that the large language model can directly generate SQL statements containing coding information in one step, which is concise and efficient, and there is no need to consider complex post-processing mapping logic.

[0060] The structured query language generation device provided by an embodiment of the present invention is described below. The structured query language generation device described below and the structured query language generation method described above can be referred to each other.

[0061] Figure 3 is a schematic diagram of the structure of the structured query language generation device provided by the present invention, such as Figure 3 As shown, the structured query language generating device may include but is not limited to; The table recall module 310 is used to: determine a target table and table header information corresponding to the target table based on a query question, wherein the query question is a natural language query question, and the target table is a table related to the query question; The coding recall module 320 is used to: retrieve the coding information of the target field in the target table based on the query question to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; The statement generation module 330 is used to generate a structured query language based on the header information and the related encoding information using a pre-trained large language model.

[0062] It should be noted that the structured query language generating device provided in the embodiment of the present invention can execute the structured query language generating method described in any of the above embodiments when it is specifically run, which will not be described in detail in this embodiment.

[0063] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the structured query language generation method, the method comprising: based on a query question, determining a target table and table header information corresponding to the target table, the query question is a natural language query question, and the target table is a table related to the query question; Based on the query question, the coding information of the target field in the target table is retrieved to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; Based on the header information and the relevant encoding information, a structured query language is generated using a pre-trained large language model.

[0064] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0065] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the structured query language generation method provided by the above methods, the method comprising: based on a query question, determining a target table and table header information corresponding to the target table, the query question is a natural language query question, and the target table is a table related to the query question; Based on the query question, the coding information of the target field in the target table is retrieved to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; Based on the header information and the relevant encoding information, a structured query language is generated using a pre-trained large language model.

[0066] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the structured query language generation method provided by the above methods, the method comprising: determining a target table and table header information corresponding to the target table based on a query question, the query question being a natural language query question, and the target table being a table related to the query question; Based on the query question, the coding information of the target field in the target table is retrieved to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; Based on the header information and the relevant encoding information, a structured query language is generated using a pre-trained large language model.

[0067] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0068] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0069] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A structured query language generation method, characterized in that: include: Determine a target table and table header information corresponding to the target table based on a query question, wherein the query question is a natural language query question, and the target table is a table related to the query question; Based on the query question, the coding information of the target field in the target table is retrieved to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; Based on the header information and the relevant encoding information, generate a structured query language using a pre-trained large language model; The header information includes coding identification information, and the coding identification information is used to identify whether each field in the target table is a coding field. Before determining the target table and the header information corresponding to the target table based on the query question, it also includes: For any coding field in the target table, the coding information of the coding field is stored in the vector library corresponding to the coding field, and the coding information of the coding field is the text-coding comparison relationship of the coding field; The step of retrieving the encoding information of the target field in the target table based on the query question to obtain relevant encoding information includes: Each field in the target table is traversed, and if the current field is a coding field, a vector library corresponding to the current field is retrieved to obtain coding information related to the query question as the related coding information.

2. The structured query language generation method according to claim 1, characterized in that: The retrieving the vector library corresponding to the current field to obtain the encoding information related to the query question as the related encoding information includes: Based on a preset scoring standard, scoring the coded information in the vector library corresponding to the current field to obtain a relevance score of each coded information, where the relevance score of each coded information reflects the relevance of each coded information to the query question; The N pieces of coding information with the largest correlation scores are used as the relevant coding information, where N is a positive integer.

3. The structured query language generation method according to claim 1, characterized in that: The table header information includes the table name, table comments and table field information of the target table.

4. The structured query language generation method according to claim 3, characterized in that: The generating structured query language based on the header information and the related encoding information using a pre-trained large language model includes: Based on the relevant coding information, updating the header information; Based on the query question and the updated header information, a query statement is generated using a preset prompt word; The query statement is input into a pre-trained large language model to obtain a structured query language output by the large language model.

5. A structured query language generation device, characterized in that: The method for generating a structured query language according to claim 1 comprises: A table recall module is used to: determine a target table and table header information corresponding to the target table based on a query question, wherein the query question is a natural language query question, and the target table is a table related to the query question; A coding recall module is used to: retrieve the coding information of the target field in the target table based on the query question to obtain relevant coding information, wherein the relevant coding information is coding information related to the query question in the coding information of the target field, the target field is a coding field related to the query question, and the coding field is a field storing data in a coded form; The statement generation module is used to generate a structured query language based on the header information and the related encoding information using a pre-trained large language model.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the structured query language generation method according to any one of claims 1 to 4 is implemented.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the structured query language generation method according to any one of claims 1 to 4 is implemented.

8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the structured query language generation method according to any one of claims 1 to 4 is implemented.

Citation Information

Patent Citations

  • Intelligent session method and server based on table data retrieval

    CN115495563A

  • SQL statement generation method and device based on large model, equipment and medium

    CN117874052A

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

    CN118796872A

  • Translation of natural language questions and requests to a structured query format

    US20180095962A1