CN117874052A - SQL sentence generation method, device, equipment and medium based on large model - Google Patents

SQL sentence generation method, device, equipment and medium based on large model Download PDF

Info

Publication number
CN117874052A
CN117874052A CN202311623084.XA CN202311623084A CN117874052A CN 117874052 A CN117874052 A CN 117874052A CN 202311623084 A CN202311623084 A CN 202311623084A CN 117874052 A CN117874052 A CN 117874052A
Authority
CN
China
Prior art keywords
target
large model
sentence
prompting
template
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311623084.XA
Other languages
Chinese (zh)
Inventor
王月岭
刘微
陈维强
孟卫明
田羽慧
冯卫森
刘鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hisense Group Holding Co Ltd
Original Assignee
Hisense Group Holding Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hisense Group Holding Co Ltd filed Critical Hisense Group Holding Co Ltd
Priority to CN202311623084.XA priority Critical patent/CN117874052A/en
Publication of CN117874052A publication Critical patent/CN117874052A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The present invention relates to the field of natural language processing technologies, and in particular, to a method, an apparatus, a device, and a medium for generating an SQL statement based on a large model. In the embodiment of the application, the electronic device determines the target table adopted when the SQL statement corresponding to the target statement is generated based on the usage of the large model and the table, then determines the target intention of the target statement according to the intention that the stored target table can be used for inquiring, and determines the target field adopted when the SQL statement corresponding to the target statement is generated according to the field corresponding to the pre-stored table, so that the large model accurately finds the content to be inquired according to the target field and the target intention to generate the SQL statement corresponding to the target statement.

Description

