SQL statement generation method and device, computer equipment, readable storage medium and program product

Through the combination of large language model and business knowledge vocabulary, entity recognition, knowledge enhancement and field matching are carried out to generate high-accurate SQL statements, solving the problem of poor accuracy in SQL statement generation in traditional technology.

CN119576975APending Publication Date: 2025-03-07CHINA TELECOM CLOUD TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411766161.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

In traditional technology, SQL statement generation is poor in accuracy and it is difficult to effectively solve the problem.

Method used

Entity recognition and table label recognition are performed through a large language model, knowledge enhancement is performed in combination with the business knowledge vocabulary, matching the target fields and value fields, generating the target prompt words of SQL statements, and generating the final SQL statement through the SQL statement generation model.

Benefits of technology

Improve the accuracy and efficiency of SQL statement generation, enhance the understanding of problem semantics and matching database tables, and reduce syntax errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576975A_ABST
    Figure CN119576975A_ABST
Patent Text Reader

Abstract

The invention relates to an SQL statement generation method and device, computer equipment, a computer readable storage medium and a computer program product. The method comprises the steps of performing entity identification, table label identification and knowledge enhancement on a question, further supplementing business knowledge for the question, and realizing accurate understanding of question semantics, accurate matching with a database table and avoidance of grammar errors in the SQL statement generation process by combining characteristic knowledge and metadata corresponding to a business field. The accuracy of the SQL statement generated through the large language model and used for solving the problem is improved, and the generation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of big data technology, and in particular to a method, apparatus, computer device, computer-readable storage medium, and computer program product for generating an SQL statement. Background Art

[0002] Traditional technology generally uses the Seq2Seq architecture and the "encoding-decoding" mechanism to treat the conversion of text to SQL as a translation task. Specifically, the SQL statement can be decomposed into "SELECT" clauses and "WHERE" clauses, and the "SELECT" clauses and "WHERE" clauses are independently generated based on the problem and then assembled to obtain the SQL statement. Since the process of generating clauses is relatively simple, the accuracy of the generated SQL is poor. Summary of the invention

[0003] Based on this, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium and computer program product for generating SQL statements that can improve the accuracy of generation in order to solve the above technical problems.

[0004] In a first aspect, the present application provides a method for generating an SQL statement, comprising:

[0005] Perform entity recognition and table label recognition on the question through a large language model to obtain entities and table labels, and determine the data table corresponding to the table labels;

[0006] Performing knowledge enhancement on the entity based on the business knowledge word library to obtain a knowledge-enhanced entity, and matching the knowledge-enhanced entity through a preset data dictionary to obtain a target field set and a value domain;

[0007] Processing based on the business knowledge word library, the question and the value range to obtain a target prompt word for the SQL statement; and filtering the data table based on the target field set to obtain a filtered data table;

[0008] The target prompt word of the SQL statement and the screened data table are processed through the SQL statement generation model to generate a target SQL statement, and the target SQL statement is used to answer the question.

[0009] In one embodiment, the business knowledge word library includes at least a plurality of businesses and business names; and the step of performing knowledge enhancement on the entity based on the business knowledge word library to obtain the knowledge enhanced entity includes:

[0010] respectively calculating the first similarity between the business name of each business in the business knowledge word library and the entity, and obtaining the business name of the target business that meets the first similarity condition based on each of the first similarities;

[0011] The entity is supplemented based on the business name of each target business to obtain a knowledge-enhanced entity.

[0012] In one embodiment, the preset data dictionary includes at least each field, a dictionary description of each field, and a dictionary value; matching the knowledge-enhanced entity through the preset data dictionary to obtain a target field set and a target value domain includes:

[0013] Matching the entities enhanced with knowledge respectively through a preset data dictionary and field descriptions in field metadata to obtain a target field set;

[0014] The second similarities between the knowledge-enhanced entity and the dictionary description of each field in the data dictionary are calculated respectively, and based on each of the second similarities, the dictionary value corresponding to the target dictionary description that meets the second similarity condition is obtained; and the value range of each of the dictionary values ​​is determined to be the target value range.

[0015] In one embodiment, the entities after knowledge enhancement are matched respectively by using a preset data dictionary and field descriptions in field metadata to obtain a target field set, including:

[0016] Calculating the third similarities between the knowledge-enhanced entity and each field description in the field metadata respectively, obtaining a target field description satisfying a third similarity condition based on each of the third similarities, and determining that the field corresponding to each of the target field descriptions is the first field;

[0017] Calculating the fourth similarities between the entity after knowledge enhancement and the dictionary value of each field in the data dictionary respectively, and obtaining a target dictionary value satisfying a fourth similarity condition based on each of the fourth similarities; and determining that the field of each of the target dictionary values ​​is the second field;

[0018] A target field set is obtained based on the first field and the second field.

[0019] In one embodiment, the processing based on the business knowledge word library, the question and the value range to obtain the target prompt word of the SQL statement includes:

[0020] Supplement the problem based on business knowledge to obtain the target problem supplemented by business knowledge;

[0021] Semantically matching the target question with each SQL question answer information contained in the business knowledge word library to obtain matched target SQL question answer information, and generating an initial prompt word of the SQL statement based on the target SQL question answer information;

[0022] The initial prompt word is supplemented based on the value range to obtain the target prompt word of the SQL statement.

[0023] In one embodiment, the generating model through the SQL statement, processing the target prompt word of the SQL statement and the screened data table to generate the target SQL statement, includes:

[0024] Semantically matching the explanation information of each custom function with the question to obtain a target custom function, and adding the target custom function to the target prompt word of the SQL statement to obtain the added target prompt word;

[0025] Input the added target prompt word and the screened data table into the SQL statement generation model to obtain an initial SQL statement;

[0026] The initial SQL statement is subjected to dialect conversion and error correction checking to obtain a target SQL statement.

[0027] In a second aspect, the present application also provides a device for generating a SQL statement, including:

