Data query method and device, electronic equipment, medium and program product
By identifying the intention of natural language query statements and generating query statements in combination with big models, the problem of difficult to ensure data query efficiency and accuracy in the consumer finance industry is solved, and efficient and accurate data query is achieved.
Patent Information
- Application Number
- CN202411639224.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-18
AI Technical Summary
In the consumer finance industry, how to efficiently support a large number of data query demands, especially when non-professional users conduct data query, there are problems that are difficult to guarantee efficiency and accuracy.
By combining the intent recognition of the target natural language query statement with the query statement generation technology based on the target big model, there is no need to pre-construct a large number of semantic matching rules, and non-professional users can quickly and efficiently conduct data queries.
It improves the efficiency and accuracy of data query, ensures the effectiveness and accuracy of database query statements output by the target large model, and at the same time improves the effectiveness and security of database query.
Smart Images

Figure CN119646016A_ABST
Abstract
Description
Technical Field
[0001] The present specification relates to the field of data processing technology, and in particular to a data query method, device, electronic device, medium and program product. Background Art
[0002] In the era of artificial intelligence, the analysis and application of big data are becoming more and more extensive. How to efficiently and accurately query and obtain data is an important challenge we face. In the consumer finance industry, the demand for data query is very extensive, especially when it is often necessary to analyze the changes of events through data. How to efficiently support a large number of data query demands has become a problem that needs to be solved urgently. Summary of the invention
[0003] The embodiments of this specification provide a data query method, device, electronic device, medium and program product, which can enable non-professional users to perform data query quickly and efficiently without pre-building a large number of semantic matching rules, by combining the intent recognition of the target natural language query sentence with the query sentence generation technology based on the target large model and the intelligent query technology, thereby improving the efficiency and accuracy of data query. The above technical solution is as follows:
[0004] In a first aspect, an embodiment of the present specification provides a data query method, including:
[0005] Receive a target data query request sent by a user terminal; the target data query request carries a target natural language query statement input by a user of the user terminal; perform intent recognition on the target natural language query statement to obtain a target intent recognition result; input the target natural language query statement and the target intent recognition result into a target big model, and output a target database query statement; the target big model is trained based on a plurality of known database query statements and natural language query statements of intent recognition results; verify whether the target database query statement meets a preset database query condition; if so, execute the target database query statement in response to the target data query request to obtain a target data query result.
[0006] In a possible implementation, the above-mentioned performing intent recognition on the above-mentioned target natural language query sentence to obtain a target intent recognition result includes: preprocessing the above-mentioned target natural language query sentence to obtain a target preprocessing result corresponding to the above-mentioned target natural language query sentence; based on the above-mentioned target preprocessing result, performing entity recognition on the above-mentioned target natural language query sentence to obtain a target entity recognition result corresponding to the above-mentioned target natural language query sentence; based on the above-mentioned target preprocessing result and the above-mentioned target entity recognition result, performing intent recognition on the above-mentioned target natural language query sentence to obtain a target intent recognition result.
[0007] In a possible implementation, the target intent recognition result includes a target query intent entity and a target query intent constraint condition;
[0008] The above-mentioned inputting the above-mentioned target natural language query statement and the above-mentioned target intent recognition result into the target big model and outputting the target database query statement includes: inputting the above-mentioned target natural language query statement and the above-mentioned target intent recognition result into the target big model, generating an initial database query statement based on the above-mentioned target query intent entity and the above-mentioned target natural language query statement, and optimizing the above-mentioned initial database query statement based on the above-mentioned target query intent constraint condition, and outputting the target database query statement.
[0009] In a possible implementation, the target intent recognition result includes a target query intent entity and a target query intent constraint condition;
[0010] After performing intent recognition on the target natural language query statement and obtaining the target intent recognition result, the method further includes: matching the target query intent entity with the query intent entities corresponding to a plurality of preset query templates respectively to obtain the target query template corresponding to the target query intent entity; optimizing the target query template based on the target query intent constraint to obtain the first database query statement corresponding to the target natural language query statement; determining the second database query statement based on the target database query statement and / or the first database query statement; and executing the second database query statement in response to the target data query request to obtain the target data query result corresponding to the target data query request.
[0011] In a possible implementation, the above-mentioned preset database query condition includes a preset table name information set and a preset field information set corresponding to the database to be queried;
[0012] The above-mentioned verification of whether the above-mentioned target database query statement meets the preset database query conditions includes: extracting the target table name information and the target field information in the above-mentioned target database query statement; verifying whether the above-mentioned target table name information exists in the above-mentioned preset table name information set, and verifying whether the above-mentioned target field information exists in the above-mentioned preset field information set; if the above-mentioned target table name information exists in the above-mentioned preset table name information set and the above-mentioned target field information exists in the above-mentioned preset field information set, it is determined that the above-mentioned target database query statement meets the above-mentioned preset database query conditions.
[0013] In a possible implementation, the target data query request further carries the target result display format specified by the user;
[0014] In response to the target data query request, the target database query statement is executed to obtain the target data query result. The method further includes: converting the format of the target data query result based on the target result display format; and sending the target data query result after format conversion to the user terminal, so that the user terminal displays the target data query result based on the target result display format.
[0015] In a possible implementation, after receiving the target data query request sent by the user terminal, the method further includes: based on the target natural language query statement, searching in the target database to obtain a target retrieval result; the target database is used to associate and store historical natural language query statements and historical database query statements corresponding to each of the historical natural language query statements; when the target retrieval result is that there is a target historical natural language query statement matching the target natural language query statement in the target database, in response to the target data query request, executing the historical database query statement corresponding to the target historical natural language query statement to obtain the target data query result; when the target retrieval result is that there is no target historical natural language query statement matching the target natural language query statement in the target database, executing the step of performing intent recognition on the target natural language query statement to obtain a target intent recognition result.
[0016] In a possible implementation, after inputting the target natural language query statement and the target intent recognition result into the target big model and outputting the target database query statement, the method further includes: associating the target natural language query statement with the target database query statement and storing them in the target database.
[0017] In a possible implementation, the method further includes: obtaining multiple known database query statements and natural language query statements of intent recognition results and a preset table name information set and a preset field information set corresponding to the database to be queried; training the pre-trained big model based on the multiple known database query statements and the natural language query statements of intent recognition results to obtain an initial big model; performing retrieval enhancement generation training on the initial big model based on the preset table name information set and preset field information set corresponding to the database to be queried to obtain a target big model.
[0018] In a second aspect, an embodiment of the present specification provides a data query device, the device comprising:
[0019] An acquisition module is used to receive a target data query request sent by a user terminal; the target data query request carries a target natural language query sentence input by a user of the user terminal;
[0020] An intent recognition module is used to perform intent recognition on the above target natural language query sentence to obtain a target intent recognition result;
[0021] A query statement generation module, used to input the above-mentioned target natural language query statement and the above-mentioned target intent recognition result into a target large model, and output a target database query statement; the above-mentioned target large model is trained based on a plurality of known database query statements and natural language query statements of intent recognition results;
[0022] A verification module is used to verify whether the above target database query statement meets the preset database query conditions;
[0023] The execution module is used to, if yes, execute the target database query statement in response to the target data query request to obtain the target data query result.
[0024] In a third aspect, an embodiment of this specification provides an electronic device, including: a processor and a memory;
[0025] The processor is connected to the memory;
[0026] The above-mentioned memory is used to store executable program code;
[0027] The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method provided by the first aspect of the embodiment of this specification or any possible implementation of the first aspect.
[0028] In a fourth aspect, an embodiment of the present specification provides a computer storage medium, wherein the computer storage medium stores a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the method provided by the first aspect of the embodiment of the present specification or any possible implementation of the first aspect.
[0029] In a fifth aspect, an embodiment of this specification provides a computer program product comprising instructions, which, when the above-mentioned computer program product runs on a computer or a processor, enables the above-mentioned computer or the above-mentioned processor to execute the data query method provided by the first aspect of the embodiment of this specification or any possible implementation method of the first aspect.
[0030] In the embodiment of this specification, the target natural language query sentence input by the user is firstly recognized for its intent, and the target intent recognition result is obtained to realize intelligent query intent recognition; then, the target natural language query sentence and the target intent recognition result are input into the target big model, and the target intent recognition result corresponding to the target natural language query sentence is used to assist the target big model to output the target database query sentence corresponding to the target natural language query sentence more accurately and efficiently, and the above-mentioned target big model is trained based on multiple known database query sentences and natural language query sentences of the intent recognition result; finally, it is verified whether the target database query sentence meets the preset database query condition, and only when the target database query sentence meets the preset database query condition, it will respond to the target data query request, execute the target database query sentence, and obtain the target data query result, thereby ensuring the validity and accuracy of the target database query sentence output by the target big model, and further improving the validity and security of the database query. Moreover, by combining the above-mentioned intent recognition of the target natural language query sentence with the query sentence generation technology based on the target big model and the intelligent query technology, it is possible to enable non-professional users to quickly and efficiently perform data query without pre-building a large number of semantic matching rules, thereby improving the efficiency and accuracy of data query. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of this specification, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 A schematic diagram of the architecture of a data query system provided by an exemplary embodiment of this specification;
[0033] Figure 2 A flowchart of a data query method provided by an exemplary embodiment of this specification;
[0034] Figure 3 A schematic diagram of an implementation flow of intent recognition provided by an exemplary embodiment of this specification;
[0035] Figure 4 A flowchart of another data query method provided as an exemplary embodiment of this specification;
[0036] Figure 5 A flowchart of another data query method provided as an exemplary embodiment of this specification;
[0037] Figure 6A flowchart of another data query method provided as an exemplary embodiment of this specification;
[0038] Figure 7 A schematic diagram of a training process of a target large model provided as an exemplary embodiment of this specification;
[0039] Figure 8 A schematic diagram of the structure of a data query device provided by an exemplary embodiment of this specification;
[0040] Fig. 9 The present invention is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0041] The technical solutions in the embodiments of this specification will be described clearly and completely below in conjunction with the drawings in the embodiments of this specification.
[0042] The terms "first", "second", "third", etc. in this specification and claims and the above drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or devices.
[0043] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in the embodiments of this specification are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions. For example, the target natural language query statements involved in this specification are all obtained with full authorization.
[0044] The relevant data query method is generally carried out through a structured SQL script, which often requires very complex query language or complicated operations. For non-professionals, they do not have the corresponding capabilities and are relatively difficult. In order to solve the demand for data query by non-professionals, a feasible solution is to achieve it by building a large number of data query statements and matching them with corresponding natural language expressions. The user enters a natural language query statement, the system matches the corresponding database query statement, and then executes the query and returns the result. However, this method requires the construction of a large number of semantic matching rules, and it is difficult to cover all natural language expressions, resulting in poor scalability of the system. Moreover, through the matching method, the overall accuracy is also affected by the matching rules, and the accuracy is not high.
[0045] Based on this, the embodiments of this specification provide a data query method, which combines the intent recognition of the target natural language query statement with the query statement generation technology based on the target big model and the intelligent query technology. Without the need to pre-build a large number of semantic matching rules, non-professional users can also perform data queries quickly and efficiently, thereby improving data query efficiency and accuracy.
[0046] Please refer to the following Figure 1 , Figure 1 The following is a schematic diagram of the architecture of a data query system provided by an exemplary embodiment of this specification. Figure 1 As shown, the data query system may include: a user terminal 110 and a server 120. Among them:
[0047] The terminal 110 may be a user terminal, and specifically may include one or more user terminals. A user version of software may be installed in the terminal 110 to implement functions such as a user inputting a target natural language query statement online. The terminal 110 may establish a data relationship with the network, and establish a data connection relationship with the server 120 through the network, such as sending a target data query request carrying a target natural language query statement, receiving a target data query result corresponding to the target data query request, etc. The terminal 110 may be, but is not limited to, a mobile phone, a tablet computer, a laptop computer, or other device with a user version of software installed.
[0048] The server 120 can be a server that can provide multiple data queries, can receive data such as a target data query request carrying a target natural language query statement sent by the network or the user end, and perform intent recognition on the above target natural language query statement to obtain a target intent recognition result; input the above target natural language query statement and the above target intent recognition result into the target big model, and output the target database query statement; the above target big model is trained based on multiple known database query statements and natural language query statements with intent recognition results; verify whether the above target database query statement meets the preset database query conditions; if so, in response to the above target data query request, execute the above target database query statement to obtain the target data query result. The server 120 can also output the above target data query result to the terminal 110, etc. The server 120 can be, but is not limited to, a hardware server, a virtual server, a cloud server, etc.
[0049] It can be understood that the above data query process is not limited to the execution of the above server 120, but can also be the terminal 110. The above terminal 110 can receive the target natural language query statement input by the user, and generate a corresponding target data query request based on the user's query trigger operation, and perform intent recognition on the above target natural language query statement to obtain the target intent recognition result, and input the above target natural language query statement and the above target intent recognition result into the target big model, and output the target database query statement, which is trained based on multiple known database query statements and natural language query statements of intent recognition results; finally, verify whether the above target database query statement meets the preset database query condition, and if so, execute the above target database query statement in response to the above target data query request to obtain the target data query result. The embodiments of this specification do not specifically limit this, and the following embodiments are all described by taking the execution of the above data query by the server 120 as an example.
[0050] The network may be a medium providing a communication link between the server 120 and the terminal 110, or may be the Internet including network devices and transmission media, but is not limited thereto. The transmission medium may be a wired link, such as but not limited to coaxial cable, optical fiber, and digital subscriber line (DSL), or a wireless link, such as but not limited to wireless fidelity (WIFI), Bluetooth, and mobile device network.
[0051] Understandably, Figure 1The number of terminals 110 and servers 120 in the data query system shown is only an example. In a specific implementation, the data query system may include any number of terminals 110 and servers. This specification embodiment does not specifically limit this. For example, but not limited to, the terminal 110 may be a terminal cluster composed of multiple terminals, and the server 120 may be a server cluster composed of multiple servers.
[0052] Next, combine Figure 1 , introduces the data query method provided by the embodiment of this specification. For details, please refer to Figure 2 , which is a flow chart of a data query method provided by an exemplary embodiment of this specification. Figure 2 As shown, the data query method includes the following steps:
[0053] S202, receiving a target data query request sent by a user terminal, where the target data query request carries a target natural language query sentence input by a user of the user terminal.
[0054] Specifically, when a user wants to query data in a server, he can enter a target natural language query statement on his user terminal, and trigger the user terminal to generate and send a target data query request of the target natural language query statement to the server through a trigger operation such as clicking. The server can receive the above-mentioned target data query request sent by the user terminal through the network. The above-mentioned target natural language query statement is a query requirement written by the user in a natural language used in daily life (for example, but not limited to English, Chinese, etc.), which is intended to retrieve or obtain specific information from the server's database, search engine, knowledge graph or other information source.
[0055] S204, performing intent recognition on the target natural language query sentence to obtain a target intent recognition result.
[0056] Specifically, after obtaining the target natural language query statement, natural language processing technology can be used to accurately analyze and understand the target natural language query statement input by the user to identify the user's query intent, obtain the corresponding target intent recognition result, and realize intelligent query intent recognition.
[0057] Optionally, the target natural language query sentence can be directly input into a pre-trained intent recognition model to output the corresponding target intent recognition result. The above-mentioned intent recognition model is trained based on multiple natural language query sentences with known intent recognition results.
[0058] Alternatively, if Figure 3 As shown, the implementation process of performing intent recognition on the target natural language query sentence in S204 to obtain the target intent recognition result may include but is not limited to:
[0059] S302, preprocessing the target natural language query statement to obtain a target preprocessing result corresponding to the target natural language query statement.
[0060] Specifically, the above preprocessing may include, but is not limited to, text cleaning, word segmentation, part-of-speech tagging, and syntactic analysis. That is, after obtaining the target natural language query statement, the target natural language query statement may be first subjected to text cleaning, such as but not limited to removing punctuation marks, special characters, etc. in the text of the target natural language query statement. Then, a word segmentation tool (such as but not limited to jieba, NLTK, etc.) may be used for word segmentation, and the cleaned target natural language query statement may be divided into independent words or phrases to obtain the corresponding target word segmentation result. At the same time, the part of speech (such as noun, verb, etc.) of each word in the target word segmentation result may also be identified and marked to obtain the corresponding target part-of-speech tagging result, and the structure of the target natural language query statement may be analyzed, such as identifying the subject, predicate, object, etc., to obtain the corresponding target syntactic analysis result. The above target preprocessing result may include, but is not limited to, target word segmentation results, target part-of-speech tagging results, and target syntactic analysis results, etc. These results are helpful to achieve more accurate intention recognition in the subsequent implementation.
[0061] S304, based on the target preprocessing result, perform entity recognition on the target natural language query sentence to obtain a target entity recognition result corresponding to the target natural language query sentence.
[0062] Specifically, the target preprocessing results and the target natural language query statement can be input together into a trained model such as BERT, GPT, etc., and the target preprocessing results can be used to assist the model in more accurate entity recognition of the target natural language query statement to obtain one or more entities and their types (i.e., the target entity recognition results) in the target natural language query statement.
[0063] S306, based on the target preprocessing result and the target entity recognition result, perform intent recognition on the target natural language query sentence to obtain a target intent recognition result.
[0064] Specifically, the target preprocessing results and target entity recognition results can be combined to use a machine learning or deep learning model to perform intent recognition on the preprocessed target natural language query statements, so that the model can more accurately understand and analyze the query intent in the target natural language query statements, and obtain intent labels corresponding to one or more entities. These labels describe the main purpose or conditions of the query.
[0065] Exemplarily, if the target natural language query statement is "Count the total number of registrations on November 8, 2024", the above intent recognition can be used to obtain the intent label corresponding to the target entity "November 8, 2024" as "target query intent time constraint entity", the intent label corresponding to the target entity "registration" as "target query intent location attribute constraint entity is user", and the intent label corresponding to the target entity "count the total number" as "target query intent entity".
[0066] Please continue to refer to Figure 2 ,like Figure 2 As shown, in the above S204, after performing intent recognition on the target natural language query sentence and obtaining the target intent recognition result, the data query method further includes:
[0067] S206, input the target natural language query statement and the target intent recognition result into the target large model, and output the target database query statement.
[0068] Specifically, the target large model can be trained based on a plurality of known database query statements and natural language query statements of intent recognition results. The target database query statement is a structured query language (SQL) instruction for retrieving data from a database.
[0069] Optionally, after obtaining the target natural language query statement and the target intent recognition result, the target natural language query statement, the target intent recognition result and the query statement generation prompt word can be input into the template big model, but is not limited to, and the target natural language query statement is converted into the query statement format based on the query statement generation prompt word and the target intent recognition result by the target big model, that is, the natural query language input by the user is converted into a structured query language that can be understood by the machine, and the target database query statement is obtained. The query statement generation prompt word includes the description information corresponding to the query statement generation task that the target big model needs to perform for the target natural language query statement and the target intent recognition result.
[0070] Optionally, the above-mentioned target intent recognition result may include, but is not limited to, a target query intent entity and a target query intent constraint condition. The above-mentioned target query intent entity is used to characterize the main query purpose in the target natural language query statement, and the above-mentioned target query intent constraint condition is composed of the target query intent constraint entity in the target natural language query statement, and is used to characterize the query constraints and requirements of the user on the attribute range corresponding to the main query purpose in the target natural language query statement. The above-mentioned S206, inputting the target natural language query statement and the target intent recognition result into the target big model, and the implementation process of outputting the target database query statement may include, but is not limited to: inputting the above-mentioned target natural language query statement and the above-mentioned target intent recognition result into the target big model, generating an initial database query statement based on the above-mentioned target query intent entity and the target natural language query statement, and optimizing the initial database query statement based on the above-mentioned target query intent constraint condition, and outputting the target database query statement.
[0071] Exemplarily, if the target natural language query statement is "Count the total number of registrations on November 8, 2024", the target big model generates an initial database query statement "SELECT COUNT{1}" based on the above target natural language query statement and its corresponding target query intent entity "Count the total number", and then optimizes the above initial database query statement based on the corresponding target query intent time constraint "November 8, 2024" and the target query intent location attribute constraint "user" to obtain the target database query statement "SELECT COUNT{1}FROM USER WHERE a="2024-11-08"".
[0072] In the illustrated embodiment, the target query intent entity is first used to assist the target big model in accurately and efficiently capturing the user's main query intent in the target natural language query statement, so as to avoid the problem that the target big model has limited semantic understanding ability of the target natural language query statement and is prone to missing or misunderstanding the user's query intent, and thus can efficiently and accurately generate the corresponding initial database query statement according to the user's main query intent; then, the target query intent constraint condition is used to assist the target big model in optimizing the initial database query statement generated by it, so as to obtain a target database query statement that is more compatible with the target natural language query statement.
[0073] Please continue to refer to Figure 2 ,like Figure 2 As shown, in the above S206, after inputting the target natural language query statement and the target intent recognition result into the target large model and outputting the target database query statement, the data query method further includes:
[0074] S208, verifying whether the target database query statement meets the preset database query condition.
[0075] Specifically, in order to ensure that the target database query statement can correctly retrieve the expected data from the database to be queried, and avoid the problem of query failure or invalid query due to the target database query statement not meeting the requirements, after obtaining the target database query statement generated by the target large model, the target database query statement will also be verified to ensure the executable and validity of the target database query statement in the database to be queried. The above-mentioned preset database query conditions are used to characterize the conditions that can be satisfied by the statements that can be executed in the database to be queried.
[0076] Optionally, the preset database query condition may include, but is not limited to, a preset table name information set and a preset field information set corresponding to the database to be queried. The above S208, the implementation process of verifying whether the target database query statement meets the preset database query condition may include, but is not limited to: firstly, parsing the target database query statement, extracting the target table name information and the target field information in the above target database query statement; then, verifying whether the target table name information exists in the preset table name information set, and verifying whether the target field information exists in the preset field information set; if the target table name information exists in the preset table name information set and the target field information exists in the preset field information set, then determining that the target database query statement meets the preset database query condition. If the target table name information does not exist in the preset table name information set or the target field information exists in the preset field information set, then determining that the target database query statement does not meet the preset database query condition, and the target database query statement may be corrected according to, but is not limited to, the preset table name information set and the preset field information set, so that the corrected target database query statement meets the preset database query condition, ensuring that the subsequent target database query statement can be effectively executed, and ensuring that the user's query can be successfully completed.
[0077] S210: If the target database query statement meets the preset database query condition, the target database query statement is executed in response to the target data query request to obtain a target data query result.
[0078] Specifically, if the target database query statement meets the preset database query condition, the target database query statement can be executed in response to the target data query request, and a corresponding query can be performed in the database to be queried to obtain the target data query result.
[0079] In the embodiment of this specification, the target natural language query sentence input by the user is firstly recognized for its intent, and the target intent recognition result is obtained to realize intelligent query intent recognition; then, the target natural language query sentence and the target intent recognition result are input into the target big model, and the target intent recognition result corresponding to the target natural language query sentence is used to assist the target big model to output the target database query sentence corresponding to the target natural language query sentence more accurately and efficiently, and the above-mentioned target big model is trained based on multiple known database query sentences and natural language query sentences of the intent recognition result; finally, it is verified whether the target database query sentence meets the preset database query condition, and only when the target database query sentence meets the preset database query condition, it will respond to the target data query request, execute the target database query sentence, and obtain the target data query result, thereby ensuring the validity and accuracy of the target database query sentence output by the target big model, and further improving the validity and security of the database query. Moreover, by combining the above-mentioned intent recognition of the target natural language query sentence with the query sentence generation technology based on the target big model and the intelligent query technology, it is possible to enable non-professional users to quickly and efficiently perform data query without pre-building a large number of semantic matching rules, thereby improving the efficiency and accuracy of data query.
[0080] Please refer to the following Figure 4 , which is a flow chart of another data query method provided by an exemplary embodiment of this specification. Figure 4 As shown, the data query method may include the following steps:
[0081] S402, receiving a target data query request sent by a user terminal, where the target data query request carries a target natural language query sentence input by a user of the user terminal.
[0082] Specifically, the above S402 is consistent with S202 and will not be repeated here.
[0083] S404, perform intent recognition on the target natural language query statement to obtain a target intent recognition result, which includes a target query intent entity and a target query intent constraint condition.
[0084] Specifically, the above S404 is consistent with S204 and will not be repeated here.
[0085] S406, input the target natural language query statement and the target intent recognition result into the target large model, and output the target database query statement.
[0086] Specifically, the above S406 is consistent with S206 and will not be repeated here.
[0087] Please continue to refer to Figure 4 ,like Figure 4 As shown, in the above S404, after performing intent recognition on the target natural language query sentence and obtaining the target intent recognition result, the data query method further includes:
[0088] S408, matching the target query intent entity with the query intent entities corresponding to the plurality of preset query templates respectively, and obtaining the target query template corresponding to the target query intent entity.
[0089] Specifically, after obtaining the target intent recognition result, the target query intent entity can be matched with the query intent entities corresponding to each of the multiple preset query templates, and the target query template whose corresponding query intent entity in the multiple preset query templates is consistent with the target query intent entity is found. The above-mentioned preset query template is a predefined SQL query statement or query statement framework with a specific query intent. Each preset query template contains at least one query intent entity and at least one placeholder, which occupies a specific position in the preset query template or serves as a parameter.
[0090] S410, optimizing the target query template based on the target query intent constraint condition to obtain a first database query statement corresponding to the target natural language query statement.
[0091] Specifically, after obtaining the target query template corresponding to the target query intent entity, the corresponding placeholders in the target query template can be directly replaced based on the target query intent constraint entity in the target query intent constraint condition, as well as redundant branches in the target query template can be removed and missing branches can be added, and other optimization processing can be performed to obtain a complete and accurate first database query statement corresponding to the target natural language query statement.
[0092] Exemplarily, if the target natural language query statement is "Count the total number of registrations on November 8, 2024", then through the above S408, the target query template corresponding to the target query intent entity "Count the total number" can be obtained as "SELECT COUNT{1}FROM{a}WHERE{b}", where a is the query intent location attribute placeholder, and b is the query intent constraint condition placeholder. Then, based on the corresponding target query intent time constraint "November 8, 2024" and the target query intent location attribute constraint "user", the placeholders in the above target query template are replaced respectively to obtain the target database query statement "SELECT COUNT{1}FROM USER WHERE a="2024-11-08"".
[0093] S412: Determine a second database query statement based on the target database query statement and / or the first database query statement.
[0094] Specifically, the second database query statement may be a statement in the target database query statement or the first database query statement that has a higher degree of compatibility with the target natural language query statement, or may be a statement jointly determined by the target database query statement and the first database query statement, which is not limited in this embodiment.
[0095] S414, in response to the target data query request, executing the second database query statement to obtain a target data query result corresponding to the target data query request.
[0096] Specifically, after determining the second database query statement, the second database query statement can be executed in response to the target data query request, and a corresponding query can be performed in the database to be queried to obtain the target data query result, thereby achieving more accurate and effective data query through a more accurate second database query statement.
[0097] Please refer to the following Figure 5 , which is a flow chart of another data query method provided by an exemplary embodiment of this specification. Figure 5 As shown, the data query method may include the following steps:
[0098] S502 , receiving a target data query request sent by a user terminal, where the target data query request carries a target natural language query sentence input by a user of the user terminal.
[0099] Specifically, the above S502 is consistent with S202 and will not be repeated here.
[0100] S504, performing intent recognition on the target natural language query sentence to obtain a target intent recognition result.
[0101] Specifically, the above S504 is consistent with S204 and will not be repeated here.
[0102] S506, input the target natural language query statement and the target intent recognition result into the target large model, and output the target database query statement.
[0103] Specifically, the above S506 is consistent with S206 and will not be repeated here.
[0104] S508: Verify whether the target database query statement meets the preset database query condition.
[0105] Specifically, the above S508 is consistent with S208 and will not be repeated here.
[0106] S510: If the target database query statement meets the preset database query condition, the target database query statement is executed in response to the target data query request to obtain the target data query result.
[0107] Specifically, the above S510 is consistent with S210 and will not be repeated here.
[0108] S512: Convert the target data query result into a format based on the target result display format.
[0109] Specifically, the target data query request may also carry a target result display format specified by the user. After obtaining the target data query result, the target data query result may be converted into the target result display format specified by the user.
[0110] S514, sending the target data query result after format conversion to the user terminal, so that the user terminal displays the target data query result based on the target result display format.
[0111] The embodiments of this specification present the target data query results to the user in accordance with the user configuration or predefined display mode, providing an interactive data display and operation interface to facilitate user viewing and analysis.
[0112] Please refer to the following Figure 6 , which is a flow chart of another data query method provided by an exemplary embodiment of this specification. Figure 6 As shown, the data query method may include the following steps:
[0113] S602, receiving a target data query request sent by a user terminal, where the target data query request carries a target natural language query sentence input by a user of the user terminal.
[0114] Specifically, the above S602 is consistent with S202 and will not be repeated here.
[0115] S604, based on the target natural language query statement, search in the target database to obtain the target search result, the target database is used to associate and store the historical natural language query statements and the historical database query statements corresponding to each historical natural language query statement.
[0116] Specifically, based on the target natural language query statement, a search can be performed in the target database to find out whether there is a target historical natural language query statement in the target database that is consistent with the target natural language query statement or has a semantic similarity greater than a threshold (for example, but not limited to 0.9, 0.95, etc.), and obtain a target search result. The target database is used to associate and store historical natural language query statements and historical database query statements corresponding to each historical natural language query statement.
[0117] S606, when the target retrieval result is that there is a target historical natural language query statement matching the target natural language query statement in the target database, in response to the target data query request, execute the historical database query statement corresponding to the target historical natural language query statement to obtain the target data query result.
[0118] Specifically, when the target retrieval result is a target historical natural language query statement that matches the target natural language query statement (consistent or with a semantic similarity greater than a threshold) in the target database, it indicates that the target database stores a historical database query statement that was previously constructed with the target natural language query statement. In this case, the target data query request can be directly responded to by executing the historical database query statement corresponding to the target historical natural language query statement that matches it to obtain the target data query result, thereby avoiding the problem that the same natural language query statement requires the target large model to repeatedly generate the corresponding database query statement, which affects the query efficiency and wastes model resources.
[0119] S608, when the target retrieval result is that there is no target historical natural language query statement matching the target natural language query statement in the target database, perform intent recognition on the target natural language query statement to obtain a target intent recognition result.
[0120] Specifically, when the target search result is that there is no target historical natural language query statement matching the target natural language query statement in the target database, it means that the user has not used the target natural language query statement to perform data query before, and it is necessary to construct a target database query statement corresponding to the target natural language query statement to perform data query. The implementation process of performing intent recognition on the target natural language query statement in the above S608 and obtaining the target intent recognition result is consistent with S204 and will not be repeated here.
[0121] S610, input the target natural language query statement and the target intent recognition result into the target large model, and output the target database query statement.
[0122] Specifically, the above S610 is consistent with S206 and will not be repeated here.
[0123] S612: associate the target natural language query statement with the target database query statement and store them in the target database.
[0124] Specifically, after obtaining the target database query statement corresponding to the target natural language query statement, the target natural language query statement and the target database query statement can be associated and stored in the target database, so that the next time the user enters the same natural language query statement, the corresponding target database query statement can be directly queried from the target database.
[0125] S614, verifying whether the target database query statement meets the preset database query condition.
[0126] Specifically, the above S614 is consistent with S208 and will not be repeated here.
[0127] S616: If the target database query statement meets the preset database query condition, the target database query statement is executed in response to the target data query request to obtain a target data query result.
[0128] Specifically, the above S616 is consistent with S210 and will not be repeated here.
[0129] Please refer to the following Figure 7 , which is a schematic diagram of a training process of a target large model provided by an exemplary embodiment of this specification. Figure 7 As shown, the training process of the target large model can include the following steps:
[0130] S702, obtaining multiple known database query statements and natural language query statements of intent recognition results, as well as a preset table name information set and a preset field information set corresponding to the database to be queried.
[0131] Specifically, the above database query statements are already written SQL statements that can be executed correctly and return results. They will serve as "correct" examples for training models. The above preset table name information set includes the names of all tables in the database to be queried. The model needs to know these table names so that it can correctly reference them when generating database query statements. The above preset field information set includes information such as the names and data types of all fields (columns) contained in each table in the database to be queried. This information is crucial for the model to generate accurate SQL queries.
[0132] S704, training the pre-trained large model based on multiple known database query statements and natural language query statements of intent recognition results to obtain an initial large model.
[0133] Specifically, a pre-trained large model (such as BERT, GPT, etc.) can be trained using the multiple known database query statements collected in the previous step and the natural language query statements of the corresponding intent recognition results. The goal of the training is to enable the model to understand the intent of the natural language query and map it to the corresponding database query statement. For example, but not limited to, the natural language query statement, the intent recognition results, and the corresponding database query statement can be aligned and formatted, and the pre-trained model can be fine-tuned using the aligned data so that it can learn the mapping relationship from natural language to SQL and obtain the initial large model.
[0134] S706, based on the preset table name information set and the preset field information set corresponding to the database to be queried, the initial large model is subjected to retrieval enhancement generation training to obtain a target large model.
[0135] Specifically, the preset table name information set and preset field information set corresponding to the database to be queried can be integrated into the initial large model in some way, so that the model can understand and utilize these database-specific knowledge. Then, when generating database query statements, the model can retrieve relevant table and field information based on database knowledge, thereby generating more accurate query statements that are more in line with the database structure.
[0136] Please refer to the following Figure 8 , Figure 8 A data query device is provided as an exemplary embodiment of this specification. Figure 8 As shown, the data query device 800 includes:
[0137] The acquisition module 810 is used to receive a target data query request sent by a user terminal; the target data query request carries a target natural language query sentence input by a user of the user terminal;
[0138] The intent recognition module 820 is used to perform intent recognition on the target natural language query sentence to obtain a target intent recognition result;
[0139] A query statement generation module 830 is used to input the above target natural language query statement and the above target intent recognition result into a target macro model, and output a target database query statement; the above target macro model is trained based on a plurality of known database query statements and natural language query statements of intent recognition results;
[0140] Verification module 840, used to verify whether the target database query statement meets the preset database query condition;
[0141] The execution module 850 is used to, if yes, execute the target database query statement in response to the target data query request to obtain the target data query result.
[0142] In a possible implementation, the intention recognition module 820 is specifically used to: preprocess the target natural language query statement to obtain a target preprocessing result corresponding to the target natural language query statement; based on the target preprocessing result, perform entity recognition on the target natural language query statement to obtain a target entity recognition result corresponding to the target natural language query statement; based on the target preprocessing result and the target entity recognition result, perform intent recognition on the target natural language query statement to obtain a target intent recognition result.
[0143] In a possible implementation, the target intent recognition result includes a target query intent entity and a target query intent constraint condition;
[0144] The above-mentioned query statement generation module 830 is specifically used to: input the above-mentioned target natural language query statement and the above-mentioned target intent recognition result into the target big model, generate an initial database query statement based on the above-mentioned target query intent entity and the above-mentioned target natural language query statement, and optimize the above-mentioned initial database query statement based on the above-mentioned target query intent constraint condition, and output the target database query statement.
[0145] In a possible implementation, the target intent recognition result includes a target query intent entity and a target query intent constraint condition; the data query device 800 further includes:
[0146] A query template matching module, used to match the above target query intent entity with the query intent entities corresponding to the plurality of preset query templates respectively, to obtain the target query template corresponding to the above target query intent entity;
[0147] An optimization module, configured to optimize the target query template based on the target query intent constraint condition to obtain a first database query statement corresponding to the target natural language query statement;
[0148] A determination module, configured to determine a second database query statement based on the target database query statement and / or the first database query statement;
[0149] The execution module 850 is further configured to: execute the second database query statement in response to the target data query request, and obtain a target data query result corresponding to the target data query request.
[0150] In a possible implementation, the above-mentioned preset database query condition includes a preset table name information set and a preset field information set corresponding to the database to be queried;
[0151] The verification module 840 is specifically used to: extract the target table name information and target field information in the target database query statement; verify whether the target table name information exists in the preset table name information set, and verify whether the target field information exists in the preset field information set; if the target table name information exists in the preset table name information set and the target field information exists in the preset field information set, then determine that the target database query statement meets the preset database query condition.
[0152] In a possible implementation, the target data query request further carries the target result display format specified by the user; the data query device 800 further includes:
[0153] A format conversion module, used to convert the format of the above target data query result based on the above target result display format;
[0154] The sending module is used to send the target data query result after format conversion to the user terminal, so that the user terminal displays the target data query result based on the target result display format.
[0155] In a possible implementation, the data query device 800 further includes:
[0156] A retrieval module, used to search in a target database based on the target natural language query statement to obtain a target retrieval result; the target database is used to associate and store historical natural language query statements and historical database query statements corresponding to each of the historical natural language query statements;
[0157] The above-mentioned execution module 850 is also used for: when the above-mentioned target retrieval result is that there is a target historical natural language query statement matching the above-mentioned target natural language query statement in the above-mentioned target database, in response to the above-mentioned target data query request, executing the historical database query statement corresponding to the above-mentioned target historical natural language query statement to obtain the target data query result; when the above-mentioned target retrieval result is that there is no target historical natural language query statement matching the above-mentioned target natural language query statement in the above-mentioned target database, executing the above-mentioned step of performing intent recognition on the above-mentioned target natural language query statement to obtain the target intent recognition result.
[0158] In a possible implementation, the data query device 800 further includes:
[0159] The storage module is used to associate the target natural language query statement with the target database query statement and store them in the target database.
[0160] In a possible implementation, the acquisition module 810 may also be used to: acquire multiple known database query statements and natural language query statements of intent recognition results, and a preset table name information set and a preset field information set corresponding to the database to be queried;
[0161] The data query device 800 further includes:
[0162] A model training module is used to train the pre-trained large model based on the above-mentioned multiple known database query statements and natural language query statements of intent recognition results to obtain an initial large model;
[0163] The retrieval enhancement generation module is used to perform retrieval enhancement generation training on the above-mentioned initial large model based on the preset table name information set and the preset field information set corresponding to the above-mentioned database to be queried, so as to obtain the target large model.
[0164] The division of the modules in the above-mentioned data query device is only for illustration. In other embodiments, the data query device can be divided into different modules as needed to complete all or part of the functions of the above-mentioned data query device. The implementation of each module in the data query device provided in the embodiments of this specification can be in the form of a computer program. The computer program can be run on a terminal or a server. The program modules constituted by the computer program can be stored in the memory of the terminal or the server. When the computer program is executed by the processor, all or part of the steps of the data query method described in the embodiments of this specification are implemented.
[0165] See next Fig. 9 , Fig. 9 This is a schematic diagram of the structure of an electronic device provided by an exemplary embodiment of this specification. Fig. 9 As shown, the electronic device 900 may include: at least one processor 910, at least one communication bus 920, a user interface 930, at least one network interface 940, and a memory 950. The communication bus 920 may be used to realize the connection and communication of the above components.
[0166] The user interface 930 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 930 may also include a standard wired interface and a wireless interface.
[0167] The network interface 940 may optionally include a Bluetooth module, a Near Field Communication (NFC) module, a Wireless Fidelity (Wi-Fi) module, and the like.
[0168] Among them, the processor 910 may include one or more processing cores. The processor 910 uses various interfaces and lines to connect various parts within the entire electronic device 900, and executes various functions and processes data of the routing electronic device 900 by running or executing instructions, programs, code sets or instruction sets stored in the memory 950, and calling data stored in the memory 950. Optionally, the processor 910 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 910 can integrate one or more combinations of a processor (Central Processing Unit, CPU), a graphics processor (Graphics Processing Unit, GPU), and a modem. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 910, but may be implemented separately through a chip.
[0169] Among them, the memory 950 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory, ROM). Optionally, the memory 950 includes a non-transitory computer-readable medium. The memory 950 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 950 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as an acquisition function, an intent recognition function, a query statement generation function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 950 may also be optionally at least one storage device located away from the aforementioned processor 910. As Fig. 9 As shown, the memory 950 as a computer storage medium may include an operating system, a network communication module, a user interface module, and an application program.
[0170] Specifically, the processor 910 may be used to call an application program stored in the memory 950, and specifically perform the following operations:
[0171] Receive a target data query request sent by a user terminal; the target data query request carries a target natural language query statement input by a user of the user terminal; perform intent recognition on the target natural language query statement to obtain a target intent recognition result; input the target natural language query statement and the target intent recognition result into a target big model, and output a target database query statement; the target big model is trained based on a plurality of known database query statements and natural language query statements of intent recognition results; verify whether the target database query statement meets a preset database query condition; if so, execute the target database query statement in response to the target data query request to obtain a target data query result.
[0172] In some possible embodiments, the processor 910 performs the above-mentioned intent recognition on the above-mentioned target natural language query sentence, and when obtaining the target intent recognition result, is specifically used to execute:
[0173] The target natural language query statement is preprocessed to obtain a target preprocessing result corresponding to the target natural language query statement; based on the target preprocessing result, entity recognition is performed on the target natural language query statement to obtain a target entity recognition result corresponding to the target natural language query statement; based on the target preprocessing result and the target entity recognition result, intent recognition is performed on the target natural language query statement to obtain a target intent recognition result.
[0174] In some possible embodiments, the target intent recognition result includes a target query intent entity and a target query intent constraint condition; when the processor 910 executes the above-mentioned inputting the target natural language query statement and the target intent recognition result into the target big model and outputting the target database query statement, it is specifically used to execute: inputting the target natural language query statement and the target intent recognition result into the target big model, generating an initial database query statement based on the target query intent entity and the target natural language query statement, optimizing the initial database query statement based on the target query intent constraint condition, and outputting the target database query statement.
[0175] In some possible embodiments, the target intent recognition result includes a target query intent entity and a target query intent constraint condition; the processor 910 performs the intent recognition on the target natural language query statement, and after obtaining the target intent recognition result, is further used to execute:
[0176] The above-mentioned target query intent entity is matched with the query intent entities corresponding to each of multiple preset query templates respectively, and the target query template corresponding to the above-mentioned target query intent entity is obtained; based on the above-mentioned target query intent constraint condition, the above-mentioned target query template is optimized to obtain the first database query statement corresponding to the above-mentioned target natural language query statement; based on the above-mentioned target database query statement and / or the above-mentioned first database query statement, the second database query statement is determined; in response to the above-mentioned target data query request, the above-mentioned second database query statement is executed to obtain the target data query result corresponding to the above-mentioned target data query request.
[0177] In some possible embodiments, the preset database query condition includes a preset table name information set and a preset field information set corresponding to the database to be queried; when the processor 910 executes the verification of whether the target database query statement satisfies the preset database query condition, it is specifically used to execute:
[0178] Extract the target table name information and target field information in the above target database query statement; verify whether the above target table name information exists in the above preset table name information set, and verify whether the above target field information exists in the above preset field information set; if the above target table name information exists in the above preset table name information set and the above target field information exists in the above preset field information set, determine that the above target database query statement meets the above preset database query condition.
[0179] In some possible embodiments, the target data query request further carries the target result display format specified by the user; the processor 910 executes the target database query statement in response to the target data query request, and after obtaining the target data query result, is further used to execute:
[0180] Based on the target result display format, the target data query result is formatted; and the target data query result after format conversion is sent to the user terminal, so that the user terminal displays the target data query result based on the target result display format.
[0181] In some possible embodiments, after the processor 910 executes the target data query request sent by the receiving user terminal, it is also used to execute: based on the target natural language query statement, searching in the target database to obtain a target retrieval result; the target database is used to associate and store historical natural language query statements and historical database query statements corresponding to each of the historical natural language query statements; when the target retrieval result is that there is a target historical natural language query statement matching the target natural language query statement in the target database, in response to the target data query request, executing the historical database query statement corresponding to the target historical natural language query statement to obtain the target data query result; when the target retrieval result is that there is no target historical natural language query statement matching the target natural language query statement in the target database, executing the step of performing intent recognition on the target natural language query statement to obtain a target intent recognition result.
[0182] In some possible embodiments, after the processor 910 executes the above-mentioned inputting of the target natural language query statement and the above-mentioned target intent recognition result into the target big model and outputting the target database query statement, it is also used to execute: associating the above-mentioned target natural language query statement with the above-mentioned target database query statement and storing them in the above-mentioned target database.
[0183] In some possible embodiments, the processor 910 is further configured to execute:
[0184] Acquire multiple known database query statements and natural language query statements of intent recognition results, as well as a preset table name information set and a preset field information set corresponding to the database to be queried; train the pre-trained big model based on the above-mentioned multiple known database query statements and natural language query statements of intent recognition results to obtain an initial big model; perform retrieval enhancement generation training on the above-mentioned initial big model based on the preset table name information set and preset field information set corresponding to the above-mentioned database to be queried to obtain a target big model.
[0185] The embodiments of this specification also provide a computer-readable storage medium, which stores instructions, and when the instructions are executed on a computer or a processor, the computer or the processor executes one or more steps in the above embodiments. If the components of the above data query device are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium.
[0186] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The above computer program product includes one or more computer instructions. When the above computer program instructions are loaded and executed on a computer, the above process or function according to the embodiment of this specification is generated in whole or in part. The above computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The above computer instructions can be stored in a computer-readable storage medium or transmitted by the above computer-readable storage medium. The above computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (Digital Subscriber Line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The above computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, data center, etc. that contains one or more available media integrated. The above-mentioned available media can be magnetic media (for example, floppy disks, hard disks, tapes), optical media (for example, digital versatile discs (DVD)), or semiconductor media (for example, solid state drives (SSD)), etc.
[0187] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes. In the absence of conflict, the technical features in this embodiment and the implementation scheme can be combined arbitrarily.
[0188] The embodiments described above are merely preferred embodiments of this specification and are not intended to limit the scope of this specification. Without departing from the design spirit of this specification, various modifications and improvements made to the technical solutions of this specification by ordinary technicians in this field should fall within the scope of protection determined by the claims.
[0189] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims and the specification can be performed in an order different from that in the embodiment recorded in the specification and still achieve the desired results. In addition, the process depicted in the drawings does not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Claims
1. A data query method, the method comprising: Receive a target data query request sent by a user terminal; The target data query request carries a target natural language query sentence input by a user of the user terminal; Performing intent recognition on the target natural language query sentence to obtain a target intent recognition result; Input the target natural language query statement and the target intent recognition result into the target macro model, and output the target database query statement; The target large model is obtained by training based on multiple known database query statements and natural language query statements of intent recognition results; Verify whether the target database query statement meets the preset database query condition; If so, in response to the target data query request, the target database query statement is executed to obtain a target data query result.
2. The method according to claim 1, wherein the step of performing intent recognition on the target natural language query sentence to obtain a target intent recognition result comprises: Preprocessing the target natural language query statement to obtain a target preprocessing result corresponding to the target natural language query statement; Based on the target preprocessing result, entity recognition is performed on the target natural language query sentence to obtain a target entity recognition result corresponding to the target natural language query sentence; Based on the target preprocessing result and the target entity recognition result, the target natural language query sentence is subjected to intent recognition to obtain a target intent recognition result.
3. The method according to claim 1, wherein the target intent recognition result includes a target query intent entity and a target query intent constraint condition; The step of inputting the target natural language query statement and the target intent recognition result into the target macro model and outputting the target database query statement comprises: The target natural language query statement and the target intent recognition result are input into the target big model, an initial database query statement is generated based on the target query intent entity and the target natural language query statement, and the initial database query statement is optimized based on the target query intent constraint condition, and a target database query statement is output.
4. The method according to claim 1, wherein the target intent recognition result includes a target query intent entity and a target query intent constraint condition; After performing intent recognition on the target natural language query sentence and obtaining a target intent recognition result, the method further includes: Matching the target query intent entity with the query intent entities corresponding to the plurality of preset query templates respectively, to obtain the target query template corresponding to the target query intent entity; Based on the target query intention constraint condition, the target query template is optimized to obtain a first database query statement corresponding to the target natural language query statement; Determine a second database query statement based on the target database query statement and / or the first database query statement; In response to the target data query request, the second database query statement is executed to obtain a target data query result corresponding to the target data query request.
5. The method according to claim 1, wherein the preset database query condition comprises a preset table name information set and a preset field information set corresponding to the database to be queried; The verifying whether the target database query statement satisfies a preset database query condition includes: Extracting target table name information and target field information from the target database query statement; Verifying whether the target table name information exists in the preset table name information set, and verifying whether the target field information exists in the preset field information set; If the target table name information exists in the preset table name information set and the target field information exists in the preset field information set, it is determined that the target database query statement meets the preset database query condition.
6. The method according to claim 1, wherein the target data query request also carries the target result display format specified by the user; After executing the target database query statement in response to the target data query request and obtaining the target data query result, the method further includes: Based on the target result display format, convert the target data query result into a format; The target data query result after format conversion is sent to the user terminal, so that the user terminal displays the target data query result based on the target result display format.
7. The method according to claim 1, after receiving the target data query request sent by the user terminal, the method further comprises: Based on the target natural language query statement, searching in the target database to obtain target search results; The target database is used to associate and store historical natural language query statements and historical database query statements corresponding to each of the historical natural language query statements; In the case where the target search result is a target historical natural language query statement that matches the target natural language query statement in the target database, in response to the target data query request, executing a historical database query statement corresponding to the target historical natural language query statement to obtain a target data query result; When the target retrieval result is that there is no target historical natural language query statement matching the target natural language query statement in the target database, the step of performing intent recognition on the target natural language query statement to obtain a target intent recognition result is performed.
8. The method according to claim 7, after inputting the target natural language query statement and the target intent recognition result into the target macro model and outputting the target database query statement, the method further comprises: The target natural language query statement is associated with the target database query statement and stored in the target database.
9. The method of claim 1, further comprising: Obtain multiple known database query statements and natural language query statements of intent recognition results, as well as a preset table name information set and a preset field information set corresponding to the database to be queried; Training the pre-trained large model based on the multiple known database query statements and the natural language query statements of the intent recognition results to obtain an initial large model; Based on the preset table name information set and the preset field information set corresponding to the database to be queried, the initial large model is subjected to retrieval enhancement generation training to obtain a target large model.
10. A data query device, comprising: An acquisition module, used to receive a target data query request sent by a user terminal; The target data query request carries a target natural language query sentence input by a user of the user terminal; An intent recognition module is used to perform intent recognition on the target natural language query sentence to obtain a target intent recognition result; A query statement generation module, used for inputting the target natural language query statement and the target intent recognition result into the target macro model, and outputting a target database query statement; The target large model is obtained by training based on multiple known database query statements and natural language query statements of intent recognition results; A verification module, used to verify whether the target database query statement meets the preset database query conditions; The execution module is used to execute the target database query statement in response to the target data query request to obtain the target data query result.
11. An electronic device, comprising: Processor and memory; The processor is connected to the memory; The memory is used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method according to any one of claims 1 to 9.
12. A computer storage medium storing a plurality of instructions, wherein the instructions are suitable for being loaded by a processor and executing the method steps according to any one of claims 1 to 9.
13. A computer program product comprising instructions, which, when executed on a computer or a processor, enables the computer or the processor to execute the data query method according to any one of claims 1 to 9.
Citation Information
Cited By
NL2SQL method, device and equipment based on preset industry large model and medium
CN119917524A
Report generation method and device, storage medium, program product and server
CN120743927A
Multi-modal grain data fusion and decision-making method based on artificial intelligence
CN120743941A
Data query method and device, equipment and storage medium
CN121117062A