SQL sentence generation method, device, equipment and medium based on large model
Technical Field
The present invention relates to the field of natural language processing technologies, and in particular, to a method, an apparatus, a device, and a medium for generating an SQL statement based on a large model.
Background
As technology advances, database management systems can manage databases, define and manipulate data, and maintain data integrity and security through structured query language (Structured Query Language, SQL). And, the natural language sentence can be converted into SQL sentence by text-to-database (Text to Structured Query Language, text2 SQL) method, and the query is performed in the database.
The existing text2sql method mainly adopts a large-scale data training mode, and the text2sql capacity is learned through a large-scale data training model. Since the release of large models in natural language processing (Natural Language Processing, NLP), SQL sentences are generally generated directly by using large models, data information contained in each table stored in a database is used as a prompt word, the prompt word and the text are input into the large models, and the large models output the corresponding SQL sentences.
However, in the prior art, a large amount of data information needs to be input at one time, and when a large number of tables are stored in a database, the attributes contained in each table are too many and the sentence intention is various, the effect of generating SQL directly based on each table information and a large model is poor and the accuracy is low.
Disclosure of Invention
The application provides a large model-based SQL sentence generation method, device, equipment and medium, which are used for solving the problems of poor effect and low accuracy of generated SQL caused by the fact that a large amount of data information needs to be input at one time when SQL sentence generation is performed in the prior art.
In a first aspect, an embodiment of the present application provides a method for generating an SQL statement based on a large model, where the method includes:
inputting a table identifier, application and target statement to be processed of a pre-configured table into a large model, and acquiring a target table identifier of a target table adopted when the large model outputs an SQL statement corresponding to the target statement;
inputting the preset intention corresponding to the target table identifier and the target sentence into the large model, and acquiring the target intention of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model;
inputting a field corresponding to the target table and the target sentence which are configured in advance into the large model, and acquiring a target field of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model;
And inputting the target intention, the target field and the target sentence into the large model to acquire an SQL sentence output by the large model.
In a second aspect, an embodiment of the present application further provides a device for generating an SQL statement based on a large model, where the device includes:
the processing module is used for inputting the table identification and the purpose of the pre-configured table and the target statement to be processed into the large model, and obtaining the target table identification of the target table adopted when the SQL statement corresponding to the target statement is generated and output by the large model;
the processing module is further configured to input a preset intent corresponding to the target table identifier and the target sentence into the large model, and obtain a target intent of the target table adopted when the large model outputs an SQL sentence corresponding to the target sentence;
the processing module is further configured to input a field corresponding to the target table and the target sentence which are configured in advance into the large model, and obtain a target field of the target table, which is output by the large model and used when the SQL sentence corresponding to the target sentence is generated;
and the generation module is used for inputting the target intention, the target field and the target sentence into the large model and obtaining the SQL sentence output by the large model.
In a third aspect, an embodiment of the present application provides an electronic device, where the electronic device includes a processor, and the processor is configured to implement, when executing a computer program stored in a memory, the steps of the large model-based SQL statement generation method according to any one of the foregoing.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the large model-based SQL statement generation method as described in any of the above.
In the embodiment of the application, the electronic device inputs the table identifier and the purpose of a pre-configured table and a target sentence to be processed into a large model, and obtains the target table identifier of the target table adopted when the large model outputs the SQL sentence corresponding to the target sentence; inputting the preset intention corresponding to the target table identifier and the target sentence into the large model, and acquiring the target intention of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model; inputting a target field corresponding to the target intention of the target table and the target sentence which are configured in advance into the large model, and acquiring the target field of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model; and inputting the target intention, the target field and the target sentence into the large model to acquire the SQL sentence output by the large model. In the embodiment of the application, the electronic device determines the target table adopted when the SQL statement corresponding to the target statement is generated based on the large model and the purpose of the table which is pre-configured, then determines the target intention of the target statement according to the intention that the pre-stored target table can be used for inquiring, and determines the target field adopted when the SQL statement corresponding to the target statement is generated according to the field which is pre-stored and the field which corresponds to the table, so that the large model accurately finds the content to be inquired according to the target field and the target intention, and generates the SQL statement corresponding to the target statement.
Drawings
In order to more clearly illustrate the technical solutions of the present application, the drawings that are needed in the description of the embodiments will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a large model-based SQL statement generation process according to an embodiment of the present application;
FIG. 2 is a flow chart for generating SQL statements according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a question answering device according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the present application more apparent, the present application will be described in further detail below with reference to the accompanying drawings, wherein it is apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
In order to improve the accuracy of SQL statement generation, the embodiment of the application provides a large model-based SQL statement generation method, device, equipment and medium.
In the embodiment of the application, the electronic device inputs the table identifier and the purpose of a pre-configured table and a target sentence to be processed into a large model, and obtains the target table identifier of the target table adopted when the large model outputs the SQL sentence corresponding to the target sentence; inputting the preset intention corresponding to the target table identifier and the target sentence into the large model, and acquiring the target intention of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model; inputting a target field corresponding to the target intention of the target table and the target sentence which are configured in advance into the large model, and acquiring the target field of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model; and inputting the target intention, the target field and the target sentence into the large model to acquire the SQL sentence output by the large model.
It should be noted that, in the embodiment of the present application, a "large model" may be understood as a model based on a converter (transducer) architecture; the "large model" may also be understood as a machine learning model with a huge parameter scale and complexity, e.g., a neural network model with millions to billions of parameters or billions of parameters; the "large model" may also be understood as a deep learning model trained on large-scale training data by semi (weakly) supervised, fully supervised, self-supervised or unsupervised techniques. In the embodiment of the application, the large model can process a plurality of different tasks, training is generally performed based on training data of a certain target task field when the large model is trained, and the large model obtained through training can be migrated to other task fields similar to the target task field for use under the general condition. The existing large model shows generalization capability beyond understanding in terms of semantic understanding, and can achieve good generalization effect under the condition of low labeling and even zero labeling.
Fig. 1 is a schematic diagram of an SQL statement generation process based on a big model according to an embodiment of the present application, where the process includes:
s101: inputting a table identifier, application and target statement to be processed of a pre-configured table into a large model, and obtaining a target table identifier of a target table adopted when the large model outputs an SQL statement corresponding to the target statement.
The SQL sentence generation method based on the large model is applied to electronic equipment, and the electronic equipment can be a PC or a server.
In the structured data question-answering scene, as the number of tables contained in the structured database is large, the data query is difficult, text2SQL mainly solves the problem of inconvenient data acquisition, the first step of the data query is to confirm the target table adopted when the SQL statement corresponding to the target statement is generated, the target table is obtained and then can be distinguished according to the query intention of the target table, the SQL statement format corresponding to each intention is fixed, and further for the same intention, different contents are queried to different columns in the target table and gradually correspond to each other, so that the contents needing to be queried are accurately found, the prompt template is executed step by step, only the current problem is focused, and the accuracy is high.
Specifically, in the embodiment of the present application, the table identifier and the purpose of each table in the database are pre-stored in the electronic device, and after the electronic device receives the target sentence to be processed, the electronic device may input the table identifier and the purpose of each table and the target sentence into the large model, so that the large model determines the target table identifier of the target table adopted when the SQL sentence corresponding to the target sentence is generated.
S102: and inputting the preset intention corresponding to the target table identifier and the target sentence into the large model, and acquiring the target intention of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model.
In an actual application process, a table may be used to provide a query service for at least one intention, for example, the economic index lookup table corresponds to an intention with a query value, a query ring ratio, a query trend, a query duty ratio, a query rank, etc., and the enterprise information lookup table corresponds to an intention with a query of information of a single enterprise, a conditional screening of the enterprise, etc.
Through tests, the large model text2sql has larger capability gap for different intentions, good supporting effect for some intentions and poor supporting effect for some intentions. In order to improve the overall accuracy, the electronic equipment classifies and generalizes intentions, and independently writes prompt words aiming at each intention to improve the effect.
Based on this, in order to improve the query speed and efficiency, in the embodiment of the present application, the electronic device stores the intent that each table can provide the query service, and after determining the target table used when generating the SQL statement corresponding to the target statement, the electronic device may determine, through a big model, the target intent of the target table used when generating the SQL statement corresponding to the target statement.
Specifically, in the embodiment of the present application, the electronic device inputs the preset intent corresponding to the target table identifier and the target sentence into the large model, so that the large model determines and outputs the target intent of the target table adopted when the SQL sentence corresponding to the target sentence is generated, and the electronic device obtains the target intent of the target table adopted when the SQL sentence corresponding to the target sentence is generated, which is output by the large model.
S103: inputting the pre-configured field corresponding to the target table and the target sentence into the big model, and obtaining the target field of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the big model.
In the actual application process, one table may be used to provide a query service to a plurality of intents, and each sentence uses a different field in the table at the time of the query. Based on this, in order to improve the efficiency and accuracy of the query, in the embodiment of the present application, the electronic device stores the field corresponding to each table, and after determining the target table adopted when generating the SQL statement corresponding to the target statement, the electronic device may determine, according to the stored field corresponding to the target table, the target field adopted when generating the SQL statement corresponding to the target statement.
Specifically, in the embodiment of the present application, after the electronic device obtains the target intention of the target table adopted when the SQL statement corresponding to the target statement is generated and output by the large model, the electronic device obtains the field corresponding to the target table configured in advance. The electronic device inputs the field and the target sentence into a large model, so that the large model determines and outputs a target field adopted when the SQL sentence corresponding to the target sentence is generated.
S104: and inputting the target intention, the target field and the target sentence into the large model to acquire an SQL sentence output by the large model.
In the embodiment of the application, after determining the target intention and the target field corresponding to the target sentence, the electronic device determines the SQL sentence corresponding to the target sentence according to the target intention and the target field.
Specifically, in the embodiment of the present application, the electronic device inputs the target intention, the target field and the target sentence into the large model, so that the large model determines and outputs the SQL sentence corresponding to the target sentence according to the target intention and the target field, and the electronic device obtains the SQL sentence output by the large model.
In the embodiment of the application, the electronic device determines the target table adopted when the SQL statement corresponding to the target statement is generated based on the large model and the purpose of the table which is pre-configured, then determines the target intention of the target statement according to the intention that the pre-stored target table can be used for inquiring, and determines the target field adopted when the SQL statement corresponding to the target statement is generated according to the field which is pre-stored and the field which corresponds to the table, so that the large model accurately finds the content to be inquired according to the target field and the target intention, and generates the SQL statement corresponding to the target statement.
In order to improve the accuracy of the SQL statement generation, in the embodiment of the present application, before the table identifier, the purpose, and the target statement to be processed of the preconfigured table are input into the large model, the method further includes:
acquiring a form identifier and a purpose of a pre-stored form;
determining a first prompt template for prompting the large model to determine a target table according to the table identification and the application of the table and a first preset prompt word for prompting the large model to determine the target table;
The inputting of the table identification, the application and the target sentence to be processed of the pre-configured table into the large model comprises the following steps:
and adding the target sentence into the first prompt template, and inputting the added first prompt template into the large model.
In the prior art, the phenomenon that the database contains more tables and is difficult to inquire exists, meanwhile, the information of the tables is directly input into a large model, and the error rate of the generated SQL sentences is high. Therefore, in order to improve the query efficiency and the accuracy of generating SQL sentences, the electronic equipment confirms the purpose of each table, and inputs the purpose and explanation of the table into the large model in a prompting word mode, so that the large model judges which table the target sentence is applied to according to the prompting word.
In the embodiment of the application, the electronic device generates a first prompt template for prompting the large model to determine the target table according to the table identifier and the purpose corresponding to each table.
Specifically, in the embodiment of the application, the electronic device acquires the form identifier and the use of the pre-stored form. The electronic equipment determines a first prompt template for prompting the large model to determine the target table according to the table identification and the application of the table and a first prompt word which is preconfigured and used for prompting the large model to determine the target table.
For example, if the table pre-stored by the electronic device is an economic index lookup table and an enterprise information lookup table, the economic index lookup table is used for querying all economic index conditions in the range of the Qingdao city for three years, the economic index values, the same ring ratio, the trend, the duty ratio and the ranking information can be queried, the enterprise information lookup table is used for querying the enterprise information of each region in the range of the Qingdao city, the information of a single enterprise can be queried, and the enterprise is screened according to the conditions, and the first prompting template determined by the electronic device is as follows:
"you are a sort expert, need to understand according to the purpose of each table, and assign the user's question to the table with the highest correlation.
# table name 1: index_info, economic index lookup table, its use is as follows: the method is used for inquiring all economic index conditions in the Qingdao city for nearly three years, and can inquire economic index values, same-ring ratios, trends, duty ratios and ranking information;
# table name 2: the company_info, the enterprise information lookup table, its purpose is as follows: the method is used for inquiring enterprise information of each region in the Qingdao city range, and can inquire information of a single enterprise and screen the enterprise according to conditions; "
Wherein, "you are a sort expert, need to understand according to the purpose of each table, assign the user's question to the table with highest correlation," is the first prompt word used for prompting the big model to determine the target table.
In the embodiment of the application, after the electronic device determines the first prompt template for prompting the large model to determine the target table, the electronic device adds the target sentence into the first prompt template, and inputs the added first prompt template into the large model, so that the large model determines and outputs the target table adopted when the SQL sentence corresponding to the target sentence is generated according to the first prompt template added with the target sentence.
In order to improve the accuracy of the SQL statement generation, in the embodiments of the present application, before the table identifier, the purpose, and the target statement to be processed of the preconfigured table are input into the large model, the method further includes:
acquiring an intention corresponding to a pre-stored form identifier;
determining a second prompting template for prompting the large model to determine the target intention according to the intention and a second prompting word which is preconfigured and used for prompting the large model to determine the target intention;
correspondingly storing the second prompt template and the form identifier;
the inputting the intent corresponding to the preconfigured target table identifier and the target sentence into the big model comprises:
Determining a target second prompting template corresponding to the target table identifier according to the target table identifier and the corresponding relation between the pre-stored table identifier and the second prompting template;
and adding the target sentence into the target second prompt template, and inputting the added target second prompt template into the large model.
In the prior art, the phenomenon that the database contains more tables and is difficult to inquire exists, meanwhile, the information of the tables is directly input into a large model, and the error rate of the generated SQL sentences is high. Therefore, in order to improve the query efficiency and the accuracy of generating the SQL statement, the electronic equipment confirms the intention corresponding to each table, constructs a second prompt template according to each intention corresponding to each table, and correspondingly stores the second prompt template and the table identification of the table, so that the large model judges which intention of the target statement is applied to the target table according to the second prompt template corresponding to the target table.
Specifically, in the embodiment of the present application, the electronic device obtains an intention corresponding to a pre-stored table identifier; determining a second prompting template for prompting the large model to determine the target intention according to the intention and a second prompting word which is preconfigured and used for prompting the large model to determine the target intention; and correspondingly storing the second prompt template and the table identifier.
For example, if the table pre-stored by the electronic device is an economic index lookup table, and the corresponding intention of the economic index lookup table is an index value, a circle-to-circle ratio, a trend, a duty ratio and a rank, the second prompting template determined by the electronic device is as follows:
"you are a sort expert, need to assign the user's question to the highest degree of relevance intent based on the understanding of each intent, the intent list is as follows:
checking an index value: inquiring the specific values of the economic index at a certain time and a certain place;
checking the ring ratio: inquiring same-loop ratio data of economic indexes;
checking trend: inquiring the change trend of the economic index in a certain period of time;
the ratio of the detection is: inquiring the proportion of the low-level place economic index value to the high-level place economic index;
searching and ranking: ranking of economic index of inquiring place in place range "
Wherein, "you are a classification expert, need to assign the user's question to the intention with the highest degree of relatedness according to the understanding of each intention, the intention list is as follows" a second prompt word for prompting the big model to determine the target intention.
In the embodiment of the application, after determining the target table adopted when the SQL statement corresponding to the target statement is generated, the electronic device determines the target second prompt template corresponding to the target table identifier of the target table according to the corresponding relation between the second prompt template and the table identifier, which is stored in advance. The electronic equipment adds the target sentence into the target second prompt template, and inputs the added target second prompt template into the large model, so that the large model determines and outputs the target intention adopted when the SQL sentence corresponding to the target sentence is generated according to the second prompt template.
In order to improve the accuracy of the SQL statement generation, in the embodiments of the present application, before the table identifier, the purpose, and the target statement to be processed of the preconfigured table are input into the large model, the method further includes:
acquiring a field corresponding to a pre-stored form;
determining a third prompting template for prompting the big model to determine SQL sentences according to the fields and a third prompting word which is preconfigured and used for prompting the big model to determine target fields;
correspondingly storing the third prompt template and the table identification of the table;
inputting the pre-configured field corresponding to the target table and the target sentence into the big model comprises:
determining a target third prompting template corresponding to the target table identifier according to the target table identifier and the corresponding relation between the pre-stored table identifier and the third prompting template;
and adding the target sentence into the target third prompting template, and inputting the added target third prompting template into the large model.
In practice, one table may be used to provide query services to multiple statements, and possibly each statement employs a different field of the table. Therefore, in order to improve the query efficiency and the accuracy of generating the SQL statement, the electronic device confirms the field of each table, constructs a third prompt template according to the field of each table, and correspondingly stores the third prompt template and the table identifier of the table, so that the large model determines the target field adopted when the SQL statement corresponding to the target statement is generated according to the target third prompt template corresponding to the target table.
Specifically, in the embodiment of the present application, the electronic device acquires a field corresponding to a pre-stored table; determining a third prompting template for prompting the large model to determine the target field according to the field and a third prompting word which is preconfigured and used for prompting the large model to determine the target field; and correspondingly storing the third prompt template and the table identification of the table.
For example, if the table pre-stored by the electronic device is an economic index lookup table, the fields corresponding to the economic index query intention of the economic index lookup table include "index_name, index name", "index_value", "priority, string, province", "city, city", "year, year" and "month"; if the table pre-stored by the electronic device is an enterprise information query table, the fields corresponding to the enterprise information query intention of the enterprise information query table include "company_name", "company_type", "company type", "register_address", "business address", "city", "distribution", county "and" register_data ", and the registration date.
For example, all intents in the economic index lookup table are used for all fields in the table, so that table recall is not needed, namely a third prompt template is not needed to be constructed for each intention; for the enterprise information lookup table, querying the individual enterprise information includes querying the enterprise registration address, the operation address, the city, the county, the registration date, and the like, and screening enterprises according to conditions can also screen according to the city, the county, the registration date, and the like, so that table column recall is necessary.
Based on this, an example of the third hint template corresponding to the enterprise information query intention of the enterprise information query table determined by the electronic device is as follows:
"you need to know the meaning of each field in the table in detail, then list the table fields that the target statement will use, get the table field list according to the following table structure definition and example.
company_name, company name
company_type, company type
register address, register address
Business_address, business address
city, city in city
distribution, county where the distribution is located
register_data, registration date
Examples: asking for: what companies are in Qingdao city? Answering: the related fields include [ city, company_name ]
Target sentence: "
Wherein, "you need to know the meaning of each field in the table in detail, then list the table fields that the target sentence will use, and get the table field list" as the third hint word for hint big model determination of the target field according to the following table structure definition and examples.
In the embodiment of the application, after determining the target table identifier adopted when the SQL statement corresponding to the target statement is generated, the electronic device determines the target third prompting template corresponding to the target table identifier according to the corresponding relation between the pre-stored table identifier and the third prompting template. The electronic equipment adds the target sentence into the target third prompting template, and inputs the added target third prompting template into a large model, so that the large model determines and outputs a target field adopted when the SQL sentence corresponding to the target sentence is generated according to the target third prompting template.
In order to improve the accuracy of the SQL statement generation, in the embodiments of the present application, the inputting the target intention, the target field, and the target statement into the large model includes:
acquiring a fourth prompt template which is stored in advance and used for prompting the big model to generate the SQL sentence, wherein the fourth prompt template comprises a fourth prompt word used for prompting the big model to determine the SQL sentence;
and adding the pre-saved examples corresponding to the target intention, the target field and the target sentence into the fourth prompt template, and inputting the added fourth prompt template into the large model.
In the embodiment of the application, after the electronic device determines the target table, the target intention and the target field adopted when the SQL statement corresponding to the target statement is generated, the electronic device adds the pre-saved example, the target field and the target statement corresponding to the target intention to a fourth prompting template for prompting the big model to generate the SQL statement, so that the big model generates and outputs the SQL statement corresponding to the target statement.
Specifically, in the embodiment of the application, the electronic device acquires a fourth prompt template which is stored in advance and used for prompting the big model to generate the SQL sentence, wherein the fourth prompt template comprises a fourth prompt word used for prompting the big model to determine the SQL sentence. The electronic equipment adds the pre-saved examples, target fields and target sentences corresponding to the target intention into a fourth prompt template, and inputs the added fourth prompt template into a large model, so that the large model generates and outputs SQL sentences corresponding to the target sentences.
For example, examples corresponding to the target intention, which are saved in advance, target fields and target sentences are added to the fourth hint template are as follows:
"you are MySQL generation tools that need to provide customers with MySQL statements that can be directly executed, which are generated according to the following table structure definition and examples.
The following is a definition of the database table structure:
table name #: index_info, index information lookup table, fields are as follows:
index_name, string, index name
index_value, int, index value
provice, string, province, fixed value: shandong province
The enumerated values of city, enum, city include Qingdao, jinan, zibo, jujube, east, tobacco stand, weifang, jining, taian, weihai, japanese, linyi, texas, chat, coast, and joze
year, enum, year in terms of year statistics, expressed in integers, enumerated values contain 2021,2022,2023
Month, enum, expressed in terms of months by integers, enumerated values contain 1,2,3,4,5,6,7,8,9,10,11,12
Other requirements for generating SQL:
examples: * Example of using target intention
Target text: "
Wherein, "you are MySQL generation tools, which need to provide MySQL statements that can be directly executed to clients, and generate MySQL statements as fourth hint words according to the following table structure definition and examples.
In order to improve the accuracy of the SQL statement generation, in the embodiments of the present application, the inputting the intent corresponding to the preconfigured target table identifier and the target statement into the large model includes:
if the target table identifier output by the large model is one, inputting the intention corresponding to the target table identifier and the target sentence into the large model;
if the target table identifiers output by the large model are at least two, at least two target tables corresponding to the at least two target table identifiers are obtained; combining the at least two target tables according to a preconfigured table combining method, and determining the combining intention of the combined target tables; the merge intent and the target statement are input into the large model.
In the embodiment of the present application, in the actual application process, when the SQL statement corresponding to the target statement is generated, one table may be adopted, or multiple tables may be adopted. On the basis, in order to better generate SQL sentences, the electronic equipment firstly judges whether the target table identifier output by the large model is one or not, if the target table identifier is one, the electronic equipment directly inputs the intention corresponding to the target table identifier and the target sentences into the large model so as to determine the target intention; if the target table marks are at least two, the electronic equipment firstly merges the tables corresponding to the at least two target table marks, and inputs the merged intention and the target statement of the target table obtained after merging into a large model so as to determine the target intention.
Specifically, in the embodiment of the present application, if the target table identifier output by the large model is one, the electronic device inputs the intent and the target sentence corresponding to the target table identifier into the large model. If the target table identifiers output by the large model are at least two, the electronic equipment acquires at least two target tables corresponding to the at least two target table identifiers; the electronic equipment merges at least two target forms according to a preconfigured form merging method, and determines merging intention of the merged target forms; the electronic device inputs the merge intent and the target sentence into the large model.
In order to improve the accuracy of the SQL statement generation, in the embodiments of the present application, the merging the at least two target tables according to the preconfigured table merging method includes:
merging the fields contained in the at least two target tables, and deleting the repeated fields if the repeated fields exist in the merged fields;
merging intents contained in the at least two target tables, and deleting the repeated intents if the repeated intents exist in the merged intents.
In the embodiment of the application, when the electronic device merges at least two target tables, the electronic device merges the fields contained in the at least two target tables, and if the repeated fields exist in the fields after being identified to be merged, the repeated fields are deleted; merging intents contained in at least two target tables, and deleting the repeated intents if the repeated intents exist in the merged intents.
For example, take the enterprise information lookup table as an example: when the city field has codes, the corresponding field is a city_code, and the city and the city_code are a single table, and are user questions: "which enterprises have city numbers", when the enterprise information lookup table is used to obtain no result, two tables must be used to combine to obtain corresponding data. In this case, the electronic device needs to map to a plurality of tables at a time or the electronic device performs table merging, and fields of different tables are combined to form a new table through views.
Fig. 2 is a schematic diagram of an SQL statement generation flow provided in an embodiment of the present application, where, as shown in fig. 2, the process includes:
s201: the number of tables and the purpose of each table are confirmed.
S202: and writing a first prompt template according to each table and the corresponding application, so that a target table corresponding to the target sentence can be determined according to the second prompt template.
S203: each intent corresponding to each form is determined.
S204: and writing a second prompt template corresponding to each table according to each intention corresponding to each table, so that the target intention of the target sentence can be analyzed according to the target second prompt template corresponding to the target table.
S205: confirming each field of each table, and writing a third prompting template corresponding to each table according to each field of each table, so that the target field of the target sentence can be analyzed according to the target third prompting template corresponding to the target table.
S206: and generating SQL sentences corresponding to the target text and inquiring answers according to the target intention and the target field.
Based on the foregoing embodiments, fig. 3 is a schematic structural diagram of a large model-based corpus generating device according to an embodiment of the present application, where the device includes:
the processing module 301 is configured to input a table identifier and a purpose of a table configured in advance and a target sentence to be processed into a large model, and obtain a target table identifier of a target table adopted when the large model outputs an SQL sentence corresponding to the target sentence;
the processing module 301 is further configured to input, into the large model, a preset intent corresponding to the target table identifier and the target sentence, and obtain a target intent of the target table that is output by the large model and used when the SQL sentence corresponding to the target sentence is generated;
The processing module 301 is further configured to input a field corresponding to the target table and the target sentence configured in advance into the large model, and obtain a target field of the target table adopted when the large model outputs an SQL sentence corresponding to the target sentence;
and the generating module 302 is configured to input the target intention, the target field and the target sentence into the large model, and obtain an SQL sentence output by the large model.
In a possible implementation manner, the processing module 301 is further configured to obtain a table identifier and a purpose of a pre-stored table; determining a first prompt template for prompting the large model to determine a target table according to the table identification and the application of the table and a first preset prompt word for prompting the large model to determine the target table;
the processing module 301 is specifically configured to add the target sentence to the first alert template, and input the added first alert template to the large model.
In a possible implementation manner, the processing module 301 is further configured to obtain an intention corresponding to a pre-stored table identifier; determining a second prompting template for prompting the large model to determine the target intention according to the intention and a second prompting word which is preconfigured and used for prompting the large model to determine the target intention; correspondingly storing the second prompt template and the form identifier;
The processing module 301 is specifically configured to determine a target second prompting template corresponding to the target table identifier according to the target table identifier and a correspondence between a pre-stored table identifier and the second prompting template; and adding the target sentence into the target second prompt template, and inputting the added target second prompt template into the large model.
In a possible implementation manner, the processing module 301 is further configured to obtain a field corresponding to the pre-stored table; determining a third prompting template for prompting the big model to determine SQL sentences according to the fields and a third prompting word which is preconfigured and used for prompting the big model to determine target fields; correspondingly storing the third prompt template and the table identification of the table;
the processing module 301 is specifically configured to determine a target third prompting template corresponding to the target table identifier according to the target table identifier and a correspondence between a pre-stored table identifier and the third prompting template; and adding the target sentence into the target third prompting template, and inputting the added target third prompting template into the large model.
In a possible implementation manner, the generating module 302 is specifically configured to obtain a fourth prompting template that is stored in advance and used for prompting the big model to generate an SQL statement, where the fourth prompting template includes a fourth prompting word that is used for prompting the big model to determine the SQL statement; and adding the pre-saved examples corresponding to the target intention, the target field and the target sentence into the fourth prompt template, and inputting the added fourth prompt template into the large model.
In a possible implementation manner, the processing module 301 is specifically configured to, if the target table identifier output by the large model is one, input the intent corresponding to the target table identifier and the target sentence into the large model; if the target table identifiers output by the large model are at least two, at least two target tables corresponding to the at least two target table identifiers are obtained; combining the at least two target tables according to a preconfigured table combining method, and determining the combining intention of the combined target tables; the merge intent and the target statement are input into the large model.
In a possible implementation manner, the processing module 301 is specifically configured to combine the fields included in the at least two target tables, and delete the repeated fields if it is identified that the repeated fields exist in the combined fields; merging intents contained in the at least two target tables, and deleting the repeated intents if the repeated intents exist in the merged intents.
On the basis of the foregoing embodiments, the embodiment of the present application further provides an electronic device, and fig. 4 is a schematic structural diagram of the electronic device provided in the embodiment of the present application, as shown in fig. 4, including: the processor 401, the communication interface 402, the memory 403 and the communication bus 404, wherein the processor 401, the communication interface 402 and the memory 403 complete communication with each other through the communication bus 404;
the memory 403 has stored therein a computer program which, when executed by the processor 401, causes the processor 401 to perform the steps of the large model based SQL statement generation method provided by the embodiments described above.
Because the principle of solving the problem of the electronic device is similar to that of the SQL statement generation method based on the large model, the implementation of the electronic device can refer to the embodiment of the method, and the repetition is omitted.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus. The communication interface 402 is used for communication between the electronic device and other devices. The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; but also digital instruction processors (Digital Signal Processing, DSP), application specific integrated circuits, field programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
On the basis of the above embodiments, the embodiments of the present invention further provide a computer readable storage medium, in which a computer program executable by a processor is stored, which when executed on the processor causes the processor to implement the steps of the large model-based SQL statement generation method provided in the above embodiments.
Since the principle of solving the problem by the above-mentioned computer readable storage medium is similar to that of the SQL statement generation method based on the large model, the implementation of the above-mentioned computer readable storage medium can refer to the embodiment of the method, and the repetition is not repeated.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made in the present application without departing from the spirit or scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims and the equivalents thereof, the present application is intended to cover such modifications and variations.

