Natural language based data query method, device and computer program product

CN122964102APending Publication Date: 2026-10-23CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611380590.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-07
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0003]本申请的主要目的在于提供一种基于自然语言的数据查询方法、设备及计算机程序产品,旨在解决数据查询的准确性较低的技术问题

Benefits of technology

利用RAG预置SQL知识库进行语义检索,将用户的自然语言问题快速匹配到最优的SQL语句模板,提升了查询语句的准确性和可靠性;通过从原始输入问题中自动提取目标参数值并进行标准化处理,将非结构化的自然语言信息转化为数据库可执行的标准化参数,有效解决了参数格式不一致、类型不匹配等执行障碍,确保了数据查询的顺畅执行;整体方案降低了用户进行数据查询的技术门槛,通过自然语言交互快速获取精准的数据查询结果,提升了数据查询的准确性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122964102A_ABST
    Figure CN122964102A_ABST
Patent Text Reader

Abstract

The application discloses a natural language-based data query method and device and a computer program product, relates to the technical field of electric digital data processing, and discloses the method, which comprises the following steps: obtaining an original input question of a user, taking the original input question as a query condition to search in a RAG preset SQL knowledge base to obtain a target SQL statement; extracting a target parameter value corresponding to a required parameter of the target SQL statement from the original input question, performing parameter standardization processing on the target parameter value according to an executable format of the target SQL statement to obtain a standardized parameter value; and performing data query in a database according to the target SQL statement and the standardized parameter value to obtain a query result. The application can quickly obtain an accurate data query result through natural language interaction, and improves the accuracy of data query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of electronic digital data processing technology, and in particular to a data query method, device and computer program product based on natural language. Background Technology

[0002] Text-to-SQL (Natural Language to Structured Query Language) technology automatically converts users' natural language queries into executable SQL statements, enabling business users without SQL programming skills to interact directly with the database. Existing Text-to-SQL methods are mainly based on rule and template matching, relying on manually defined syntax rules and keywords for mapping. While offering strong interpretability, they struggle to handle query requirements in complex business scenarios, resulting in lower data query accuracy. Summary of the Invention

[0003] The main purpose of this application is to provide a data query method, device, and computer program product based on natural language, which aims to solve the technical problem of low accuracy in data query.

[0004] To achieve the above objectives, this application proposes a natural language-based data query method, which includes: Obtain the user's original input question, and use the original input question as a query condition to retrieve the target SQL statement from the RAG pre-built SQL knowledge base; Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, and perform parameter standardization processing on the target parameter values ​​according to the executable format of the target SQL statement to obtain standardized parameter values; Based on the target SQL statement and the standardized parameter values, a data query is performed in the database to obtain the query results.

[0005] In one embodiment, the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question includes: Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question; If there are no missing parameters that have not been extracted, then the step of standardizing the target parameter value according to the executable format of the target SQL statement is performed to obtain the standardized parameter value. If there are missing parameters, a supplementary query for the missing parameters is initiated to the user through the large language model or interactive interface, and the user's reply with the supplementary target parameter value is received.

[0006] In one embodiment, the method further includes: All target parameter values ​​extracted in each round of dialogue are stored as key parameter information in the state cache for updating; In the next round of dialogue, the key parameter information updated in the previous round is used as context information. Based on the context information, the system initiates a supplementary query for the missing parameters to the user through the large language model or interactive interface, and receives the supplementary target parameter values ​​from the user, until all target parameter values ​​required by the target SQL statement have been extracted.

[0007] In one embodiment, the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question includes: Based on the parameters required by the target SQL statement, determine the semantic slots corresponding to each parameter in the original input question. The parameters include time parameters and business entity parameters. Extract the target parameter values ​​corresponding to each parameter from the semantic slots.

[0008] In one embodiment, the step of performing a data query in the database based on the target SQL statement and the standardized parameter values ​​to obtain query results includes: Determine the execution category corresponding to the target SQL statement; If the execution category is MCP call mode, then the corresponding MCP tool pre-configured in the MCP Server is called according to the target SQL statement and the standardized parameters to perform data query and obtain query results; If the execution category is direct execution, then the data query is directly executed in the database according to the target SQL statement and the standardized parameters to obtain the query result.

[0009] In one embodiment, before the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, the method further includes: The user's permission information is compared with the permission information corresponding to the target SQL statement to determine whether the user has query permission. If the user does not have query permission, a permission denied message will be returned to the user. If the user has query privileges, then the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question is executed.