[0028] A first recognition module is used to perform entity recognition and table label recognition on the question through a large language model, obtain entities and table labels, and determine the data table corresponding to the table labels;

[0029] A first enhancement module is used to perform knowledge enhancement on the entity based on a business knowledge vocabulary to obtain a knowledge-enhanced entity, and to match the knowledge-enhanced entity through a preset data dictionary to obtain a target field set and a value domain;

[0030] A first screening module is used to process based on the business knowledge word library, the question and the value range to obtain a target prompt word of the SQL statement; and to screen the data table based on the target field set to obtain a screened data table;

[0031] The first generation module is used to generate a model through an SQL statement, process the target prompt word of the SQL statement and the screened data table, and generate a target SQL statement, wherein the target SQL statement is used to answer the question.

[0032] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above embodiments when executing the computer program.

[0033] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the steps in the above embodiments when executed by a processor.

[0034] In a fifth aspect, the present application also provides a computer program product, including a computer program, which implements the steps in the above embodiment when executed by a processor.

[0035] The above-mentioned SQL statement generation method, device, computer equipment, computer-readable storage medium and computer program product can perform entity recognition, table label recognition and knowledge enhancement on the problem by adopting this method, further supplement the business knowledge for the problem, combine the characteristic knowledge and metadata corresponding to the business field, realize accurate understanding of the problem semantics, accurate matching with the database table, and avoid grammatical errors in the process of generating SQL statements, etc., improve the accuracy of SQL statements generated by the large language model for solving problems and improve the generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0037] Figure 1 A flowchart of a method for generating an SQL statement in an embodiment;

[0038] Figure 2 A schematic diagram of a flow chart of a knowledge enhancement step in an embodiment;

[0039] Figure 3 A schematic diagram of a process for determining a target value range in one embodiment;

[0040] Figure 4 A schematic diagram of a flow chart of steps for obtaining a target field set in one embodiment;

[0041] Figure 5 A schematic diagram of a flow chart of a step of obtaining a prompt word in an embodiment;

[0042] Figure 6 A flowchart of the steps of generating SQL statements in one embodiment;

[0043] Figure 7 is a schematic diagram of an architecture in an embodiment;

[0044] Figure 8 A flowchart of a method for generating an SQL statement in another embodiment;

[0045] Fig. 9 A schematic diagram of an architecture for obtaining a target field set in one embodiment;

[0046] Fig.10 is a schematic diagram of the architecture of a model in an embodiment;

[0047] Fig.11 is a structural block diagram of a device for generating SQL statements in one embodiment;

[0048] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0050] In one embodiment, Figure 1 As shown, a method for generating SQL statements is provided. This embodiment uses the method applied to a terminal as an example. It is understandable that the method can also be applied to a server, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. The above-mentioned terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, etc. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services. In this embodiment, the method for generating SQL statements includes the following steps:

[0051] Step 102: perform entity recognition and table label recognition on the question through a large language model to obtain entities and table labels, and determine the data table corresponding to the table labels.

[0052] Among them, the large language model is a model specifically used to process text and understand the semantic information in the text. It processes the grammar, vocabulary, relationship between words, context and deep meaning expressed by the text information in the sentences to obtain the output result of the large language model LLM (Large Language Model). The large language model is a combination of recurrent neural networks, long short-term memory networks (LSTM) or transformers in deep learning; questions can be questions raised by users, such as questions in natural language related to business; entities can be data obtained by extracting prompt words from questions through the large language model to complete entity extraction. Table label recognition can be based on the natural language of the question to obtain table labels that match the natural language of the question. The data table corresponding to the table label can be the data table where the table label matching the entity is located.

[0053] Specifically, the terminal can obtain a question in the form of natural language input by the user, and perform entity recognition on the question through a large language model. For example, the question can be input into the large language model to obtain an entity or multiple entities contained in the question identified by the large language model. Correspondingly, multiple data tables can be pre-stored in the terminal, each of which contains a table label and multiple fields of the data table; the terminal can also perform table label recognition on the natural language of the question, obtain a table label associated with the question, and obtain a table label that matches the question. The terminal can filter in multiple pre-stored data tables based on the table label to obtain an initial data table that meets the first filtering condition. If the table label of the data table is consistent with the table label corresponding to the question, it can be determined that the data table is an initial data table that meets the first filtering condition.

[0054] In this way, the terminal can also match the entity corresponding to the question with each field contained in the business knowledge word library, obtain the field in the business knowledge word library that matches the question, and calculate the similarity based on the field and the fields existing in multiple initial data tables, obtain the similarity corresponding to each initial data table, and screen based on each similarity to obtain a data table that meets the second screening condition, and determine that the data table that meets the second screening condition is the data table corresponding to the table label. For example, when screening in each initial data table, the terminal can determine the data table whose similarity exceeds the preset similarity threshold as the data table that meets the second screening condition. In this way, the terminal can determine the initial data table whose similarity exceeds the preset similarity threshold as the data table corresponding to the table label; in addition, the terminal can sort the initial data tables according to the order of each similarity from large to small, and determine the initial data tables of the target number as the data table that meets the second screening condition. Among them, the preset similarity threshold can be 85%, and the specific value of the target number is not limited in this disclosure, and those skilled in the art can determine it based on the actual application scenario.

[0055] Step 104 , based on the business knowledge vocabulary, the entity is enhanced to obtain the knowledge-enhanced entity, and the knowledge-enhanced entity is matched through a preset data dictionary to obtain a target field set and a value domain.

[0056] Among them, the business knowledge vocabulary can be a knowledge base associated with the business field where the problem is located, and the business knowledge vocabulary can at least include various businesses, business synonyms, business types and business descriptions; among them, the table data type of the business can be a FLOAT_VECTOR type, and the actual meaning of the business is the name of the business knowledge; the table data type of the synonym can be a FLOAT_VECTOR type, and the actual meaning of the synonym is the synonym of the business knowledge; the table data type of the business type can be a VECTOR type, and the actual meaning of the business type includes table labels and business knowledge; the table data type of the business description can be a FLOAT_VECTOR type, and the actual meaning of the business description is the description information of the business knowledge.