Claims (10)

1. A large model-based SQL statement generation method, the method comprising:
inputting a table identifier, application and target statement to be processed of a pre-configured table into a large model, and acquiring a target table identifier of a target table adopted when the large model outputs an SQL statement corresponding to the target statement;
inputting the preset intention corresponding to the target table identifier and the target sentence into the large model, and acquiring the target intention of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model;
inputting a field corresponding to the target table and the target sentence which are configured in advance into the large model, and acquiring a target field of the target table adopted when the SQL sentence corresponding to the target sentence is generated and output by the large model;
and inputting the target intention, the target field and the target sentence into the large model to acquire an SQL sentence output by the large model.
2. The method of claim 1, wherein prior to entering the table identification, purpose, and target statement to be processed of the pre-configured table into the large model, the method further comprises:
Acquiring a form identifier and a purpose of a pre-stored form;
determining a first prompt template for prompting the large model to determine a target table according to the table identification and the application of the table and a first preset prompt word for prompting the large model to determine the target table;
the inputting of the table identification, the application and the target sentence to be processed of the pre-configured table into the large model comprises the following steps:
and adding the target sentence into the first prompt template, and inputting the added first prompt template into the large model.
3. The method of claim 1, wherein prior to entering the table identification, purpose, and target statement to be processed of the pre-configured table into the large model, the method further comprises:
acquiring an intention corresponding to a pre-stored form identifier;
determining a second prompting template for prompting the large model to determine the target intention according to the intention and a second prompting word which is preconfigured and used for prompting the large model to determine the target intention;
correspondingly storing the second prompt template and the form identifier;
the inputting the intent corresponding to the preconfigured target table identifier and the target sentence into the big model comprises:
Determining a target second prompting template corresponding to the target table identifier according to the target table identifier and the corresponding relation between the pre-stored table identifier and the second prompting template;
and adding the target sentence into the target second prompt template, and inputting the added target second prompt template into the large model.
4. The method of claim 1, wherein prior to entering the table identification, purpose, and target statement to be processed of the pre-configured table into the large model, the method further comprises:
acquiring a field corresponding to a pre-stored form;
determining a third prompting template for prompting the big model to determine SQL sentences according to the fields and a third prompting word which is preconfigured and used for prompting the big model to determine target fields;
correspondingly storing the third prompt template and the table identification of the table;
inputting the pre-configured field corresponding to the target table and the target sentence into the big model comprises:
determining a target third prompting template corresponding to the target table identifier according to the target table identifier and the corresponding relation between the pre-stored table identifier and the third prompting template;
And adding the target sentence into the target third prompting template, and inputting the added target third prompting template into the large model.
5. The method of claim 1, wherein the inputting the target intent, the target field, and the target sentence into the large model comprises:
acquiring a fourth prompt template which is stored in advance and used for prompting the big model to generate the SQL sentence, wherein the fourth prompt template comprises a fourth prompt word used for prompting the big model to determine the SQL sentence;
and adding the pre-saved examples corresponding to the target intention, the target field and the target sentence into the fourth prompt template, and inputting the added fourth prompt template into the large model.
6. The method of claim 1, wherein the inputting the preconfigured intent and the target statement corresponding to the target table identification into the large model comprises:
if the target table identifier output by the large model is one, inputting the intention corresponding to the target table identifier and the target sentence into the large model;
If the target table identifiers output by the large model are at least two, at least two target tables corresponding to the at least two target table identifiers are obtained; combining the at least two target tables according to a preconfigured table combining method, and determining the combining intention of the combined target tables; the merge intent and the target statement are input into the large model.
7. The method of claim 6, wherein the merging the at least two target tables according to a pre-configured table merging method comprises:
merging the fields contained in the at least two target tables, and deleting the repeated fields if the repeated fields exist in the merged fields;
merging intents contained in the at least two target tables, and deleting the repeated intents if the repeated intents exist in the merged intents.
8. A large model-based SQL statement generation apparatus, the apparatus comprising:
the processing module is used for inputting the table identification and the purpose of the pre-configured table and the target statement to be processed into the large model, and obtaining the target table identification of the target table adopted when the SQL statement corresponding to the target statement is generated and output by the large model;
The processing module is further configured to input a preset intent corresponding to the target table identifier and the target sentence into the large model, and obtain a target intent of the target table adopted when the large model outputs an SQL sentence corresponding to the target sentence;
the processing module is further configured to input a field corresponding to the target table and the target sentence which are configured in advance into the large model, and obtain a target field of the target table, which is output by the large model and used when the SQL sentence corresponding to the target sentence is generated;
and the generation module is used for inputting the target intention, the target field and the target sentence into the large model and obtaining the SQL sentence output by the large model.
9. An electronic device comprising a processor for implementing the steps of a large model based SQL statement generation method according to any of claims 1-7 when executing a computer program stored in a memory.
10. A computer readable storage medium, characterized in that it stores a computer program which, when executed by a processor, implements the steps of a large model based SQL statement generation method as claimed in any of claims 1-7.
CN202311623084.XA 2023-11-30 2023-11-30 SQL sentence generation method, device, equipment and medium based on large model Pending CN117874052A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311623084.XA CN117874052A (en) 2023-11-30 2023-11-30 SQL sentence generation method, device, equipment and medium based on large model

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311623084.XA CN117874052A (en) 2023-11-30 2023-11-30 SQL sentence generation method, device, equipment and medium based on large model

