Structured query statement generation method and device, medium, equipment and product

By generating query statements through a multi-level retrieval mechanism and a large language model, the problem of poor applicability of NL2SQL in existing technologies is solved, and accurate, low-cost query statement generation and adaptive optimization are achieved.

CN121658505APending Publication Date: 2026-03-13INNOVATION QIZHI TECH GRP CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-11
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Existing technologies struggle to adapt to complex and varied natural language queries during NL2SQL generation, resulting in poor applicability, requiring manual intervention, and incurring high maintenance costs.

Method used

A multi-level retrieval mechanism is used to retrieve data from the query example library. Query statements are generated through the target large language model and then validated, corrected, and the model is optimized to reduce human intervention.

Benefits of technology

It achieves accurate generation in various complex query scenarios, reduces maintenance costs, and improves the system's adaptability and user interaction convenience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121658505A_ABST
    Figure CN121658505A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of natural language processing, and particularly provides a structured query statement generation method and device, a medium, equipment and a product. The method can comprise the steps that retrieval is conducted in a query example library by adopting a multi-level retrieval mechanism on the basis of a user query intention, obtaining retrieval data of each stage of retrieval mechanism under the multi-stage retrieval mechanism; wherein the retrieval data comprises a retrieval example and the confidence coefficient of the retrieval example; performing fusion analysis on retrieval data of each stage of retrieval mechanism, and determining model input data; wherein the model input data comprises at least one retrieval example; and processing the model input data by utilizing a target large language model to generate a query statement matched with the user query intention. According to the embodiment of the invention, the relatively accurate query statement can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing technology, and more specifically, to a method, apparatus, medium, device, and product for generating structured query statements. Background Technology

[0002] NL2SQL (Natural Language to SQL) technology aims to automatically convert users' natural language queries into Structured Query Language (SQL), thereby lowering the barrier to database access and enabling natural human-computer interaction.

[0003] Currently, the process of generating NL2SQL typically involves manually writing grammar and semantic parsing rules for a specific business scenario. Natural speech is then converted into NL2SQL based on these rules within that specific scenario. However, this conversion method is limited to specific scenarios and cannot accurately convert complex and varied natural language, resulting in poor applicability.

[0004] Therefore, how to provide a technical solution for generating structured query statements that is more accurate and widely applicable has become an urgent technical problem to be solved. Summary of the Invention

[0005] The purpose of some embodiments of this application is to provide a method, apparatus, medium, device and product for generating structured query statements. The technical solutions of the embodiments of this application can generate more accurate query statements, which are applicable to various complex query scenarios, do not require manual intervention, have low cost and are easy to maintain.

[0006] In a first aspect, some embodiments of this application provide a method for generating structured query statements, comprising: based on a user's query intent, performing a multi-level retrieval mechanism to search a query example library, and obtaining retrieval data for each level of the multi-level retrieval mechanism; wherein the retrieval data includes retrieval examples and the confidence levels of the retrieval examples; performing fusion analysis on the retrieval data of each level of the retrieval mechanism to determine model input data; wherein the model input data includes at least one of the retrieval examples; and processing the model input data using a target large language model to generate a query statement that matches the user's query intent.

[0007] Some embodiments of this application employ a multi-level retrieval mechanism to search a query example library based on the user's query intent, obtaining retrieval data for each level of the retrieval mechanism. Then, the retrieval data from each level is used to determine the model input data. Finally, the model input data is input into the target large language model, outputting the query statement. These embodiments can generate relatively accurate query statements, are suitable for various complex query scenarios, require no manual intervention, are low-cost, easy to maintain, and highly practical.

[0008] In some embodiments, the step of searching in the query example library based on the user's query intent using a multi-level retrieval mechanism to obtain retrieval data for each level of the multi-level retrieval mechanism includes: retrieving first-level retrieval data similar to the user's query intent from the query example library; determining second-level retrieval data matching the user's query intent based on the table database and the query example library; and using historical query data related to the user's query intent as third-level retrieval data; wherein the first-level retrieval data, the second-level retrieval data, and the third-level retrieval data are the retrieval data for each level of the multi-level retrieval mechanism.

