Natural language based query method, apparatus, device, medium and program product

The intelligent query system, which combines natural language processing and knowledge graphs, solves the problems of cumbersome data query operations and insufficient security in enterprise-level business systems, and achieves efficient and secure data acquisition and adaptive querying.

CN122489686APending Publication Date: 2026-07-31INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
INDUSTRIAL AND COMMERCIAL BANK OF CHINA
Filing Date
2026-03-16
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing enterprise-level business systems suffer from cumbersome data query operations, low efficiency for non-technical users, insufficient access control, vulnerability to SQL injection attacks, and a lack of semantic parsing capabilities for business terms, resulting in system susceptibility to errors and poor adaptability.

Method used

By combining natural language processing and knowledge graphs, we can achieve standardized text generation, semantic parsing, permission verification, and dynamic query statement generation, and build an intelligent query system with full-link dynamic data security control. We use a preset semantic understanding model and domain knowledge graph for semantic parsing, perform access control based on permission knowledge graph, generate access tokens, and directly connect to the database.

Benefits of technology

It achieves end-to-end mapping from natural language queries to structured queries, improving query accuracy and security, lowering the usage threshold for non-technical personnel, and enhancing the system's adaptability and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122489686A_ABST
    Figure CN122489686A_ABST
Patent Text Reader

Abstract

This application provides a natural language-based query method, apparatus, device, medium, and program product, relating to the field of big data. The method includes: standardizing the raw natural language query text input by the user to generate standardized query text; performing semantic parsing on the standardized query text based on a preset semantic understanding model and a pre-built domain knowledge graph to obtain semantic understanding results; verifying the user's access permissions to the target entity based on a pre-built permission knowledge graph, and generating an access token upon successful verification; generating a query statement based on the access token and the semantic understanding results; and executing the query statement to obtain the target query results. This method achieves a closed loop from natural language query to secure and efficient data acquisition, improving query accuracy, security, and processing efficiency while lowering the barrier to entry for non-technical personnel.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data, and in particular to a query method, apparatus, device, medium, and program product based on natural language. Background Technology

[0002] In enterprise-level business systems (such as Customer Relationship Management (CRM), Enterprise Resource Planning (ERP), and Business Intelligence (BI), users' needs for data querying and analysis are becoming increasingly complex and diverse. Taking data-intensive industries such as finance, retail, and manufacturing as examples, business personnel often need to complete cross-dimensional data filtering through multi-field form input interfaces, such as querying composite conditions like "the top 10 customers in East China in terms of sales volume in the second half of 2024 with a return rate of less than 5%". Existing systems rely on users manually selecting dozens of parameters such as time range, product category, and region code, which is cumbersome, error-prone, and leads to low efficiency for non-technical personnel. Summary of the Invention

[0003] This application provides a natural language-based query method, apparatus, device, medium, and program product to solve the technical problems of cumbersome operation and low efficiency for non-technical personnel in traditional systems.

[0004] Firstly, this application provides a natural language-based query method, including:

[0005] The raw natural language query text input by the user is standardized to generate standardized query text;

[0006] Based on a preset semantic understanding model and a pre-built domain knowledge graph, semantic parsing is performed on the standardized query text to obtain a semantic understanding result. The semantic understanding result includes at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities.

[0007] The user's access rights to the target entity are verified based on a pre-built permission knowledge graph, and an access token is generated after the verification is successful.

[0008] Generate a query statement based on the access token and the semantic understanding result;

[0009] Execute the query statement to obtain the target query result.

[0010] Secondly, this application provides a natural language-based query device, comprising:

[0011] The standardization processing module is used to standardize the raw natural language query text input by the user and generate standardized query text.

[0012] The semantic parsing module is used to perform semantic parsing on the standardized query text based on a preset semantic understanding model and a pre-built domain knowledge graph to obtain a semantic understanding result. The semantic understanding result includes at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities.

[0013] The verification module is used to verify the user's access rights to the target entity based on a pre-built permission knowledge graph, and generate an access token after the verification is successful.

[0014] The generation module is used to generate a query statement based on the access token and the semantic understanding result;

[0015] The execution module is used to execute the query statement to obtain the target query result.

[0016] Thirdly, this application provides a natural language-based query device, comprising: a processor, and a memory communicatively connected to the processor;

[0017] The memory stores computer-executed instructions;

[0018] The processor executes computer execution instructions stored in the memory to implement the first aspect and / or various possible implementations of the first aspect as described above.

[0019] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible embodiments of the first aspect.

[0020] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.

[0021] The natural language query method, apparatus, device, medium, and program products provided in this application eliminate colloquial expressions, redundant information, and format differences by standardizing the original natural language query text, thus providing a unified and standardized input for subsequent semantic parsing and reducing ambiguity caused by differences in expression. Combined with a pre-set semantic understanding model and domain knowledge graph, multi-dimensional semantic parsing can be performed on the standardized text. This enables accurate capture of the intent of queries with complex conditions. Based on a pre-built permission knowledge graph, user access permissions to target entities can be automatically verified after semantic parsing. A four-level permission control chain (role-organization-entity-field) ensures that only authorized users can access specified data entities and fields. Query statements dynamically generated based on access tokens and semantic understanding results can be directly and seamlessly integrated with the database execution layer, completing an end-to-end mapping from natural language queries to structured queries. This solution, through a full-chain design of "standardization-parsing-permission verification-query execution," achieves a closed loop from natural language querying to secure and efficient data acquisition, improving query accuracy, security, and processing efficiency while lowering the barrier to entry for non-technical personnel. Attached Figure Description

[0022] 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.

[0023] Figure 1 A flowchart illustrating the natural language-based query method provided in this application. Figure 1 ;

[0024] Figure 2 A flowchart illustrating the natural language-based query method provided in this application. Figure 2 ;

[0025] Figure 3 A schematic diagram of the structure of the natural language-based query device provided in this application;

[0026] Figure 4 A schematic diagram of the structure of the natural language-based query device provided in this application.

[0027] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0028] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0029] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of the relevant data all comply with the relevant laws, regulations, and standards of the relevant countries and regions, have taken necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation access points for users to choose to authorize or refuse.

