Data query method and device based on natural language

By performing semantic parsing on natural language input and generating structured query plans, the problems of semantic deviation and logical confusion in query statements in complex business scenarios are solved, thereby improving the accuracy and reliability of query results.

CN122019568APending Publication Date: 2026-05-12CHINA UNIONPAY
View PDF 0 Cites 1 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA UNIONPAY
Filing Date
2026-01-26
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In complex business scenarios, the query statements of existing natural language query databases are prone to semantic bias and logical confusion, resulting in low accuracy and reliability of query results.

Method used

By performing semantic parsing on natural language input, user intent and multiple semantic elements are determined. An explicit structured query plan is generated based on a sequence of query operators, and query statements are generated using the target database object identifier, thereby improving the accuracy and interpretability of the query statements.

Benefits of technology

This improves the accuracy and interpretability of query statements, thereby enhancing the accuracy and reliability of query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122019568A_ABST
    Figure CN122019568A_ABST
Patent Text Reader

Abstract

The invention discloses a data query method and device based on a natural language. The method comprises the following steps: receiving natural language input of a user; performing semantic analysis on the natural language input, and determining a user intention and a plurality of semantic elements; based on the user intention, target query operators corresponding to the semantic elements respectively are determined in a query operator sequence, and the query operator sequence comprises a plurality of query operators arranged according to the execution sequence; generating a query plan based on the target query operators, the semantic elements corresponding to the target query operators and the execution sequence of the multiple target query operators; a query statement is generated based on the query plan and target database object identifiers corresponding to the semantic elements respectively, and the target database object identifiers comprise at least one of table names and field names; and performing data query based on the query statement. According to the embodiment of the invention, the accuracy and the interpretability of the query statement can be improved, so that the accuracy and the reliability of the query result are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of data query technology, and in particular relates to a data query method and apparatus based on natural language. Background Technology

[0002] With breakthroughs in the fields of large language model (LLM) for natural language understanding and structured data generation, natural language query databases have become an important technological direction for improving the intelligence level of enterprise data analysis.

[0003] In current practices of natural language database question answering, by combining large models with prompt words, knowledge bases and pre-set question-answer pairs, natural language can be converted into query statements. By executing these query statements, data query results can be obtained, enabling users to directly query the database using natural language to obtain data query results.

[0004] However, in real-world complex business scenarios, especially when dealing with multi-table joins and complex business logic, query statements generated in the above manner are prone to semantic bias and logical confusion, resulting in low accuracy of the query statements and directly affecting the accuracy and reliability of the query results. Summary of the Invention

[0005] This application provides a data query method, apparatus, electronic device, computer-readable storage medium, and computer program product based on natural language, which can improve the accuracy and interpretability of query statements, thereby improving the accuracy and reliability of query results.

[0006] In a first aspect, embodiments of this application provide a data query method based on natural language, the method comprising: Receive natural language input from users; Semantic parsing is performed on the natural language input to determine the user's intent and multiple semantic elements; Based on the user intent, target query operators corresponding to the plurality of semantic elements are determined in the query operator sequence, wherein the query operator sequence includes a plurality of query operators arranged in execution order; A query plan is generated based on the target query operator and its corresponding semantic elements, as well as the execution order of the multiple target query operators; Based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements, a query statement is generated, wherein the target database object identifier includes at least one of table name and field name; Based on the query statement, perform a data query.

[0007] Secondly, embodiments of this application provide a data query device based on natural language, the device comprising: The receiving module is used to receive the user's natural language input; The parsing module is used to perform semantic parsing on the natural language input to determine the user's intent and multiple semantic elements; The determination module is used to determine, based on the user intent, the target query operators corresponding to the plurality of semantic elements in the query operator sequence, wherein the query operator sequence includes a plurality of query operators arranged in execution order; The generation module is used to generate a query plan based on the target query operator and its corresponding semantic elements, as well as the execution order of the multiple target query operators; The generation module is further configured to generate a query statement based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements respectively, wherein the target database object identifiers include at least one of table name and field name; The query module is used to perform data queries based on the query statement.

[0008] Thirdly, embodiments of this application provide an electronic device, which includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements any of the possible implementations of the first aspect described above.

[0009] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the method in any of the possible implementations of the first aspect described above.

[0010] Fifthly, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform a method as described in any of the possible implementations of the first aspect above.

[0011] In this embodiment, the query operator sequence includes multiple query operators arranged in execution order. Based on this, by performing semantic parsing on natural language input to determine user intent and multiple semantic elements, and then determining the target query operators corresponding to each of the multiple semantic elements in the query operator sequence based on the user intent, and generating a query plan based on the target query operators, their corresponding semantic elements, and the execution order of the multiple target query operators, the natural language input can be converted into a clear, structured query plan. By generating a query statement based on this clear, structured query plan and the target database object identifiers corresponding to the multiple semantic elements, the accuracy and interpretability of the query statement can be improved. Thus, by performing data queries based on the query statements generated in this embodiment, the accuracy and reliability of the query results can be improved. Attached Figure Description

[0012] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart illustrating a natural language-based data query method provided in one embodiment of this application; Figure 2 This is a flowchart illustrating a natural language-based data query method provided in another embodiment of this application; Figure 3 This is a schematic diagram of a natural language-based data query method provided in one embodiment of this application; Figure 4 This is a schematic diagram of the structure of a natural language-based data query device provided in one embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device provided in one embodiment of this application. Detailed Implementation

[0014] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.

[0015] It should be noted that, in this document, relational terms such as "first" and "second" are used merely 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..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.

[0016] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.

[0017] Furthermore, the acquisition, storage, use, and processing of data in this application's technical solution all comply with relevant national laws and regulations.

[0018] With breakthroughs in the fields of large language model (LLM) for natural language understanding and structured data generation, natural language query databases have become an important technological direction for improving the intelligence level of enterprise data analysis.

[0019] In current practices of natural language database question answering, by combining large models with prompt words, knowledge bases and pre-set question-answer pairs, natural language can be converted into query statements. By executing these query statements, data query results can be obtained, enabling users to directly query the database using natural language to obtain data query results.

[0020] However, in real-world complex business scenarios, especially when dealing with multi-table joins and complex business logic, query statements generated in the above manner are prone to semantic bias and logical confusion, resulting in low accuracy of the query statements and directly affecting the accuracy and reliability of the query results.

[0021] To address the related technical problems, embodiments of this application provide a data query method, apparatus, electronic device, computer-readable storage medium, and computer program product based on natural language. This natural language-based data query method can be executed by a data query system. The data query system may include a front-end interface and a back-end server. The front-end interface can be used to interact with the user, receive the user's natural language input, and send the natural language input to the back-end server. The back-end server can be used to convert the natural language into a query statement, execute the query statement to obtain data query results, and return the data query results to the front-end interface, so that the front-end interface can provide feedback on the data query results to the user.

[0022] The following describes the natural language-based data query method provided in the embodiments of this application.

[0023] Figure 1 A flowchart illustrating a natural language-based data query method according to an embodiment of this application is shown. Figure 1 As shown, the natural language-based data query method provided in this application includes the following steps: S110, Receive natural language input from the user; S120. Perform semantic parsing on natural language input to determine user intent and multiple semantic elements; S130. Based on user intent, determine the target query operators corresponding to multiple semantic elements in the query operator sequence, the query operator sequence including multiple query operators arranged in execution order; S140. Generate a query plan based on the target query operator and its corresponding semantic elements, as well as the execution order of multiple target query operators; S150. Generate a query statement based on the query plan and the target database object identifiers corresponding to multiple semantic elements. The target database object identifiers include at least one of table name and field name. S160. Perform data query based on the query statement.

[0024] In this embodiment, the query operator sequence includes multiple query operators arranged in execution order. Based on this, by performing semantic parsing on natural language input to determine user intent and multiple semantic elements, and then determining the target query operators corresponding to each of the multiple semantic elements in the query operator sequence based on the user intent, and generating a query plan based on the target query operators, their corresponding semantic elements, and the execution order of the multiple target query operators, the natural language input can be converted into a clear, structured query plan. By generating a query statement based on this clear, structured query plan and the target database object identifiers corresponding to the multiple semantic elements, the accuracy and interpretability of the query statement can be improved. Thus, by performing data queries based on the query statements generated in this embodiment, the accuracy and reliability of the query results can be improved.

[0025] The specific implementation methods for each of the above steps are described below.

[0026] In some embodiments, in S110, the front-end interface of the data query system can receive natural language input from the user for data querying and send the natural language input to the back-end server of the data query system.

[0027] In some embodiments, in S120, the semantic elements can be structured elements obtained by decomposing the natural language input. Multiple semantic elements can include time elements, geographic elements, metric elements, aggregation elements, subject elements, etc. For example, if the natural language input is "Query which customers in East China had sales exceeding 1 million last year", then multiple semantic elements can include the time element "last year", the geographic element "East China", the metric element "sales exceeding 1 million", the aggregation element "top 10", the subject element "customers", etc.

[0028] As an example, after receiving natural language input, the backend server of the data query system can use a Large Language Model (LLM) based on Chain-of-Thought (CoT) technology to identify user intent and decompose the natural language input into multiple semantic elements based on user intent.

[0029] If the complexity of the natural language input is high, the accuracy of multiple semantic elements may be low, thereby reducing the accuracy of the subsequently generated query statement. Therefore, in order to improve the accuracy of multiple semantic elements and thus improve the accuracy of the query statement, in some embodiments, the above-mentioned S120 may specifically include: Perform semantic parsing on natural language input to determine user intent and query complexity; When the query complexity characterizes the natural language input as a complex query, the natural language input is decomposed into multiple sub-query tasks based on the user intent of the natural language input. Semantic parsing is performed on each subquery task to determine the user intent and multiple semantic elements of each subquery task.

[0030] Here, the data query system may include a complexity detection module and a query task graph construction module. Furthermore, the multiple semantic elements of the natural language input may include multiple semantic elements corresponding to multiple sub-query tasks.

[0031] As an example, after receiving natural language input, the backend server can first perform semantic parsing on the input using a complexity detection module to determine the user's intent and query complexity. If the query complexity indicates that the natural language input is a simple query, it can be semantically decomposed using the thought chain technique to obtain multiple semantic elements. If the query complexity indicates that the natural language input is a complex query, it can be decomposed into multiple sub-query tasks using a query task graph construction module, based on the thought chain technique and user intent, and the dependencies between these sub-query tasks can be determined. These dependencies can be data dependencies, meaning that the output of an upstream sub-query task is the input of a downstream sub-query task.

[0032] As an example, using subquery tasks as nodes and the dependencies between subquery tasks as edges, a directed acyclic graph (i.e., a query task graph) can be constructed. This directed acyclic graph can guide the execution order of multiple subquery tasks. Specifically, for each subquery task, the following operations can be performed: semantic parsing of the subquery task to determine the user intent and multiple semantic elements of the subquery task; generating a subquery statement corresponding to the subquery task based on the user intent and multiple semantic elements; and finally, generating a complete query statement based on multiple subquery statements.

[0033] For example, if the natural language input is "to statistically analyze the activity rate of new users within 90 days of their first login in the past year, compare it with the activity rate of returning users within a 90-day window in the third quarter, display the top 5 users by region and channel, and sort them by the difference in activity rate," then this query involves time, grouping, and nesting, making it highly complex. Therefore, we can use the MindChain technique to decompose the natural language input into multiple query subtasks, Task A-Task E, and their dependencies. The specific details of the multiple query subtasks and their dependencies are as follows: Task A: New user set. Definition: The set of users who logged in for the first time in the past year. Task B: New user 90-day activity rate. Definition: Based on the users in Task A, calculate whether a second login occurred within 0-90 days from the first login. Task C: Returning user set. Definition: Users who logged in before the past year. Task D: Returning user 90-day window activity rate. Definition: Calculate the activity of returning users within a 90-day window in the past year. Task E: Result alignment and Top 5 selection. Merge the results of Task B and Task D, aggregate by (region + channel), calculate the difference in activity rate, and select the top 5. The directed acyclic graph constructed based on the above multiple subquery tasks and their dependencies can be shown as follows: Task A → Task B, Task C → Task D, Task B, Task D → Task E.

[0034] This application embodiment determines the query complexity of the natural language input before determining multiple semantic elements of the natural language input. Then, when the query complexity indicates that the natural language input is a complex query, the natural language input is decomposed into multiple sub-query tasks. The user intent and multiple semantic elements of each sub-query task are determined respectively. This can improve the accuracy of the semantic elements corresponding to each sub-query task, thereby improving the accuracy of the multiple semantic elements corresponding to the natural language input, and thus improving the accuracy of the query statement.

[0035] Therefore, to improve the accuracy of determining query complexity, in some embodiments, the above-mentioned semantic parsing of natural language input to determine user intent and query complexity may specifically include: Semantic parsing of natural language input yields thought chain data representing the user's intent; Identify target description text related to query complexity within the thought chain data; Based on the user intent represented by the target description text and the thought chain data, the complexity label is determined. Determine the query complexity based on the complexity label.

[0036] Here, the thought chain data can be a mid-level representation that decomposes a natural language query into structured semantic elements, operational intent, and implicit needs through step-by-step reasoning. For example, thought chain data could include: "This is a comparative analysis query involving a comparison of two cities," or "The comparison dimension is cities." Target description text could include, for example, "comparison," "same period," or "simultaneously satisfying the following conditions." Complexity tags could include, for example, multiple time periods, multiple clusters, or multiple subqueries.

[0037] As an example, after receiving natural language input, the backend server can first perform semantic parsing on the input using thought chain technology to obtain thought chain data representing the user's intent. Then, through a complexity detection module, based on the natural language understanding capabilities of LLM, it can identify the target description text related to query complexity within the thought chain data, as well as the user intent represented by the target description text and the thought chain data, to determine the complexity label. If the complexity label includes at least two of the following: multiple time periods, multiple clusters, and multiple subqueries, then the natural language input can be determined to be a complex query.

[0038] This application's embodiments utilize rule-based and LLM-based natural language understanding capabilities to jointly determine query complexity, thereby improving the accuracy of query complexity determination. The rules can include which target description texts correspond to which complexity tags, and what conditions must be met to determine if a natural language input is a complex query.

[0039] In some embodiments, in S130, the query operator sequence may include multiple query operators arranged in execution order. Each query operator may correspond to a query operation, and each query operation may correspond to one or more semantic elements. Therefore, based on the query operator sequence, the execution order of multiple query actions can be determined. The query operator sequence may, for example, be: FROM / JOIN graph, WHERE, GROUP BY, aggregation, window, HAVING, ORDER BY, LIMIT.

[0040] As an example, a data query system may also include a query plan generation module. Based on user intent, the query plan generation module can determine target query operators corresponding to multiple semantic elements within a sequence of query operators. Each semantic element may correspond to one or more target query operators. Each target query operator may also correspond to one or more semantic elements.

[0041] In some embodiments, in S140, the query plan may include multiple query steps arranged in sequence.

[0042] As an example, the query plan generation module can generate query steps based on target query operators and their corresponding semantic elements using LLM, and generate a query plan based on the execution order of multiple target query operators and multiple query steps. Furthermore, the query plan generation module can also output the purpose of generating multiple query steps and their dependencies. To enable the query plan generation module to generate executable query plans using LLM, the corresponding prompts can include suggestions such as "Avoid multi-table joins with unrelated conditions to prevent Cartesian products, and ensure that the dimensions of aggregate queries are explicit and consistent."

[0043] One embodiment of this application provides a query plan that may be as follows: {"steps": [ {"op": "FILTER", "on": "Orders", "condition": "Order time in the last three months"}, {"op": "GROUP_BY", "key": "province"}, {"op": "AGG", "metric": "sum(transaction amount)"}, {"op": "ORDER_BY", "by": "sum(transaction amount)", "direction": "DESC"}]} In the example above, "steps" represents the complete query plan, "op" represents a single query step, "FILTER", "GROUP_BY", "AGG", "ORDER_BY", etc. represent query operators, and "order", "order time in the last three months", "province", "sum(transaction amount)", "DESC", etc. represent semantic elements.

[0044] In some embodiments, in S150, the target database object identifier can be a table name or field name obtained by retrieving and mapping semantic elements. For example, "order" can be mapped to the table name "order", and "province" can be mapped to the combination of the table name and field name "order.province".

[0045] In this way, the query plan generation module can also replace multiple semantic elements with their respective target database object identifiers, and generate query statements by combining the query plan.

[0046] Therefore, in order to improve the accuracy of the target database object identifier, in some embodiments, before S150 above, the method may further include: Based on the hybrid retrieval method, candidate database object identifiers corresponding to multiple semantic elements are determined from the original set of database object identifiers, resulting in candidate sets corresponding to multiple semantic elements. For each semantic element, perform the following operations: By using a reordering model, the confidence level of multiple candidate database object identifiers in the candidate set is determined based on the database schema index corresponding to the candidate set. The candidate data object identifiers corresponding to the confidence levels that meet the confidence level conditions are determined as the target database object identifiers.

[0047] Here, the original set of database object identifiers can include multiple original database object identifiers. These multiple original database object identifiers can be the database schema and all database object identifiers pre-recorded in the knowledge base. A hybrid retrieval method can be used to initially screen the original set of database object identifiers using multiple retrieval methods, resulting in a candidate set including multiple candidate database object identifiers. For example, the candidate set corresponding to each semantic element can include, for example, the tables with the top 200 initial screening scores and the columns with the top 50 initial screening scores in each table.

[0048] In addition, database schema indexes can include tables, columns, aliases, data dictionaries, sample values, etc. After the initial screening, for each semantic feature, a re-ranking model can be used to determine the confidence levels of multiple candidate database object identifiers in the candidate set based on the database schema index corresponding to the candidate set. The candidate database object identifiers are then re-ranked in descending order of confidence level, and the candidate database object identifier with the highest confidence level is determined as the target database object identifier. The re-ranking model can be, for example, a cross-encoder architecture re-ranking model, such as the BEG re-ranking large model (BAAI General EmbeddingReranker Large, bge-reranker-large) or the monolingual BERT re-ranking model (monoBER).

[0049] This application embodiment first performs a preliminary screening of the original database object identifier set based on a hybrid retrieval method to obtain a candidate set, and then, for each semantic element, performs a two-stage screening and mapping method to reorder multiple candidate database object identifiers in the candidate set based on a reordering model to determine the target database object identifier corresponding to each semantic element, which can improve the accuracy of the target database object identifier.

[0050] Based on this, in order to further improve the accuracy of the target database object identifier, in some embodiments, the above-mentioned determination of the candidate data object identifier corresponding to the confidence level that meets the confidence level condition as the target database object identifier may specifically include: Among multiple confidence levels, if the difference between the highest confidence level and the second highest confidence level is less than the difference threshold, a database object identifier confirmation request is output. The database object identifier confirmation request is used to ask the user to determine the target database object identifier from the database object identifiers corresponding to the highest confidence level and the database object identifiers corresponding to the second highest confidence level.

[0051] Here, before determining the target database object identifier, the difference between the highest confidence level and the second-highest confidence level can be compared first. If the difference is large (i.e., the difference is greater than or equal to the difference threshold), the candidate database object identifier corresponding to the highest confidence level can be directly determined as the target database object identifier. If the difference is small (i.e., the difference is less than the difference threshold), a database object identifier confirmation request can be output to the user, requesting the user to determine the target database object identifier from the database object identifier corresponding to the highest confidence level and the database object identifier corresponding to the second-highest confidence level. For example, the database object identifier confirmation request can be used to request confirmation of whether the credit limit is a net amount or a total amount.

[0052] This application embodiment, by asking the user a reverse question when the difference between the maximum confidence level and the second-highest confidence level is small, guides the user to clarify their intentions through the reverse question, rather than forcing a choice, which can further improve the accuracy of the target database object identifier and provide a clear explanation for their decision-making.

[0053] Furthermore, to improve the accuracy of candidate database object identifiers, and thus further improve the accuracy of target database object identifiers, in some embodiments, the above-mentioned method of determining candidate database object identifiers corresponding to multiple semantic elements in the original database object identifier set based on a hybrid retrieval approach may specifically include: For each semantic element, perform the following operations: The semantic elements are determined to have the first similarity to each original database object identifier by word literal matching. The second similarity between semantic elements and each original database object identifier is determined by vector matching. Using a reordering model, based on the database schema index corresponding to each original database object identifier, the third similarity between semantic elements and each original database object identifier is determined. The first similarity, second similarity and third similarity are weighted and summed to obtain the retrieval score of each original database object identifier; The original database object identifiers corresponding to the search scores that meet the search score criteria are identified as candidate database object identifiers.

[0054] Here, word-based matching can be used for sparse matching. For example, word-based matching can be implemented using the Best Matching 25 (BM25) algorithm or the Sparse Lexical AnDExpansion Model (SPLADE). Vector matching can be used for dense matching. For example, vector matching can be implemented using General Text Embeddings (gte) or BAAI General Embedding (bge). Furthermore, the method of determining the third similarity between semantic elements and each original database object identifier using the re-ranking model, based on the database pattern index corresponding to each original database object identifier, is the same as the method described above, which uses the re-ranking model to determine the confidence scores of multiple candidate database object identifiers in the candidate set based on the database pattern index corresponding to the candidate set; therefore, it will not be repeated here.

[0055] Furthermore, the weight corresponding to the first similarity score could be, for example, 0.2, the weight corresponding to the second similarity score could be, for example, 0.3, and the weight corresponding to the third similarity score could be, for example, 0.5. By weighting and summing the first, second, and third similarities based on these weights, the retrieval score for each original database object identifier can be obtained. Additionally, these weights can be initial weights, and more intelligent methods, such as the Lambda Gradient Boosted MART (LambdaMART), can be used to automatically learn and optimize these weights. Furthermore, a retrieval score that meets the retrieval score criteria can include at least one of the following: a retrieval score greater than a preset score and a retrieval score ranking highly.

[0056] This application's embodiments, through literal word matching, ensure a basic match of the query intent, effectively preventing semantic drift caused by LLM rewriting or ambiguous user expressions; through vector matching, it captures long-tail information with different literals but related concepts; and through a re-ranking model, it performs deep fine-grained ranking. Thus, by jointly determining candidate database object identifiers based on literal word matching, vector matching, and re-ranking, the accuracy of candidate database object identifiers can be improved, thereby further improving the accuracy of target database object identifiers.

[0057] Furthermore, after generating the query plan and determining the target database object identifier, the query plan and target database object identifier can be introspected and self-healed before generating the query statement to improve the accuracy of the query statement.

[0058] Specifically, in order to improve the accuracy of the query statement, in some embodiments, the above-mentioned S150 may specifically include: Based on the query plan and the target database object identifier, a logical structure consistency check is performed to obtain the first check result. The logical structure consistency check includes at least one of the following: connection reachability check, data object existence check, data type consistency check, and aggregation dimension consistency check. If the first verification result is successful, a query statement is generated based on the query plan and the target database object identifiers corresponding to the multiple semantic elements.

[0059] Here, connection reachability verification can be based on the database schema graph to verify whether the table connection path specified in the query plan is valid and reachable; data object existence verification can verify whether the table and column indicated by the target database object identifier exist in the database; data type consistency verification can verify whether the database type of the query operator in the query plan is compatible with the database type of the column indicated by the target database object identifier; and aggregation dimension consistency verification can verify whether the aggregation operation in the query plan and the grouping dimension are logically matched.

[0060] As an example, a data query system may also include an L2 introspection and self-healing module. This module can perform a logical structure consistency check based on the query plan and the target database object identifier. If the check passes, it can be determined that the query plan and the target database object identifier are correct and matched. Therefore, subsequent steps to generate query statements can be performed to improve the accuracy of the query statements.

[0061] In addition, to improve system repair efficiency and the accuracy of query statements, in some embodiments, after obtaining the first verification result, the method may further include: If the first verification result is a verification failure, and the reason for the failure is that the connection is unreachable or the data object does not exist, the target database object identifier is re-determined, and the execution is returned to perform a logical structure consistency check based on the query plan and the target database object identifier to obtain the first verification result, until the first verification result is a verification pass; If the first verification result is a failure, and the reason for the failure is inconsistent data types or inconsistent aggregation dimensions, the query plan is regenerated, and the execution is returned to perform a logical structure consistency check based on the query plan and the target database object identifier to obtain the first verification result, until the first verification result is a successful verification.

[0062] Here, if the validation result for the query plan and the target database object identifier fails, the L2 layer introspection and self-healing module can analyze the validation result to determine the cause of the failure and generate a reflection report including the cause of the failure. If the cause of failure is that the connection is unreachable or the data object does not exist, it can be determined that there is an error in the retrieval and mapping of the target database object identifier. In this case, it can fall back to the retrieval and mapping layer to re-perform the retrieval and mapping, re-determine the target database object identifier, and initiate validation again until the validation passes.

[0063] On the other hand, if the failure is due to inconsistent data types or inconsistent aggregation dimensions, it can be determined that the query plan is inaccurate. In this case, it can be rolled back to the query plan generation layer to regenerate the query plan and initiate the verification again until the verification passes.

[0064] This application embodiment, when the verification of the query plan and the target database object identifier fails, reverts to the retrieval and mapping layer or the query plan generation layer based on the reason for the failure, instead of reverting to the semantic parsing layer. This not only accurately locates and repairs implementation errors at specific levels, avoiding unnecessary full-link backtracking and significantly improving system repair efficiency, but also ensures that the query plan and the target database object identifier are correct and matched before executing the subsequent steps of generating query statements, thereby improving the accuracy of the query statements.

[0065] Furthermore, in this embodiment, if the natural language input is a simple query, the query statement corresponding to the natural language input can be directly generated using the above method. If the natural language input is a complex query, the above method can generate sub-query statements corresponding to each sub-query task. Based on this, merging these multiple sub-query statements yields a complete query statement.

[0066] Therefore, in order to improve the accuracy of query statements corresponding to complex natural language input, in some embodiments, the above-mentioned S150 may specifically include: For each subquery task, a subquery statement is generated based on the query plan and the target database object identifiers corresponding to multiple semantic elements. A query statement is generated based on the dependencies between multiple subquery tasks and multiple subquery statements.

[0067] Here, the data query system may also include a query statement orchestration module. This module can obtain the dependencies between multiple subquery tasks from the query task graph, and based on these dependencies, merge the multiple subquery statements to obtain a complete query statement.

[0068] In this embodiment, for natural language input with high query complexity, the natural language input is first decomposed into multiple sub-query tasks. Then, for each sub-query task, a sub-query statement is generated based on the query plan and the target database object identifiers corresponding to multiple semantic elements. Finally, a complete query statement is generated based on the dependencies between multiple sub-query tasks and multiple sub-query statements. This can improve the accuracy of the query statement corresponding to complex natural language input.

[0069] Therefore, in order to further improve the accuracy of query statements corresponding to complex natural language input, in some embodiments, the above-mentioned generation of query statements based on the dependencies between multiple sub-query tasks and multiple sub-query statements may specifically include: Based on the dependencies between multiple subquery tasks, a global consistency check is performed on multiple subquery statements to obtain the fifth check result. The global consistency check includes at least one of the following: time range alignment check, business definition consistency check, data granularity consistency check, and data flow reachability check. If the fifth verification result is successful, a query statement is generated based on the dependencies between multiple subquery tasks and multiple subquery statements.

[0070] Here, time range alignment verification can check whether all time-related subqueries (such as filter conditions, aggregation windows, and time partitions) in multiple subqueries adhere to a unified time base and range. Business definition consistency verification can verify whether the business concepts, indicator definitions, and audience tags used in multiple subqueries remain strictly consistent throughout the query chain. Data granularity consistency verification can check whether the aggregation or summary levels of data in multiple subqueries match. Data flow reachability verification can verify whether the data (fields, intermediate tables) produced by upstream steps can be correctly accessed and used by downstream steps.

[0071] As an example, a data query system may also include a global consistency introspection and self-healing module, which can perform global consistency checks on multiple subquery statements. If the check passes, it can be determined that the multiple subquery statements are correct and matched, and therefore, the subsequent steps of generating query statements can be executed.

[0072] This application embodiment improves the accuracy of query statements corresponding to complex natural language input by performing a global consistency check on the multiple subquery statements based on the dependencies between the multiple subquery tasks before generating a complete query statement after obtaining multiple subquery statements. If the check passes, the query statement is generated based on the dependencies between the multiple subquery tasks and the multiple subquery statements.

[0073] In addition, to further improve the accuracy of query statements corresponding to complex natural language input, in some embodiments, after obtaining the fifth verification result, the method may further include: If the fifth verification result is a verification failure, determine the second verification type and the first subquery task that caused the verification failure; Based on the second verification type, the target level for correcting the first subquery task is determined. The target level is one of the multiple processing levels involved in the process of generating the subquery statement corresponding to the first subquery task. The output of the first subquery task at the target level is corrected to obtain the corrected result; Based on the correction results, the subquery statement corresponding to the first subquery task is regenerated, and the execution is returned based on the dependencies between multiple subquery tasks. A global consistency check is performed on multiple subquery statements until the fifth check result is a pass.

[0074] Here, the second verification type can be any one of time range alignment verification, business definition consistency verification, data granularity consistency verification, and data flow reachability verification. The first subquery task can be any one of multiple subquery tasks. Furthermore, multiple processing layers can include a semantic parsing layer, a retrieval and mapping layer, a query plan generation layer, and a query statement generation layer. The semantic parsing layer can be used to perform semantic parsing on natural language input to determine user intent and multiple semantic elements. The retrieval and mapping layer can be used to determine the target database object identifiers corresponding to each of the multiple semantic elements. The query plan generation layer can be used to generate a query plan based on multiple semantic elements. The query statement generation layer can be used to generate a query statement based on the query plan and the target database object identifiers corresponding to each of the multiple semantic elements.

[0075] If the second verification type, time range alignment verification or business definition consistency verification, fails, the target level can be determined as the query plan generation layer; if the second verification type, data granularity consistency verification, fails, the target level can be determined as the query plan generation layer; if the second verification type, data flow reachability verification, fails, the target level can be determined as the retrieval and mapping layer or the query statement generation layer.

[0076] Once the target level is determined, you can roll back to the target level and re-execute a series of operation steps corresponding to the target level (such as regenerating the query plan, re-searching and mapping, etc.), as well as regenerating the subquery statement corresponding to the first subquery task and re-validating it until the validation passes.

[0077] For example, if a new user is defined as a user who logs in for the first time within the past year, and an old user is defined as a user who logged in for the first time before the past year and had operational behavior within the statistical period, and the global consistency self-introspection and self-healing module finds that a certain subquery task defines an old user as a user who has logged in multiple times during the business definition consistency verification, then it can be determined that the business definition consistency verification has failed, and the reason for the failure is marked as inconsistent user definition. Based on the correspondence between the second verification type and the target level, it rolls back to the query plan generation layer, regenerates the subquery plan corresponding to the subquery task in the query plan generation layer, and regenerates the subquery statement based on the corrected subquery plan.

[0078] This application embodiment achieves accurate and efficient self-healing by performing a global consistency check on multiple subquery statements based on the dependencies between them before generating a complete query statement. If the check fails, the target level is determined based on the reason for the failure, and then the process is reversed to the target level for correction. Based on the correction result, the subquery statement corresponding to the first subquery task is regenerated. This further improves the accuracy of query statements corresponding to complex natural language inputs.

[0079] In some embodiments, in S160, after generating the query statement, the data can be queried by executing the query statement to obtain the data query results. The query statement can be, for example, a Structured Query Language (SQL) statement.

[0080] Therefore, in order to improve the accuracy of data query results, in some embodiments, the above-mentioned S160 may specifically include: The query statement is matched with multiple semantic elements to obtain the matching results. If the matching result is successful, perform data retrieval based on the query statement.

[0081] Here, multiple query elements can include query operators such as WHERE, HAVING, and GROUP BY, as well as query objects, filter conditions, aggregation conditions, etc.

[0082] As an example, a data query system can also include an L1 layer introspection and self-healing module. After completing the conversion from natural language input to a query statement, before executing the query statement, the L1 layer introspection and self-healing module can also match multiple query elements in the query statement with multiple semantic elements, check whether the query statement covers elements such as filtering, dimensions, and measures in multiple semantic elements, and whether multiple semantic elements are correctly and completely represented in the query statement.

[0083] Thus, by ensuring that multiple semantic elements are correctly and completely represented in the query statement, data retrieval based on the query statement can improve the accuracy of the data query results.

[0084] In addition, to improve the accuracy of data query results, in some embodiments, after obtaining the matching results, the method may further include: If the matching result is a failure, return to perform semantic parsing on the natural language input to determine the user's intent and multiple semantic elements until the matching result is a success.

[0085] Here, if the matching results for multiple query elements and multiple semantic elements fail, the L1 layer introspection and self-healing module can analyze the matching results to determine the reason for the failure and generate a reflection report including the reason for the failure. For example, if the natural language input explicitly mentions "statistics by city", but the generated query statement lacks GROUP BY city, the L1 layer introspection and self-healing module will generate a clear description of this anomaly (such as detecting that the city dimension is not reflected in the GROUP BY clause) and repair suggestions (such as suggesting adding a GROUP BY city clause), and fall back to the semantic parsing layer to re-determine the multiple semantic elements of the natural language input, generate a query statement based on these multiple semantic elements, and verify it again until the verification passes.

[0086] This application embodiment performs semantic reverse matching after generating a query statement and before executing it. If the matching fails, it reverts to the semantic parsing layer to redetermine multiple semantic elements of the natural language input, generate a query statement based on these multiple semantic elements, and verify it again until the verification passes. This process can obtain an accurate query statement, thereby improving the accuracy of data query results.

[0087] In addition, if the natural language input is a complex query, for each subquery task, after generating the subquery statement but before generating the complete query statement, the L1 introspection and self-healing module can be used to verify the subquery statement. If multiple subquery statements pass the verification, the complete query statement can be generated based on the multiple subquery statements.

[0088] Furthermore, in order to improve the accuracy, reliability, and efficiency of data queries, in some embodiments, the above-mentioned S160 may specifically include: The query statement is subjected to dual-channel introspection to obtain a second verification result. Dual-channel introspection includes formal rule verification and semantic consistency verification. If the second verification result is successful, a performance evaluation is performed on the query statement before execution to obtain the performance evaluation result; If the performance evaluation results indicate that the query statement meets the execution conditions, then data retrieval is performed based on the query statement.

[0089] Here, formal rule validation includes at least one of the following: key filter condition missing validation, aggregate function validity validation, window function integrity validation, and table join reachability validation. Key filter condition missing validation can check if the query statement is missing a necessary WHERE or HAVING clause. Aggregate function validity validation can check if the use of GROUP BY matches that of aggregate functions (such as SUM). Window function integrity validation can check if the window function is missing a necessary PARTITION BY or ORDER BY clause. Table join reachability validation can be based on the schema graph (foreign key mapping) to detect whether the JOIN link is reachable.

[0090] Based on this, the above-mentioned dual-channel introspection verification of the query statement yields a second verification result, which may specifically include: The query statement is subjected to formal rule validation to obtain the third validation result; Based on the semantic similarity between the query statement and the natural language input, a semantic consistency check is performed to obtain the fourth check result; If both the third and fourth verification results are successful, the second verification result is determined to be successful.

[0091] Here, semantic consistency verification can be used to compare the similarity between the query statement and the original query intent.

[0092] As an example, a data query system can also include a Layer 3 introspection and self-healing module. This module performs dual-channel introspection and verification on the generated query statement. Firstly, based on the abstract syntax tree of the query statement, it performs formal rule checks such as checking for missing key filtering conditions, the rationality of aggregate functions, the integrity of window functions, and the reachability of table joins, resulting in a third verification result. Secondly, based on the semantic similarity between the query statement and the natural language input, it performs semantic consistency checks, resulting in a fourth verification result. The second verification result is then determined based on both the third and fourth verification results. If both the third and fourth verification results pass, the second verification result is considered successful. If either the third or fourth verification result fails, the second verification result is considered unsuccessful.

[0093] If the second verification passes, a pre-execution performance evaluation of the query statement can proceed. This pre-execution performance evaluation can be a layered verification process: First, perform an Explain-based audit in an isolated environment (such as a read-only / shadow database) using the EXPLAIN command to obtain a preliminary performance evaluation result including the estimated number of rows scanned and the execution cost. If this result indicates a high risk (such as an excessively high estimated cost or an execution plan containing a full table scan), then proceed to the empirical verification stage: perform sampled executions of the query in the shadow database (e.g., by adding a LIMIT clause to obtain a limited sample) to actually verify its performance and resource consumption. The sampled execution test data will serve as a crucial supplement, together with the EXPLAIN estimate, to constitute the final, more reliable performance evaluation result.

[0094] If the final performance evaluation results indicate that the query statement meets the execution conditions, then data can be queried based on the query statement.

[0095] This application embodiment performs dual-channel introspection verification and pre-execution performance evaluation sequentially after generating the query statement and before executing it. This effectively identifies and intercepts queries that are semantically incomplete, logically incorrect, or unreliable before execution, thereby significantly improving the accuracy, security, and system stability of data queries. It also avoids invalid or high-cost queries from impacting the production system, and improves the accuracy, reliability, and efficiency of data queries.

[0096] Therefore, in order to further improve the accuracy of data query, in some embodiments, after obtaining the second verification result, the method may further include: If the third verification result is a verification failure, determine the first verification type that caused the verification failure; Based on the first verification type, determine the first query optimization strategy; Based on the first query optimization strategy, the query plan is reconstructed to obtain the first optimized query plan; Based on the first optimized query plan, the query statement is regenerated and returned to perform dual-channel introspection verification on the query statement until the third verification result is a successful verification. If the fourth verification result is a verification failure, return to perform semantic parsing on the natural language input to determine the user's intent and multiple semantic elements until the fourth verification result is a verification success.

[0097] Here, if the reason the second verification result fails is that the third verification result fails, the L3 introspection and self-healing module can determine the cause of failure by analyzing the third verification result and generate a reflection report including the cause of failure. Specifically, determining the cause of failure can involve identifying the first verification type that caused the failure. The first verification type can be any one of the following: missing key filter condition verification, aggregate function validity verification, window function integrity verification, or table join reachability verification. Different first verification types can correspond to different first query optimization strategies. For example, if the first verification type is missing key filter condition verification, the first query optimization strategy could be to supplement the correct filter logic. If the first verification type is aggregate function validity verification, the first query optimization strategy could be to correct the relationship between the aggregate and the dimension. If the first verification type is window function integrity verification, the first query optimization strategy could be to complete the window function specification. If the first verification type is table join reachability verification, the first query optimization strategy could be to correct the join path or conditions.

[0098] In addition, if the third verification result is a verification failure, it can fall back to the query plan generation layer to reconstruct the query plan based on the first query optimization strategy, obtain the first optimized query plan, and continue to regenerate the query statement based on the first optimized query plan, and verify again until the third verification result is a verification success.

[0099] Furthermore, if the reason the second verification result fails is that the fourth verification result fails, the L3 layer introspection and self-healing module can analyze the fourth verification result to determine the reason for the failure and generate a reflection report including the reason for the failure. The reason for the failure could be a semantic parsing error in the natural language input. In this case, it can fall back to the semantic parsing layer to re-parse the natural language input semantically, determine the user intent and multiple semantic elements, and generate a query statement based on the user intent and multiple semantic elements, and then verify it again until the fourth verification result passes.

[0100] Additionally, if the natural language input is a complex query, the failure might be due to a semantic parsing error in the subquery task. In this case, it's possible to fall back to the semantic parsing layer to re-parse the subquery task, determine the user intent and multiple semantic elements, and generate the corresponding subquery statement based on that intent and elements. This process is then repeated until the fourth verification result is successful. Furthermore, the introspection and self-healing processes for multiple subquery tasks are independent of each other.

[0101] This application embodiment, when the third verification result is a verification failure, determines a first query optimization strategy based on the first verification type that caused the failure, and reconstructs the query plan based on the first query optimization strategy to obtain a first optimized query plan, thereby achieving accurate and efficient local repair. Furthermore, when the fourth verification result is a verification failure, intent calibration is performed by falling back to the semantic parsing starting point, ensuring the correctness of the query logic from the source. Thus, this application embodiment further improves the accuracy of data queries.

[0102] In addition, to further improve data query efficiency, in some embodiments, after obtaining the performance evaluation results, the method may further include: If the performance evaluation results indicate that the query statement does not meet the execution conditions, the performance bottleneck operation is determined based on the performance evaluation results. Based on the performance bottleneck operation, a second query optimization strategy was determined; Based on the second query optimization strategy, the query plan is reconstructed to obtain the second optimized query plan; Based on the second optimized query plan, the query statement is regenerated, and the execution is returned to perform dual-channel introspection verification on the query statement until the performance evaluation result indicates that the query statement meets the execution conditions.

[0103] Here, the performance bottleneck operation can be a query operator or query fragment identified as consuming the majority of computing resources or causing excessively long execution times. The second query optimization strategy can be specific rules and methods for transforming or rewriting the query logic to eliminate or alleviate the identified performance bottleneck operation, while maintaining approximately equivalence in the query's business semantics. For example, a query calculating the "daily moving average activity rate over 90 days" might have a performance bottleneck operation involving a full table scan and complex window function calculations. The second query optimization strategy could be to "replace the sliding window aggregation with discrete aggregation at a fixed time granularity (such as by day, week, or month)."

[0104] Thus, by reconstructing the query plan based on the second query optimization strategy to obtain the second optimized query plan, and regenerating the query statement based on the second optimized query plan and verifying it again until the verification passes, the static performance prediction before execution can be transformed into a dynamic, iterative optimization loop. This enables accurate identification and automated rewriting of high-cost query patterns, thereby systematically avoiding potential performance risks and resource overload while ensuring basic consistency of query semantics, and further improving data query efficiency.

[0105] Furthermore, to improve the user's data query experience, in some embodiments, after the above S160, such as Figure 2 As shown, the natural language-based data query method may also include steps S210-S260.

[0106] S210, Display the query results corresponding to the query statement. The query results include at least one interactive element corresponding to the target data, which is the query data corresponding to the variable query conditions.

[0107] Here, variable query conditions refer to statement components automatically identified from the generated query statement whose values ​​can be safely modified by the user, and whose modifications can generate a semantically reasonable new query. Variable query conditions may include, for example, time-based conditions, enumeration / categorization fields, aggregation metrics, grouping dimensions, and numerical thresholds. Additionally, interactive elements can be clickable and operable visual elements (such as highlighted text, buttons, and links).

[0108] As an example, when the backend server returns query results to the frontend interface, it can include metadata. This metadata can specify which data in the query results corresponds to which variable query conditions. After receiving the query results and metadata, the frontend interface can render the target data corresponding to the variable query conditions as interactive elements when displaying the query results.

[0109] In fact, there may be many variable query conditions corresponding to a query statement. Therefore, to further improve the user's data query experience, in some embodiments, before S210 above, the method may further include: Based on the abstract syntax tree of the query statement, multiple initial variable query conditions are determined; Based on the semantic keyness and interaction value of the initial variable query conditions, the value of multiple initial variable query conditions is evaluated, and the value evaluation results are obtained. Based on the value assessment results, at least one variable query condition is determined from multiple initial variable query conditions.

[0110] Here, multiple initial variable query conditions may include, for example, time-based conditions, enumeration / categorization fields, aggregation metrics, grouping dimensions, numerical thresholds, etc.

[0111] As an example, after generating a query statement, the backend server can automatically identify multiple initial variable query conditions from the abstract syntax tree of the query statement, such as time-related conditions, enumeration / categorization fields, aggregation metrics, grouping dimensions, and numerical thresholds. Based on the semantic criticality and interaction value of the initial variable query conditions, the server can evaluate the value of these conditions and obtain the evaluation results.

[0112] Specifically, the value assessment process can involve value assessment rules such as syntactic role and business criticality rules, data distribution and interactivity rules, and control type and default value mapping rules. Among these, syntactic role and business criticality rules can be used to assess the importance of a condition in the query logic. For example, time-type fields, because they are crucial for defining the query scope in filtering or grouping conditions, are usually assigned the highest criticality weight, thus obtaining a high value score. Data distribution and interactivity rules can be used to assess whether the form of the data corresponding to the condition is suitable for limited interaction formats. For example, for enumeration columns or low-cardinality categorical columns (by querying database statistics, such as the number of DISTINCT values ​​being less than a threshold), the system will determine that they are suitable for presentation as dropdown lists, thus obtaining a higher interaction value score. Control type and default value mapping rules can be used to pre-map the interaction format of a condition based on its data type and typical use case. For example, a LIMIT clause or a numerical comparison threshold will be mapped to a slider or numeric input box, and a reasonable default value range (such as 10, 20, 50, 100) will be set based on experience. These types of conditions obtain stable basic value scores due to their clear interaction paradigms.

[0113] Finally, by integrating the scores from the above multi-dimensional rules, a value assessment result can be generated for each initial variable query condition, and the top few initial variable query conditions with better value assessment results (i.e., higher scores) can be identified as variable query conditions.

[0114] In this embodiment, the value assessment result not only determines which conditions will be presented to the user, but also implies the recommended interaction methods (such as drop-down boxes, date pickers, and sliders). This ensures the effectiveness of the interaction while avoiding the risk of interface complexity or misuse due to excessive parameterization, thereby further improving the user's data query experience.

[0115] S220, receiving the first input from the user to select a target interactive element from at least one interactive element.

[0116] Here, the first input can be the user's action of clicking on the target interactive element in the query results.

[0117] As an example, after displaying query results with interactive elements, users can click on the target interactive element in the query results.

[0118] S230, in response to the first input, displays the target interface corresponding to the target interactive element.

[0119] Here, different types of variable query conditions can correspond to different types of display interfaces. For example, for enumeration / categorization fields, in response to the first input, a drop-down selection box can pop up listing all available regions. For time conditions, in response to the first input, a date picker can pop up, allowing the user to reselect the start date. For numerical thresholds, in response to the first input, a slider or numeric input box can pop up, allowing the user to adjust the number of results within a preset range.

[0120] As an example, after identifying the target interactive element, the target variable query conditions corresponding to the target interactive element can be determined based on the correspondence between the interactive element and the target data, as well as the correspondence between the target data and the variable query conditions. Then, based on the correspondence between the variable query conditions and the display interface, the target interface corresponding to the target variable query conditions can be determined and displayed.

[0121] In addition, the target interface can also display relevant knowledge bases and field definitions, providing users with interpretable results.

[0122] S240, receive a second input from the user in the target interface to modify the variable query conditions corresponding to the target interactive element from the first query data to the second query data.

[0123] Here, if the variable query condition corresponding to the target interactive element (i.e. the target variable query condition) is a date, then the first query data can be the query date included in the query results, and the second query data can be the query date that the user reselects in the date picker.

[0124] S250, in response to the second input, update the query statement.

[0125] Here, the front-end interface can respond to the second input, determine the second query data, and send the second query data to the back-end server. After receiving the second query data, the back-end server can replace the first query data in the query statement with the second query data to obtain the updated query statement.

[0126] S260, perform data retrieval based on the updated query statement.

[0127] This application embodiment renders key data in the query results directly as interactive elements, enabling users to intuitively express changes in their query intent based on these interactive elements, quickly obtain updated data query results, and improve the user's data query experience.

[0128] Furthermore, for some variable query conditions, such as aggregate metrics or grouping dimensions, simply replacing the first query data with the second query data may result in a query statement that is syntactically or semantically incorrect, unable to execute, or producing misleading results. For example, if a user clicks sum(passenger flow) and then selects avg(passenger flow), an error will occur after the query is written back. This is because avg must correspond to an aggregate clause, and the original query statement does not have an aggregate clause.

[0129] Therefore, in order to improve the reliability of data query, in some embodiments, the above-mentioned S260 may specifically include: The updated query statement is subjected to dual-channel introspection verification to obtain the sixth verification result. If the sixth verification result is a verification failure, determine the third verification type that caused the verification failure; Based on the third verification type, determine the third query optimization strategy; Based on the third query optimization strategy, the query plan is reconstructed to obtain the third optimized query plan; Based on the third optimized query plan, the query statement is regenerated; Data is retrieved based on the regenerated query statement.

[0130] Here, after receiving the second query data, the backend server replaces the first query data in the query statement with the second query data, resulting in an updated query statement. This triggers a multi-layered introspection and self-healing process. First, the updated query statement can be submitted to the L3 layer introspection and self-healing module for dual-channel introspection verification, resulting in a sixth verification result. If the sixth verification result passes, it indicates that the updated query statement has no problems in terms of syntax rules and semantic intent, and data can be directly queried based on this query statement.

[0131] If the sixth check result is a failure, the system will not directly report an error, but will instead initiate intelligent self-healing. The process is as follows: First, the L3 layer introspection and self-healing module can parse the sixth check result to determine the type of the third check that caused the failure. For example, in a scenario where SUM (passenger flow) is replaced with AVG (passenger flow), the semantic consistency check channel of the L3 layer introspection and self-healing module will determine that the new SQL (calculating the overall average) is inconsistent with the user's original query intent (which may implicitly involve group comparison), thus identifying the third check type as an inconsistency in the context semantics of the aggregate function. Second, based on the preset error type-repair strategy mapping table, a third query optimization strategy can be determined. For the aggregate function context semantic inconsistency type, the strategy could be, for example, to fall back to the L2 layer introspection and self-healing module and supplement the necessary grouping logic in the query plan. The L2 layer introspection and self-healing module can recommend appropriate grouping columns based on the database schema and supplement the recommended grouping logic into the original query plan, completing the reconstruction of the query plan and obtaining the third optimized query plan. Then, based on the third optimized query plan, the query statement can be regenerated and validated until it passes the validation. Based on the regenerated query statement, the data can be queried.

[0132] This application embodiment ensures the reliability of the final executed query statement by performing multi-layered introspection and self-healing on the updated query statement, thereby improving the reliability of data query.

[0133] In summary, through the embodiments of this application, variable conditions in query statements are automatically identified and parameterized. The parameters and optional values ​​are then used to generate a structured interactive configuration with types, ranges, etc., which is sent to the front end. This allows the front end to render and generate interactive intelligent query cards, while also providing explanatory descriptions of the data results, thus improving the credibility of the results. Users can recombine the query with a click. Furthermore, by combining hierarchical introspective semantic planning and a local self-healing mechanism, the system can securely write back and verify after user parameter adjustments. This transforms traditional one-way data queries into a two-way, guided, and self-verifying intelligent dialogue process, improving the flexibility and efficiency of data analysis while fundamentally ensuring the reliability of query results and the smoothness of the user experience.

[0134] To better understand the above solutions, some specific examples are given based on the above embodiments.

[0135] For example, a schematic diagram of a data query method based on natural language input provided in one embodiment of this application can be as follows: Figure 3 As shown.

[0136] like Figure 3As shown, the data query system can first receive natural language input from users for data querying through the front end, and then send this natural language input to the complexity detection module. The complexity detection module can determine the query complexity of the natural language input. If it is a simple query, it can send the natural language input to the local self-healing engine. If it is a complex query, it can first decompose the natural language input into multiple sub-query tasks, and then send each sub-query task to the local self-healing engine separately. Specifically, if it is a complex query, the complexity detection module can send the natural language input to the query task graph construction module. The query task graph construction module decomposes the natural language input into multiple sub-query tasks, determines the dependencies between the multiple sub-query tasks, and constructs a directed acyclic graph (i.e., the query task graph) with sub-query tasks as nodes and the dependencies between sub-query tasks as edges. Subsequently, the query task graph construction module can send the query task graph to the globally consistent introspective self-healing module.

[0137] The local self-healing engine may include a semantic parsing module, a retrieval and mapping module, a query plan generation module, a query statement generation module, an L1 layer self-introspection and self-healing module, an L2 layer self-introspection and self-healing module, and an L3 layer self-introspection and self-healing module.

[0138] Upon receiving a natural language input / subquery task, the local self-healing engine first performs semantic parsing on the task using the semantic parsing module. This identifies multiple semantic elements, which are then sent to the retrieval and mapping module and the query plan generation module, respectively. The retrieval and mapping module determines the target database object identifiers corresponding to these semantic elements, and the query plan generation module generates a query plan based on these elements. Subsequently, the L2 layer introspection and self-healing module performs a logical structure consistency check based on the query plan and the target database object identifiers. If the check passes, it sends the query plan and target database object identifiers to the query statement generation module; otherwise, it generates a reflection report and performs local reconstruction based on the report. The local reconstruction process is described above and will not be repeated here.

[0139] Upon receiving the query plan and the target database object identifier, the query statement generation module generates a query statement corresponding to the natural language input, or a subquery statement corresponding to a subquery task, based on the query plan and the target database object identifier. Subsequently, the L1 layer introspection and self-healing module matches multiple query elements in the query statement with multiple semantic elements. If a match is successful, it sends the query statement to the query statement execution module so that the query statement generation module can execute the query statement. If a match fails, it generates a reflection report and performs local reconstruction based on the reflection report. The local reconstruction process here is described above and will not be repeated here.

[0140] On the other hand, the L3 introspection and self-healing module can perform dual-channel introspection verification on the query statement. If the verification passes, it continues to perform pre-execution performance evaluation on the query statement. If the performance evaluation result indicates that the query statement meets the execution conditions, it can send the query statement to the query statement execution module so that the query statement generation module can execute the query statement. If the verification fails, or the performance evaluation result indicates that the query statement does not meet the execution conditions, it can generate a targeted reflection report and perform local reconstruction based on the reflection report. The local reconstruction process here is described above and will not be repeated here.

[0141] Furthermore, after all subquery statements have passed validation, the L3 introspection and self-healing module can send the subquery statement to the global consistency introspection and self-healing module. Upon receiving multiple subquery statements corresponding to the query task graph, the global consistency introspection and self-healing module performs global consistency validation on the multiple subquery statements based on the dependencies between them. If the validation passes, it sends the multiple subquery statements to the query orchestration module, allowing the module to merge them into a single complete query statement. If the validation fails, it initiates a global consistency self-healing process. The global consistency self-healing process is described above and will not be repeated here.

[0142] In addition, each self-introspection and self-healing module can be integrated with LLM for verification when appropriate.

[0143] Furthermore, after the query execution module executes the query statement and obtains the query results, it can determine at least one variable query condition based on the abstract syntax tree of the query statement. Based on the variable query condition and the query results, it generates metadata and returns both the query results and metadata to the front-end interface for configurable interaction with the user. The metadata specifies which data in the query results corresponds to which variable query conditions.

[0144] In summary, this application provides a system architecture that integrates query planning, introspection verification, causal self-healing, and front-end interactivity, as well as an interactive natural language query data flow that integrates multiple layers of introspection and self-healing, enabling natural language queries to have the capabilities of generation, verification, repair, interpretation, and interaction.

[0145] Specifically, the query plan generation layer generates an executable query chain, determines "how to query," and clearly and executablely defines the task logic, converting natural language input into an explicit structured query plan, thus providing a foundation for subsequent multi-layer introspection verification and query statement generation.

[0146] By employing a layered self-reflection and self-healing mechanism, if a problem is detected, it automatically performs a partial reconstruction instead of rewriting the entire sentence, thus avoiding unnecessary full-link backtracking and significantly improving system repair efficiency.

[0147] By automatically breaking down complex natural language queries into multiple sub-query tasks, constructing a query task graph, and performing multi-level introspection and local self-healing at the task node level, as well as global consistency introspection and self-healing, we can ensure consistent alignment of time, clustering, dimensions, etc. in each sub-task, thereby improving the accuracy and reliability of complex queries.

[0148] Furthermore, the interactive reorganization layer realizes the transformation from natural language to operable data cards. Specifically, it enables users to modify parameters through the front-end page, automatically rewrite query statements, and perform verification and self-healing before system execution. It combines variable query conditions such as filtering conditions, aggregate functions, dimensions, and sorting in complex query statements with their types and candidate values ​​to generate structured configurations for front-end rendering. This transforms static query statements into reusable, adjustable, and interpretable intelligent query cards. Combined with query plans and self-healing mechanisms, it effectively improves the executability and stability of dynamic queries.

[0149] Based on the natural language-based data query method provided in the above embodiments, this application also provides specific implementations of a natural language-based data query device. Please refer to the following embodiments.

[0150] like Figure 4 As shown, an embodiment of this application provides a natural language-based data query device 400, which includes the following modules: Receiver module 410 is used to receive natural language input from the user; The parsing module 420 is used to perform semantic parsing on natural language input to determine user intent and multiple semantic elements; The determination module 430 is used to determine, based on user intent, target query operators corresponding to multiple semantic elements in a query operator sequence, the query operator sequence including multiple query operators arranged in execution order; The generation module 440 is used to generate a query plan based on the target query operator and its corresponding semantic elements, as well as the execution order of multiple target query operators; The generation module 440 is also used to generate a query statement based on the query plan and the target database object identifiers corresponding to multiple semantic elements, wherein the target database object identifiers include at least one of table name and field name; The query module 450 is used to perform data queries based on query statements.

[0151] The above-mentioned natural language-based data query device 400 is described in detail below: In some embodiments, the natural language-based data query device 400 may further include: The determination module 430 is also used to determine candidate database object identifiers corresponding to multiple semantic elements in the original database object identifier set based on a hybrid retrieval method before generating a query statement based on the query plan and the target database object identifiers corresponding to multiple semantic elements, so as to obtain a candidate set corresponding to multiple semantic elements. The execution module performs the following operations for each semantic element: By using a reordering model, the confidence level of multiple candidate database object identifiers in the candidate set is determined based on the database schema index corresponding to the candidate set. The candidate data object identifiers corresponding to the confidence levels that meet the confidence level conditions are determined as the target database object identifiers.

[0152] In some embodiments, the execution module may specifically include: The output submodule is used to output a database object identifier confirmation request when the difference between the highest confidence level and the second highest confidence level is less than the difference threshold among multiple confidence levels. The database object identifier confirmation request is used to ask the user to determine the target database object identifier from the database object identifiers corresponding to the highest confidence level and the database object identifiers corresponding to the second highest confidence level.

[0153] In some embodiments, the set of original database object identifiers includes multiple original database object identifiers. Based on this, the execution module may specifically include: The execution submodule performs the following operations for each semantic element: The semantic elements are determined to have the first similarity to each original database object identifier by word literal matching. The second similarity between semantic elements and each original database object identifier is determined by vector matching. Using a reordering model, based on the database schema index corresponding to each original database object identifier, the third similarity between semantic elements and each original database object identifier is determined. The first similarity, second similarity and third similarity are weighted and summed to obtain the retrieval score of each original database object identifier; The original database object identifiers corresponding to the search scores that meet the search score criteria are identified as candidate database object identifiers.

[0154] In some embodiments, the generation module 440 may specifically include: The verification submodule is used to perform logical structure consistency verification based on the query plan and the target database object identifier to obtain the first verification result. The logical structure consistency verification includes at least one of the following: connection reachability verification, data object existence verification, data type consistency verification, and aggregation dimension consistency verification. The generation submodule is used to generate query statements based on the query plan and the target database object identifiers corresponding to multiple semantic elements, provided that the first verification result is successful.

[0155] In some embodiments, the generation module 440 may further include: The determination submodule is used to, after obtaining the first verification result, if the first verification result is a verification failure and the reason for the failure is that the connection is unreachable or the data object does not exist, re-determine the target database object identifier, and return to perform a logical structure consistency verification based on the query plan and the target database object identifier to obtain the first verification result, until the first verification result is a verification pass; The generation submodule is also used to regenerate the query plan and return the execution based on the query plan and the target database object identifier to perform logical structure consistency verification, and obtain the first verification result, until the first verification result is a successful verification.

[0156] In some embodiments, the query module 450 may specifically include: The matching submodule is used to match multiple query elements in a query statement with multiple semantic elements to obtain the matching results; The query submodule is used to perform data queries based on the query statement if the matching result is successful.

[0157] In some embodiments, the query module 450 may further include: The execution submodule is also used to perform semantic parsing on the natural language input after obtaining the matching result. If the matching result is a failure, it returns to perform semantic parsing on the natural language input to determine the user's intent and multiple semantic elements until the matching result is a successful match.

[0158] In some embodiments, the query module 450 may specifically include: The validation submodule is also used to perform dual-channel introspection validation on the query statement to obtain a second validation result. The dual-channel introspection validation includes formal rule validation and semantic consistency validation. The evaluation submodule is used to perform a pre-execution performance evaluation on the query statement if the second verification result is successful, and obtain the performance evaluation result. The query submodule is also used to perform data queries based on the query statement, provided that the performance evaluation results indicate that the query statement meets the execution conditions.

[0159] In some embodiments, the verification submodule may specifically include: The verification unit is used to perform formal rule verification on the query statement and obtain the third verification result. The formal rule verification includes at least one of the following: key filter condition missing verification, aggregate function rationality verification, window function integrity verification, and table join reachability verification. The verification unit is also used to perform semantic consistency verification based on the semantic similarity between the query statement and the natural language input, and obtain a fourth verification result; The determining unit is used to determine that the second verification result is verified as passed if both the third and fourth verification results are verified as passed.

[0160] In some embodiments, the verification submodule may further include: The determination submodule is also used to determine the first verification type that caused the verification failure when the third verification result is a verification failure after obtaining the second verification result; The determination submodule is also used to determine the first query optimization strategy based on the first verification type; The refactoring submodule is used to refactor the query plan based on the first query optimization strategy to obtain the first optimized query plan; The generation submodule is also used to regenerate the query statement based on the first optimized query plan, and return to perform dual-channel introspection verification on the query statement until the third verification result is a successful verification. The execution submodule is also used to return to the execution of semantic parsing of natural language input to determine user intent and multiple semantic elements if the fourth verification result is a verification failure, until the fourth verification result is a verification success.

[0161] In some embodiments, the query module 450 may further include: The determination submodule is also used to identify performance bottleneck operations based on the performance evaluation results after obtaining the performance evaluation results, when the performance evaluation results indicate that the query statement does not meet the execution conditions. The identified submodule is also used to determine a second query optimization strategy based on performance bottleneck operations; The refactoring submodule is also used to refactor the query plan based on the second query optimization strategy to obtain the second optimized query plan; The execution submodule is also used to regenerate the query statement based on the second optimized query plan, and return to perform dual-channel introspection verification on the query statement until the performance evaluation result indicates that the query statement meets the execution conditions.

[0162] In some embodiments, the parsing module 420 may specifically include: The parsing submodule is used to perform semantic parsing on natural language input to determine user intent and query complexity. The decomposition submodule is used to decompose the natural language input into multiple sub-query tasks based on the user intent of the natural language input when the query complexity characterization of the natural language input is a complex query. The determination submodule is used to perform semantic parsing on each subquery task, determining the user intent and multiple semantic elements for each subquery task.

[0163] In some embodiments, the parsing submodule may specifically include: The parsing unit is used to perform semantic parsing on natural language input to obtain thought chain data that represents the user's intent; The unit of determination is also used to identify target description text related to query complexity in the thought chain data; The unit is also used to determine complexity labels based on user intent represented by target description text and thought chain data. The unit of determination is also used to determine the query complexity based on the complexity label.

[0164] In some embodiments, the generation module 440 may specifically include: The generation submodule is also used to generate a subquery statement for each subquery task based on the query plan and the target database object identifiers corresponding to multiple semantic elements. The generation submodule is also used to generate query statements based on the dependencies between multiple subquery tasks and multiple subquery statements.

[0165] In some embodiments, the generation submodule may specifically include: The verification unit is also used to perform global consistency verification on multiple subquery statements based on the dependencies between multiple subquery tasks, and obtain the fifth verification result. The global consistency verification includes at least one of time range alignment verification, business definition consistency verification, data granularity consistency verification and data flow reachability verification. The generation unit is used to generate a query statement based on the dependencies between multiple subquery tasks and multiple subquery statements, provided that the fifth verification result is successful.

[0166] In some embodiments, the generation submodule may further include: The determining unit is also used to determine the second verification type and the first subquery task that caused the verification failure after obtaining the fifth verification result, in the case that the fifth verification result is a verification failure. The determining unit is also used to determine the target level for modifying the first subquery task based on the second verification type. The target level is one of the multiple processing levels involved in the process of generating the subquery statement corresponding to the first subquery task. The correction unit is used to correct the output of the first subquery task at the target level to obtain the correction result; The execution unit is used to regenerate the subquery statement corresponding to the first subquery task based on the correction result, and return the execution based on the dependency relationship between multiple subquery tasks to perform global consistency verification on multiple subquery statements until the fifth verification result is successful.

[0167] In some embodiments, the natural language-based data query device 400 may further include: The display module is used to display the query results corresponding to the query statement after performing a data query based on the query statement. The query results include at least one interactive element corresponding to the target data, which is the query data corresponding to the variable query conditions. The receiving module 410 is also configured to receive a first input from a user selecting a target interactive element from at least one interactive element; The display module is used to respond to the first input and display the target interface corresponding to the target interactive element. The receiving module 410 is also used to receive a second input from the user in the target interface, in which the variable query conditions corresponding to the target interactive element are modified from the first query data to the second query data. The update module is used to update the query statement in response to the second input; The query module 450 is also used to perform data queries based on the updated query statement.

[0168] In some embodiments, the natural language-based data query device 400 may further include: The determination module 430 is also used to determine multiple initial variable query conditions based on the abstract syntax tree of the query statement before displaying the query results corresponding to the query statement; The evaluation module is used to evaluate the value of multiple initial variable query conditions based on the semantic keyness and interaction value of the initial variable query conditions, and obtain the value evaluation results. The determination module 430 is also used to determine at least one variable query condition from among multiple initial variable query conditions based on the value assessment results.

[0169] In some embodiments, the query module 450 may specifically include: The verification submodule is also used to perform dual-channel introspection verification on the updated query statement to obtain the sixth verification result; The determination submodule is also used to determine the third verification type that caused the verification failure if the sixth verification result is a verification failure. The determination submodule is also used to determine the third query optimization strategy based on the third verification type; The refactoring submodule is also used to refactor the query plan based on the third query optimization strategy to obtain the third optimized query plan; The generation submodule is also used to regenerate query statements based on the third optimized query plan; The query submodule is also used to perform data queries based on the regenerated query statement.

[0170] In this embodiment, the query operator sequence includes multiple query operators arranged in execution order. Based on this, by performing semantic parsing on natural language input to determine user intent and multiple semantic elements, and then determining the target query operators corresponding to each of the multiple semantic elements in the query operator sequence based on the user intent, and generating a query plan based on the target query operators, their corresponding semantic elements, and the execution order of the multiple target query operators, the natural language input can be converted into a clear, structured query plan. By generating a query statement based on this clear, structured query plan and the target database object identifiers corresponding to the multiple semantic elements, the accuracy and interpretability of the query statement can be improved. Thus, by performing data queries based on the query statements generated in this embodiment, the accuracy and reliability of the query results can be improved.

[0171] Based on the natural language-based data query method provided in the above embodiments, this application also provides specific implementation methods for electronic devices. Figure 5 A schematic diagram of the structure of an electronic device provided in one embodiment of this application is shown.

[0172] like Figure 5 As shown, the electronic device 500 may include a processor 510 and a memory 520 storing computer program instructions.

[0173] Specifically, the processor 510 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.

[0174] Memory 520 may include mass storage for data or instructions. For example, and not limitingly, memory 520 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 520 may include removable or non-removable (or fixed) media. Where appropriate, memory 520 may be internal or external to electronic device 500. In a particular embodiment, memory 520 is a non-volatile solid-state memory.

[0175] In specific embodiments, the memory 520 may be implemented as a read-only memory (ROM), random access memory (RAM), static storage device, dynamic storage device, etc. The memory 520 may store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 520 and executed by the processor 510. The processor 510 reads and executes the computer program instructions stored in the memory 520 to implement any of the natural language-based data query methods in the above embodiments.

[0176] The processor 510 reads and executes computer program instructions stored in the memory 520 to implement any of the natural language-based data query methods in the above embodiments.

[0177] In one example, electronic device 500 may also include communication interface 530 and bus 540. Wherein, as... Figure 5 As shown, the processor 510, memory 520, and communication interface 530 are connected through bus 540 and complete communication with each other.

[0178] The communication interface 530 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.

[0179] Bus 540 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-E) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Where appropriate, bus 540 may include one or more buses. Although specific buses are described and illustrated in the embodiments of this application, this application considers any suitable bus or interconnection.

[0180] For example, the electronic device 500 can be a mobile phone, tablet computer, laptop computer, handheld computer, in-vehicle electronic device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc.

[0181] The electronic device can execute the natural language-based data query method in the embodiments of this application, thereby achieving a combination of Figures 1 to 3 The natural language-based data query method described, and the beneficial effects of the corresponding method implementations, will not be elaborated further here.

[0182] Furthermore, in conjunction with the natural language-based data query methods in the above embodiments, this application embodiment can provide a computer-readable storage medium for implementation. This computer-readable storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the natural language-based data query methods in the above embodiments. Examples of such computer-readable storage media include non-transitory computer-readable storage media, such as read-only memory (ROM).

[0183] The computer program instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the natural language-based data query method as shown in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0184] Based on the natural language-based data query methods described in the above embodiments, this application provides a computer program product for implementation. When the instructions in this computer program product are executed by the processor of an electronic device, they implement any of the natural language-based data query methods described in the above embodiments.

[0185] The computer program products of the above embodiments are used to implement the natural language-based data query method shown in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0186] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.

[0187] The functional blocks shown in the above-described block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.

[0188] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.

[0189] The aspects of this application have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by dedicated hardware performing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.

[0190] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.

Claims

1. A data query method based on natural language, characterized in that, include: Receive natural language input from users; Semantic parsing is performed on the natural language input to determine the user's intent and multiple semantic elements; Based on the user intent, target query operators corresponding to the plurality of semantic elements are determined in the query operator sequence, wherein the query operator sequence includes a plurality of query operators arranged in execution order; A query plan is generated based on the target query operator and its corresponding semantic elements, as well as the execution order of the multiple target query operators; Based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements, a query statement is generated, wherein the target database object identifier includes at least one of table name and field name; Based on the query statement, perform a data query.

2. The method according to claim 1, characterized in that, Before generating the query statement based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements, the method further includes: Based on a hybrid retrieval method, candidate database object identifiers corresponding to the multiple semantic elements are determined from the original set of database object identifiers, thereby obtaining candidate sets corresponding to the multiple semantic elements. For each of the semantic elements, perform the following operations: Using a reordering model, the confidence levels of multiple candidate database object identifiers in the candidate set are determined based on the database schema index corresponding to the candidate set. The candidate data object identifier corresponding to the confidence level that meets the confidence level condition is determined as the target database object identifier.

3. The method according to claim 2, characterized in that, The step of determining the candidate data object identifier corresponding to the confidence level that meets the confidence level condition as the target database object identifier includes: Among the multiple confidence levels, if the difference between the highest confidence level and the second highest confidence level is less than a difference threshold, a database object identifier confirmation request is output. The database object identifier confirmation request is used to request the user to determine the target database object identifier from the database object identifier corresponding to the highest confidence level and the database object identifier corresponding to the second highest confidence level.

4. The method according to claim 2, characterized in that, The original database object identifier set includes multiple original database object identifiers. The step of determining candidate database object identifiers corresponding to the multiple semantic elements from the original database object identifier set based on a hybrid retrieval method includes: For each of the semantic elements, perform the following operations: The semantic element is determined to have a first similarity to each of the original database object identifiers by means of word literal matching. The second similarity between the semantic element and each of the original database object identifiers is determined by vector matching. Using the reordering model, based on the database schema index corresponding to each original database object identifier, the third similarity between the semantic element and each original database object identifier is determined; The first similarity, the second similarity, and the third similarity are weighted and summed to obtain the retrieval score for each original database object identifier; The original database object identifier corresponding to the retrieval score that meets the retrieval score condition is determined as the candidate database object identifier.

5. The method according to claim 2, characterized in that, The step of generating a query statement based on the query plan and the target database object identifiers corresponding to the multiple semantic elements includes: Based on the query plan and the target database object identifier, a logical structure consistency check is performed to obtain a first check result. The logical structure consistency check includes at least one of the following: connection reachability check, data object existence check, data type consistency check, and aggregation dimension consistency check. If the first verification result is successful, a query statement is generated based on the query plan and the target database object identifiers corresponding to the multiple semantic elements.

6. The method according to claim 5, characterized in that, After obtaining the first verification result, the method further includes: If the first verification result is a verification failure, and the reason for the failure is that the connection is unreachable or the data object does not exist, the target database object identifier is re-determined, and the execution of the logical structure consistency verification based on the query plan and the target database object identifier is returned to obtain the first verification result, until the first verification result is a verification pass; If the first verification result is a verification failure, and the reason for the failure is inconsistent data types or inconsistent aggregation dimensions, the query plan is regenerated, and the execution of the logical structure consistency verification based on the query plan and the target database object identifier is returned to obtain the first verification result, until the first verification result is a verification pass.

7. The method according to claim 1, characterized in that, The data query based on the query statement includes: The query elements in the query statement are matched with the semantic elements to obtain the matching results; If the matching result is successful, a data query is performed based on the query statement.

8. The method according to claim 7, characterized in that, After obtaining the matching result, the method further includes: If the matching result is a failure, the process returns to performing semantic parsing on the natural language input to determine the user's intent and multiple semantic elements until the matching result is a success.

9. The method according to claim 1, characterized in that, The data query based on the query statement includes: The query statement is subjected to dual-channel introspection verification to obtain a second verification result. The dual-channel introspection verification includes formal rule verification and semantic consistency verification. If the second verification result is successful, a performance evaluation is performed on the query statement before execution to obtain the performance evaluation result. If the performance evaluation results indicate that the query statement meets the execution conditions, then a data query is performed based on the query statement.

10. The method according to claim 9, characterized in that, The process of performing dual-channel introspection on the query statement to obtain a second verification result includes: The query statement is subjected to formal rule validation to obtain a third validation result. The formal rule validation includes at least one of the following: key filter condition missing validation, aggregate function rationality validation, window function integrity validation, and table join reachability validation. Based on the semantic similarity between the query statement and the natural language input, a semantic consistency check is performed to obtain the fourth check result; If both the third and fourth verification results are successful, the second verification result is determined to be successful.

11. The method according to claim 10, characterized in that, After obtaining the second verification result, the method further includes: If the third verification result is a verification failure, the first verification type that caused the verification failure is determined. Based on the first verification type, determine the first query optimization strategy; Based on the first query optimization strategy, the query plan is reconstructed to obtain the first optimized query plan; Based on the first optimized query plan, the query statement is regenerated, and the dual-channel introspection check on the query statement is performed until the third check result is a pass. If the fourth verification result is a verification failure, the process returns to performing semantic parsing on the natural language input to determine the user's intent and multiple semantic elements until the fourth verification result is a verification success.

12. The method according to claim 9, characterized in that, After obtaining the performance evaluation results, the method further includes: If the performance evaluation result indicates that the query statement does not meet the execution conditions, the performance bottleneck operation is determined based on the performance evaluation result. Based on the aforementioned performance bottleneck operation, a second query optimization strategy is determined; Based on the second query optimization strategy, the query plan is reconstructed to obtain the second optimized query plan; Based on the second optimized query plan, the query statement is regenerated, and the dual-channel introspection check on the query statement is performed until the performance evaluation result indicates that the query statement meets the execution conditions.

13. The method according to claim 1, characterized in that, The step of semantically parsing the natural language input to determine the user's intent and multiple semantic elements includes: Semantic parsing is performed on the natural language input to determine the user intent and query complexity; When the query complexity characterizes the natural language input as a complex query, the natural language input is decomposed into multiple sub-query tasks based on the user intent of the natural language input; Semantic parsing is performed on each of the subquery tasks to determine the user intent and multiple semantic elements of each subquery task.

14. The method according to claim 13, characterized in that, The step of semantically parsing the natural language input to determine user intent and query complexity includes: Semantic parsing is performed on the natural language input to obtain thought chain data representing the user's intent; Identify the target description text related to query complexity from the thought chain data; Based on the target description text and the user intent represented by the thought chain data, a complexity label is determined. The query complexity is determined based on the complexity label.

15. The method according to claim 13, characterized in that, The step of generating a query statement based on the query plan and the target database object identifiers corresponding to the multiple semantic elements includes: For each of the subquery tasks, a subquery statement corresponding to each subquery task is generated based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements respectively; The query statement is generated based on the dependencies between the multiple subquery tasks and the multiple subquery statements.

16. The method according to claim 15, characterized in that, The step of generating the query statement based on the dependencies between the multiple subquery tasks and the multiple subquery statements includes: Based on the dependencies between the multiple subquery tasks, a global consistency check is performed on the multiple subquery statements to obtain a fifth check result. The global consistency check includes at least one of time range alignment check, business definition consistency check, data granularity consistency check, and data flow reachability check. If the fifth verification result is successful, the query statement is generated based on the dependencies between the multiple subquery tasks and the multiple subquery statements.

17. The method according to claim 16, characterized in that, After obtaining the fifth verification result, the method further includes: If the fifth verification result is a verification failure, determine the second verification type and the first subquery task that caused the verification failure; Based on the second verification type, a target level for correcting the first subquery task is determined. The target level is one of multiple processing levels involved in the process of generating the subquery statement corresponding to the first subquery task. The output of the first subquery task at the target level is corrected to obtain the corrected result; Based on the correction result, the subquery statement corresponding to the first subquery task is regenerated, and the execution is returned to perform a global consistency check on the multiple subquery statements based on the dependency relationship between the multiple subquery tasks, until the fifth check result is a pass check.

18. The method according to any one of claims 1-17, characterized in that, After performing a data query based on the query statement, the method further includes: Display the query results corresponding to the query statement. The query results include at least one interactive element corresponding to target data, where the target data is the query data corresponding to variable query conditions. Receive first input from the user to select a target interactive element from at least one of the interactive elements; In response to the first input, the target interface corresponding to the target interactive element is displayed; Receive a second input from the user in the target interface, in which the variable query conditions corresponding to the target interactive element are modified from the first query data to the second query data; In response to the second input, update the query statement; Based on the updated query statement, perform a data query.

19. The method according to claim 18, characterized in that, Before displaying the query results corresponding to the query statement, the method further includes: Based on the abstract syntax tree of the query statement, multiple initial variable query conditions are determined; Based on the semantic keyness and interaction value of the initial variable query conditions, the value of the multiple initial variable query conditions is evaluated to obtain the value evaluation results. Based on the value assessment results, at least one of the variable query conditions is determined from the plurality of initial variable query conditions.

20. The method according to claim 18, characterized in that, The data query based on the updated query statement includes: The updated query statement is subjected to dual-channel introspection verification to obtain the sixth verification result; If the sixth verification result is a verification failure, determine the third verification type that caused the verification failure; Based on the third verification type, a third query optimization strategy is determined; Based on the third query optimization strategy, the query plan is reconstructed to obtain the third optimized query plan; Based on the third optimized query plan, the query statement is regenerated; Based on the regenerated query statement, perform a data query.

21. A data query device based on natural language, characterized in that, The device includes: The receiving module is used to receive the user's natural language input; The parsing module is used to perform semantic parsing on the natural language input to determine the user's intent and multiple semantic elements; The determination module is used to determine, based on the user intent, the target query operators corresponding to the plurality of semantic elements in the query operator sequence, wherein the query operator sequence includes a plurality of query operators arranged in execution order; The generation module is used to generate a query plan based on the target query operator and its corresponding semantic elements, as well as the execution order of the multiple target query operators; The generation module is further configured to generate a query statement based on the query plan and the target database object identifiers corresponding to the plurality of semantic elements respectively, wherein the target database object identifiers include at least one of table name and field name; The query module is used to perform data queries based on the query statement.

22. An electronic device, characterized in that, The electronic device includes: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the natural language-based data query method as described in any one of claims 1-20.

23. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the natural language-based data query method as described in any one of claims 1-20.

24. A computer program product, characterized in that, When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device performs the natural language-based data query method as described in any one of claims 1-20.