Database query method and device, equipment, medium and product
By using a general large model in Text2SQL technology to synthesize query templates and build a test suite, and combining it with the pattern linking model and the open source code large model for fine-tuning, the support issues of multi-table joins and complex queries are solved, and the reliability and response rate of database queries are improved.
Patent Information
- Application Number
- CN202510741357.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-04
- Publication Date
- 2025-09-12
AI Technical Summary
Existing Text2SQL technology has limitations in supporting multi-table joins and complex queries, and the diversity of client requirements leads to poor database query reliability.
A general large model is used to synthesize query templates, and the templates are verified and expanded by building a test suite. The pattern linking model and the open source code large model are combined for fine-tuning to generate corresponding SQL query statements.
It improves the intelligent analysis capability and response rate of database queries, saves the cost of human data annotation, and enhances the reliability and diversity of database queries.
Smart Images

Figure CN120632058A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of database technology, and in particular to a database query method, apparatus, device, medium, and product. Background Art
[0002] Among related technologies, Text2SQL is becoming a key tool for database queries in the field of natural language processing. While existing Text2SQL datasets are rich and diverse, they still have certain limitations. For example, WikiSQL, while containing approximately 80,000 natural language queries and their corresponding SQL statements, primarily focuses on single-table queries, with relatively limited support for multi-table joins and complex queries. Besides the limitations of technical implementation and dataset size, the diversity of client requirements also presents a major challenge for Text2SQL.
[0003] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the Invention
[0004] The present disclosure aims to provide a database query method, apparatus, device, medium and product, which are used to overcome, at least to a certain extent, the problems of poor database query reliability caused by the limitations and defects of related technologies.
[0005] According to a first aspect of an embodiment of the present disclosure, a database query method is provided, comprising: synthesizing a query template for a target database using a general big model, the query template comprising a query question and a SQL query statement; constructing a test suite for the query template, and verifying the query template based on the test suite; expanding the content of the query template verified by the test suite to obtain a query template sample set; and fine-tuning a pattern link model and an open source code big model connected in sequence based on the query template sample set, wherein the fine-tuned pattern link model and the open source code big model are configured to generate corresponding SQL query statements in response to a query question input by a client.
[0006] In an exemplary embodiment of the present disclosure, synthesizing a query template for a target database using a general large model includes:
[0007] In response to a query pattern of the target database, synthesizing an initial query template using the general large model, wherein the initial query template does not include field values, and the query template includes field information;
[0008] Performing field replacement enhancement on the field information of the query template to generate a new query template that has the same field type as the field information;
[0009] The initial query template and the new query template are determined as query templates of the target database.
[0010] In an exemplary embodiment of the present disclosure, constructing a test suite for the query template and verifying the query template based on the test suite includes:
[0011] Selecting field values in the target database to fill the query template to obtain a query template value assignment sample;
[0012] Using a test-suite-generation algorithm to obtain an approximate SQL query statement that is similar to the SQL query statement in the query template assignment sample;
[0013] Generate an initial test database corresponding to the target database using Fuzzing technology and / or Random Selection technology;
[0014] Using a greedy algorithm to screen the initial test database to obtain a test database that can completely distinguish the SQL query statement from the similar SQL query statements, where the SQL query statement and the similar SQL query statements have different execution results in the test database;
[0015] Inputting the query question in the query template into the general large model to obtain a prediction of the execution result of the general large model on the test database;
[0016] An execution result of the general large model on the test database is determined as a test suite of the query template.
[0017] In an exemplary embodiment of the present disclosure, expanding the query template verified by the test suite to obtain a query template sample set includes:
[0018] Verifying the query template using the test suite;
[0019] Determine the test template that passes the verification as a valid query template;
[0020] The target database field value is selected to perform n content expansions on the valid query template to obtain n pairs of query template samples.
[0021] In an exemplary embodiment of the present disclosure, fine-tuning the sequentially connected pattern link model and the open source code model based on the query template sample set includes:
[0022] For the n pairs of query template samples, parsing the SQL query statements in the n pairs of query template samples to obtain field information and field values of the target database;
[0023] Combining the field information, field value, and query question to form supervised fine-tuning data, wherein the supervised fine-tuning data is used to fine-tune a pattern linking model, wherein the pattern linking model is used to output field information and field value that match the query question;
[0024] The query question in the query template sample and the pattern matching result output by the pattern linking model are combined as the prompt word input of the open source code big model, and the SQL query statement corresponding to the query question is used as the output of the open source code big model. The open source code big model is fine-tuned, and the open source code big model is used to convert the query question into an SQL query statement.
[0025] In an exemplary embodiment of the present disclosure, it further includes:
[0026] In response to a query question input by a client, the query question input by the client is input into the fine-tuned pattern link model and the open source code model to generate a corresponding SQL query statement.
[0027] In an exemplary embodiment of the present disclosure, in response to a query question input by a client, the query question is input into the schema link model and the open source code model that are sequentially connected to generate a corresponding SQL query statement, including:
[0028] Inputting the query question input by the client into the pattern linking model to obtain a pattern matching result, wherein the pattern matching result includes corresponding field information and field values in the target database;
[0029] The query question input by the client and the prompt word formed by the pattern matching result are input into the open source code model to obtain the SQL query statement corresponding to the query question input by the client.
[0030] According to a second aspect of an embodiment of the present disclosure, there is provided a database query device, comprising:
[0031] A synthesis model is configured to use a general large model to synthesize a query template for a target database, wherein the query template includes a query question and an SQL query statement;
[0032] a verification model, configured to construct a test suite for the query template and verify the query template based on the test suite;
[0033] an expansion model configured to expand the content of the query template verified by the test suite to obtain a query template sample set;
[0034] A fine-tuning model is configured to fine-tune the pattern link model and the open source code model connected in sequence based on the query template sample set. The fine-tuned pattern link model and the open source code model are configured to generate corresponding SQL query statements in response to the query questions input by the client.
[0035] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the above methods based on instructions stored in the memory.
[0036] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a program is stored. When the program is executed by a processor, the database query method as described in any one of the above items is implemented.
[0037] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein the computer program implements any one of the above-described database query methods when executed by a processor.
[0038] In an embodiment of the present disclosure, a universal big model is used to synthesize a query template for a target database. The query template includes a query question and an SQL query statement. A test suite is constructed for the query template, and the query template is verified based on the test suite. Then, the query template verified by the test suite is expanded to obtain a query template sample set. Finally, based on the query template sample set, the pattern linking model and the open source code big model connected in sequence are fine-tuned. The fine-tuned pattern linking model and the open source code big model are configured to generate corresponding SQL query statements in response to the query question input by the client, which saves the cost of human data annotation while realizing model fine-tuning, that is, the query question is converted into an SQL query statement through the fine-tuned pattern linking model and the open source code big model, effectively improving the database intelligent query analysis capability and response rate.
[0039] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification, are used to explain the principles of the present disclosure. Obviously, the drawings described below are only some embodiments of the present disclosure, and those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0041] Figure 1 A schematic diagram showing an exemplary system architecture to which the database query solution of the embodiments of the present disclosure can be applied;
[0042] Figure 2 is a flowchart of a database query method in an exemplary embodiment of the present disclosure;
[0043] Figure 3 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0044] Figure 4 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0045] Figure 5 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0046] Figure 6 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0047] Figure 7 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0048] Figure 8 is a flowchart of another database query method in an exemplary embodiment of the present disclosure;
[0049] Figure 9 is a schematic diagram of the architecture of another database query solution in an exemplary embodiment of the present disclosure;
[0050] Figure 10 is a block diagram of a database query device in an exemplary embodiment of the present disclosure;
[0051] Figure 11 is a block diagram of an electronic device in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0052] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the present disclosure will be more comprehensive and complete and will fully convey the concepts of the example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or that other methods, components, devices, steps, etc. may be employed. In other cases, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0053] The accompanying drawings are merely schematic illustrations of the present disclosure. Identical reference numerals in the drawings denote identical or similar components, and thus their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities that do not necessarily correspond to physically or logically independent entities. These functional entities may be implemented in software, in one or more hardware models or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0054] Figure 1 A schematic diagram showing an exemplary system architecture to which the database query solution of the embodiments of the present disclosure can be applied is shown.
[0055] like Figure 1 As shown, system architecture 100 may include one or more terminal devices 101, 102, 103, a network 104, and a server 105. Network 104 is a medium for providing a communication link between terminal devices 101, 102, 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0056] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as needed. For example, the server 105 may be a server cluster consisting of multiple servers.
[0057] The client can use terminal devices 101, 102, 103 to interact with server 105 via network 104 to receive or send messages, etc. Terminal devices 101, 102, 103 can be various electronic devices with display screens, including but not limited to smartphones, tablet computers, laptop computers, desktop computers, etc.
[0058] In some embodiments, the database query method provided by the embodiments of the present disclosure is generally executed by the server 105. Accordingly, the database query device is generally provided in the terminal device 103 (which may also be the terminal device 101 or 102). In other embodiments, certain terminals may have similar functions to the server device to execute the present method.
[0059] Hereinafter, exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings.
[0060] Figure 2 is a flowchart of a database query method in an exemplary embodiment of the present disclosure.
[0061] refer to Figure 2 , the database query method may include:
[0062] Step S202: synthesize a query template for the target database using a general large model, wherein the query template includes a query question and an SQL query statement.
[0063] In the above embodiment, the query template may include field information of a designated table in the target database, such as serial number, name, weight, age, etc., but is not limited thereto.
[0064] In the above embodiment, the query template cannot include field values of a specified table in the target database.
[0065] Step S204: construct a test suite for the query template, and verify the query template based on the test suite.
[0066] In the above embodiment, a set of small-scale test databases and SQL query statement execution results are constructed for the query template as a test suite, and then the content of the verified query template is expanded to obtain the final high-quality synthetic data samples, thereby improving the correctness of the synthetic data sets in various fields. Then, the pattern linking model and the code big model are trained with the synthetic data sets, which saves the cost of manually annotating samples while achieving the optimization of the pattern linking model and the code big model.
[0067] Step S206 : Expand the content of the query template verified by the test suite to obtain a query template sample set.
[0068] In the above embodiment, the query template is verified by the test suite, and the content of the verified query template is expanded, that is, the field information in the query template is expanded, and the corresponding field values are assigned to obtain the final high-quality synthetic data sample.
[0069] Step S208: Fine-tune the pattern link model and the open source code model that are connected in sequence based on the query template sample set. The fine-tuned pattern link model and the open source code model are configured to generate corresponding SQL query statements in response to the query question input by the client.
[0070] In the above embodiment, the fine-tuned pattern linking model is used to identify the query question to determine the keywords and / or field information corresponding to the query question, and the code model is used to identify the query question and the results output by the pattern linking model to determine the corresponding SQL query statement.
[0071] In an embodiment of the present disclosure, a universal big model is used to synthesize a query template for a target database. The query template includes a query question and an SQL query statement. A test suite is constructed for the query template, and the query template is verified based on the test suite. Then, the query template verified by the test suite is expanded to obtain a query template sample set. Finally, based on the query template sample set, the pattern linking model and the open source code big model connected in sequence are fine-tuned. The fine-tuned pattern linking model and the open source code big model are configured to generate corresponding SQL query statements in response to the query question input by the client, which saves the cost of human data annotation while realizing model fine-tuning, that is, the query question is converted into an SQL query statement through the fine-tuned pattern linking model and the open source code big model, effectively improving the database intelligent query analysis capability and response rate.
[0072] Below, each step of the database query method is described in detail.
[0073] In an exemplary embodiment of the present disclosure, Figure 3 As shown, the query template synthesized for the target database using a general large model includes:
[0074] Step S302 : In response to the query mode of the target database, an initial query template is synthesized using the general large model. The initial query template does not include field values, and the query template includes field information.
[0075] In the above embodiment, the initial query template only includes the key fields in the target database, that is, the above field information. The key fields can reflect the query scenario of the target database, and then a large number of personalized query templates are synthesized for the target database.
[0076] Step S304: Perform field replacement enhancement on the field information of the query template to generate a new query template that has the same field type as the field information.
[0077] In the above embodiment, field replacement enhancement is performed on the field information of the query template to generate a new query template that belongs to the same type of field as the field information. The same type of field is used to implement scenario constraints. That is, on the premise of satisfying the query scenario constraints, a large number of similar new query templates are derived from the initial query template through field replacement enhancement.
[0078] Step S306: Determine the initial query template and the new query template as query templates of the target database.
[0079] In the above embodiment, the initial query template and the new query template are determined as query templates of the target database, and a large number of query templates that meet scenario constraints are synthesized for the target database.
[0080] In an exemplary embodiment of the present disclosure, Figure 4 As shown, building a test suite for the query template and verifying the query template based on the test suite includes:
[0081] Step S402: Select field values in the target database to fill the query template to obtain a query template value assignment sample.
[0082] Step S404: using a test-suite-generation algorithm to obtain an approximate SQL query statement that is similar to the SQL query statement in the query template assignment sample.
[0083] In the above embodiment, an approximate SQL query statement similar to the SQL query statement in the query template assignment sample is obtained by adopting the test-suite-generation algorithm. Under the premise of keeping the query structure unchanged, diverse SQL query statements are generated through legal variations of syntax and semantics in the test-suite-generation algorithm.
[0084] Step S406: Generate an initial test database corresponding to the target database using Fuzzing technology and / or Random Selection technology.
[0085] In the above embodiment, the fuzzing technology is abnormal data injection, and the implementation process of using the random selection technology to generate the initial test database corresponding to the target database includes the following:
[0086] (1) Boundary value attack:
[0087] Integer: MAX_INT+1, MIN_INT-1, 0;
[0088] String: empty string, extra-long string (>1000 characters);
[0089] Date: 0000-00-00, 9999-12-31.
[0090] (2) Type confusion attack:
[0091] Injecting strings into integer fields;
[0092] Injects floating point numbers into date fields.
[0093] (3) Special character attacks:
[0094] SQL injection vector: 'OR 1=1--;
[0095] Unicode abnormal characters: \u0000, \u2028;
[0096] (3) Null value attack:
[0097] Inject NULL into the non-null constraint column;
[0098] Proportional control: 10-20% of the records contain outliers.
[0099] In the above embodiment, an example of using the Random Selection technology to generate an initial test database corresponding to the target database is shown in Table 1 below.
[0100] Table 1
[0101]
[0102]
[0103] Step S408: Using a greedy algorithm to screen the initial test database to obtain a test database that can completely distinguish the SQL query statement from the similar SQL query statements, where the execution results of the SQL query statement and the similar SQL query statements in the test database are different.
[0104] In the above embodiment, the greedy algorithm is used to screen the initial test database, which improves the reliability and accuracy of the test suite, and further improves the reliability and accuracy of the synthetic query template samples generated based on the test suite.
[0105] Step S410: Input the query question in the query template into the general big model to obtain the general big model to predict the execution result on the test database.
[0106] Step S412: Determine the execution result of the general large model on the test database as the test suite of the query template.
[0107] In the above embodiment, the query template is verified by constructing a test suite, and the content of the verified query template is expanded to obtain the final high-quality synthetic data sample, thereby ensuring the correctness of the synthetic query template data set for the target database in various fields.
[0108] In an exemplary embodiment of the present disclosure, Figure 5 As shown, the query template verified by the test suite is expanded to obtain a query template sample set including:
[0109] Step S502: verifying the query template through the test suite.
[0110] Step S504: Determine the verified test template as a valid query template.
[0111] Step S506 : Select the target database field value to perform n content expansions on the valid query template to obtain n pairs of query template samples, where n is a positive integer greater than or equal to 1.
[0112] In the above embodiment, the query template is verified by the test suite, and the verified test template is determined to be a valid query template, and then the target database field value is selected to perform n types of content expansion on the valid query template to obtain n pairs of query template samples, thereby realizing data enhancement of the query template and improving the diversity of the query template data sets of the target databases in various fields.
[0113] In an exemplary embodiment of the present disclosure, Figure 6 As shown, fine-tuning the sequentially connected pattern link model and the open source code model based on the query template sample set includes:
[0114] Step S602: parsing the SQL query statements in the n pairs of query template samples to obtain field information and field values of the target database.
[0115] Step S604: Combining the field information, field value, and query question to form supervised fine-tuning data, wherein the supervised fine-tuning data is used to fine-tune the pattern linking model, and the pattern linking model is used to output field information and field value that match the query question.
[0116] In the above embodiment, if the model connection model outputs multiple pattern matching results or 0 model matching results for the input query question, prompt information is fed back to the client to instruct the client to further supplement the key fields of the query question.
[0117] Step S606: Combine the query question in the query template sample and the pattern matching result output by the pattern linking model as the prompt word input of the open source code big model, use the SQL query statement corresponding to the query question as the output of the open source code big model, and fine-tune the open source code big model. The open source code big model is used to convert the query question into an SQL query statement.
[0118] In the above embodiment, the query question in the query template sample and the pattern matching result output by the pattern linking model are combined as the prompt word input of the open source code big model, and the SQL query statement corresponding to the query question is used as the output of the open source code big model. The open source code big model is fine-tuned. The fine-tuned open source code big model can recognize the query question and the SQL query statement corresponding to the pattern matching result, and the SQL query statement can accurately obtain the field information and / or field value in the target database.
[0119] In an exemplary embodiment of the present disclosure, Figure 7 As shown, it also includes:
[0120] Step S702: In response to a query question input by a client, the query question input by the client is input into the fine-tuned pattern link model and the open source code model to generate a corresponding SQL query statement.
[0121] In an exemplary embodiment of the present disclosure, Figure 8 As shown, in response to the query question input by the client, the query question is input into the pattern link model and the open source code model connected in sequence to generate the corresponding SQL query statement including:
[0122] Step S802: Input the query question input by the client into the pattern linking model to obtain a pattern matching result, where the pattern matching result includes corresponding field information and field values in the target database.
[0123] Step S804: input the query question input by the client and the prompt word formed by the pattern matching result into the open source code model to obtain the SQL query statement corresponding to the query question input by the client.
[0124] In an exemplary embodiment of the present disclosure, Figure 9As shown, a database query architecture 900 based on synthetic verification data is also proposed. The database query architecture 900 includes a synthesis stage 902, a training stage 904 and a query stage 906. The specific implementation process is as follows.
[0125] Step 1: For a given database table, a large number of different query templates 9022 are synthesized using a general large model (such as GPT-4o or DeepSeek). The query templates 9022 include a mapping group such as <query question, SQL query statement>, and data enhancement is performed on these query templates 9022, specifically:
[0126] Step 1.1: Based on a given database table, a hint engineering approach is used and a general large model (such as GPT-4o or QWen 2.5 72B) is used to synthesize a large number of query templates of different types 9022, which do not contain specific field values.
[0127] For example, based on a given table x of a target database, the synthetic query template 9022 is <I want to know the name of the person whose age is num, select name from x where age=num>.
[0128] Step 1.2: Perform data augmentation on each synthesized program template and replace the field names with fields of the same type in the database.
[0129] For example, replace the field age in the query template 9022 <I want to know the name of the person whose age is num, select name from x where age = num> with weight, and obtain the new query template 9022 <I want to know the name of the person whose weight is num, select name from x where weight = num>.
[0130] Step 2: For each query template 9022, build a set of small-scale test databases and SQL query statements, and obtain the execution results of the query template 9022 on these test databases, which are used as a test suite 9024 for the query template 9022. Specifically:
[0131] Step 2.1: For each query template 9022 obtained in step 1, randomly select field values from the corresponding database table to fill in, obtaining a <query question, SQL query statement> sample pair, and then use the test-suite-generation algorithm to obtain SQL query statements similar to the existing SQL query statements.
[0132] Step 2.2: Based on the database table corresponding to query template 9022, use Fuzzing technology (or Random Selection technology) to generate a large number of small-scale test databases. These small-scale test databases are completely consistent with the schema of the original target database, but have fewer data entries. For example, each table in the test database contains no more than 10 data entries.
[0133] Step 2.3: Use a greedy algorithm to select the small-scale test database obtained in the previous step, and select a group of databases that can completely distinguish the SQL query statement in query template 9022 from similar SQL query statements, that is, the execution results of the two SQL query statements on this database are different.
[0134] Step 2.4: For the query problem in query template 9022, a general large model (such as GPT-4o or QWen2.5 72B) is used to predict its execution results on a set of small-scale test databases obtained in the previous step, and then this set of small-scale test databases and the execution results predicted by the general large model are used as a test suite 9024 for the query template 9022.
[0135] Step 3: For each query template 9022, verify it with the test suite 9024 obtained in step 2, and expand the content of the query template 9022 that passes the verification to obtain the final high-quality synthetic data, specifically:
[0136] Step 3.1: For each query template 9022, verify it on the test suite 9024 obtained in step 2. If it passes the verification, the template is considered a valid template.
[0137] Step 3.2: For the query template 9022 that has passed verification, select the field values in the corresponding database table to fill in. Perform n types of filling for each template to obtain n pairs of <query question, SQL query statement> samples.
[0138] Step 3.3: Use a general large model (such as GPT-4o or QWen 2.5 72B) to rewrite the query questions in all samples, using a more colloquial questioning method while maintaining the semantics, to obtain the final high-quality synthetic samples.
[0139] Step 4: Based on the synthesized <query question, SQL query statement> sample set, fine-tune the pattern linking model (such as the RESDSQL model) and the open source code model (such as DeepseekCoder-1.3B). The pattern linking model and the open source code model are used to generate the corresponding SQL query statement according to the query question. Specifically:
[0140] Step 4.1: For the synthesized <query question, SQL query statement> sample set, parse the SQL query statement to obtain the involved tables, fields, and field values, and combine them with the query question to form supervised fine-tuning data to fine-tune the pattern linking model.
[0141] Step 4.2: Combine the query question in the <query question, SQL query statement> sample set and the pattern linking result obtained in step 4.1 as prompt input, and use the SQL query statement corresponding to the query question as output to fine-tune the open source code model (such as DeepseekCoder-1.3B).
[0142] Step 5: When the client enters a new query question, the corresponding SQL query statement is generated for it through the pattern link model and the code model, specifically:
[0143] Step 5.1: Input the query question entered by the client into the pattern linking model to obtain the pattern matching result, that is, find the corresponding table and field / field value in the target database.
[0144] If the query question is ambiguous, the client is prompted to clearly indicate the required data entries. That is, after the query question entered by the client is input into the pattern linking model, if the pattern linking model outputs multiple matching results or 0 matching results, the query question is considered ambiguous.
[0145] Step 5.2: The query question input by the client and the result of pattern matching are combined into a prompt input code model, and the code model generates the corresponding SQL query statement.
[0146] At this point, through steps 1 to 5, a database query solution based on synthetic verification data has been implemented.
[0147] Corresponding to the above method embodiments, the present disclosure also provides a database query device, which can be used to execute the above method embodiments.
[0148] Figure 10 It is a block diagram of a database query device in an exemplary embodiment of the present disclosure.
[0149] refer to Figure 10 , the database query device 1000 may include:
[0150] Synthesis model 1002 is configured to synthesize a query template for a target database using a general large model, wherein the query template includes a query question and an SQL query statement;
[0151] A verification model 1004 is configured to construct a test suite for the query template and verify the query template based on the test suite;
[0152] An expansion model 1006 is configured to expand the content of the query template verified by the test suite to obtain a query template sample set;
[0153] The fine-tuning model 1008 is configured to fine-tune the pattern link model and the open source code model connected in sequence based on the query template sample set. The fine-tuned pattern link model and the open source code model are configured to generate corresponding SQL query statements in response to the query questions input by the client.
[0154] In an exemplary embodiment of the present disclosure, the synthesis model 1002 is further configured to:
[0155] In response to a query pattern of the target database, synthesizing an initial query template using the general large model, wherein the initial query template does not include field values, and the query template includes field information;
[0156] Performing field replacement enhancement on the field information of the query template to generate a new query template that has the same field type as the field information;
[0157] The initial query template and the new query template are determined as query templates of the target database.
[0158] In an exemplary embodiment of the present disclosure, the verification model 1004 is further configured to:
[0159] Selecting field values in the target database to fill the query template to obtain a query template value assignment sample;
[0160] Using a test-suite-generation algorithm to obtain an approximate SQL query statement that is similar to the SQL query statement in the query template assignment sample;
[0161] Generate an initial test database corresponding to the target database using Fuzzing technology and / or Random Selection technology;
[0162] Using a greedy algorithm to screen the initial test database to obtain a test database that can completely distinguish the SQL query statement from the similar SQL query statements, where the SQL query statement and the similar SQL query statements have different execution results in the test database;
[0163] Inputting the query question in the query template into the general large model to obtain a prediction of the execution result of the general large model on the test database;
[0164] An execution result of the general large model on the test database is determined as a test suite of the query template.
[0165] In an exemplary embodiment of the present disclosure, the augmented model 1006 is further configured to:
[0166] Verifying the query template using the test suite;
[0167] Determine the test template that passes the verification as a valid query template;
[0168] The target database field value is selected to perform n content expansions on the valid query template to obtain n pairs of query template samples.
[0169] In an exemplary embodiment of the present disclosure, the fine-tuning model 1008 is further configured to:
[0170] For the n pairs of query template samples, parsing the SQL query statements in the n pairs of query template samples to obtain field information and field values of the target database;
[0171] Combining the field information, field value, and query question to form supervised fine-tuning data, wherein the supervised fine-tuning data is used to fine-tune a pattern linking model, wherein the pattern linking model is used to output field information and field value that match the query question;
[0172] The query question in the query template sample and the pattern matching result output by the pattern linking model are combined as the prompt word input of the open source code big model, and the SQL query statement corresponding to the query question is used as the output of the open source code big model. The open source code big model is fine-tuned, and the open source code big model is used to convert the query question into an SQL query statement.
[0173] In an exemplary embodiment of the present disclosure, the database query device 1000 is further configured to:
[0174] In response to a query question input by a client, the query question input by the client is input into the fine-tuned pattern link model and the open source code model to generate a corresponding SQL query statement.
[0175] In an exemplary embodiment of the present disclosure, the database query device 1000 is further configured to:
[0176] Inputting the query question input by the client into the pattern linking model to obtain a pattern matching result, wherein the pattern matching result includes corresponding field information and field values in the target database;
[0177] The query question input by the client and the prompt word formed by the pattern matching result are input into the open source code model to obtain the SQL query statement corresponding to the query question input by the client.
[0178] Since the functions of the apparatus 1000 have been described in detail in the corresponding method embodiments, they will not be described in detail in this disclosure.
[0179] It should be noted that although several models or units of the device for action execution are mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more models or units described above can be embodied in one model or unit. Conversely, the features and functions of one model or unit described above can be further divided into multiple models or units to be embodied.
[0180] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0181] Those skilled in the art will appreciate that various aspects of the present disclosure may be implemented as systems, methods, or program products. Therefore, various aspects of the present disclosure may be implemented in the following forms: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software implementations, which may be collectively referred to herein as "circuits," "models," or "systems."
[0182] Refer to the following Figure 11 1100 according to this embodiment of the present disclosure will be described. Figure 11 The electronic device 1100 shown is merely an example and should not limit the functions and scope of use of the embodiments of the present disclosure.
[0183] like Figure 11 As shown, electronic device 1100 is implemented as a general-purpose computing device. Components of electronic device 1100 may include, but are not limited to, the aforementioned at least one processing unit 1110, the aforementioned at least one storage unit 1120, and a bus 1130 connecting various system components (including storage unit 1120 and processing unit 1110).
[0184] The storage unit stores program code, which can be executed by the processing unit 1110, so that the processing unit 1110 performs the steps described in the "Exemplary Methods" section above according to various exemplary embodiments of the present disclosure. For example, the processing unit 1110 can perform the method shown in the embodiments of the present disclosure.
[0185] The storage unit 1120 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 11201 and / or a cache 11202 , and may further include a read-only memory unit (ROM) 11203 .
[0186] The storage unit 1120 may also include a program / utility 11204 having a set (at least one) of program models 11205, such program models 11205 including but not limited to: an operating system, one or more application programs, other program models, and program data, each of which or some combination may include an implementation of a network environment.
[0187] The bus 1130 may represent one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0188] Electronic device 1100 may also communicate with one or more external devices 1140 (e.g., a keyboard, pointing device, Bluetooth device, etc.), one or more devices that enable clients to interact with electronic device 1100, and / or any device that enables electronic device 1100 to communicate with one or more other computing devices (e.g., a router, modem, etc.). Such communication may occur via input / output (I / O) interface 1150. Furthermore, electronic device 1100 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network such as the Internet) via network adapter 1160. As shown, network adapter 1160 communicates with other components of electronic device 1100 via bus 1130. It should be understood that, although not shown, other hardware and / or software components may be used in conjunction with electronic device 1100, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0189] In summary, compared with the prior art, the main inventive features of the present disclosure include but are not limited to:
[0190] (1) Compared with the query solutions in related technologies, which use text similarity to filter the generated questions and SQL data sets, or do not verify the correctness of the generated SQL templates, the present disclosure improves the accuracy of synthetic data by automating the generation and verification of test samples, which helps to improve the accuracy of the database query system.
[0191] (2) Compared with the model training scheme in the related art, which directly uses the synthetic data set to train the model, the present invention fine-tunes the pattern linking model and the code model based on the synthetic sample set to generate SQL query statements, which can significantly improve the accuracy of the SQL statement generation results.
[0192] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.
[0193] In exemplary embodiments of the present disclosure, a computer-readable storage medium is also provided, on which is stored a program product capable of implementing the aforementioned methods of this specification. In some possible implementations, various aspects of the present disclosure may also be implemented in the form of a program product comprising program code. When the program product is executed on a terminal device, the program code is configured to cause the terminal device to execute the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of the present disclosure.
[0194] The program product for implementing the above-mentioned method according to an embodiment of the present disclosure may be a portable compact disc read-only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto. In this document, a readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0195] The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0196] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0197] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0198] In an exemplary embodiment of the present disclosure, a computer program product is also provided, which can be loaded or stored using any combination of one or more readable media, and can be written in any combination of one or more programming languages to perform the operations of the present disclosure. The programming languages include object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the client computing device, partially on the client device, as a separate software package, partially on the client computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device can be connected to the client computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0199] Furthermore, the figures above are merely illustrative of the processes included in the methods according to exemplary embodiments of the present disclosure and are not intended to be limiting. It is readily understood that the processes illustrated in the figures above do not indicate or limit the temporal order of these processes. Furthermore, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple models.
[0200] Other embodiments of the present disclosure will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the present disclosure being indicated by the claims.
Claims
1. A database query method, characterized in that: include: Using a general large model to synthesize a query template for a target database, the query template includes a query question and an SQL query statement; Building a test suite for the query template, and verifying the query template based on the test suite; Expanding the query templates verified by the test suite to obtain a query template sample set; Based on the query template sample set, the pattern link model and the open source code model connected in sequence are fine-tuned, and the fine-tuned pattern link model and the open source code model are configured to generate corresponding SQL query statements in response to the query questions input by the client.
2. The database query method according to claim 1, wherein: The query templates synthesized for the target database using a general large model include: In response to a query pattern of the target database, synthesizing an initial query template using the general large model, wherein the initial query template does not include field values, and the query template includes field information; Performing field replacement enhancement on the field information of the query template to generate a new query template that has the same field type as the field information; The initial query template and the new query template are determined as query templates of the target database.
3. The database query method according to claim 1 or 2, characterized in that: Constructing a test suite for the query template and verifying the query template based on the test suite includes: Selecting field values in the target database to fill the query template to obtain a query template value assignment sample; Using a test-suite-generation algorithm to obtain an approximate SQL query statement that is similar to the SQL query statement in the query template assignment sample; Generate an initial test database corresponding to the target database using Fuzzing technology and / or Random Selection technology; Using a greedy algorithm to screen the initial test database to obtain a test database that can completely distinguish the SQL query statement from the similar SQL query statements, where the SQL query statement and the similar SQL query statements have different execution results in the test database; Inputting the query question in the query template into the general large model to obtain a prediction of the execution result of the general large model on the test database; An execution result of the general large model on the test database is determined as a test suite of the query template.
4. The database query method according to claim 3, wherein: The query templates verified by the test suite are expanded to obtain a query template sample set including: Verifying the query template using the test suite; Determine the test template that passes the verification as a valid query template; The target database field value is selected to perform n content expansions on the valid query template to obtain n pairs of query template samples.
5. The database query method according to claim 4, wherein: Fine-tuning the sequentially connected pattern link model and the open source code model based on the query template sample set includes: For the n pairs of query template samples, parsing the SQL query statements in the n pairs of query template samples to obtain field information and field values of the target database; Combining the field information, field value, and query question to form supervised fine-tuning data, wherein the supervised fine-tuning data is used to fine-tune a pattern linking model, wherein the pattern linking model is used to output field information and field value that match the query question; The query question in the query template sample and the pattern matching result output by the pattern linking model are combined as the prompt word input of the open source code big model, and the SQL query statement corresponding to the query question is used as the output of the open source code big model. The open source code big model is fine-tuned, and the open source code big model is used to convert the query question into an SQL query statement.
6. The database query method according to claim 5, wherein: Also includes: In response to a query question input by a client, the query question input by the client is input into the fine-tuned pattern link model and the open source code model to generate a corresponding SQL query statement.
7. The database query method according to claim 6, wherein: In response to a query question input by a client, the query question is input into the schema link model and the open source code model connected in sequence to generate a corresponding SQL query statement including: Inputting the query question input by the client into the pattern linking model to obtain a pattern matching result, wherein the pattern matching result includes corresponding field information and field values in the target database; The query question input by the client and the prompt word formed by the pattern matching result are input into the open source code model to obtain the SQL query statement corresponding to the query question input by the client.
8. A database query device, characterized in that: include: A synthesis model is configured to use a general large model to synthesize a query template for a target database, wherein the query template includes a query question and an SQL query statement; a verification model, configured to construct a test suite for the query template and verify the query template based on the test suite; an expansion model configured to expand the content of the query template verified by the test suite to obtain a query template sample set; A fine-tuning model is configured to fine-tune the pattern link model and the open source code model connected in sequence based on the query template sample set. The fine-tuned pattern link model and the open source code model are configured to generate corresponding SQL query statements in response to the query questions input by the client.
9. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, wherein the processor is configured to execute the database query method according to any one of claims 1 to 7 based on instructions stored in the memory.
10. A computer-readable storage medium having a program stored thereon, wherein when the program is executed by a processor, the database query method according to any one of claims 1 to 7 is implemented.
11. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the database query method according to any one of claims 1 to 7 is implemented.