[0030] It should be noted that the natural language-based query methods, devices, equipment, media, and program products provided in this application can be used in the field of big data, as well as in any other field. The application fields of the natural language-based query methods, devices, equipment, media, and program products in this application are not limited.

[0031] Existing enterprise-level business systems generally adopt a three-tier architecture: a front-end form input interface, a middleware layer that concatenates query parameters into Structured Query Language (SQL), and a back-end database execution engine. Users input query parameters through front-end form controls (such as dropdown boxes and date pickers), the middleware layer concatenates these parameters into SQL, and the back-end database executes the query and returns the results. Some systems simplify common query processes with pre-built SQL templates, but cannot handle complex combinations of conditions. Regarding access control, mainstream solutions are based on the RBAC model, statically filtering query results at the application layer (e.g., "Salespeople can only access customer data within their department"). Visualization output relies on independent reporting tools, requiring users to manually export data or configure chart parameters.

[0032] The existing technology has at least the following drawbacks:

[0033] Multi-field form interaction processes are cumbersome, requiring training for non-technical personnel to use proficiently, and queries based on multiple conditions are time-consuming. For example, when querying composite conditions such as "the top 10 customers in East China in terms of sales revenue in the second half of 2024 with a return rate of less than 5%", at least 6 field selections and parameter inputs need to be completed in the form, which is tedious and prone to errors.

[0034] The RBAC model filters sensitive data only after the result is returned, and attackers can bypass permission checks through SQL injection; static permission rules cannot adapt to the needs of dynamic business scenarios.

[0035] The system lacks the ability to semantically analyze business terms (e.g., "Beifen" is not recognized as "Beijing Branch"), and the pre-set query templates are prone to failure when the database table structure changes, leading to system errors.

[0036] The natural language-based query method provided in this application can be widely applied to data query and analysis scenarios in enterprise-level business systems. This application constructs an intelligent query system with end-to-end dynamic data security control through the deep integration of natural language processing and knowledge graphs. This system replaces traditional multi-field form operations with natural language interaction, uses knowledge graphs to achieve semantic expansion and logical parsing of business terms, dynamically injects access control rules during the SQL generation stage, and ultimately drives model iteration through user feedback, forming a closed loop of continuous optimization. By organically combining natural language understanding, dynamic access control, and adaptive updates of the knowledge graph, it solves the three major pain points of existing systems in terms of usability, security, and adaptability.

[0037] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0038] Figure 1 A flowchart illustrating the natural language-based query method provided in this application. Figure 1 ,like Figure 1 As shown, the method includes:

[0039] S101. Standardize the original natural language query text input by the user to generate standardized query text.