[0009] Some embodiments of this application retrieve first-level, second-level, and third-level search data that match the user's query intent through a multi-level search mechanism, providing support for subsequently determining accurate model input data and thereby improving the accuracy of the model output results.

[0010] In some embodiments, the step of fusing and analyzing the retrieval data of each retrieval mechanism to determine the model input data includes: confirming that the retrieval data of each retrieval mechanism is the same, then using the retrieval example in the retrieval data as the model input data.

[0011] Some embodiments of this application determine the model input data by judging whether the retrieved data of each level of the retrieval mechanism is the same, thereby achieving effective and accurate determination of model data.

[0012] In some embodiments, the step of fusing and analyzing the retrieval data of each retrieval mechanism to determine the model input data includes: if it is confirmed that the retrieval data of each retrieval mechanism are not completely identical, taking the retrieval example with the highest confidence level in the retrieval examples as the model input data.

[0013] Some embodiments of this application determine the model input data by judging whether the retrieved data of each level of the retrieval mechanism is the same, thereby achieving effective and accurate determination of model data.

[0014] In some embodiments, the step of fusing and analyzing the retrieval data of each retrieval mechanism to determine the model input data includes: if the retrieval data of each retrieval mechanism is not completely identical, sorting the retrieval examples according to the confidence level to obtain a sorting result; and selecting at least one retrieval example from the sorting result as the model input data.

[0015] Some embodiments of this application, by confirming that the retrieval data of each level of the retrieval mechanism is not completely identical, determine the model input data through confidence level, thereby achieving effective and accurate determination of model data.

[0016] In some embodiments, the step of processing the model input data using a target large language model to generate a query statement that matches the user's query intent includes: identifying at least one table of the retrieval examples and obtaining the table name; generating an initial query statement that matches the query fields and query conditions in at least one of the retrieval examples; and completing the table structure of the initial query statement to obtain the query statement; wherein the table structure represents the relationship between the tables in at least one of the retrieval examples.

[0017] Some embodiments of this application process the model input data in stages using a target large language model to generate query statements, thereby ensuring the accuracy and efficiency of the generated statements.

[0018] In some embodiments, before performing a multi-level retrieval in the query example database based on the user's query intent, the method further includes: obtaining user input information; wherein the type of the user input information includes text, voice, or image; and performing structured processing on the user input information to obtain the user's query intent.

[0019] Some embodiments of this application locate the user's query intent through user input information. The user input information can be various types of data. By supporting multiple input formats, it is convenient to conduct interactive queries with the user.

[0020] In some embodiments, after generating a query statement that matches the user's query intent, the method further includes: validating and correcting the query statement to obtain a corrected statement; and performing desensitization filtering on the corrected statement to obtain a target query statement.

[0021] Some embodiments of this application obtain the target query statement by verifying, correcting and desensitizing the query statement, which can meet the requirements of accurate generation of standard query statements in various scenarios.

[0022] Secondly, some embodiments of this application provide an apparatus for generating structured query statements, comprising: a retrieval module, configured to perform a retrieval in a query example library based on a user's query intent using a multi-level retrieval mechanism, and obtain retrieval data for each level of the multi-level retrieval mechanism; wherein the retrieval data includes retrieval examples and the confidence levels of the retrieval examples; a determination module, configured to perform fusion analysis on the retrieval data of each level of the retrieval mechanism to determine model input data; wherein the model input data includes at least one of the retrieval examples; and a generation module, configured to process the model input data using a target large language model to generate a query statement that matches the user's query intent.

[0023] Thirdly, some embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the method described in any embodiment of the first aspect.

[0024] Fourthly, some embodiments of this application provide an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, can implement the method as described in any embodiment of the first aspect.

[0025] Fifthly, some embodiments of this application provide a computer program product, the computer program product including a computer program, wherein the computer program, when executed by a processor, can implement the method described in any embodiment of the first aspect. Attached Figure Description

[0026] To more clearly illustrate the technical solutions of some embodiments of this application, the accompanying drawings used in some embodiments of this application will be briefly described below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 System diagrams for generating structured query statements provided for some embodiments of this application; Figure 2 One of the flowcharts for a method of generating structured query statements provided for some embodiments of this application; Figure 3 Flowchart 2 of the method for generating structured query statements provided for some embodiments of this application; Figure 4 A block diagram of the apparatus for generating structured query statements provided for some embodiments of this application; Figure 5A schematic diagram of an electronic device provided for some embodiments of this application. Detailed Implementation