[0057] Specifically, for each entity in the question, the terminal can calculate the vector similarity between the entity and each business contained in the business knowledge vocabulary, obtain the vector similarity between the entity and the business name of each business, and determine the business name that exceeds the vector similarity threshold as the description supplementary information of the entity; the terminal can obtain the knowledge-enhanced entity based on each entity and the description supplementary information corresponding to each entity. For example, the terminal can add the description supplementary information corresponding to each entity to the entity to obtain the knowledge-enhanced entity. The preset vector similarity threshold can be 0.85. In this way, the terminal can perform field matching on the knowledge-enhanced entity through the preset data dictionary to obtain the matching target field set and value domain.

[0058] Optionally, the business knowledge vocabulary in a specific application scenario may be as shown in Table 1 below:

[0059] Table 1

[0060]

[0061] Step 106: Processing is performed based on the business knowledge word library, the question and the value range to obtain the target prompt word of the SQL statement, and the data table is screened based on the target field set to obtain the screened data table.

[0062] The target prompt word of the SQL statement can be prompt information for prompting the generation process of the SQL statement in the SQL statement generation model; the data table can be a data table corresponding to the table tag obtained after multiple screening based on the table tag after the table tag is identified for the entity. The screened data table can be a data table obtained after fine screening of the target field set and value range obtained in the above steps for the data table corresponding to the table tag.

[0063] Specifically, the terminal can supplement the question with business knowledge through the business knowledge word library to obtain the question after business knowledge supplementation. The terminal can match the data stored in the business knowledge word library based on the question after business knowledge supplementation to obtain the initial prompt word used to prompt the generation process of the SQL statement; accordingly, the terminal processes and supplements the initial prompt word based on the value domain obtained in the above steps to obtain the target prompt word of the SQL statement. Similarly, the terminal can also finely screen the data table corresponding to the table tag based on each field included in the target field set to obtain the screened data table, which is used to generate the SQL statement.

[0064] Optionally, the data table is filtered based on the target field set, and the specific process of obtaining the filtered data table may be: in the data table corresponding to the table tag, the target fields included in the target field set are calculated and the similarity is calculated with the table fields (table DDL fields) in each data table respectively, to obtain the similarity between the target fields and the table fields in each data table respectively, and the table fields in the data table whose similarity exceeds the similarity threshold are retained, that is, the table fields in the data table whose similarity is less than the similarity threshold are removed, and the key fields in the data table also need to be retained, which may include primary keys, partition fields, and foreign key fields participating in the calculation table, etc., that is, the filtered data table includes fields whose similarity with the target fields is greater than or equal to the similarity threshold and the key fields of each data table.

[0065] Step 108, using the SQL statement generation model, the target prompt words of the SQL statement and the screened data table are processed to generate a target SQL statement, which is used to answer the question.

[0066] The input data of the SQL statement generation model may be the target prompt word of the SQL statement and the filtered data table, and the output data of the SQL statement generation model may be an SQL statement for solving the question raised by the user, and the SQL statement may generate answer information for answering the question raised by the user. The SQL statement generation model may be a pre-configured large language model LLM.

[0067] Specifically, the terminal may input the target prompt word of the SQL statement and the filtered data table into the SQL statement generation model, and in the SQL statement generation model, the target prompt word of the SQL statement and the filtered data table are processed to generate the SQL statement. Optionally, the SQL statement generation model may include a generation module, and may also include a SQL statement checking module and a SQL statement error correction module, based on which the initial SQL statement output by the generation module is checked and corrected to obtain the target SQL statement.

[0068] In the above SQL statement generation method, entity recognition, table label recognition and knowledge enhancement can be performed on the problem to further supplement business knowledge for the problem. Combined with the characteristic knowledge and metadata corresponding to the business field, accurate understanding of the problem semantics can be achieved, accurate matching with the database table, and avoidance of syntax errors in the process of generating SQL statements, etc., thereby improving the accuracy of SQL statements generated by the large language model for solving problems and improving generation efficiency.

[0069] In one embodiment, the business knowledge word library includes at least a plurality of businesses and business names. Optionally, the business knowledge word library may be a knowledge library associated with the business field in which the problem is located, and the business knowledge word library may include at least each business, business synonyms, business type and business description.

[0070] like Figure 2 As shown, the step of "enhancing the entity through the business knowledge vocabulary to obtain the knowledge-enhanced entity" includes:

[0071] Step 202 , respectively calculating the first similarities between the business name of each business in the business knowledge word library and the entity, and obtaining the business name of the target business that meets the first similarity condition based on each first similarity.

[0072] Specifically, the business knowledge word library may contain multiple businesses and the business names corresponding to each business. After the terminal performs entity recognition on the problem, one or more entities can be obtained. For each entity obtained, the terminal can perform business knowledge enhancement on the entity to obtain an entity after business knowledge enhancement. Specifically, the terminal can calculate the vector similarity between the entity and the business name of each business in the business knowledge word library. The vector similarity can be referred to as the first similarity below. The terminal screens each business name based on each first similarity to obtain a target business that meets the first similarity condition, and determines the business name of the target business. For example, the terminal can determine a business whose first similarity is greater than or equal to the first similarity threshold as a target business that meets the first similarity condition. That is, if the first similarity between the business name of the business and the entity is greater than the first similarity threshold, the terminal can determine that the business is the target business, and the business name of the target business is the description supplementary information of the entity. The first similarity threshold can be determined by the present disclosure based on the actual application scenario, for example, it can be 0.85.

[0073] Step 204: supplement the entity based on the business name of each target business to obtain a knowledge-enhanced entity.

[0074] Specifically, the terminal can obtain the service name corresponding to each target service, and determine the name of each target service as the description supplementary information of the entity. The terminal can obtain the knowledge-enhanced entity based on each entity extracted from the question and the description supplementary information corresponding to each entity. For example, the terminal can add the description supplementary information corresponding to each entity to the corresponding entity to obtain the knowledge-enhanced entity.