[0040] In this step, the raw natural language query text input by the user is standardized to generate a standardized query text with a regular structure and clear semantics, providing a unified input basis for subsequent semantic parsing.

[0041] S102. Based on the preset semantic understanding model and the pre-built domain knowledge graph, perform semantic parsing on the standardized query text to obtain semantic understanding results. The semantic understanding results include at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities.

[0042] In this step, a pre-defined semantic understanding model and a pre-built domain knowledge graph (such as an industry terminology database and an entity relationship database) are used to perform in-depth analysis of standardized text and extract the core elements in the user query—including target entities (such as "customer" and "order"), entity attributes (such as "sales revenue" and "return rate"), and relationships between entities (such as "East China region includes Shanghai and Jiangsu"), to form a complete semantic understanding result.

[0043] S103. Verify the user's access rights to the target entity based on the pre-built permission knowledge graph, and generate an access token after the verification is successful.

[0044] In this step, based on the pre-built permission knowledge graph, the user's access permissions to the parsed target entity are verified (e.g., a salesperson can only access customer contact information but not financial data). After the verification is successful, an access token with time validity and permission scope is generated as the permission credential for subsequent queries.

[0045] S104. Generate a query statement based on the access token and semantic understanding results.

[0046] In this step, the access token (to ensure permission compliance) and the semantic understanding results (to clarify the query intent) are combined to transform the natural language intent into a structured query statement (such as SQL) that conforms to the database syntax rules, thus achieving a precise conversion from "user intent" to "machine-executable instructions".

[0047] S105. Execute the query statement to obtain the target query result.

[0048] The generated query statement is executed, the database is connected to complete the data retrieval, and the target query results that are highly matched with the user's original query intent are finally output, completing a complete closed loop from "natural language input" to "data result output".

[0049] The query method based on natural language provided in this embodiment eliminates colloquial expressions, redundant information, and format differences through the standardization process of the original natural language query text, enabling subsequent semantic parsing to obtain unified and standardized inputs, reducing parsing ambiguities caused by expression differences; combines a preset semantic understanding model with a domain knowledge graph to perform multi-dimensional semantic parsing on the standardized text, achieving precise intention capture for complex conditional queries; based on a pre-constructed permission knowledge graph, it can automatically verify the user's access permissions to the target entity after semantic parsing. Through a four-level permission control link of role - institution - entity - field, it ensures that only authorized users can access specified data entities and fields; the query statement dynamically generated based on the access token and semantic understanding results can be directly and seamlessly connected to the database execution layer to complete the end-to-end mapping from natural language query to structured query. This solution realizes a closed-loop from natural language query to secure and efficient data acquisition through a full-link design of "standardization - parsing - permission verification - query execution", while improving query accuracy, security, and processing efficiency, and reducing the usage threshold for non-technical personnel.

[0050] Figure 2 It is a flowchart illustration of the query method based on natural language provided in this application Figure 2 , such as Figure 2 shown. Based on the Figure 1 embodiment, the query method based on natural language will be described in detail. The method includes:

[0051] S201. Perform standardization processing on the original natural language query text input by the user to generate a standardized query text.

[0052] In a possible implementation manner, performing standardization processing on the original natural language query text input by the user to generate a standardized query text may specifically include the following steps:

[0053] Perform punctuation normalization and stop word filtering on the original natural language query text input by the user to generate a standardized query text.

[0054] In this implementation manner, convert the full-width punctuation in the original natural language query text input by the user into the corresponding half-width punctuation to ensure that all punctuation marks adopt a unified character encoding format. Further, based on a predefined stop word list (such as a word library containing function words and auxiliary words like "de", "le", "a", "ne"), perform lexical filtering on the text after punctuation normalization to generate a standardized query text .

[0055] The standardization process can be expressed as:

[0056] =RemoveStopwords(NormalizePunctuation( ))。

[0057] Punctuation normalization and stop-word filtering constitute a progressive processing chain of "format unification - noise elimination": the former solves the standardization problem at the text format level, and the latter solves the noise interference problem at the semantic level. The two work together to transform the original natural language query text with colloquialism and mixed formats into a standardized query text with regular structure and focused semantics, laying a high-quality input foundation for subsequent accurate semantic parsing based on a preset semantic understanding model and a domain knowledge graph.

[0058] In a possible implementation manner, the natural language-based query method provided by this application may specifically further include the following steps:

[0059] Perform error correction on the standardized query text.