[0028] The technical solutions of some embodiments of this application will now be described with reference to the accompanying drawings.

[0029] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0030] In related technologies, the process of automatically converting a user's natural language query into structured query language (SQL) typically includes rule-based methods, template-based methods, model training-based methods, and Few-shot methods based on prompt engineering.

[0031] Specifically, rule-based methods primarily rely on manually written grammar and semantic parsing rules for transformation. While this approach offers strong controllability within defined scenarios, it suffers from extremely poor flexibility and scalability, struggling to handle complex and ever-changing natural language expressions and query logic; essentially, it's an extension of "human programming." Furthermore, this method only supports predefined grammatical structures and keyword patterns, making it difficult to handle complex queries (such as nested subqueries and multi-table joins); rule maintenance costs are high, requiring continuous manual intervention to adapt to new query expressions; it also exhibits poor adaptability to the diversity and ambiguity of natural language, resulting in low generalization. Template-based methods, on the other hand, use predefined SQL templates, generating queries by filling slot values. Compared to pure rule-based methods, they offer some flexibility, but the completeness and maintenance costs of the template library become bottlenecks, making it unable to adapt to open-domain queries; essentially, it's a query assembly of a "finite state machine." That is, the template coverage is limited, making it difficult to cope with flexible and ever-changing query needs (such as dynamic condition combinations and complex aggregation calculations); the number of templates increases exponentially with query complexity, leading to high maintenance costs; and for semantically similar queries, templates may need to be repeatedly defined, resulting in low efficiency. Model-trained methods primarily utilize large-scale <natural language, SQL> pairing data to fine-tune pre-trained models, achieving end-to-end generation. This method exhibits strong generalization ability but suffers from fundamental drawbacks such as strong data dependency, high training costs, uncontrollable generation results, and poor interpretability; it is essentially a "black box" probabilistic generation approach. Furthermore, this method relies on large-scale labeled data (<natural language, SQL> pairings), resulting in high data labeling costs and long cycles; model training requires high-performance computing resources (such as GPUs / TPUs), leading to high deployment and inference costs; its performance is unstable in out-of-domain queries or complex logical queries due to limitations in training data distribution; and the syntactic correctness and execution efficiency of the generated SQL are difficult to guarantee, potentially requiring additional post-processing. Finally, the Few-shot method based on prompting engineering leverages the contextual learning capabilities of large models, guiding generation by providing a small number of examples (Few-shots). This method requires no training but is highly sensitive to example quality and retrieval relevance, and it is difficult to systematically inject complex domain business logic; its essence is "example-driven" experience imitation. Moreover, this method relies on high-quality demonstrations to build prompts, and writing demonstrations requires expertise; demonstration recall depends on retrieval algorithms, and recalling irrelevant demonstrations will mislead the model into generating incorrect SQL.

[0032] As can be seen from the above-mentioned related technologies, the existing technologies have a single input format in the process of generating SQL, which limits the convenience of user interaction; when faced with complex queries, the generation is prone to errors, requiring manual intervention to correct them, which consumes a lot of manpower; moreover, the system does not have self-optimization capabilities, resulting in high maintenance costs.

[0033] In view of this, some embodiments of this application provide a method for generating structured query statements. This method employs a multi-level retrieval mechanism to determine the retrieval data at each level based on the user's query intent; based on this retrieval data, model input data can be determined; finally, the target large language model is used to process and analyze the model input data to generate query statements. The embodiments of this application can accurately and efficiently generate query statements for various simple or complex scenarios. Subsequent automatic verification and correction can further optimize the model. The entire process requires no manual intervention, has low maintenance costs, and high practicality.

[0034] The following is in conjunction with the appendix Figure 1 The overall structure of the system for generating structured query statements provided by some embodiments of this application is illustrated by way of example.