[0075] In this embodiment, the missing content of the natural language question is supplemented to ensure the completeness of the question, and to provide a reliable data basis for the large language model to accurately understand the semantic information in the question in the subsequent process.

[0076] In one embodiment, the preset data dictionary includes at least each field, a dictionary description of each field, and a dictionary value. Figure 3 As shown, the step of "matching the knowledge-enhanced entities through a preset data dictionary to obtain a target field set and a target value range" includes:

[0077] Step 302 , matching the knowledge-enhanced entities respectively through a preset data dictionary and field descriptions in field metadata to obtain a target field set.

[0078] Among them, the field description in the field metadata can be a supplement to the field, or it can be a definition of the header field. For example, the field in the student data table can be a name, that is, the student data table contains a name field, and the corresponding field description of the field can be the student's name; that is, the field description is further supplementary explanatory information for the field combined with the actual content of the data table.

[0079] Specifically, the terminal can perform field matching on the knowledge-enhanced entity through a preset data dictionary to obtain a field set that matches the knowledge-enhanced entity. The terminal can also match the knowledge-enhanced entity through the field description in the field metadata to obtain a matching field set. The terminal can determine the field set obtained in the above steps as the target field set.

[0080] Step 304, respectively calculate the second similarity between the knowledge-enhanced entity and the dictionary description of each field in the data dictionary, and based on each second similarity, obtain the dictionary value corresponding to the target dictionary description that meets the second similarity condition, and determine the value range of each dictionary value as the target value range.

[0081] The preset data dictionary includes fields and dictionary descriptions and dictionary values ​​of each field. The dictionary descriptions correspond to the dictionary values, that is, each dictionary description has a dictionary value corresponding to the dictionary description.

[0082] Specifically, for the knowledge-enhanced entity, the terminal can calculate the vector similarity between the knowledge-enhanced entity and the dictionary description of each field in the data dictionary, which can be referred to as the second similarity below. The terminal screens each dictionary description based on each second similarity to obtain a target dictionary description that meets the second similarity condition, and determines the dictionary value of the target dictionary description. For example, the terminal can determine the dictionary description whose second similarity is greater than or equal to the second similarity threshold as the target dictionary description that meets the second similarity condition. That is, if the second similarity between the dictionary description of the field and the knowledge-enhanced entity is greater than the second similarity threshold, the terminal can determine that the dictionary description is the target dictionary description, and query in the data dictionary to determine the dictionary value corresponding to the target dictionary description; in this way, the terminal can determine the value range of the dictionary value of each target dictionary description, and determine each value range as the target value range. The second similarity threshold can be determined by the present disclosure based on the actual application scenario, for example, it can be 0.85.

[0083] Optionally, the content of the data dictionary may be as shown in Table 2 below:

[0084] Table 2

[0085]

[0086] In this embodiment, by performing knowledge enhancement on the question, industry knowledge can be further supplemented in the question to facilitate the recognition of the SQL statement generation model. The matching target field set and target value domain are determined based on the knowledge-enhanced entity, which can ensure a strong association between the subsequently screened data table and the question.

[0087] In one embodiment, Figure 4 The step of "matching the knowledge-enhanced entities respectively through the preset data dictionary and the field description in the field metadata to obtain the target field set" includes:

[0088] Step 402, respectively calculate the third similarities between the knowledge-enhanced entity and each field description in the field metadata, obtain the target field description that meets the third similarity condition based on each third similarity, and determine that the field corresponding to each target field description is the first field.

[0089] Specifically, for the entity after knowledge enhancement, the terminal can calculate the vector similarity between the entity after knowledge enhancement and each field description in the field metadata. The vector similarity can be referred to as the third similarity below. The terminal screens each field description based on each third similarity to obtain the target field description that meets the third similarity condition, and determines the field corresponding to the target field description. That is to say, the field metadata is the metadata corresponding to the field, and the metadata contains the field description. After finally screening out the target field descriptions that match the entity after knowledge enhancement, the terminal can determine the fields corresponding to each target field description as the first field.

[0090] That is, if the third similarity between the field description and the knowledge-enhanced entity is greater than the third similarity threshold, the terminal can determine that the field description is a target field description, and perform a query to determine the field corresponding to the target field description; in this way, the terminal can determine that the field of each target field description is the first field. The third similarity threshold can be determined by the present disclosure based on actual application scenarios, for example, it can be 0.85.

[0091] Step 404, respectively calculate the fourth similarities between the knowledge-enhanced entity and the dictionary value of each field in the data dictionary, obtain the target dictionary value satisfying the fourth similarity condition based on each fourth similarity, and determine the field of each target dictionary value as the second field.

[0092] Among them, dictionary values ​​can also be dictionary keys.

[0093] Specifically, for the knowledge-enhanced entity, the terminal can calculate the vector similarity between the knowledge-enhanced entity and the dictionary values ​​of each field in the data dictionary, which may be referred to as the fourth similarity below. The terminal screens each dictionary value based on each fourth similarity to obtain a target dictionary value that satisfies the fourth similarity condition, and determines the field corresponding to the target dictionary value. For example, the terminal may determine a dictionary value whose fourth similarity is greater than or equal to a fourth similarity threshold as a target dictionary value that satisfies the fourth similarity condition. That is, if the fourth similarity between the dictionary value and the knowledge-enhanced entity is greater than the fourth similarity threshold, the terminal may determine that the dictionary value is the target dictionary value, and perform a query to determine that the field corresponding to the target dictionary value is the second field. The fourth similarity threshold may be determined by the present disclosure based on an actual application scenario, such as 0.85.

[0094] Step 406: Get a target field set based on the first field and the second field.

[0095] Specifically, the terminal may combine the first field and the second field to obtain a target field set, that is, the terminal may determine the set of the first field and the second field as the target field set.

[0096] In this embodiment, field recognition is performed through questions with knowledge enhancement, thereby improving the accuracy of the identified field set matching the entity.

[0097] In one embodiment, Figure 5 As shown, the step of "processing based on the business knowledge vocabulary, questions and value range to obtain the target prompt word of the SQL statement" includes:

[0098] Step 502, supplement the question based on business knowledge to obtain the target question supplemented with business knowledge.

[0099] The business knowledge may be knowledge data associated with the business field in which the problem is located.

[0100] Specifically, the terminal can perform query matching in business knowledge based on the question. For example, it can calculate the vector similarity between the question and each piece of business knowledge respectively, determine the business knowledge that exceeds the vector similarity threshold as the business knowledge that matches the question, and add the matching business knowledge to the question to obtain the target question after the business knowledge is supplemented.

[0101] Step 504 , semantically match the target question with each SQL question answer information contained in the business knowledge word library to obtain matched target SQL question answer information, and generate an initial prompt word of the SQL statement based on the target SQL question answer information.

[0102] The business knowledge word base may be an enterprise knowledge base, and the enterprise knowledge base may contain a plurality of SQL question and answer FAQ knowledge data in the business field, that is, each piece of SQL question and answer FAQ knowledge data may be SQL question answer information.

[0103] Specifically, the terminal can perform semantic matching between the target question and each SQL question answer information stored in the enterprise knowledge base, that is, calculate the vector similarity between the target question and each SQL question answer information, and compare each vector similarity with a preset similarity threshold to obtain a vector similarity that exceeds the preset similarity threshold, and determine the SQL question answer information corresponding to the vector similarity that exceeds the preset similarity threshold as the target SQL question answer information. In this way, the terminal can determine each target SQL question answer information corresponding to the target question as the initial prompt word of the SQL statement. The process of generating the prompt word can be that the terminal determines the target SQL question answer information as the initial prompt word of the SQL statement.

[0104] Step 506: supplement the initial prompt word based on the value range to obtain the target prompt word of the SQL statement.

[0105] Specifically, the value domain may include single value and multiple value. If the value domain is single value, the corresponding supplementary information may be key-value. If the value domain is multiple value, the corresponding supplementary information may be key in(). The terminal may obtain the supplementary information based on the type of the value domain, and add the supplementary information to the initial prompt word to obtain the target prompt word of the SQL statement.

[0106] In this embodiment, by supplementing the question with business knowledge, it is possible to avoid the loss of business information in the natural language question, and ensure the integrity of the question and the comprehensiveness of the prompt word generated.

[0107] In one embodiment, Figure 6 As shown, the step of "generating a model through an SQL statement, processing the target prompt word of the SQL statement and the filtered data table to generate a target SQL statement" includes:

[0108] Step 602 , semantic matching is performed based on the explanation information of each user-defined function and the question to obtain a target user-defined function, and the target user-defined function is added to the target prompt word of the SQL statement to obtain the added target prompt word.

[0109] Among them, the custom function can be a plurality of pre-configured custom functions, and is also configured with explanation information of the custom function. The explanation information can be description information of the custom function, for example, it can include description of the input, processing and output process of the function, etc.; for example, it can be a custom function related to SQL statement generation.

[0110] Specifically, the terminal can semantically match the target question with the explanation information of each custom function, that is, calculate the similarity between the target question and the explanation information of each custom function, and determine the custom function corresponding to the explanation information whose similarity exceeds the similarity threshold as the target custom function matching the question. In this way, the terminal can add each target custom function to the target prompt word to obtain the added prompt word.

[0111] Step 604: input the added target prompt words and the filtered data table into the SQL statement generation model to obtain an initial SQL statement.

[0112] Specifically, the terminal can input the added target prompt words and the filtered data table into the SQL statement generation model, instruct the SQL statement generation model through the SQL statement generation instruction, and process the added target prompt words and the filtered data table through the generation module in the SQL statement generation model to obtain an initial SQL statement.

[0113] Step 606: perform dialect conversion and error correction check on the initial SQL statement to obtain a target SQL statement.

[0114] The SQL statement generation model may include a generation module, a SQL statement checking module and a SQL statement error correction module.

[0115] Specifically, after obtaining the initial SQL statement, the terminal can determine the dialect type with the highest accuracy in the SQL statement generation model, and convert the initial SQL statement to the dialect type to obtain the initial SQL statement after dialect conversion. In this way, the terminal can also check the SQL statement after dialect conversion through the SQL statement checking module, for example, it can be a syntax check, an executable check, and a performance check, and based on the problem corresponding to the check result and the preset coding model, obtain the prompt words of the problem-solving step, and correct the SQL statement after dialect conversion based on the prompt words of the problem-solving step, and the corrected SQL statement, that is, obtain the target SQL statement. Among them, the terminal can also record each problem and the corresponding solution prompt word for each problem, and add each problem and the corresponding solution prompt word for each problem to the problem-solving step knowledge base, so as to provide a reliable data basis for the subsequent generation of SQL statements with higher accuracy and timely finding solutions when encountering problems.

[0116] In this embodiment, the accuracy of the generated SQL statements is further guaranteed through the entire process of SQL statement generation, SQL statement error correction, and SQL statement checking.

[0117] In the following, in conjunction with a specific embodiment, the specific implementation process of the above-mentioned SQL statement generation method is described in detail. The process of generating SQL statements in traditional technology generally includes: through the Seq2Seq architecture, using the classic "encoding-decoding" mechanism, treating the conversion of text to SQL as a translation task, decomposing the SQL statement into "SELECT" clauses and "WHERE" clauses for independent generation, and finding that its accuracy is poor in practice; it is also possible to pre-set the task sketch through the sketch guidance method, clearly define the logic of each subtask and its mutual dependence, and the output of each subtask depends only on its directly related input information, and the correlation between each other is poor; it is also possible to enrich the semantic depth of natural language queries by introducing external knowledge graphs, or generate SQL around large language model technology, and deepen the conversion of text to SQL by means of comprehensive word segmentation, word embedding, model training and verification. However, all of the above methods have problems such as semantic understanding deviation, inaccurate database table matching, frequent SQL syntax errors, and difficulty in capturing the knowledge background of a specific industry, resulting in poor accuracy of the generated SQL statements used to answer questions.

[0118] Currently, there is a large coding model for natural language generation of SQL, but due to the uniqueness of each enterprise's database structure and business logic, customization requirements significantly affect the accuracy of SQL generation. In the information construction of each industry, there is a large amount of industry knowledge, data metadata, and development precipitation. Therefore, the SQL statement generation method provided by the present disclosure can integrate industry characteristic knowledge, metadata details and enterprise-specific SQL interaction records, fine-tune the SQL statement generation process, further break through the existing accuracy bottleneck, and improve the accuracy of generated SQL statements.

[0119] First, various technical terms involved in the method for generating SQL statements provided by the present disclosure are introduced:

[0120] Knowledge base: An enterprise knowledge management tool that realizes the comprehensive accumulation and deep sedimentation of data domain knowledge. Through efficient knowledge management, it promotes the high reuse and circulation of data knowledge and improves the efficiency and level of enterprise data governance.

[0121] Data table: It is the main structure for storing and organizing data. Each data table contains multiple fields, which define the data items in the table and have specific data types, such as integers, characters, dates, etc. Fields determine the type and range of data that a data table can store.

[0122] Large language model: a model used to process and understand semantic information in text; it can be used for a variety of natural language processing tasks, such as text classification, sentiment analysis, question-answering systems, machine translation, etc.

[0123] Vector model: Convert text information into numerical vectors. In the vector model, each word, phrase or sentence is represented as a multi-dimensional vector.

[0124] Code Large Language Models (Code LLMs): Large language models pre-trained using a large amount of code data to support the generation of multiple codes.

[0125] Data governance refers to the process of transforming an enterprise's data from being uncontrollable, unavailable, and difficult to use to being controllable, easy to use, and extremely helpful to the business. Through a series of standardized processes such as collection, transmission, and storage, the originally scattered data is transformed into data with a standardized format and unified structure.

[0126] Recall: Usually refers to finding and extracting relevant information from a large amount of data, and ultimately returning the relevant or likely parts that meet the needs. For example, when a search engine receives a query, it will "recall" pages related to the query from the web pages it indexes.

[0127] Prompt: refers to a phrase or sequence of words added to the model input to guide the model to perform a specific prediction or generation task. A prompt can be a question, the beginning of a sentence, a topic, or any other type of instruction. Its purpose is to guide the output of the model and tell the model what kind of answer or result you want to see. One-Shot Prompt Learning: refers to the model giving a sample during inference, but not allowing weight updates. One-shot works by providing 1 sample and then expecting the model to generate the corresponding result. The main advantage is that it greatly reduces the demand for task-specific data and reduces the learning of overly narrow distributions from fine-tuning datasets. Zero-Shot Prompt Learning: It does not provide samples, but only gives natural language instructions describing the task. Ensure the maximum convenience, robustness, and avoidance of false possibilities of prompts. Data augmentation: used to expand the size of data samples. The larger the size of the data, the better the model quality and generalization ability.

[0128] like Figure 7As shown, it can be a schematic diagram of the architecture of a method for generating SQL statements provided by this embodiment: it mainly includes data services, NL2SQL, knowledge base and basic model; users can input natural language queries into data services. Data services include data authentication, SQL execution and result data, NL2SQL includes knowledge retrieval, table retrieval, knowledge enhancement, SQL generation and SQL error correction; the knowledge base includes SQL questions and answers, business instructions, data dictionary, table metadata and field metadata; the basic model can include a vector model and an LLM model, the vector model is used to calculate vector similarity, and the LLM model is used to perform entity recognition and generate SQL statements.

[0129] Specifically, the knowledge base can supplement industry knowledge and metadata information. The process of generating SQL from natural language first performs knowledge retrieval to supplement the question and answer content. Then, table retrieval is performed to generate SQL for the target table. In order to ensure the accuracy of SQL, SQL inspection and problem correction are also required. Data services mainly include data authentication to prevent unauthorized access to data. The generated SQL is executed and the data results are returned to the user.

[0130] The present disclosure may also include a natural language SQL generation method based on data enhancement, for example, the data enhancement method may include a rewriting method, a noise-based method, and a sampling-based method. The rewriting-based method rewrites sentences to enhance sentence semantics; the noise-based method improves the robustness of the model by adding noise; the sampling-based method samples data and outputs diversified data to meet more model reasoning requirements. This embodiment can rewrite the question sentence through the rewriting method, add industry knowledge, metadata, and master data information to enhance the semantics of the question sentence, obtain questions after knowledge enhancement and questions after business knowledge supplementation, etc.

[0131] like Figure 8 As shown, it can be a specific schematic diagram of a method for generating an SQL statement provided in this embodiment: it mainly includes knowledge mapping, table recall, prompt learning, and SQL generation parts: users can input natural language queries into the query interface; in the query interface, entity extraction and SQL question and answer retrieval can be performed respectively.

[0132] Entities are extracted from natural language questions through the LLM model to obtain entities; entities are supplemented based on the knowledge base to obtain knowledge supplement (entities after knowledge supplement), dictionary values, field values ​​and enhanced prompt words. The dictionary value is the dictionary value that matches the entity after knowledge supplement; the field value is the field value that matches the entity after knowledge supplement.

[0133] SQL question and answer retrieval is performed through the SQL questions and answers (data) in the business knowledge to determine the knowledge similarity. If it is greater than or equal to 0.85, it is determined as the oneshot prompt word of the SQL question and answer; if it is less than 0.85, table recall is performed and the number of tables is determined, and a list of participating question and answer tables is obtained based on manual confirmation.

[0134] Through the LLM model, the field values, enhanced prompt words, oneshot prompt words of SQL questions and answers, and the list of participating question and answer forms are processed. SQL dialect generation, SQL execution verification, and SQL error correction can be performed based on the above data to obtain the target SQL statement.