[0060] In this implementation manner, the vocabulary in the standardized query text can be matched with the standard terms in a pre-constructed domain vocabulary. Specifically, the semantic similarity between the vocabulary and the standard terms in the vector space can be calculated, and the glyph difference between the vocabulary and the standard terms can be quantified through the edit distance algorithm. The edit distance and the semantic similarity are weighted and fused to obtain a comprehensive similarity score value. If this score value exceeds a preset score threshold, a replacement mechanism is triggered. For example, correct "Huadong" to "East China", or expand "Beifen" to "Beijing Branch", and record the error correction log for subsequent model optimization. This process ensures strict alignment between the key business vocabulary (such as regional entities, metric attributes, institution abbreviations) in the standardized query text and the standard terms in the domain vocabulary through the dual verification of "glyph similarity - semantic relevance".

[0061] S202. Based on a preset semantic understanding model and a pre-constructed domain knowledge graph, perform semantic parsing on the standardized query text to obtain a semantic understanding result, where the semantic understanding result includes at least one of the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities.

[0062] The domain knowledge graph is constructed based on multi-source heterogeneous data, encompassing enterprise-level business system data, business documents, and historical query logs. This multi-source heterogeneous data can be cleaned and formatted. Then, business entities are extracted from the cleaned data to construct an entity set, which includes at least customers, orders, and products. Based on dependency syntax and business rules, semantic relationships between entities are identified and defined, such as the "ownership" relationship for "customer → order" and the "containment" relationship for "order → product." Subsequently, attribute information is added to entities and relationships. Attribute values ​​are populated through data mining (such as association rule mining) or user annotation (such as expert review) to support multi-dimensional attribute queries.

[0063] In this step, the corrected, standardized query text can be input into a pre-trained BERT-BiLSTM joint model for semantic parsing. Simultaneously, the model's parsing results are semantically enhanced using a pre-built domain knowledge graph to obtain semantic understanding results. For example, when the fuzzy concept "major customer" is detected, its associated business rules can be retrieved from the graph. In the graph, "major customer" might be explicitly defined as "contract amount ≥ 1 million yuan," and this rule can subsequently be added to the query logic tree.

[0064] By employing dual verification through model extraction and graph expansion, the semantic understanding results are ensured to contain complete information on target entities (such as "customers"), attributes (such as "sales revenue"), and relationships (such as "customer-region"), eliminating ambiguity in vague expressions such as "major customers." This significantly improves the accuracy, completeness, and business adaptability of semantic parsing, laying a high-quality semantic foundation for subsequent permission verification and query generation.

[0065] S203. Verify the user's access rights to the target entity based on the pre-built permission knowledge graph, and generate an access token after the verification is successful.

[0066] In this step, based on the pre-built permission knowledge graph, the user's access permissions to the parsed target entity are verified. If the verification passes, an access token with time validity and permission scope is generated. Otherwise, the permission blocking mechanism is triggered, and an error message of "insufficient access permission" or "access prohibited" is returned, interrupting the subsequent processing flow of the current query request.

[0067] In one possible implementation, the natural language-based query method provided in this application may further include the following steps:

[0068] Based on the hierarchical relationship between user roles and institutional nodes, the hierarchical relationship between data entities and institutional nodes, and the access control policies for each field in the data entity, a permission knowledge graph is constructed. Each node in the permission knowledge graph records at least the user role, the institution to which the user role belongs, the data entity authorized to be accessed by the institution, and the authorization access level for the data entity. Different authorization access levels correspond to different authorization access fields.

[0069] In this embodiment, the construction of the permission knowledge graph is based on the enterprise RBAC (Role-Based Access Control) system. First, role permission information is obtained from the RBAC system, including user roles, affiliated organizations, authorized data entities, and access permissions. Based on this role permission information, the affiliation relationships between user roles and organization nodes, the affiliation relationships between data entities and organization nodes, and the access control policies for each field in the data entities are determined, thereby constructing the permission knowledge graph. The node construction of the permission knowledge graph is shown below:

[0070] ←⟨Role,Dept,DataEntity,AccessLevel>;

[0071] When a new field is added to the database, the permission knowledge graph update process is automatically triggered to ensure the real-time nature and accuracy of permission control.

[0072] By integrating user roles, organizations, data entities, and field-level permissions into the data graph, fine-grained control over data access is achieved, ensuring that users can only access the fields they are authorized to access, thereby significantly improving system security. Compared to traditional role-based access control (RBAC), this method can reduce the problem of over-assignment of permissions due to role generalization and reduce the risk of data leakage.

[0073] S204. Map the semantic understanding results to a logic tree structure to obtain the query logic tree.

[0074] In this step, the semantic understanding results are transformed into a structured logic tree. This logic tree expresses the query logic in a tree topology. The root node can be defined as the query target, the branch nodes are logical operators (such as AND and OR), and the leaf nodes store entity attributes and constraints.

[0075] The logic tree can be optimized using strategies such as path merging, redundancy pruning, and complexity balancing to obtain an optimized logic tree. For example, the constraints of "East China Region" and "Zhejiang Province" can be merged into "East China Region ∩ Zhejiang", unreferenced fields can be pruned, and complex query logic trees can be split into multiple subquery trees to avoid full table scans. The optimized logic tree improves query efficiency and accuracy.

[0076] S205. Parse the database metadata, map the node elements in the query logic tree to physical table fields, and generate a query tree that matches the current field.

[0077] In this step, database metadata is parsed, mapping abstract node elements in the logical tree to specific physical table fields. This process ensures an accurate correspondence between logical nodes and physical fields through metadata matching. For example, the "region" attribute in the logical tree is mapped to the "area" field of the "region" table, generating a query tree that matches the database's physical storage structure. When the database table structure changes, the mapping dictionary and knowledge graph nodes are automatically updated. For instance, if the "area" field in the "region" table is renamed to "location," all related query tree field references are synchronously updated, and the node updates in the permission knowledge graph are triggered, ensuring the correctness of subsequent permission checks and query execution.

[0078] S206. Based on the access token, call the preset access control policy function to perform attribute-level access control verification on the metadata of the fields mapped in the query tree, and generate a query statement based on the query tree after the verification is passed.

[0079] In this step, based on the access token, a preset access control policy function is invoked to perform attribute-level permission verification on the field metadata mapped in the query tree. For example, it verifies whether the user has permission to access the "Order Amount" field, or whether the "Edit" permission overrides the current field. The field metadata contains information such as the field's name, type, and access permissions, which is used to determine whether the user has permission to access the field. After successful verification, a query statement (such as SQL) conforming to database syntax rules is generated based on the query tree structure. This ensures that the final generated query statement only contains the fields the user is authorized to access and conforms to the physical table structure constraints, completing the transformation from a logical query to an executable query.

[0080] Injecting dynamic permission conditions into the WHERE clause of SQL can be done as follows:

[0081] WHERE visible_flag=1 AND ABE_Verify(Token,column_meta);

[0082] Here, `visible_flag=1` ensures that only records marked as visible are queried, while `ABE_Verify(Token, column_meta)` dynamically verifies the user's access permissions to the current field. `Token` is the access token, and `column_meta` is the field's metadata.

[0083] This process ensures the security and compliance of data access, preventing unauthorized data leaks.

[0084] In one possible implementation, after successful validation, a query statement is generated based on the query tree, which may specifically include the following steps:

[0085] After successful validation, the query tree is parsed to generate a standardized query syntax framework, and the query conditions in the query tree are embedded into the standardized query syntax framework as bind variables to generate query statements.

[0086] In this implementation, the query tree is parsed, its logical structure is extracted, and a standardized query syntax framework is generated. This framework is the "skeleton" of the SQL statement, containing the basic structure of the query, but it is not yet populated with specific user input values. To ensure query security and effectively prevent SQL injection attacks, user input values ​​(i.e., query conditions) are embedded into the query syntax framework as bind variables. For example, for date range conditions, the generated query statement can be as follows:

[0087] WHERE order_date BETWEEN :start AND :end;

[0088] In this approach, `:start` and `:end` are bind variables that are replaced with the specific values ​​entered by the user during query execution. Bind variables are placeholders used to dynamically insert user input values ​​during query execution. This method effectively avoids directly embedding user input into SQL statements, thus completely eliminating the risk of SQL injection attacks. This approach not only ensures the security and compliance of data access but also improves system performance and maintainability.

[0089] S207. Execute the query statement to obtain the target query result.

[0090] In one possible implementation, executing a query statement to obtain the target query result may specifically include the following steps:

[0091] Execute the query statement to obtain the initial query results;

[0092] If the initial query results contain numerical results, random noise is added to the numerical results based on the pre-built permission knowledge graph to generate the target query results.

[0093] In this implementation, random noise is added to the numerical results to protect data privacy and prevent the leakage of sensitive information. This technique is commonly used in differential privacy, where noise is added to obscure the true data, thereby protecting privacy without significantly affecting data usability. Specifically, Laplace noise can be added to the numerical results based on a pre-built permission knowledge graph, effectively protecting the privacy of the numerical data.

[0094] In one possible implementation, executing a query statement to obtain initial query results may specifically include the following steps:

[0095] Encode the query statement into a corresponding query feature vector;

[0096] Calculate the similarity between the query feature vector and the cached query feature vector;

[0097] If the similarity calculation result meets the preset similarity condition, the execution plan corresponding to the cached query feature vector will be used as the target execution plan.

[0098] The execution plan is executed to obtain the initial query results.

[0099] In this implementation, the query statement is encoded into a corresponding query feature vector. The current query feature vector is then compared with cached query feature vectors in the cache library for similarity calculation, which can employ the Hamming distance algorithm. If the similarity calculation result meets a preset similarity condition, the execution plan corresponding to the cached query feature vector that meets the preset similarity condition is used as the target execution plan and directly applied to the current query. If no cached query feature vector meets the preset similarity condition, a new execution plan is generated and executed. Simultaneously, the current query feature vector and execution plan are stored in the cache library for reuse in subsequent queries.

[0100] By reusing execution plans, the repeated parsing and optimization of similar queries are avoided. Reusing execution plans reduces the consumption of computing resources in the query optimization and plan generation stages and improves query execution efficiency.

[0101] In one possible implementation, after executing the query statement to obtain the target query result, the natural language-based query method provided in this application may further include the following steps:

[0102] Based on the field type of the target query result, match and generate the corresponding type of visualization chart.

[0103] In this implementation, after executing the query and obtaining the target query results, corresponding visualization charts can be automatically generated based on the data field types. This automated chart generation helps users understand the data more intuitively. For example, if the target query results contain time series fields, a line chart is generated; if the target query results contain geographic coordinate fields, a heatmap is generated; if the target query results contain both categorical and numerical fields, a bar chart is generated. This approach not only provides intuitive data visualization, helping users better understand and analyze data, but also improves the user experience and the system's automation level.

[0104] Optionally, the target query results can be populated into an Excel worksheet, with corresponding conditional formatting bars added to numeric fields, automatic line wrapping for excessively long text data, and region-sensitive formatting set for date fields. Additionally, the Echarts rendering engine can be used to generate interactive SVG charts, supporting data drill-down and interactive operations, thereby significantly improving user experience and data visualization.

[0105] In one possible implementation, the natural language-based query method provided in this application may further include the following steps:

[0106] When a user's adjustment to the target query result is detected, the operation sequence is recorded and an action chain is generated;

[0107] Transform the action chain into labeled training samples;

[0108] The negative log-likelihood loss function is used as the optimization objective, and the model parameters are updated by training the preset semantic understanding model with training samples.

[0109] In this implementation, users may adjust the query results when viewing them, such as modifying the time range or changing the sorting fields. These adjustments reflect users' further needs for the query results and can serve as important data for optimizing the semantic understanding model.

[0110] The system monitors user actions that modify target query results. It records detailed information for each modification, including the action type, parameter values, and timestamp. All modifications are then arranged chronologically to generate an action chain. Each action in the chain is labeled with its corresponding semantic intent. The labeled action chain is then transformed into training samples, and a pre-defined semantic understanding model is trained using a negative log-likelihood loss function as the optimization objective. The model parameters are updated by minimizing the loss function. This process not only continuously optimizes model performance but also improves the accuracy of semantic understanding and query processing, significantly enhancing user experience and the system's intelligence.

[0111] Optionally, query logs can be scanned periodically and analyzed using the TF-IDF algorithm to extract new business terms. For example, if users frequently query "live-streaming e-commerce," this term will be identified as a new business term. If a new business term is identified, a corresponding node is created in the domain knowledge graph and relationship edges are established with existing nodes. To maintain the efficiency and accuracy of the domain knowledge graph, outdated nodes need to be cleaned up periodically. These nodes may no longer be referenced by users and can therefore be discarded.

[0112] The natural language-based query method provided in this embodiment eliminates colloquial expressions, redundant information, and format differences by standardizing the original natural language query text, ensuring a unified and standardized input for subsequent semantic parsing and reducing ambiguity caused by differences in expression. Combined with a pre-set semantic understanding model and domain knowledge graph, multi-dimensional semantic parsing can be performed on the standardized text. This enables accurate capture of the intent of queries with complex conditions. Based on a pre-built permission knowledge graph, user access permissions to target entities can be automatically verified after semantic parsing. A four-level permission control chain (role-organization-entity-field) ensures that only authorized users can access specified data entities and fields. Query statements dynamically generated based on access tokens and semantic understanding results can be directly and seamlessly integrated with the database execution layer, completing an end-to-end mapping from natural language queries to structured queries. This solution, through a full-chain design of "standardization-parsing-permission verification-query execution," achieves a closed loop from natural language queries to secure and efficient data acquisition, improving query accuracy, security, and processing efficiency while lowering the barrier to entry for non-technical personnel.

[0113] Figure 3 A schematic diagram of the structure of the natural language-based query device provided in this application is shown below. Figure 3 As shown, the natural language-based query device 30 provided in this embodiment includes:

[0114] The standardization processing module 301 is used to standardize the raw natural language query text input by the user and generate standardized query text.

[0115] The semantic parsing module 302 is used to perform semantic parsing on standardized query text based on a preset semantic understanding model and a pre-built domain knowledge graph to obtain semantic understanding results. The semantic understanding results include at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities.

[0116] The verification module 303 is used to verify the user's access rights to the target entity based on the pre-built permission knowledge graph, and generate an access token after the verification is successful.

[0117] Module 304 is used to generate query statements based on access tokens and semantic understanding results;

[0118] Execution module 305 is used to execute query statements to obtain the target query results.

[0119] In one possible implementation, the generation module is specifically used for:

[0120] The semantic understanding results are mapped to a logic tree structure to obtain the query logic tree;

[0121] Parse the database metadata, map the node elements in the query logic tree to physical table fields, and generate a query tree that matches the current field;

[0122] Based on the access token, the preset access control policy function is called to perform attribute-level access control verification on the metadata of the fields mapped in the query tree, and a query statement is generated based on the query tree after the verification is passed.

[0123] In one possible implementation, the generation module is specifically used for:

[0124] After successful validation, the query tree is parsed to generate a standardized query syntax framework, and the query conditions in the query tree are embedded into the standardized query syntax framework as bind variables to generate query statements.

[0125] In one possible implementation, the execution module is specifically used for:

[0126] Execute the query statement to obtain the initial query results;

[0127] If the initial query results contain numerical results, random noise is added to the numerical results based on the pre-built permission knowledge graph to generate the target query results.

[0128] In one possible implementation, the execution module is specifically used for:

[0129] Encode the query statement into a corresponding query feature vector;

[0130] Calculate the similarity between the query feature vector and the cached query feature vector;

[0131] If the similarity calculation result meets the preset similarity condition, the execution plan corresponding to the cached query feature vector will be used as the target execution plan.

[0132] The execution plan is executed to obtain the initial query results.

[0133] In one possible implementation, the natural language-based query device provided in this embodiment is further used for:

[0134] Based on the field type of the target query result, match and generate the corresponding type of visualization chart.

[0135] In one possible implementation, the natural language-based query device provided in this embodiment is further used for:

[0136] When a user's adjustment to the target query result is detected, the operation sequence is recorded and an action chain is generated;

[0137] Transform the action chain into labeled training samples;

[0138] The negative log-likelihood loss function is used as the optimization objective, and the model parameters are updated by training the preset semantic understanding model with training samples.

[0139] In one possible implementation, the standardization processing module is specifically used for:

[0140] The system performs punctuation normalization and stop word filtering on the raw natural language query text input by the user to generate standardized query text.

[0141] In one possible implementation, the natural language-based query device provided in this embodiment is further used for:

[0142] Based on the hierarchical relationship between user roles and institutional nodes, the hierarchical relationship between data entities and institutional nodes, and the access control policies for each field in the data entity, a permission knowledge graph is constructed. Each node in the permission knowledge graph records at least the user role, the institution to which the user role belongs, the data entity authorized to be accessed by the institution, and the authorization access level for the data entity. Different authorization access levels correspond to different authorization access fields.

[0143] The natural language-based query device provided in this embodiment can execute the methods provided in the above-described method embodiments. Its implementation principle and technical effects are similar, and will not be described in detail here.

[0144] Figure 4 A schematic diagram of the structure of the natural language-based query device provided in this application. Figure 4 As shown, the natural language-based query device 40 provided in this embodiment includes at least one processor 401 and a memory 402. Optionally, the device 40 further includes a communication component 403. The processor 401, memory 402, and communication component 403 are connected via a bus.

[0145] In a specific implementation, at least one processor 401 executes computer execution instructions stored in memory 402, causing at least one processor 401 to perform the above-described method.

[0146] The specific implementation process of processor 401 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0147] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0148] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0149] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0150] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0151] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0152] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0153] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0154] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0155] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0156] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0157] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0158] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0159] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

Claims

1. A query method based on natural language, characterized in that, The method includes: The raw natural language query text input by the user is standardized to generate standardized query text; Based on a preset semantic understanding model and a pre-built domain knowledge graph, semantic parsing is performed on the standardized query text to obtain a semantic understanding result. The semantic understanding result includes at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities. The user's access rights to the target entity are verified based on a pre-built permission knowledge graph, and an access token is generated after the verification is successful. Generate a query statement based on the access token and the semantic understanding result; Execute the query statement to obtain the target query result.

2. The method of claim 1, wherein, The step of generating a query statement based on the access token and the semantic understanding result includes: The semantic understanding results are mapped to a logic tree structure to obtain the query logic tree; Parse the database metadata, map the node elements in the query logic tree to physical table fields, and generate a query tree that matches the current field; Based on the access token, a preset access control policy function is invoked to perform attribute-level access control verification on the metadata of the fields mapped in the query tree, and a query statement is generated based on the query tree after the verification passes.

3. The method of claim 2, wherein, The step of generating a query statement based on the query tree after successful verification includes: After successful verification, the query tree is parsed to generate a standardized query syntax framework, and the query conditions in the query tree are embedded in the standardized query syntax framework as bind variables to generate query statements.

4. The method of claim 3, wherein, The process of executing the query statement to obtain the target query result includes: Execute the query statement to obtain the initial query results; If the initial query results contain numerical results, random noise is added to the numerical results based on the pre-built permission knowledge graph to generate the target query results.

5. The method of claim 4, wherein, The process of executing the query statement to obtain the initial query results includes: The query statement is encoded into a corresponding query feature vector; Calculate the similarity between the query feature vector and the cached query feature vector; If the similarity calculation result meets the preset similarity condition, then the execution plan corresponding to the cached query feature vector will be used as the target execution plan; The target execution plan is executed to obtain the initial query results.

6. The method according to any one of claims 1 to 5, characterized in that, After obtaining the target query result by executing the query statement, the method further includes: Based on the field type of the target query result, a corresponding visualization chart is matched and generated.

7. The method according to any one of claims 1 to 5, characterized in that, The method further includes: When a user is detected to have adjusted the target query result, the operation sequence is recorded and an action chain is generated; The action chain is then converted into labeled training samples; The negative log-likelihood loss function is used as the optimization objective, and the preset semantic understanding model is trained using the training samples to update the model parameters.

8. The method according to any one of claims 1 to 5, characterized in that, The process of standardizing the raw natural language query text input by the user to generate standardized query text includes: The system performs punctuation normalization and stop word filtering on the raw natural language query text input by the user to generate standardized query text.

9. The method according to any one of claims 1 to 5, characterized in that, The method further includes: Based on the affiliation between user roles and institutional nodes, the affiliation between data entities and institutional nodes, and the access control policies for each field in the data entity, a permission knowledge graph is constructed. Each node in the permission knowledge graph records at least the user role, the institution to which the user role belongs, the data entity authorized for access by the institution, and the authorized access level for the data entity. Different authorized access levels correspond to different authorized access fields.

10. A natural language based query apparatus, characterized by The device includes: The standardization processing module is used to standardize the raw natural language query text input by the user and generate standardized query text. The semantic parsing module is used to perform semantic parsing on the standardized query text based on a preset semantic understanding model and a pre-built domain knowledge graph to obtain a semantic understanding result. The semantic understanding result includes at least one of the following: the target entity queried by the user, the attribute information of the target entity, and the relationship information between the target entity and other entities. The verification module is used to verify the user's access rights to the target entity based on a pre-built permission knowledge graph, and generate an access token after the verification is successful. The generation module is used to generate a query statement based on the access token and the semantic understanding result; The execution module is used to execute the query statement to obtain the target query result.

11. A natural language based query device, characterized by include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 9.

13. A computer program product, characterised in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 9.