[0035] like Figure 1 As shown in the diagram, some embodiments of this application provide a system diagram for generating structured query statements. This system may include a terminal 100 and a generation server 200. The terminal 100 allows users to input their query statement generation needs according to their requirements. The terminal 100 supports three input methods: text, voice, and image, and users can choose at least one method to input into the terminal 100. After receiving the user's request from the terminal 100, the generation server 200 can locate the user's query intent; then, it uses a multi-level retrieval mechanism to determine the retrieval data matching the user's query intent; based on the retrieval data under the multi-level retrieval mechanism, it can determine the model input data; finally, it inputs this data into a pre-deployed large language model to output the corresponding query statement, i.e., SQL.

[0036] In some embodiments of this application, the terminal 100 can be a mobile terminal or a non-portable computer terminal, and the embodiments of this application are not specifically limited here.

[0037] In some other embodiments of this application, if the terminal 100 possesses some or all of the functions of the generation server 200 in locating user query intent, retrieving data, and determining model input data, then the corresponding functions can be delegated to the terminal 100 for execution, and the generation server 200 can only perform the remaining operations except for the target large language model and the operations for processing the target large language model. Specifically, the configuration can be flexibly adjusted according to the actual application scenario, and the embodiments of this application are not limited thereto.

[0038] The following is in conjunction with the appendix Figure 2 The present application provides an exemplary embodiment of the implementation process for generating structured query statements executed by the generation server 200.

[0039] Please see the appendix Figure 2 , Figure 2 A flowchart illustrating a method for generating structured query statements, provided for some embodiments of this application.

[0040] In some embodiments of this application, before performing the following structured query statement generation process, the method for generating structured query statements may further include (not shown in the figure): obtaining user input information; wherein the type of the user input information includes text, voice, or image; and performing structured processing on the user input information to obtain the user query intent.

[0041] For example, in a specific embodiment of this application, a user can input at least one of text, voice, and image as user input information according to their needs. The user input information is then processed in a unified structure to obtain the user's query intent. Voice can be converted to text using ASR technology; images can have their table structure and key information extracted using OCR and visual recognition technologies to obtain the corresponding text. If the user input information contains only one type of information, it is processed to obtain the user's query intent. If the user input information contains multiple types of information, the text converted from voice or image is combined with the input text to obtain the user's query intent.

[0042] Additionally, the query sample library (referred to as the sample library) can be pre-built. The initial sample library can be manually constructed, containing multiple question-SQL pairs (called sample pairs or examples). During system operation, successful and failed query logs can be automatically collected. Then, a sample generator automatically generates new sample pairs based on the query logs and stores them in the sample library. Subsequently, a sample quality assessment model is used to filter all sample pairs in the sample library to optimize and deduplicate the sample library. Filtering primarily removes low-quality examples; for example, SQL with syntax errors or writing style issues is considered a low-quality example.

[0043] The following example illustrates the process of generating a structured query statement. The method for generating this structured query statement may include: S210, based on the user's query intent, a multi-level retrieval mechanism is used to search the query example database to obtain the retrieval data of each level of the multi-level retrieval mechanism; wherein, the retrieval data includes retrieval examples and the confidence level of the retrieval examples.

[0044] For example, in a specific embodiment of this application, based on the user's query intent, a three-level retrieval mechanism is used to search the constructed example library described above, obtaining retrieval examples under different retrieval mechanisms and the confidence level corresponding to each retrieval example. The multi-level retrieval mechanism can be added or removed according to actual needs, and this embodiment of the application does not impose specific limitations here.

[0045] In some embodiments of this application, S210 may include: retrieving first-level search data similar to the user's query intent from the query example library; determining second-level search data matching the user's query intent based on the table database and the query example library; and using historical query data related to the user's query intent as third-level search data; wherein the first-level search data, the second-level search data, and the third-level search data are the search data for each level of the multi-level search mechanism.

[0046] For example, in a specific embodiment of this application, the first-level retrieval mechanism is query intent-based classification retrieval; a similarity algorithm is used to retrieve at least one example similar to the user's query intent from the example library, along with the confidence score corresponding to each example in the at least one example, as the first-level retrieval data. The second-level retrieval mechanism is table structure similarity-based retrieval; specifically, table structures similar to the user's query intent are first retrieved from the table database, and then at least one example similar to the table structure is retrieved from the example library; this at least one example and its corresponding confidence score are used as the second-level retrieval data. The third-level retrieval mechanism is historical query pattern-based retrieval; specifically, questions similar to the user's query intent are found from historical query records, and then the historical query data corresponding to this question (containing at least one example and its corresponding confidence score) is used as the third-level retrieval data.

[0047] The similarity algorithm used for the aforementioned similarity calculation can be flexibly selected, and this application embodiment does not impose specific limitations on it.

[0048] S220, perform fusion analysis on the retrieval data of each level of retrieval mechanism to determine the model input data; wherein, the model input data includes at least one of the retrieval examples.

[0049] For example, in a specific embodiment of this application, the retrieved three-level search data are fused and analyzed to obtain few-shots (as a specific example of model input data) which are then input into the target large language model.

[0050] In some embodiments of this application, S220 may include: confirming that the retrieval data of each level of retrieval mechanism is the same, then using the retrieval example in the retrieval data as the model input data.

[0051] For example, in a specific example of this application, if the examples in the search data of the above three levels are all the same, then at least one of the above examples (as a specific example of the search example) is taken as few-shots.

[0052] In some other embodiments of this application, S220 may include: if it is confirmed that the retrieval data of each level of retrieval mechanism are not completely identical, using the retrieval example with the highest confidence level in the retrieval examples as the model input data.

[0053] For example, in a specific example of this application, if the examples in the above three levels of retrieval data are not completely identical, the determination can be made based on the confidence of at least one example, that is, the example with the highest confidence is selected as the model input data few-shots.

[0054] In some other embodiments of this application, S220 may include: if it is confirmed that the search data of each level of the search mechanism are not completely the same, sorting the search examples according to the confidence level to obtain a sorting result; and selecting at least one search example from the sorting result as the model input data.

[0055] For example, in a specific example of this application, if the examples in the above three levels of search data are not completely identical, at least one example can be sorted in descending order based on confidence level to obtain a sorting result. The top N examples from the sorting result are selected as model input data (few-shots), where N is a positive integer. Alternatively, at least one example with a confidence level greater than a preset threshold can be used as model input data (few-shots).

[0056] Understandably, the model input data can be determined using any of the methods mentioned above, depending on the actual situation.

[0057] S230, The target large language model is used to process the model input data to generate a query statement that matches the user's query intent.

[0058] For example, in a specific embodiment of this application, few-shots are input into a target large language model, and corresponding query statements are output. The target large language model can be of the type GPT-4, CodeLlama, etc.

[0059] In some embodiments of this application, S230 may include: identifying at least one table of the retrieval example and obtaining the table name; generating an initial query statement that matches the query fields and query conditions in at least one of the retrieval examples; and completing the table structure of the initial query statement to obtain the query statement; wherein the table structure represents the association relationship between the tables in at least one of the retrieval examples.

[0060] For example, in a specific embodiment of this application, the target large language model can process few-shots in three stages before outputting a query statement. The first stage is the table identification stage, which first identifies the table structure in the few-shots and outputs the table names. Then, based on the few-shots, corresponding fields (e.g., fields that can represent which data to query) and conditions (e.g., certain conditions for filtering data) are generated, and a complete initial SQL (as a specific example of an initial query statement) is output. Finally, complex structures in the initial SQL are completed, such as join relationships between tables, subqueries, and aggregation relationships between tables (as a specific example of association relationships), thereby outputting SQL (as a specific example of a query statement).

[0061] In some embodiments of this application, after executing S230, the method for generating a structured query statement further includes: verifying and correcting the query statement to obtain a corrected statement; and performing desensitization filtering on the corrected statement to obtain a target query statement.

[0062] For example, in a specific embodiment of this application, an SQL syntax and logic validator is used to verify and correct the generated SQL result, resulting in a corrected SQL that is free of syntax errors and can be executed normally (as a specific example of a corrected statement). Subsequently, an enterprise permission system can be integrated into the permission awareness and security filtering module to automatically filter out tables and fields that users do not have permission to access within the corrected SQL; sensitive queries in the corrected SQL can be anonymized or blocked to obtain the final target SQL (as a specific example of a target query statement). Besides using an SQL syntax and logic validator, a rule engine can also be used for verification; this embodiment of the application does not specifically limit the use of such a method.

[0063] Afterwards, users can evaluate and correct the generated target SQL. Based on the evaluation and correction results, the example library is automatically updated, the retrieval mechanism is optimized, or the target large language model is improved, thereby reducing the cost of manual maintenance. The example library update can adopt a semi-supervised learning method or a fully automated synthesis method.

[0064] The following is in conjunction with the appendix Figure 3 The present application provides an exemplary description of the specific process for generating structured query statements through some embodiments.

[0065] Please see the appendix Figure 3 , Figure 3 A flowchart illustrating a method for generating structured query statements, provided for some embodiments of this application.

[0066] The above process is illustrated below by example.

[0067] S310, obtains user input information.

[0068] S320 performs structured processing on the user input information to obtain the user's query intent.

[0069] S330, retrieve first-level search data from the query example library that are similar to the user's query intent.

[0070] S340, based on the table database and query example library, determines the second-level retrieval data that matches the user's query intent.

[0071] S350 uses historical query data related to the user's query intent as third-level retrieval data.

[0072] S360 performs fusion analysis on the first-level, second-level, and third-level search data to determine the model input data.

[0073] S370 inputs the model input data into the target large language model and outputs the query statement.

[0074] S380: Validate and correct the query statement, and obtain the corrected statement.

[0075] S390, perform desensitization filtering on the modified statement to obtain the target query statement.

[0076] It should be noted that the specific implementation process of S310~S390 can refer to the method embodiments provided above. To avoid repetition, detailed descriptions are omitted here. The execution order of S330~S350 can be flexibly adjusted, and this application is not limited to the above embodiments.

[0077] As can be seen from the above embodiments of this application, this application, through a self-learning mechanism, enables the system to continuously optimize the example library and generation effects from actual use, reducing manual maintenance costs and exhibiting strong adaptability; the embodiments of this application support voice and image input, improving system applicability and user experience; in addition, after the model outputs the query statement, a phased generation and verification mechanism can be implemented, significantly improving the generation accuracy of complex SQL; at the same time, the integration of permission and sensitive information detection meets enterprise-level data security requirements; the visual tracking of the entire generation process facilitates debugging and trust establishment.

[0078] Please refer to Figure 4 , Figure 4 The diagram illustrates the composition of an apparatus for generating structured query statements according to some embodiments of this application. It should be understood that this apparatus corresponds to the method embodiments described above and is capable of performing the various steps involved in the method embodiments. The specific functions of this apparatus can be found in the description above; detailed descriptions are omitted here to avoid repetition.

[0079] Figure 4 The structured query statement generation device includes at least one software functional module that can be stored in a memory or embedded in the structured query statement generation device in the form of software or firmware. The structured query statement generation device includes: a retrieval module 410, used to perform a retrieval in a query example library based on the user's query intent and using a multi-level retrieval mechanism to obtain retrieval data of each level of the multi-level retrieval mechanism; wherein the retrieval data includes retrieval examples and the confidence of the retrieval examples; a determination module 420, used to perform fusion analysis on the retrieval data of each level of the retrieval mechanism to determine the model input data; wherein the model input data includes at least one of the retrieval examples; and a generation module 430, used to process the model input data using a target large language model to generate a query statement that matches the user's query intent.

[0080] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the aforementioned method, and will not be elaborated further here.

[0081] Some embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can perform the operation of any of the methods corresponding to the methods provided in the above embodiments.

[0082] Some embodiments of this application also provide a computer program product, which includes a computer program, wherein when the computer program is executed by a processor, it can implement the operation of any of the methods corresponding to the above embodiments provided in the above embodiments.

[0083] like Figure 5 As shown, some embodiments of this application provide an electronic device 500, which includes a memory 510, a processor 520, and a computer program stored in the memory 510 and executable on the processor 520. When the processor 520 reads the program from the memory 510 via a bus 530 and executes the program, it can implement the methods of any of the above embodiments.

[0084] Processor 520 can process digital signals and can include various computing architectures. For example, it can be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 520 can be a microprocessor.

[0085] The memory 510 can be used to store instructions executed by the processor 520 or data related to the execution of instructions. These instructions and / or data may include code for implementing some or all of the functions of one or more modules described in the embodiments of this application. The processor 520 of this disclosure embodiment can be used to execute the instructions in the memory 510 to implement the methods shown above. The memory 510 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memories well known to those skilled in the art.

[0086] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0087] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0088] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method for generating structured query statements, characterized in that, include: Based on the user's query intent, a multi-level retrieval mechanism is used to search the query example database to obtain the retrieval data of each level of the multi-level retrieval mechanism; wherein, the retrieval data includes retrieval examples and the confidence level of the retrieval examples; The retrieval data of each level of the retrieval mechanism are fused and analyzed to determine the model input data; wherein, the model input data includes at least one of the retrieval examples; The target large language model is used to process the input data of the model to generate a query statement that matches the user's query intent.

2. The method as described in claim 1, characterized in that, The process involves using a multi-level retrieval mechanism based on the user's query intent to search the query example database and obtaining retrieval data for each level of the multi-level retrieval mechanism, including: Retrieve first-level search data that are similar to the user's query intent from the query example library; Based on the table database and the query example library, determine the second-level retrieval data that matches the user's query intent; Historical query data related to the user's query intent will be used as the third-level retrieval data. The first-level search data, the second-level search data, and the third-level search data are the search data for each level of the multi-level search mechanism.

3. The method as described in claim 1 or 2, characterized in that, The process of fusing and analyzing the retrieval data at each level of the retrieval mechanism to determine the model input data includes: If the search data for each level of the search mechanism is confirmed to be the same, then the search example in the search data is used as the input data for the model.

4. The method as described in claim 1 or 2, characterized in that, The process of fusing and analyzing the retrieval data at each level of the retrieval mechanism to determine the model input data includes: If it is confirmed that the retrieval data of each retrieval mechanism is not completely identical, the retrieval example with the highest confidence level in the retrieval examples shall be used as the input data of the model.

5. The method as described in claim 1 or 2, characterized in that, The process of fusing and analyzing the retrieval data at each level of the retrieval mechanism to determine the model input data includes: If it is confirmed that the search data of each level of the search mechanism are not completely identical, the search examples are sorted according to the confidence level to obtain the sorting results; At least one retrieval example is selected from the sorting results as input data for the model.

6. The method as described in claim 1 or 2, characterized in that, The step of processing the input data of the target large language model to generate a query statement that matches the user's query intent includes: Identify at least one table of the retrieval example and obtain the table name; Generate an initial query statement that matches the query fields and query conditions in at least one of the retrieval examples; The initial query statement is completed by table structure completion to obtain the query statement; wherein the table structure represents the relationship between at least one table in the retrieval example.

7. The method as described in claim 1 or 2, characterized in that, Before performing a multi-level retrieval mechanism in the query example database based on the user's query intent, the method further includes: Obtain user input information; wherein the type of user input information includes text, voice, or image; The user input information is structured to obtain the user's query intent.

8. The method as described in claim 1 or 2, characterized in that, After generating a query statement that matches the user's query intent, the method further includes: The query statement is validated and corrected to obtain the corrected statement; The modified statement is then desensitized and filtered to obtain the target query statement.

9. An apparatus for generating structured query statements, characterized in that, include: The retrieval module is used to search the query example library based on the user's query intent using a multi-level retrieval mechanism, and to obtain the retrieval data of each level of the multi-level retrieval mechanism; wherein, the retrieval data includes retrieval examples and the confidence level of the retrieval examples; The determination module is used to perform fusion analysis on the retrieval data of each level of the retrieval mechanism to determine the model input data; wherein, the model input data includes at least one of the retrieval examples; The generation module is used to process the input data of the model using the target large language model to generate a query statement that matches the user's query intent.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is executed by a processor to perform the method as described in any one of claims 1-8.

11. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored on the memory and running on the processor, wherein the computer program is executed by the processor to perform the method as described in any one of claims 1-8.

12. A computer program product, characterized in that, The computer program product includes a computer program, wherein the computer program is executed by a processor to perform the method as described in any one of claims 1-8.