Publications (1)

Publication Number Publication Date
CN117874052A true CN117874052A (en) 2024-04-12

Family

ID=90592400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311623084.XA Pending CN117874052A (en) 2023-11-30 2023-11-30 SQL sentence generation method, device, equipment and medium based on large model

Country Status (1)

Country Link
CN (1) CN117874052A (en)

Similar Documents

Publication Publication Date Title
CN109284363B (en) Question answering method and device, electronic equipment and storage medium
CN109284323B (en) Management method and device for detection data
CN110955714B (en) Method and device for converting unstructured text into structured text
CN111078776A (en) Data table standardization method, device, equipment and storage medium
CN114528312A (en) Method and device for generating structured query language statement
CN110222047B (en) Dynamic form generation method and device
US10678514B2 (en) Method and device for generating code assistance information
CN111858236A (en) Knowledge graph monitoring method and device, computer equipment and storage medium
CN110704635B (en) Method and device for converting triplet data in knowledge graph
CN117874052A (en) SQL sentence generation method, device, equipment and medium based on large model
CN112214494B (en) Retrieval method and device
CN113127617A (en) Knowledge question answering method of general domain knowledge graph, terminal equipment and storage medium
CN112988986A (en) Man-machine interaction method, device and equipment
CN111563094A (en) Data query method and device, electronic equipment and computer-readable storage medium
CN117828041A (en) Method, device, equipment and medium for generating reply corpus based on large model
CN117149985A (en) Question and answer method, device, equipment and medium based on large model
CN115357687A (en) Data processing method and device of insurance product and electronic equipment
CN117540004B (en) Industrial domain intelligent question-answering method and system based on knowledge graph and user behavior
CN117035695B (en) Information early warning method and device, readable storage medium and electronic equipment
Uduwela et al. An Approach To Automate The Relational Database Design Process
CN117421415A (en) Data processing method, device, electronic equipment and storage medium
CN117909454A (en) Text completion method, device and equipment based on multi-round dialogue
CN116909528A (en) Text generation method, apparatus, computer device and storage medium
Korshunov et al. Ontological approach to the integration ofknowledge from external sources
CN117807982A (en) Data computing method, device, equipment and medium based on large language model

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination