Method, device and equipment for fine-tuning query statement model based on large model
By fine-tuning the query statement model and generating accurate prompt information and query statements, the problem that the AI model cannot meet personalized query requests is solved, and the query efficiency and accuracy of the business system are improved.
Patent Information
- Application Number
- CN202411671872.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2044-11-21
AI Technical Summary
The existing AI model cannot generate prompt information that can provide in-depth prompts for query statements and query statements that cannot perform in-depth operations on the database of the business system, resulting in the in-depth improvement of the query efficiency of the business system.
By constructing prompt information including intent information of the query request, basic table information and statement structure information of the query statement, the first model and the second model in the query statement model are fine-tuned to generate accurate prompt information and query statements.
The fine-tuned query statement model can meet various personalized query requests from front-end users of various working departments in the business system, improving query efficiency and accuracy.
Smart Images

Figure CN119599131B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device and equipment for fine-tuning a query statement model based on a large model. Background Art
[0002] In the business systems of various enterprises, institutions and group companies, the database is usually connected to the front-end application through the back-end server, so that the front-end business personnel can perform operations such as querying the data in the database. In actual operation, the front-end business personnel send a query request through the front-end application, and the back-end server determines the corresponding query statement based on the query request and sends the query statement to the database, so that the database can query the data in the database according to the query statement, and then transmit the query results to the front-end application through the back-end server.
[0003] In the existing technology, the back-end server can generate query statements through an AI (Artificial Intelligence) big model. In actual operation, an AI big model is first used to generate prompt information based on the query request, and then another AI big model is used to generate a query statement based on the query request and the prompt information.
[0004] In the above technical solution, although the prompt information can effectively prompt the generation of query statements, according to actual experience, the existing AI big models used to generate prompt information and query statements in different business systems are usually only pre-trained, resulting in the inability to use AI big models to generate prompt information that can provide deep prompts for query statements and query statements that can perform deep operations on the database of the business system. That is, the existing AI big models are simply unable to meet the various personalized query requests of front-end users of various work departments in the business system, which ultimately leads to the query efficiency of the business system being unable to be effectively improved. Summary of the Invention
[0005] In view of this, the purpose of this application is to provide a query statement model fine-tuning method, device and equipment based on a large model to solve the technical problem that the existing AI large model for generating prompt information and generating query statements is simply unable to meet the various personalized query requests of front-end users of various work departments in the business system, which ultimately leads to the query efficiency of the business system cannot be effectively improved.
[0006] In a first aspect, the present application provides a method for fine-tuning a query statement model based on a large model, the method comprising:
[0007] Determine the prompt information corresponding to the query corpus of the target business system;
[0008] The query corpus includes: multiple query requests and query statements corresponding to each query request; the query request is in natural language form; the prompt information includes: intent information and basic table information of the query request and sentence structure information of the query statement;
[0009] Fine-tuning the query statement model based on the plurality of query requests and the query statement and the prompt information corresponding to each query request;
[0010] Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information according to the target query request input by the user to the target business system; the second model is used to generate a target query statement according to the target query request and the target prompt information.
[0011] In a second aspect, the present application provides a query statement model fine-tuning device based on a large model, the device comprising: a prompt information module and a fine-tuning module;
[0012] The prompt information module is used to determine the prompt information corresponding to the query corpus of the target business system;
[0013] The query corpus includes: multiple query requests and query statements corresponding to each query request; the query request is in natural language form; the prompt information includes: intent information and basic table information of the query request and sentence structure information of the query statement;
[0014] The fine-tuning module is configured to fine-tune the query statement model based on the plurality of query requests and the query statement and the prompt information corresponding to each query request;
[0015] Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information according to the target query request input by the user to the target business system; the second model is used to generate a target query statement according to the target query request and the target prompt information.
[0016] In a third aspect, the present application provides an electronic device comprising a processor and a memory, wherein the memory is used to store an application program, and the processor runs or executes a software program stored in the memory so that the electronic device implements the above-mentioned large-model-based query statement model fine-tuning method.
[0017] In a fourth aspect, the present application provides a computer-readable storage medium, which is used to store program code executed by a processor, and the program code is used to implement the above-mentioned large-model-based query statement model fine-tuning method.
[0018] In a fifth aspect, the present application provides a computer program product, which includes computer instructions. When the computer instructions are run on an electronic device, the electronic device implements the above-mentioned large-model-based query statement model fine-tuning method.
[0019] Beneficial effects:
[0020] The present application provides a method for fine-tuning a query statement model based on a large model, the method comprising: determining prompt information corresponding to a query corpus of a target business system; wherein the query corpus comprises: multiple query requests and a query statement corresponding to each query request; the query request is in a natural language form; the prompt information comprises: intent information and basic table information of the query request and sentence structure information of the query statement; fine-tuning a query statement model is performed based on the multiple query requests and the query statement corresponding to each query request and the prompt information; wherein the query statement model comprises: a first model and a second model; the first model is used to generate target prompt information according to a target query request input by a user to the target business system; the second model is used to generate a target query statement according to the target query request and the target prompt information;
[0021] In summary, the query statement model fine-tuning method based on a large model provided in the present application is used to simultaneously fine-tune the first model and the second model in the query statement model by constructing prompt information including the intent information of the query request, basic table information, and statement structure information of the query statement, so that the fine-tuned first model can generate accurate prompt information according to various personalized query requests of front-end users of various work departments in the business system, and the fine-tuned second model can generate accurate query statements according to various personalized query requests and corresponding prompt information. Therefore, the fine-tuned query statement model in the present application can meet various personalized query requests of front-end users of various work departments in the business system. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. The following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 A structural diagram of a data query system provided in an embodiment of the present application;
[0024] Figure 2 A flowchart of a method for fine-tuning a query statement model based on big data provided in an embodiment of the present application;
[0025] Figure 3 This is a structural diagram of the query statement model fine-tuning device based on big data provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] In various enterprises, institutions, and group companies, in order to facilitate business expansion and company management, various personalized query requirements often arise, such as "Count contracts with a contract value of 5 million and a contract term of more than two years" or "Count the employee numbers and names of employees with more than 5 days of remaining annual leave and an average salary of 8,000." When the above data is stored in a database, since query operations against the database usually require query statements corresponding to the database, such as SQL (Structured Query Language), technical personnel who are capable of writing query statements are usually required to write query statements based on the query requirements. For some query requests with lower difficulty, the corresponding query statements are usually pre-installed in the business system content for direct retrieval. For some query requests with higher difficulty, technical personnel are required to write query statements in real time. This results in a constant time interval between "issuing the query request" and "receiving the query results." If the query request changes during this period, the above time interval will be further extended, resulting in very low efficiency of manual query.
[0027] With the development of AI big models, backend servers can use AI big models to generate query statements. First, an AI big model is used to generate prompt information based on the query request, and then another AI big model is used to generate query statements based on the query request and prompt information. However, based on actual experience, existing AI big models are unable to generate prompt information that can provide in-depth prompts for query statements or query statements that can perform in-depth operations on the business system database.
[0028] The reason for this is that the database settings corresponding to different business systems are determined based on actual needs. This makes it impossible for existing AI models to accurately understand the database table structure. For example, even for the same query request, when the corresponding data is in different databases, the query statements generated based on the query request are usually different. Therefore, the query statements are highly dependent on the manually designed database table structure.
[0029] For example, for the query request "Count the employee numbers and names of employees with less than 5 days of annual leave remaining," since this query request is relatively simple, it may only need to query one basic table to obtain the query results. Therefore, the corresponding query statement is relatively simple, and the existing AI model is fully capable of handling it. However, for the query request mentioned above, "Count the employee numbers and names of employees with more than 5 days of annual leave remaining and an average salary of 8,000," according to common sense, employee annual leave and employee salaries are usually counted in different basic tables. However, the query statements generated by the existing large model, which has only been simply fine-tuned, for query requirements involving multiple basic tables are often inaccurate, resulting in inaccurate query results.
[0030] For another example, for the query request "collect the information of the private enterprise suppliers with the largest number of winning bids in projects with an open bidding amount of more than 500,000 in our city in the past 20 years, preferably with information such as years of establishment and company size", since the above query indicators include "open bidding amount", "number of winning bids" and "years of establishment", the above query indicators may be scattered in multiple basic tables. For example, some enterprises and institutions tend to count annual bidding data in a basic table, and some enterprises and institutions tend to count bidding data every two years in a basic table, which greatly increases the difficulty of determining the statement structure of the corresponding query statement; in addition, since the amount of data in the basic table related to "city bidding" may be very large, it may cause the database 300 to be delayed or even stuck when executing certain query statements, further resulting in delayed query results or even the return of erroneous query results, ultimately seriously affecting query efficiency and query quality.
[0031] In today's era of rapid technological development, the popularity of AI big models is unstoppable. In order to solve the application difficulties of existing AI big models in generating query statements, this application provides a technical solution for fine-tuning the query statement model based on a big model. The solution is based on Figure 1 The data query system implementation shown is different from the prior art in that the present application improves the ability of the query statement generated by the fine-tuned query statement model based on the large model and the accuracy of the generated query statements by providing more prompt information in the fine-tuning stage of the AI large model.
[0032] In summary, the existing AI big model cannot meet the various personalized query requests of front-end users in various work departments in the business system, which ultimately leads to the inability to effectively improve the query efficiency of the business system.
[0033] In order to solve the above technical problems, this application provides a data query system; Figure 1 As shown, Figure 1This is a structural diagram of a data query system provided in an embodiment of the present application. The data query system includes: a front-end application 100, a back-end server 200 and a database 300. In actual operation, the user inputs a query request in natural language to the front-end application 100 in text form or voice form, such as "Query the employee number and name of employees with a remaining annual leave of more than 5 days and an average salary of 8,000". The front-end application 100 transmits the query request to the back-end server 200. The back-end server 200 generates prompt information corresponding to the query request through the first model in the preset query statement model, and then generates a query statement corresponding to the query request and the prompt information through the second model in the query statement model; the back-end server 200 sends the query statement to the database 300, and the database 300 executes the query statement to obtain the query result, and then sends the query result to the user through the back-end server 200 and the front-end application 100.
[0034] It should be emphasized that in the database system, it is the database management system that receives query statements and executes query statements to control the processing of data in the database. Since the execution steps of the database system are existing technologies, the cooperation between the database management system and the database is referred to separately by database 300.
[0035] The terms used in the following examples of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. As used in the specification and appended claims of the present application, the singular expressions "a", "an", "above", "the", and "this" are intended to include plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in the present application refers to and includes any or all possible combinations of one or more of the listed items.
[0036] First, this application provides a query statement model fine-tuning method based on a large model, such as Figure 2 As shown, Figure 2 This is a flowchart of a method for fine-tuning a query statement model based on a large model provided in an embodiment of the present application. The method includes: S110 to S120, as detailed below:
[0037] S110: Determine prompt information corresponding to the query corpus of the target business system;
[0038] The query corpus includes: multiple query requests and query statements corresponding to each query request; the query request is in natural language form; and the prompt information includes: intent information of the query statement, basic table information, and statement structure information.
[0039] Specifically, the target business system refers to the various office systems used by users of various enterprises, institutions and group companies in the course of their office work. For example, the target business system corresponding to an insurance company is the insurance business system, and the data therein mostly involves insurance business data such as the insured amount; the target business system corresponding to a financial company is the financial business system, and the data therein mostly involves financial business data such as profit margin.
[0040] In an embodiment of the present application, in order to improve the matching of the query statement model with the target business system, the query statement model is enabled to generate accurate and efficient query statements based on an accurate understanding of the query requests issued by the user in natural language. Therefore, it is necessary to obtain various query requests from various work departments with data query needs in the target business system.
[0041] It should be noted that there are many types of databases and query statements. The embodiments of this application will subsequently use relational databases and SQL statements as examples to provide specific examples of the method for fine-tuning the query statement model based on a large model.
[0042] In the embodiment of the present application, the query request used to fine-tune the query statement model is in natural language form. This is because if the fine-tuned query statement model can generate query statements based on the query statements in natural language form, the processing capability of the fine-tuned query statement model can be significantly improved.
[0043] In the embodiment of the present application, the query corpus includes: a plurality of query requests and a query statement corresponding to each query request;
[0044] The query request is retrieved from the operation records of the target business system. In actual applications, the types of query requests should cover as many personalized query requests as possible from users of multiple work departments in the target business system. In actual implementation, in order to improve the statement generation capability of the fine-tuned query statement model, it is also necessary to construct query requests that cannot be accurately resolved by the existing query statement model based on the business data of the target business system and use them as query requests to fine-tune the query statement model, so as to improve the fine-tuned query statement model's ability to understand and process query requests.
[0045] For query requests retrieved from the operation records of the target business system, the query statements can be retrieved from the query records of the existing query statement model; as for the constructed query requests, the corresponding query statements can be determined by technical personnel.
[0046] In an embodiment of the present application, the prompt information includes: the intent information of the query request and the basic table information and statement structure information of the query statement; in actual applications, the determination of the "intent information" helps to determine the "basic table information" and "statement structure information".
[0047] Among them, "intent information" refers to the "background knowledge" of the query request. For example, the intent information can be "sales department" or "July 2024";
[0048] "Basic table information" refers to the basic table information in the database for the data involved in the query request. In actual applications, the database includes various basic tables pre-built by users from different work departments of the target business system based on business needs, such as a basic table recording employee recruitment information and a basic table recording the returns of the funds on sale over the past three years. Therefore, the prompt information should include basic table information that points to and / or prompts the above basic tables;
[0049] "Statement structure information" refers to the structure and composition information of a query statement. In actual applications, since a query request may correspond to multiple query statements with different statement structures, for example, the query efficiency will be higher when the current query request uses the xxx clause, the prompt information should also include pointing to and / or the above-mentioned statement structure information that can improve the query accuracy and / or query efficiency. For example, the statement structure information may be "use JOIN clause."
[0050] In one implementation, after S110, the method further includes: steps (1) to (3), the details of which are as follows:
[0051] Step (1): replacing the spatiotemporal information and / or query indicators of the query request in the query corpus to obtain a first new query request, and determining the query statement corresponding to the first new query request.
[0052] Specifically, spatiotemporal information includes time information such as year, month, day, and hour, as well as geographical information such as xxx province and xxx street.
[0053] The purpose of obtaining new query requests is to enrich the types and number of fine-tuning samples, improve the generalization of the fine-tuned query statement model, and further improve the accuracy of the query statements generated by the query statement model; in an embodiment of the present application, a fine-tuning sample includes at least: a query request, a query statement corresponding to the query request, and a prompt message corresponding to the query request.
[0054] For example, for the query request "find contracts with a contract value of 5 million and a contract term of more than two years", "two years" can be replaced with "three years" to obtain the first new query request "find contracts with a contract value of 5 million and a contract term of more than three years".
[0055] For another example, for the query request "Count the employee numbers and names of employees with 5 days of remaining annual leave", "annual leave" can be replaced with "marriage leave" to obtain the first new query request "Count the employee numbers and names of employees with 5 days of remaining marriage leave".
[0056] The query indicator in a query request is key information that can affect the query result of the query request. The query indicator is usually related to the filter condition. An example is shown below:
[0057] "SELECT Sname,Sno
[0058] FROM Student;”
[0059] The above SQL statement means to query the names and student numbers of all students from the basic table named Student; among them, "name" and "student number" are query indicators in the query request.
[0060] It should be emphasized that, in the process of obtaining the first newly added query request, the information that can be replaced for the query request is not limited to spatiotemporal information and / or query indicators, but any information that can affect the query statement can be replaced.
[0061] Step (2): performing synonym replacement on the single words and / or short words in the query request and the first newly added query request to obtain a second newly added query request.
[0062] Specifically, for the query request "Contracts with a statistical contract amount of 5 million and a contract term of more than two years", the "contract amount" can be replaced with "total price" to obtain the second new query request "Contracts with a statistical total price of 5 million and a contract term of more than two years".
[0063] Step (3): determining prompt information corresponding to the first new query request and the second new query request respectively according to the first new query request, the second new query request and the query statements respectively corresponding thereto;
[0064] The first new query request, the query statement corresponding to the first new query request, and the prompt information, and the second new query request, the query statement corresponding to the second new query request, and the prompt information are used to fine-tune the query statement model.
[0065] Specifically, after generating the query statements and prompt information corresponding to the first new query request and the second new query request respectively, each first new query request and each second new query request and their corresponding query statements and prompt information can be assembled into a fine-tuning sample for fine-tuning the query statement model.
[0066] In one implementation, the intent information includes: business scenario information, context information, and spatiotemporal information; S110 includes: step (4), details of which are as follows:
[0067] Step (4): determining the business scenario information, context information, and spatiotemporal information corresponding to each of the multiple query requests through an intent recognition model according to the query request;
[0068] Among them, the business scenario information indicates the business scope of the work department corresponding to the query request in the target business system; the context information indicates the association information between the current query request and the previous query request; and the spatiotemporal information indicates the time information and geographical information in the query request.
[0069] Specifically, the query statement model in the embodiment of the present application is used to serve the query requests in natural language output by users of the target business system. Therefore, the query requests are usually colloquial and lack key elements, which causes the existing query statement model to be unable to accurately understand the query requests, and further leads to the inability to generate accurate query statements. Therefore, it is necessary to supplement the query requests in natural language with corresponding information, such as business scenario information, context information and spatiotemporal information.
[0070] Business scenario information is used to supplement the business scope of the work department for the query request. In actual business, different indicators may have different meanings for different work departments.
[0071] For example, for the query indicator "sales", this query indicator may refer to the contract amount completed in the sales department, but in the finance department, this query indicator may refer to the part of revenue that has been confirmed. Therefore, it is necessary to supplement the query request with the prompt information of the above part so that the query statement model can clarify the actual meaning of the query indicator and the basic table corresponding to the query indicator before generating the query statement.
[0072] The context information indicates the correlation between the current query request and the previous query request. Because some key information may exist in the previous query request, the current query request will not further explain the key information.
[0073] For example, if the previous query request was "Which contracts with a contract value of 6 million are currently being executed?", and the current query request is "What about those with a contract value of 5 million?"; in the second query request mentioned above, "5 million" is obviously used to replace the "6 million" in the first query request. However, if the connection between the two query requests is not prompted, it is likely that the existing query statement model will not be able to accurately understand the query request, and further lead to the inability to generate accurate query statements.
[0074] In actual operation, new query requests can be added by adding modal particles in multiple positions in the query request to try to imitate various types of query requests that the target business system may receive, thereby further expanding the query request.
[0075] It should be emphasized that during the use of the query statement model, the business department that issues the query request is provided to the query statement model by the front-end application 100 through the back-end server 200. In actual operation, it can be specifically determined through interface information, and this application will not go into details about this.
[0076] In an embodiment of the present application, the intent recognition model is obtained by training a large AI model.
[0077] In one implementation, the basic table information includes: the number of basic tables, table structure information of each basic table, and the size of the data in each basic table; the query request includes at least one query index; S110 further includes: step (5), the details of which are as follows:
[0078] Step (5): according to the query index, determining the basic table information of the target basic table corresponding to the query request in the database corresponding to the target business system;
[0079] The target basic table is a basic table including fields corresponding to the query index.
[0080] Specifically, after determining the query index, the number of target basic tables may be determined among all basic tables in the database, as well as the table structure information of each target basic table and the size of the data in each target basic table.
[0081] Table structure information usually includes: table name, fields, records, data types, primary keys (primary codes), foreign keys (foreign codes), constraints and indexes, etc.; the fields in the basic table are the attribute names of the attribute columns, which correspond to the query indicators in the query request. For example, the query indicators in the query request "Query the employee numbers and names of employees with more than 5 days of remaining annual leave and an average salary of 8,000" are "annual leave", "average salary", "employee number" and "name". In order to generate the corresponding query statement (the query statement needs to specify the basic table where the data is located), it is necessary to find the basic tables with fields such as "annual leave", "holiday", "salary", "average salary", "employee number" and "name" in the multiple existing basic tables in the database, and determine the above multiple basic tables as the target basic tables.
[0082] In one implementation, the statement structure information includes query strategies and query clauses. The query strategies include join queries, nested queries, set queries, and queries based on derived tables. S110 also includes step (6), details of which are as follows:
[0083] Step (6): Determine the corresponding statement structure information according to the query statement.
[0084] Specifically, in the prior art, technicians can select appropriate query strategies and query clauses based on a comprehensive consideration of factors such as specific needs, the amount of data in the basic table, and system performance. However, a query statement model that has not been fine-tuned through the fine-tuning samples in the embodiments of this application cannot determine the query strategy and query clause. It can only fill in the relevant parameters into the preset template, which ultimately causes the generated SQL statement to occupy more system resources, resulting in a decrease in query performance.
[0085] After determining the query statement, the query strategy and query clauses in the query statement can be determined accordingly. When the number of basic tables including the query indicators is greater than or equal to 2, a "multi-table query" is required. When performing a multi-table query, query statements using different query strategies need to be constructed according to different situations. Query strategies include join queries, nested queries, set queries, and queries based on derived tables. Query statements using different query strategies have different statement structures.
[0086] In the query statement for the query request, certain query clauses with fixed operation meanings can be used to perform data operations. For example, in SQL statements, the more common clauses used for data query usually include: SELECT clause, FROM clause and WHERE clause, and the more special clauses used for data query usually include: GROUP BY clause, HAVING clause, ORDER BY clause, LIMIT clause, JOIN clause, DISTINCT clause and INTO clause; among them, the GROUP BY clause is used to group data by one or more columns; the HAVING clause is used to filter the grouped results; the ORDER BY clause is used to sort the query results; the LIMIT clause is used to limit the number of records returned; the JOIN clause: used to connect multiple tables and retrieve data based on the related fields between these tables; the DISTINCT clause is used to remove duplicate records in the query results; the INTO clause is used to insert the query results into another table.
[0087] In one implementation, after S120, the method further includes: step (7), the details of which are as follows:
[0088] Step (7): inputting the target query request input by the user into the target business system into the first model, and allowing the first model to determine the target prompt information according to the target query request;
[0089] Among them, the intent information and basic table information in the target prompt information are determined by the first model based on the target query request; the query strategy in the target prompt information is determined by the first model based on the scale of data volume and the number of basic tables in the basic table information; the query clause in the target prompt information is determined by the first model based on the data operation corresponding to the query request, and the data operations include: grouping, filtering, sorting and deduplication.
[0090] Specifically, step (7) is the process of using the fine-tuned query statement model;
[0091] In actual operation, the front-end application 100 sends the target query request in the natural language form input by the user and the target interface information of the electronic device where the front-end application 100 is located to the back-end server 200, and the back-end server 200 transmits the query request and the interface information to the first model; wherein the "target" mentioned in step (7) is used to indicate that the query request is determined by the user in the process of using the fine-tuned query statement model;
[0092] The inference logic of the first model to generate target prompt information is as follows:
[0093] 1) The first model determines the intent information (including business scenario information, context information, and spatiotemporal information), basic table information, and the data operations corresponding to the query request (including grouping, filtering, sorting, and deduplication) based on the target query request and target interface information;
[0094] The process of determining the query strategy and query clauses requires reference to the size of the data in the basic tables and the number of the basic tables. Therefore, before determining the query statement structure information, the basic table information needs to be determined first.
[0095] In the embodiment of the present application, the number of basic tables and the size of the data in each basic table can be set to multiple intervals respectively; the interval of the number of basic tables can be referred to as the quantity interval, and the interval of the size of the data in the basic tables can be referred to as the size interval; in actual operation, the corresponding query strategy and query clause can be determined according to the quantity interval of the number of basic tables corresponding to the query request and the size interval of the corresponding data size;
[0096] For example, the quantity interval can be set to [0, 1], [2, 4], [5, ∞], with the unit being pieces;
[0097] The scale interval can be set to [0, 200], [201, 800], [801, 2000], and the unit is the number of records.
[0098] After the above-mentioned intervals are set, for a specific query request, if the number interval to which the number of basic tables belongs is [2, 4], the scale interval to which the number of two basic tables belongs is [0, 200], and the scale interval to which the number of the third basic table belongs is [201, 800]; in this embodiment of the present application, the query strategy corresponding to the query request is determined to be a connection query.
[0099] In practical applications, how to determine different query strategies based on different quantity intervals and scale intervals can be determined according to actual needs.
[0100] 2) The first model determines a query strategy based on the amount of data in the basic table and the number of basic tables in the basic table information, and the first model determines a query clause based on the data operation;
[0101] When the query request is determined, the data operation required for the data in the basic table of the database can also be determined, and accordingly, the query clause corresponding to the data operation can also be determined.
[0102] In actual operation, the functions of the above-mentioned special clauses in the SQL statement can also be completed by other clauses; for example, the results of multiple SELECT statements can be merged and aggregate functions can be used in each SELECT statement to calculate group statistical information. Although the above-mentioned execution logic can also realize the function of the GROUP BY clause, it is far less efficient than using the GROUP BY clause. Therefore, the embodiment of the present application prompts query requests that require the use of special clauses, so that the fine-tuned query statement model can obtain accurate query statements.
[0103] It should be emphasized that the data operations corresponding to the query request are not limited to grouping, filtering, sorting, and deduplication. The specific operations can be determined according to actual needs. The above are only shown for example.
[0104] 3) The first model assembles intent information, basic table information and sentence structure information (including query strategy and intent information) into target prompt information.
[0105] Among them, in actual operation, in the process of fine-tuning the first model through fine-tuning samples, inference guidance information can be added to the fine-tuning samples, such as "first determine the intent information, and then based on...", to guide the first model to generate prompt information according to the inference logic mentioned above; it should be emphasized that the essence of "inference guidance information" is also prompt information, but there are two reasons for defining it as inference guidance information: first, the inference guidance information is only used in the fine-tuning stage for the first model. After fine-tuning the first model through a large number of fine-tuning samples, the first model can master the inference logic. Therefore, when the user uses the fine-tuned first model and the second model, there is no need to generate the inference guidance information to assist the first model in generating prompt information; second, in order to distinguish the prompt information used by the second model in the embodiment of the present application and prevent semantic confusion;
[0106] It should be emphasized that the reason why the inference guidance information is only used in the fine-tuning stage of the first model is because the inference logic guided by the inference guidance information is fixed and will not change due to different query requests; however, the prompt information generated by the first model will change according to different information such as the query request. Therefore, accurate prompt information must be generated by the first model to prompt the second model to generate accurate query statements.
[0107] S120: fine-tuning a query statement model based on the plurality of query requests and the query statement and the prompt information corresponding to each query request;
[0108] Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information according to the target query request input by the user to the target business system; the second model is used to generate a target query statement according to the target query request and the target prompt information.
[0109] Specifically, in actual operation, in addition to query requests, query statements and prompt information, the fine-tuning sample usually also includes: a query statement generation command, which is used to command the query statement model to generate a query statement, such as "Please generate an SQL query statement."
[0110] An example of a fine-tuning sample is shown below:
[0111] For the question "Please generate an SQL query statement to query the profit margin [indicator name] in X District [region], X City, X Province, from October 2023 to October 2024 [date]", the prompt word can be "There are 2 basic tables, the data volume of basic table A is 500, and the data volume of basic table B is 800. Generate an SQL query statement based on basic table A {field 1, field 2, ...} and basic table B {field 1, field 2, ...} to query the average profit margin of the sales department [scenario]. It is recommended to use a nested query..."
[0112] In actual operation, the query statement model can be an open source large model, or it can be a query statement model currently used by the target business system to generate SQL statements. This application does not make specific restrictions on this.
[0113] In summary, the query statement model fine-tuning method based on a large model provided in the embodiment of the present application is used to simultaneously fine-tune the first model and the second model in the query statement model by constructing prompt information including the intent information of the query request, basic table information, and statement structure information of the query statement, so that the fine-tuned first model can generate accurate prompt information according to various personalized query requests of front-end users of various work departments in the business system, and the fine-tuned second model can generate accurate query statements according to various personalized query requests and corresponding prompt information. Therefore, the fine-tuned query statement model in the present application can meet various personalized query requests of front-end users of various work departments in the business system.
[0114] In the second aspect, the present application provides a query statement model fine-tuning device based on a large model, such as Figure 3 As shown, Figure 3 This is a structural diagram of a query statement model fine-tuning device based on a large model provided in an embodiment of the present application. The device includes: a prompt information module 410 and a fine-tuning module 420;
[0115] The prompt information module 410 is used to determine prompt information corresponding to the query corpus of the target business system; wherein the query corpus includes: multiple query requests and query statements corresponding to each query request; the query requests are in natural language form; the prompt information includes: query request intent information and basic table information and query statement structure information;
[0116] A fine-tuning module 420 is configured to fine-tune the query statement model based on multiple query requests and the query statements and prompt information corresponding to each query request;
[0117] Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information according to the target query request input by the user to the target business system; the second model is used to generate a target query statement according to the target query request and the target prompt information.
[0118] In one implementation, the fine-tuning module 420 is further configured to replace the spatiotemporal information and / or query indicators of the query request in the query corpus to obtain a first newly added query request, and determine a query statement corresponding to the first newly added query request;
[0119] The fine-tuning module 420 is further configured to perform synonym replacement on the single words and / or short words in the query request in the query corpus and the first newly added query request to obtain a second newly added query request, and determine a query statement corresponding to the second newly added query request;
[0120] The fine-tuning module 420 is further configured to determine the prompt information corresponding to the first newly added query request and the second newly added query request, respectively, based on the first newly added query request, the second newly added query request, and the query statements corresponding thereto;
[0121] The first newly added query request, the query statement corresponding to the first newly added query request, and the prompt information, and the second newly added query request, the query statement corresponding to the second newly added query request, and the prompt information are used to fine-tune the query statement model.
[0122] In one implementation, the intent information includes: business scenario information, context information, and spatiotemporal information; the prompt information module 410 is further configured to determine, based on the query request, the business scenario information, context information, and spatiotemporal information corresponding to each of the multiple query requests using the intent recognition model;
[0123] Among them, the business scenario information indicates the business scope of the work department corresponding to the query request in the target business system; the context information indicates the association information between the current query request and the previous query request; and the spatiotemporal information indicates the time information and geographical information in the query request.
[0124] In one implementation, the basic table information includes: the number of basic tables, table structure information of each basic table, and the size of the data in each basic table; the query request includes at least one query index; the prompt information module 410 is further configured to determine, in the database corresponding to the target business system, basic table information corresponding to the query request based on the query index;
[0125] The target basic table is a basic table including fields corresponding to the query index.
[0126] In one implementation, the statement structure information includes query strategies and query clauses. The query strategies include join queries, nested queries, set queries, and queries based on derived tables. The prompt information module 410 is also used to determine the corresponding statement structure information based on the query statement.
[0127] In one implementation, the apparatus further includes: a data transmission module;
[0128] A data transmission module, configured to input the target query request input by the user into the target business system into the first model, and enable the first model to determine the target prompt information according to the target query request;
[0129] Among them, the intention information and the basic table information in the target prompt information are determined by the first model according to the target query request; the query strategy in the target prompt information is determined by the first model according to the scale of the data volume in the basic table in the basic table information and the number of basic tables; the query clause in the target prompt information is determined by the first model according to the data operation corresponding to the query request, and the data operation includes: grouping, filtering, sorting and deduplication.
[0130] Third, the present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, steps S110 to S120 provided in the above embodiment are implemented.
[0131] Fourth, the present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, steps S110 to S120 of the above embodiment are executed.
[0132] Fifth, the computer program product provided in this application includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method in the previous method embodiment. For specific implementation, please refer to steps S110 to S120 of the method embodiment, which will not be repeated here.
[0133] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interface, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0134] In addition, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0135] Furthermore, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0136] It should be noted that if the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0137] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any actual relationship or order between these entities or operations.
[0138] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, various modifications and variations of the present application are possible. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A query statement model fine-tuning method based on a large model, characterized in that: The method comprises: Determine the prompt information corresponding to the query corpus of the target business system; The query corpus includes: multiple query requests and query statements corresponding to each query request; the query request is in natural language form; the prompt information includes: intent information and basic table information of the query request and statement structure information of the query statement; the intent information includes: business scenario information, the business scenario information indicates the business scope of the work department corresponding to the query request in the target business system, and the same query indicator has the same or different meanings for different work departments; the statement structure information includes: query strategies and query clauses, and the query strategies include: join query, nested query, set query and query based on derived table; Fine-tuning the query statement model based on the plurality of query requests and the query statement and the prompt information corresponding to each query request; Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information based on the target query request input by the user to the target business system; the second model is used to generate a target query statement based on the target query request and the target prompt information; the query strategy is determined by the first model based on the scale of the data volume in the basic table in the basic table information and the number of the basic tables; the query clause is determined by the first model based on the data operation corresponding to the query request.
2. The method according to claim 1, characterized in that Before fine-tuning the query statement model, the method further includes: Replacing the spatiotemporal information and / or query index of the query request in the query corpus to obtain a first new query request, and determining the query statement corresponding to the first new query request; performing synonym replacement on the single words and / or short words in the query request in the query corpus and the first newly added query request to obtain a second newly added query request, and determining the query statement corresponding to the second newly added query request; Determining prompt information corresponding to the first new query request and the second new query request, respectively, according to the first new query request, the second new query request, and the query statements corresponding thereto; The first new query request, the query statement corresponding to the first new query request, and the prompt information, and the second new query request, the query statement corresponding to the second new query request, and the prompt information are used to fine-tune the query statement model.
3. The method according to claim 1, characterized in that The intention information includes: context information and spatiotemporal information; the prompt information corresponding to the query corpus of the target business system includes: According to the query request, determining the business scenario information, context information and spatiotemporal information corresponding to each of the multiple query requests through an intent recognition model; The context information indicates the association information between the current query request and the previous query request; the spatiotemporal information indicates the time information and geographical information in the query request.
4. The method according to claim 1, wherein The basic table information includes: the number of basic tables, table structure information of each basic table, and the size of the data in each basic table; the query request includes at least one query indicator; the prompt information corresponding to the query corpus of the target business system is determined, and further includes: Determining, in a database corresponding to the target business system, basic table information corresponding to a target basic table of the query request according to the query index; The target basic table is a basic table including fields corresponding to the query index.
5. The method according to claim 1, wherein The prompt information corresponding to the query corpus of the target business system is determined, and further includes: According to the query statement, the corresponding statement structure information is determined.
6. The method according to claim 5, characterized in that After fine-tuning the query statement model, the method further includes: Inputting the target query request input by the user to the target business system into the first model, and allowing the first model to determine the target prompt information according to the target query request; The intention information and the basic table information in the target prompt information are determined by the first model according to the target query request; and the data operations include: grouping, filtering, sorting and deduplication.
7. A query statement model fine-tuning device based on a large model, characterized in that: For implementing the method according to claim 1, the device comprises: a prompt information module and a fine-tuning module; The prompt information module is used to determine the prompt information corresponding to the query corpus of the target business system; The query corpus includes: multiple query requests and query statements corresponding to each query request; the query request is in natural language form; the prompt information includes: intent information and basic table information of the query request and statement structure information of the query statement; the intent information includes: business scenario information, the business scenario information indicates the business scope of the work department corresponding to the query request in the target business system, and the same query indicator has the same or different meanings for different work departments; the statement structure information includes: query strategies and query clauses, and the query strategies include: join query, nested query, set query and query based on derived table; The fine-tuning module is configured to fine-tune the query statement model based on the plurality of query requests and the query statement and the prompt information corresponding to each query request; Among them, the query statement model includes: a first model and a second model; the first model is used to generate target prompt information based on the target query request input by the user to the target business system; the second model is used to generate a target query statement based on the target query request and the target prompt information; the query strategy is determined by the first model based on the scale of the data volume in the basic table in the basic table information and the number of the basic tables; the query clause is determined by the first model based on the data operation corresponding to the query request.
8. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory is used to store an application, and the processor runs or executes a software program stored in the memory so that the electronic device implements the large model-based query statement model fine-tuning method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium is used to store program codes executed by a processor, and the program codes are used to implement the query statement model fine-tuning method based on a large model as described in any one of claims 1 to 6.
10. A computer program product, characterized in that The computer program product includes computer instructions. When the computer instructions are executed on an electronic device, the electronic device implements the query statement model fine-tuning method based on a large model as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data query method and device, electronic equipment and computer readable storage medium
CN117349315A
Database query statement generation method and device, equipment and storage medium
CN118227655A