[0135] Specifically, natural language SQL generation is to identify the query target table, data query conditions, query data content, and generate SQL in natural language; knowledge mapping is to convert natural language into query conditions and query content; table recall, query target table, prompt learning and SQL generation are to generate executable SQL dialects.

[0136] Knowledge mapping: The goal of knowledge mapping is to convert natural language into query conditions and query content, that is, to extract field information and field value ranges. First, entity recognition is performed, and then field recognition and value range recognition are performed based on entities and knowledge. Specifically, Fig. 9 As shown, the LLM model is used to perform entity recognition on natural language questions to obtain entities, and the entities are processed through the LLM model, business knowledge, data dictionary and field metadata to obtain field knowledge (target field set).

[0137] The process of entity recognition can be: based on the LLM large language model, entity extraction is completed through entity extraction prompt words, and a business knowledge vocabulary is established to improve the accuracy of entity recognition; the definition of business knowledge and examples of business knowledge vocabulary have been introduced in the above embodiments and will not be repeated here.

[0138] The process of field identification can be: entity information can correspond to table fields, data content or industry knowledge in non-metadata; entity information knowledge enhancement can be performed based on business knowledge. For example, vector similarity calculation can be performed between the entity and the knowledge base, and the business name corresponding to the entity with a similarity of more than 0.85 can be retrieved as a supplement to the entity description to obtain the knowledge-enhanced entity. This can avoid the possibility of missing information in natural language questions, and can also enable the general large model to understand industry knowledge. The knowledge-enhanced entity and the field description in the field metadata are vector similarity calculated, and the field information with a similarity of more than 0.85 is retrieved to obtain the first field. The knowledge-enhanced entity and the data dictionary value description are vector similarity calculated, and the dictionary key with a similarity of more than 0.85 is retrieved. The dictionary key is then matched with the field to query the corresponding field information and obtain the second field; based on the first field and the second field, the target field set is obtained, that is, the matched field set is obtained.

[0139] The process of value range identification can be: The value range includes dictionary enumeration values, continuous values, time range values, etc., among which dictionary enumeration values ​​have data encoding and professional characteristics. By identifying the value range, the understanding of the general large model can be guaranteed. Enumeration value identification is achieved by matching the enhanced entity with the data dictionary, calculating the vector similarity between the enhanced entity description and the data dictionary description, finding the data dictionary value corresponding to the dictionary description, and determining the value range of the dictionary value as the target value range corresponding to the entity. Optionally, the question can be "What is the cumulative revenue of popular products from January to April?" The knowledge-enhanced entity can include popular products: cloud computer, cloud host, aone, and cumulative revenue: column revenue, January to April. The entity description and the dictionary description of the data dictionary are vector similarity calculated, and the dictionary values ​​corresponding to the cloud computer, cloud host and aone are matched to be 1, 2, and 3 respectively.

[0140] Correspondingly, if the entity is a non-dictionary value, the recognition of the non-dictionary value is calculated based on the field and the enhanced entity similarity, and then the information is completed according to the data value description. This part creates an independent agent for processing. For example, the months from January to April are matched with the field "month", but the value format of the data field "month" is YYYYMM, and the year needs to be completed and the required time format is generated.

[0141] The process of table recall can be as follows: natural language table recall, first extract entity and identify table labels for the natural language of the query, then preliminarily screen the data table set according to the table labels. Then match the entity information with the knowledge base field set, and finally calculate the similarity between the field set and the field set of the data set to obtain a table set with a similarity of more than 85%, or the top N.

[0142] The process of prompt learning can be as follows: Step 1. The enterprise knowledge base usually maintains common SQL question and answer FAQ knowledge, which is used for model fine-tuning or oneshot or fewshot prompts for SQL generation. In order to supplement the missing information of natural language questions, firstly, the business knowledge is collected and matched with the query, and then the business knowledge is supplemented. Then, semantic matching is performed with the SQL question and answer FAQ of the business knowledge base, and SQL FAQ information with a similarity greater than 0.85 is queried for reference of SQL statements for OneShot or fewshot generated by SQL. Step 2. The target field set is used for SQL condition and query field information filtering, and the similarity threshold is set to 0.6. In addition, in order to ensure the correctness of the generated SQL syntax, key field information needs to be retained, such as primary key, partition field, foreign key of the calculation table, etc., to obtain the filtered data table. Step 3. The prompt information generated by SQL is obtained based on the target value domain. The single value is supplemented by key=value, and the multi-value is supplemented by the key in() format.

[0143] The process of SQL generation can be: In order to ensure that the generated SQL syntax is correct, such as Fig.10 As shown, the SQL statement generation model may include an SQL generation agent, an SQL check agent, and an SQL error correction agent, forming a self-closed loop link.

[0144] First, determine the SQL dialect with the highest accuracy of the large coding model through natural language questions and supplemented prompt words. Add custom function descriptions to the target prompt words, semantically match the explanation of custom functions with natural language queries, query similar custom functions and add them to the prompt words, and obtain the added target prompt words. Finally, generate SQL through SQL generation instructions based on the large coding model. Then perform dialect conversion. The SQL checking agent mainly performs syntax checking, executable checking, and performance checking on the generated SQL. The agent processes by checking rules and the SQL execution plan of the database, and performs executable checking through pre-execution. It also records syntax errors, performance issues, missing fields, and other issues for SQL error correction. The SQL error correction agent mainly corrects SQL statements with execution errors, performs SQL error correction based on the large coding model through the problem solving step prompt word engineering, and precipitates a problem solving step knowledge base for different problems.

[0145] The method disclosed in this disclosure can be applied to business analysis scenarios such as data governance platforms and BI report intelligent data products, and the accuracy of the generated SQL can reach 65%. The HumanEval evaluation method and pass@k indicators can be used to evaluate the effectiveness of the SQL statements generated by this disclosure. For questions of medium difficulty, the accuracy can reach 92.5%; therefore, the method provided in this disclosure can improve the R&D efficiency of data developers. In addition, business personnel can use intelligent data products to query the required data through natural language and perform self-service analysis.