[0010] In one embodiment, after the step of obtaining query results by performing a data query in the database based on the target SQL statement and the standardized parameter values, the method further includes: Using a large language model, data analysis is performed based on the original input question and the query results to generate data analysis results with at least two analytical dimensions. In response to the user's selection action, select the target data analysis result from at least two of the data analysis results; Obtain report style guidelines from user input; A data analysis report is generated based on the reported style instructions and the target data analysis results.

[0011] In one embodiment, prior to the step of obtaining the user's original input question, the method further includes: Construct a pre-built SQL knowledge base for RAG, which stores at least one pre-built SQL record. Each record includes at least one of the following: main question description, sub-question description, SQL statement, and required parameters. The steps of using the original input question as a query condition to retrieve the target SQL statement from the RAG pre-built SQL knowledge base include: Determine the similarity score between the original input question and the main question description and / or sub-question description of each of the preset SQL records; The target SQL statement is determined based on the SQL record with the highest similarity score; If multiple records have the same and highest similarity scores, the top N records are selected. These N records are then input into the large language model along with the original input question. The SQL records selected by the large language model are obtained, and the target SQL statement is determined based on the selected SQL records.

[0012] Furthermore, to achieve the above objectives, this application also proposes a natural language-based data query device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the natural language-based data query method described above.

[0013] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the natural language-based data query method described above.

[0014] One or more technical solutions proposed in this application have at least the following technical effects: By leveraging the pre-built SQL knowledge base of RAG for semantic retrieval, the system quickly matches users' natural language questions to the optimal SQL statement template, improving the accuracy and reliability of query statements. By automatically extracting target parameter values ​​from the original input questions and standardizing them, unstructured natural language information is transformed into standardized parameters executable by the database, effectively resolving execution obstacles such as inconsistent parameter formats and type mismatches, ensuring smooth data query execution. The overall solution lowers the technical barrier for users to perform data queries, enabling them to quickly obtain accurate data query results through natural language interaction, thus improving the accuracy of data queries. Attached Figure Description

[0015] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart illustrating an embodiment of the natural language-based data query method of this application. Figure 2 This is a flowchart illustrating Embodiment 2 of the natural language-based data query method of this application; Figure 3 This is a flowchart illustrating the data flow-driven multi-turn dialogue interaction process in the natural language-based data query method of this application; Figure 4 This is a flowchart illustrating Embodiment 3 of the natural language-based data query method of this application; Figure 5 This is a schematic diagram of the data query execution process in the natural language-based data query method of this application; Figure 6 This is a flowchart illustrating the overall execution of the intelligent data analysis method based on data flow and large models in the natural language-based data query method of this application. Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the data query method based on natural language in the embodiments of this application.

[0018] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0019] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0020] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0021] The main solution of this application embodiment is as follows: obtain the user's original input question, use the original input question as a query condition to search the RAG pre-built SQL knowledge base to obtain the target SQL statement; extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, perform parameter standardization processing on the target parameter values ​​according to the executable format of the target SQL statement to obtain standardized parameter values; and perform data query in the database according to the target SQL statement and the standardized parameter values ​​to obtain the query results.

[0022] In this embodiment, for ease of description, the following description uses a natural language-based data query device as the execution subject.

[0023] This application provides a solution that utilizes a pre-built SQL knowledge base in RAG for semantic retrieval, quickly matching the user's natural language question to the optimal SQL statement template, thus improving the accuracy and reliability of the query statement. By automatically extracting target parameter values ​​from the original input question and performing standardization processing, unstructured natural language information is transformed into standardized parameters executable by the database, effectively solving execution obstacles such as inconsistent parameter formats and type mismatches, ensuring smooth execution of data queries. The overall solution lowers the technical threshold for users to perform data queries, enabling them to quickly obtain accurate data query results through natural language interaction, thereby improving the accuracy of data queries.

[0024] It should be noted that the execution subject of this embodiment, the data query device based on natural language, can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device capable of performing the above functions. The following description uses a data query device based on natural language as an example to illustrate this embodiment and the subsequent embodiments.

[0025] Based on this, embodiments of this application provide a data query method based on natural language, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the natural language-based data query method of this application.

[0026] In this embodiment, the natural language-based data query method includes steps S10 to S40: Step S10: Obtain the user's original input question, and use the original input question as a query condition to retrieve the target SQL statement from the RAG pre-built SQL knowledge base.

[0027] RAG pre-built SQL knowledge base refers to a knowledge base built on the RAG (Retrieval-Augmented Generation) framework, used to store and retrieve pre-built SQL (Structured Query Language) statements. The RAG pre-built SQL knowledge base can be generated by vectorizing user questions and performing semantic similarity matching with pre-built questions in the database, or by relying on precise keyword matching or large language models.

[0028] In an optional embodiment, before step S10, the method further includes: constructing a RAG pre-built SQL knowledge base, wherein the knowledge base stores at least one pre-built SQL record, and each record includes at least one of the following: main problem description, sub-problem description, SQL statement, and required parameters.

[0029] Optionally, the RAG pre-built SQL knowledge base table structure includes: main question description, sub-question description, SQL description, indicator classification, permissions, SQL statements, parameters, display format, etc. The indicator classification and permission fields are used to implement access control and indicator classification management for different users. Each pre-built SQL statement corresponds to a distinctive main question description, while the sub-questions can cover most user input scenarios, thereby further improving the accuracy of RAG recognition.

[0030] It should be noted that the main problem description stores the main business problem statement corresponding to the pre-set SQL record. This description should be distinctive and accurately summarize the core business problem solved by the SQL statement. The sub-problem description stores various natural language variations corresponding to the pre-set SQL record. By setting the sub-problem description field and entering multiple common expressions under the same query intent, the accuracy and recall rate of RAG retrieval can be effectively improved, ensuring that the correct pre-set SQL record is matched regardless of the expression used by the user. The SQL description provides a brief textual explanation of the function and applicable scenarios of the SQL statement, facilitating developers' quick understanding of the SQL's purpose when maintaining and managing the knowledge base. The indicator classification identifies the analytical indicator category to which the SQL query belongs, such as sales revenue, cost, profit, and safety production, facilitating subsequent classification, organization, and statistical analysis of query results by indicator category. The permission information identifies the access permission level required to execute the SQL query. Different SQL queries may involve data with different levels of sensitivity. By pre-setting permission information, subsequent steps can verify whether the current user has permission to execute the query, achieving fine-grained data access control. The SQL statement field stores the validated, executable SQL statement text. This field stores the complete, parameterized SQL statement, where variable parts are represented as parameter placeholders. The parameter list defines one or more parameters required to execute the SQL statement. Each parameter includes a parameter name, parameter type, and parameter description. The display format specifies how the query results should be visualized. For example, trend analysis results are best displayed as line charts, comparative analysis results as bar charts, and detailed data results as tables. By pre-binding the display format, the query results can be automatically displayed according to preset methods after being retrieved, without requiring manual selection by the user.

[0031] When business needs change or new query requirements are added, records in the knowledge base can be added, deleted, or modified, or the MCP tool configuration can be maintained without changing the program code or redeploying.

[0032] By pre-building a structured RAG pre-built SQL knowledge base, the main question description, sub-question description, SQL statement and parameter information are stored together, which realizes the standardized management and reuse of query templates, enhances the fine granularity of semantic matching, and enables more accurate understanding of user intent and retrieval of the most suitable SQL template, thereby improving the accuracy of natural language to SQL conversion.

[0033] In an optional embodiment, step S10 includes: determining the similarity score between the original input question and the main question description and / or sub-question description of each preset SQL record; determining the target SQL statement based on the SQL record with the highest similarity score; if multiple records have the same and highest similarity score, then the first N records are selected, and the N records are input into the large language model along with the original input question to obtain the SQL record selected by the large language model, and the target SQL statement is determined based on the selected SQL record.

[0034] It should be noted that the user's original input question is semantically vectorized and compared with the text descriptions of each record in the RAG pre-built SQL knowledge base, including the main question description and / or sub-question descriptions, to calculate semantic similarity and obtain a similarity score for each record. The SQL statement corresponding to the record with the highest similarity score is selected as the target SQL statement. If multiple records have the same highest similarity score, the top N records are selected, where N is greater than 1. These N records, along with the user's original input question, are input into the large language model. The large language model then selects the SQL statement corresponding to the most matching record as the target SQL statement. This model-selected fallback ensures that the user's input matches a record, preventing the generation of an incorrect answer.

[0035] By calculating the similarity score between the original input question and the main question description and / or sub-question description in the pre-set SQL records, a rapid initial screening based on semantic matching is achieved, which can efficiently locate the most relevant SQL records. For scenarios where multiple records have the same and highest similarity scores, a large language model is introduced for secondary intelligent adjudication. The top N high-scoring records are input into the model along with the original input question for deep semantic understanding and contextual analysis. The powerful semantic reasoning capability of the large language model is fully utilized to solve the fuzzy matching problem that is difficult to distinguish by simple vector similarity calculation, avoiding the risk of misselection caused by the limitations of similarity algorithms. Thus, the accuracy of target SQL statement determination is improved while ensuring retrieval efficiency.

[0036] Step S20: Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, and perform parameter standardization processing on the target parameter values ​​according to the executable format of the target SQL statement to obtain standardized parameter values.

[0037] In this embodiment, since user input may be inconsistent and non-standardized, the parameters for extracting slots need to be standardized into a format usable for executing SQL, i.e., parameter standardization. In this embodiment, parameter standardization refers to converting non-standardized and non-normalized parameter values ​​in user input into a standardized format executable by the target SQL statement. Optionally, non-standardized time descriptions are converted into standard date formats; non-standardized business entity descriptions are converted into corresponding standard entity identifiers. For example, the time parameter value "beginning of this year" is converted into the standard date format "2026-01-01", and the business entity parameter value "xx customer" is converted into the corresponding standard customer number or customer name, etc.

[0038] In this embodiment, at least one parameter required to execute the target SQL statement is determined based on the parameter list defined in the target SQL statement. Based on the determined parameter, the parameter values ​​corresponding to each parameter are identified and extracted from the user's original input question.

[0039] In an optional embodiment, step S20, which involves extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, includes: determining the semantic slots corresponding to each parameter in the original input question based on the parameters required by the target SQL statement, where the parameters include time parameters and business entity parameters; and extracting the target parameter values ​​corresponding to each parameter from the semantic slots.

[0040] Semantic slots include parameters such as time, customer type, and business type, corresponding to all parameters in pre-defined SQL statements. For example, "beginning of the year" is identified as a time parameter, and "xx customer" is identified as a customer parameter. The system identifies the semantic slots corresponding to each parameter in the user input and extracts the corresponding parameter values ​​from the semantic slots. For example, when the target SQL statement requires two parameters, "time range" and "group name," the system identifies the time parameter corresponding to "last month" and the group name parameter corresponding to "group A" in the user input "check group A's sales last month," and extracts the values.

[0041] Based on the parameter types required by the target SQL statement, the corresponding semantic slots are determined in the original input problem, mapping unstructured natural language text to a predefined parameter semantic framework. This solves the problem of inaccurate extraction in traditional keyword matching methods when dealing with complex expressions, synonyms, and implicit information. By extracting target parameter values ​​from semantic slots in a targeted manner, the parameter recognition process is tightly coupled with the execution requirements of the SQL statement, avoiding interference from irrelevant information and parameter misalignment.

[0042] In an optional embodiment, before step S20, the method further includes: comparing the permission information corresponding to the target SQL statement with the user's permission information to determine whether the user has query permission; if the user does not have query permission, returning a permission-free message to the user; if the user has query permission, then executing step S20.

[0043] By comparing the permission information corresponding to the target SQL statement with the user's permission information, access permission determination is completed at the very beginning of data query execution. This effectively avoids invalid parameter extraction and subsequent resource waste due to insufficient permissions, thus improving system operating efficiency. For users without permissions, a prompt message is returned directly instead of proceeding to the next processing step, blocking unauthorized data access paths at the source, reducing the risk of sensitive data leakage, and strengthening the system's security protection capabilities. At the same time, this design binds permission control to SQL templates, realizing fine-grained data access control, ensuring that different user groups can only access data resources within their authorized scope. This meets the security requirements of multi-level business scenarios while also improving system compliance.

[0044] Step S30: Based on the target SQL statement and the standardized parameter values, perform a data query in the database to obtain the query results.

[0045] In one embodiment, the preset SQL record corresponding to the target SQL statement also stores the display format field corresponding to the target SQL statement. After the query is executed, the query result is directly drawn and displayed in the corresponding chart form according to the display format field.

[0046] In an optional embodiment, after step S30, the method further includes: performing data analysis based on the original input question and query results using a large language model, and generating a data analysis report. Optionally, the large language model is used to perform data analysis based on the original input question and query results to generate data analysis results in at least two analysis dimensions; in response to a user's selection operation, a target data analysis result is selected from the at least two data analysis results; a report style instruction input by the user is obtained; and a data analysis report is generated based on the report style instruction and the target data analysis result.

[0047] Optionally, in response to the user's selection operation, the step of selecting the target data analysis result from at least two data analysis results includes: displaying the indicator names and / or dimension names corresponding to each of the at least two data analysis results; and in response to the user's check-in operation of the indicator names and / or dimension names, determining the checked data analysis results as the target data analysis result.

[0048] By leveraging a large language model, data analysis results are automatically generated from at least two analytical dimensions based on the original input question and query results. This breaks through the limitations of a single analytical perspective, providing users with more comprehensive and in-depth data insights and enhancing the richness of the analysis results and their decision-making reference value. By responding to user selections to determine the target data analysis results, the flexibility of the service and user engagement are enhanced. Customized data analysis reports are generated by combining user-inputted report style instructions to meet the differentiated needs of different scenarios for report format, language style, and professional depth.

[0049] In this embodiment, the RAG pre-built SQL knowledge base is used for semantic retrieval, quickly matching the user's natural language question to the optimal SQL statement template, thus improving the accuracy and reliability of the query statement. By automatically extracting target parameter values ​​from the original input question and performing standardization processing, unstructured natural language information is transformed into standardized parameters executable by the database, effectively solving execution obstacles such as inconsistent parameter formats and type mismatches, ensuring smooth execution of data queries. The overall solution lowers the technical threshold for users to perform data queries, enabling them to quickly obtain accurate data query results through natural language interaction, thereby improving the accuracy of data queries.

[0050] Based on the first embodiment of this application, in the second embodiment of this application, the same or similar content as the above embodiment can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 Step S20 includes: Step S21: Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question; Step S22: If there are no missing parameters that have not been extracted, then perform the step of standardizing the target parameter value according to the executable format of the target SQL statement to obtain the standardized parameter value. Step S23: If there are missing parameters, a supplementary query for the missing parameters is initiated to the user through the large language model or interactive interface, and the supplementary target parameter value is received from the user.

[0051] In one embodiment, when one or more required parameter values ​​cannot be extracted from the original input question, a supplementary query for the missing parameters is initiated to the user in the current round of response, and the user inputs the supplementary parameter values ​​in the next round of dialogue, until all parameters are extracted.

[0052] When a missing parameter is detected, the system prompts the user with a supplementary query for that missing parameter in the current round of responses. Optionally, based on the parameter name and description of the missing parameter, a natural language supplementary query is generated to prompt the user for which parameters still need to be added. For example, if the user's first input is only "Check sales figures," and the system detects that the "group name" and "time range" parameters are missing, the system replies to the user: "Which group's sales figures do you want to check? Please provide the time range." Optionally, in each round of dialogue, only key parameter information directly related to the execution of the target SQL statement is retained, including the extracted parameter names and their corresponding values. Dialogue content unrelated to parameter extraction, such as irrelevant user queries, explanatory responses from the system, or all of the user's original input text, is not saved.

[0053] In each round of dialogue, only all the extracted parameter values ​​are passed as context information instead of passing all historical dialogue records to the large language model, and the extracted parameter information is updated and maintained in real time after each round of dialogue.

[0054] In an optional embodiment, the method further includes: storing all target parameter values ​​extracted in each round of dialogue as key parameter information in a state cache for updating; in the next round of dialogue, using the key parameter information updated in the previous round as context information, and based on the context information, initiating a supplementary query for missing parameters to the user through a large language model or interactive interface, and receiving the supplementary target parameter values ​​replied by the user, until all target parameter values ​​required by the target SQL statement have been extracted.

[0055] An initial parameter storage container is created to store all identified key parameter information. After each round of user interaction, only the parameter values ​​that have changed in the parameter storage container are updated. In the next round of dialogue, all parameters in the parameter storage container are passed as context to the large language model, rather than the entire historical dialogue record. Simultaneously, any unrecognized parameters are carried over to the next round's questions, prompting the user to indicate which parameters still need to be added.

[0056] Reference Figure 3 , Figure 3This is a dataflow-driven multi-turn dialogue interaction process involving three parties: the user, a large language model, and a database. The user first poses an initial question Q1 to the large language model, which then provides the corresponding answer A1. During this process, the system extracts key parameters from the dialogue, updates the dialogue parameter record, and incorporates these parameters as contextual information into the next round of dialogue. Subsequently, the user poses a new question Q2 based on the previous round's answer, and the model generates the answer A2 using the updated dialogue parameter record, and so on. Throughout the process, parameters accumulate and update with each round of dialogue, driving the continuous advancement of multi-turn interactions, while the database provides persistent support for parameter storage and updates. By maintaining independent dialogue parameter records, key information is effectively transferred between rounds, thus avoiding the context loss problem caused by token restrictions in the large language model, demonstrating a dataflow-driven dialogue management mechanism.

[0057] In multi-turn dialogue scenarios, the context passed to the large language model in the next round of dialogue only includes key parameter information {Group Name: Group A, Time Range: Last Month} and the user input to be processed in the current round, rather than the entire dialogue history of the first and second rounds. Simultaneously, any missing parameter information that has not yet been identified is also carried over to the next round's question, continuously prompting the user which parameters still need to be supplemented. For example, if the time range parameter is still missing after two rounds of dialogue, the system will continue to ask in the next response, "Please provide the time range you need to query."

[0058] Optionally, in the next round of dialogue, the step of using the updated key parameter information from the previous round as context information includes: maintaining a key parameter state table, which records all identified and standardized parameter key-value pairs in the current session, as well as a list of missing parameters that have not yet been identified; after each round of dialogue, updating the parameter key-value pairs in the state table according to the newly extracted target parameter values, and removing the extracted parameters from the list of missing parameters; using the updated state table as context information for the next round of dialogue, and the context information for the next round of dialogue does not include all historical dialogue records before this round.

[0059] By storing and updating the parameter values ​​extracted in each round as key parameter information, and replacing all historical dialogue records with the updated key parameter information as context in the next round of dialogue, the lengthy historical dialogues avoid occupying and interfering with the model context. This reduces the consumption of computing resources and response latency, while ensuring the focus and accuracy of parameter information, thus achieving more efficient and accurate data query and analysis services in multi-round interaction scenarios.

[0060] In the technical solution of this embodiment, the completeness of the target parameter values ​​extracted from the original input question is verified, distinguishing between complete extraction and missing parameters, enabling the system to adaptively select the subsequent processing path. When the parameters are completely extracted, standardization processing is performed directly and the query is executed, ensuring the efficiency of the query process. When missing parameters exist, a targeted supplementary question is initiated to the user through a large language model or interactive interface. The semantic understanding capability of the large language model is used to generate natural and accurate guiding words, or the standardized interactive interface is used to reduce the user's operational cost of completing information. This effectively solves the problem of query interruption or failure due to incomplete user input information, and significantly improves the system's fault tolerance and user-friendliness.

[0061] Based on any embodiment of this application, in the third embodiment of this application, the content that is the same as or similar to the above embodiments can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 4 Step S30 includes: Step S31: Determine the execution category corresponding to the target SQL statement; Step S32: If the execution type is MCP call mode, then the corresponding MCP tool pre-configured in the MCP Server is called to perform data query according to the target SQL statement and the standardized parameters to obtain the query result; Step S33: If the execution category is direct execution mode, then the data query is directly executed in the database according to the target SQL statement and the standardized parameters to obtain the query result.

[0062] In one embodiment, step S33 includes: identifying parameter placeholders in the target SQL statement, wherein the parameter placeholders correspond one-to-one with the target parameters required by the target SQL statement; filling the standardized parameters into the corresponding parameter placeholders to generate an executable SQL statement; and performing data query in the database based on the target SQL statement and the standardized parameters, specifically: performing data query in the database based on the executable SQL statement.

[0063] In one embodiment, an MCP Server is pre-established, and multiple MCP (Model Context Protocol) tools are configured within the MCP Server. Each MCP tool is associated with a corresponding pre-defined SQL statement. When the target SQL statement corresponds to the MCP tool invocation method, the corresponding MCP tool is invoked to execute the query and obtain the result. The configuration of the MCP tools is independent of the program code. When adding new query metrics, it is achieved by maintaining the configuration of the MCP tools or the RAG pre-defined SQL knowledge base, without changing the program code.

[0064] The large language model is invoked to perform data analysis based on the user's original question and query results. In order to display the data analysis results more intuitively, the corresponding graph or table for the query is also saved in the preset SQL details. The query results can be directly drawn in the form of graphs or tables.

[0065] Reference Figure 5 , Figure 5 This demonstrates two parallel paths from the target SQL to data query execution and subsequent analysis, ultimately converging on the data analysis and charting stages. The target SQL and the database, both serving as data sources, converge on the central MCP Server. Internally, the MCP Server operates on two parallel execution routes: one where the MCP Server directly executes the SQL, submitting the target SQL statement directly to the database for query execution via its built-in database connection capabilities; and another where the MCP Server dynamically invokes pre-registered query tools or services based on the semantics or configuration of the target SQL to acquire data. The results of both paths are fed into the downstream data analysis and charting modules, ultimately generating a visual data analysis report. Through the unified scheduling of the MCP Server, both the traditional direct database connection SQL execution mode and the flexible extension to a tool-invoking mode are supported, thus achieving diversification of query execution methods and decoupling of business logic.

[0066] In the technical solution of this embodiment, the execution category corresponding to the target SQL statement is intelligently determined, enabling the system to automatically select the optimal execution path based on the characteristics of the query scenario. When it is determined to be an MCP call method, the corresponding MCP tool pre-configured in the MCP Server is invoked to execute the data query. With the help of the standardized interface capabilities of the MCP protocol, seamless integration with heterogeneous data sources, third-party services, or dedicated computing engines is achieved, expanding the data access scope and functional boundaries of the system. At the same time, the centralized management of the MCP Server improves the maintainability and reusability of tool configuration. When it is determined to be a direct execution method, the data query is executed directly in the database, ensuring the execution efficiency and response speed in conventional query scenarios, balancing the flexibility and performance of query execution. It supports external capability expansion in complex scenarios while retaining efficient pass-through processing in simple scenarios, thereby improving the execution efficiency of the natural language data query system.

[0067] Based on any embodiment of this application, an optional embodiment is proposed, with reference to... Figure 6 , Figure 6This demonstrates the overall execution flow of an intelligent data analysis method based on data flow-driven and large-scale models. The process begins at the start node, where the user input is used to search the RAG pre-built SQL knowledge base to obtain a matching target SQL statement. Next, the first judgment node checks if RAG returns a unique result. If the result is not unique (i.e., multiple SQL records with the same similarity exist), the large language model intervenes to assist in selection, determining a unique target SQL. If the result is unique, the target SQL is directly determined. After determining the target SQL, its details are queried, and a permission verification node is executed. If the permission verification fails, the user is notified that they have no permission to query, and the process ends. If the verification passes, LLM extracts the slots and retrieves the parameters required for the target SQL. After extraction, a retry node is executed. If the parameters are incomplete or have problems, a retry is performed, and slot extraction is repeated. If the parameters are successfully extracted, parameter standardization is performed. After standardization, the process proceeds to either execute the SQL or call the MCP tool, depending on the configuration. Finally, the query results are analyzed, and the process ends. The entire algorithm process starts from user input and goes through multiple stages, including RAG retrieval, SQL selection, permission verification, multi-round parameter extraction and standardization, query execution, and data analysis, forming a complete closed loop. Multiple decision nodes ensure the fault tolerance and robustness of the process.

[0068] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the natural language-based data query method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0069] This application provides a natural language-based data query device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, which are executed by the at least one processor to enable the at least one processor to perform the natural language-based data query method in the first embodiment described above.

[0070] The following is for reference. Figure 7The diagram illustrates a structural schematic of a data query device suitable for implementing embodiments of this application. The data query device based on natural language in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, personal digital assistants (PDAs), tablet computers (PADs), portable multimedia players (PMPs), and fixed terminals such as computers. Figure 7 The natural language-based data query device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0071] like Figure 7 As shown, a natural language-based data query device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.) that can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the natural language-based data query device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touchscreen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices 1003 including, for example, magnetic tape, hard disk, etc.; and communication devices 1009. Communication device 1009 allows the natural language-based data query device to communicate wirelessly or wiredly with other devices to exchange data. While the figure shows a natural language-based data query device with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.

[0072] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0073] The natural language-based data query device provided in this application, employing the natural language-based data query method in the above embodiments, can solve the technical problem of low accuracy in data queries. Compared with the prior art, the beneficial effects of the natural language-based data query device provided in this application are the same as those of the natural language-based data query method provided in the above embodiments, and other technical features in this natural language-based data query device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0074] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.

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

[0076] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the natural language-based data query method in the above embodiments.

[0077] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.

[0078] The aforementioned computer-readable storage medium may be included in a natural language-based data query device; or it may exist independently and not be assembled into a natural language-based data query device.

[0079] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by a natural language-based data query device, the device enables the following: It utilizes a pre-built SQL knowledge base (RAG) for semantic retrieval, quickly matching the user's natural language question to the optimal SQL statement template, thus improving the accuracy and reliability of the query statement; it automatically extracts target parameter values ​​from the original input question and performs standardization processing, transforming unstructured natural language information into standardized parameters executable by the database, effectively solving execution obstacles such as inconsistent parameter formats and type mismatches, ensuring smooth execution of data queries; the overall solution lowers the technical threshold for users to perform data queries, enabling them to quickly obtain accurate data query results through natural language interaction, thereby improving the accuracy of data queries.

[0080] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, as well as conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0081] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0082] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0083] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described natural language-based data query method, thereby solving the technical problem of low accuracy in data queries. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the natural language-based data query method provided in the above embodiments, and will not be repeated here.

[0084] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the natural language-based data query method described above.

[0085] The computer program product provided in this application can solve the technical problem of low accuracy in data querying. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the natural language-based data query method provided in the above embodiments, and will not be repeated here.

[0086] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A data query method based on natural language, characterized in that, The natural language-based data query method includes: Obtain the user's original input question, and use the original input question as a query condition to retrieve the target SQL statement from the RAG pre-built SQL knowledge base; Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, and perform parameter standardization processing on the target parameter values ​​according to the executable format of the target SQL statement to obtain standardized parameter values; Based on the target SQL statement and the standardized parameter values, a data query is performed in the database to obtain the query results.

2. The data query method based on natural language as described in claim 1, characterized in that, The step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question includes: Extract the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question; If there are no missing parameters that have not been extracted, then the step of standardizing the target parameter value according to the executable format of the target SQL statement is performed to obtain the standardized parameter value. If there are missing parameters, a supplementary query for the missing parameters is initiated to the user through the large language model or interactive interface, and the user's reply with the supplementary target parameter value is received.

3. The data query method based on natural language as described in claim 2, characterized in that, The method further includes: All target parameter values ​​extracted in each round of dialogue are stored as key parameter information in the state cache for updating; In the next round of dialogue, the key parameter information updated in the previous round is used as context information. Based on the context information, the system initiates a supplementary query for the missing parameters to the user through the large language model or interactive interface, and receives the supplementary target parameter values ​​from the user, until all target parameter values ​​required by the target SQL statement have been extracted.

4. The data query method based on natural language as described in claim 1, characterized in that, The step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question includes: Based on the parameters required by the target SQL statement, determine the semantic slots corresponding to each parameter in the original input question. The parameters include time parameters and business entity parameters. Extract the target parameter values ​​corresponding to each parameter from the semantic slots.

5. The data query method based on natural language as described in claim 1, characterized in that, The step of performing a data query in the database based on the target SQL statement and the standardized parameter values ​​to obtain the query results includes: Determine the execution category corresponding to the target SQL statement; If the execution category is MCP call mode, then the corresponding MCP tool pre-configured in the MCP Server is called according to the target SQL statement and the standardized parameters to perform data query and obtain query results; If the execution category is direct execution, then the data query is directly executed in the database according to the target SQL statement and the standardized parameters to obtain the query result.

6. The data query method based on natural language as described in claim 1, characterized in that, Before the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question, the method further includes: The user's permission information is compared with the permission information corresponding to the target SQL statement to determine whether the user has query permission. If the user does not have query permission, a permission denied message will be returned to the user. If the user has query privileges, then the step of extracting the target parameter values ​​corresponding to the parameters required by the target SQL statement from the original input question is executed.

7. The data query method based on natural language as described in claim 1, characterized in that, After the step of obtaining query results by performing a data query in the database based on the target SQL statement and the standardized parameter values, the method further includes: Using a large language model, data analysis is performed based on the original input question and the query results to generate data analysis results with at least two analytical dimensions. In response to the user's selection action, select the target data analysis result from at least two of the data analysis results; Obtain report style guidelines from user input; A data analysis report is generated based on the reported style instructions and the target data analysis results.

8. The data query method based on natural language as described in claim 1, characterized in that, Before the step of obtaining the user's original input question, the method further includes: Construct a pre-built SQL knowledge base for RAG, which stores at least one pre-built SQL record. Each record includes at least one of the following: main question description, sub-question description, SQL statement, and required parameters. The steps of using the original input question as a query condition to retrieve the target SQL statement from the RAG pre-built SQL knowledge base include: Determine the similarity score between the original input question and the main question description and / or sub-question description of each of the preset SQL records; The target SQL statement is determined based on the SQL record with the highest similarity score; If multiple records have the same and highest similarity scores, the top N records are selected. These N records are then input into the large language model along with the original input question. The SQL records selected by the large language model are obtained, and the target SQL statement is determined based on the selected SQL records.

9. A data query device based on natural language, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the natural language-based data query method as described in any one of claims 1 to 8.

10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the steps of the natural language-based data query method as described in any one of claims 1 to 8.