[0146] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0147] Based on the same inventive concept, the embodiment of the present application also provides a device for generating SQL statements for implementing the method for generating SQL statements involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations of the embodiments of the device for generating one or more SQL statements provided below can refer to the limitations of the method for generating SQL statements above, and will not be repeated here.

[0148] In an exemplary embodiment, Fig.11As shown, a device 1100 for generating SQL statements is provided, including: a first recognition module 1102, used to perform entity recognition and table label recognition on questions through a large language model, obtain entities and table labels, and determine the data table corresponding to the table labels; a first enhancement module 1104, used to perform knowledge enhancement on entities based on a business knowledge vocabulary to obtain knowledge-enhanced entities, and match the knowledge-enhanced entities through a preset data dictionary to obtain a target field set and a value range; a first screening module 1106, used to process based on the business knowledge vocabulary, questions and value ranges to obtain target prompt words for SQL statements; and screen the data table based on the target field set to obtain the screened data table; a first generation module 1108, used to process the target prompt words of the SQL statement and the screened data table through a SQL statement generation model to generate a target SQL statement, and the target SQL statement is used to answer the question.

[0149] Each module in the above-mentioned SQL statement generation device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0150] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.12 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database of the computer device is used to store data generated by SQL statements. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for generating SQL statements is implemented. Those skilled in the art can understand that Fig.12 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0151] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the steps of the above embodiments are implemented when the processor executes the computer program.

[0152] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above embodiments are implemented.

[0153] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps in the above embodiments are implemented.

[0154] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0155] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.

[0156] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.

[0157] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for generating a SQL statement, characterized in that: The method comprises: Perform entity recognition and table label recognition on the question through a large language model to obtain entities and table labels, and determine the data table corresponding to the table labels; Performing knowledge enhancement on the entity based on the business knowledge word library to obtain a knowledge-enhanced entity, and matching the knowledge-enhanced entity through a preset data dictionary to obtain a target field set and a value domain; Processing based on the business knowledge word library, the question and the value range to obtain a target prompt word for the SQL statement; and filtering the data table based on the target field set to obtain a filtered data table; The target prompt word of the SQL statement and the screened data table are processed through the SQL statement generation model to generate a target SQL statement, and the target SQL statement is used to answer the question.

2. The method according to claim 1, characterized in that The business knowledge word library at least includes a plurality of businesses and business names; the knowledge enhancement of the entity based on the business knowledge word library to obtain the knowledge-enhanced entity includes: respectively calculating the first similarity between the business name of each business in the business knowledge word library and the entity, and obtaining the business name of the target business that meets the first similarity condition based on each of the first similarities; The entity is supplemented based on the business name of each target business to obtain a knowledge-enhanced entity.

3. The method according to claim 1, characterized in that The preset data dictionary at least includes each field, a dictionary description of each field and a dictionary value; The entity after knowledge enhancement is matched by a preset data dictionary to obtain a target field set and a target value range, including: Matching the entities enhanced with knowledge respectively through a preset data dictionary and field descriptions in field metadata to obtain a target field set; The second similarities between the knowledge-enhanced entity and the dictionary description of each field in the data dictionary are calculated respectively, and based on each of the second similarities, the dictionary value corresponding to the target dictionary description that meets the second similarity condition is obtained; and the value range of each of the dictionary values ​​is determined to be the target value range.

4. The method according to claim 3, characterized in that The entities after knowledge enhancement are matched respectively through the preset data dictionary and the field description in the field metadata to obtain the target field set, including: Calculating the third similarities between the knowledge-enhanced entity and each field description in the field metadata respectively, obtaining a target field description satisfying a third similarity condition based on each of the third similarities, and determining that the field corresponding to each of the target field descriptions is the first field; Calculating the fourth similarities between the entity after knowledge enhancement and the dictionary value of each field in the data dictionary respectively, and obtaining a target dictionary value satisfying a fourth similarity condition based on each of the fourth similarities; and determining that the field of each of the target dictionary values ​​is the second field; A target field set is obtained based on the first field and the second field.

5. The method according to claim 1, characterized in that The processing based on the business knowledge word library, the question and the value range to obtain the target prompt word of the SQL statement includes: Supplement the problem based on business knowledge to obtain the target problem supplemented by business knowledge; Semantically matching the target question with each SQL question answer information contained in the business knowledge word library to obtain matched target SQL question answer information, and generating an initial prompt word of the SQL statement based on the target SQL question answer information; The initial prompt word is supplemented based on the value range to obtain the target prompt word of the SQL statement.

6. The method according to claim 1, characterized in that The method of generating a model through an SQL statement, processing the target prompt word of the SQL statement and the screened data table to generate a target SQL statement includes: Semantically matching the explanation information of each custom function with the question to obtain a target custom function, and adding the target custom function to the target prompt word of the SQL statement to obtain the added target prompt word; Input the added target prompt word and the screened data table into the SQL statement generation model to obtain an initial SQL statement; The initial SQL statement is subjected to dialect conversion and error correction checking to obtain a target SQL statement.

7. A device for generating SQL statements, characterized in that: The device comprises: A first recognition module is used to perform entity recognition and table label recognition on the question through a large language model, obtain entities and table labels, and determine the data table corresponding to the table labels; A first enhancement module is used to perform knowledge enhancement on the entity based on a business knowledge word library to obtain a knowledge-enhanced entity, and to match the knowledge-enhanced entity through a preset data dictionary to obtain a target field set and a value domain; A first screening module is used to process based on the business knowledge word library, the question and the value range to obtain a target prompt word of the SQL statement; and to screen the data table based on the target field set to obtain a screened data table; The first generation module is used to generate a model through an SQL statement, process the target prompt word of the SQL statement and the screened data table, and generate a target SQL statement, wherein the target SQL statement is used to answer the question.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Domain knowledge supplement and SQL generation optimization method and device based on large model

    CN119938891A