A method for generating a database query from a natural language

By constructing a schema attribute graph and index library, combined with an entity recognition model, the problems of complex table structure and implicit relationships in telecommunications operation and maintenance databases were solved. This achieved accurate mapping from natural language to SQL and stability of query generation, improving the intelligence and consistency of queries.

CN121880369BActive Publication Date: 2026-05-19CENT SOUTH UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CENT SOUTH UNIV
Filing Date
2026-03-18
Publication Date
2026-05-19

AI Technical Summary

Technical Problem

Existing Text-to-SQL technology suffers from complex table structures and implicitly scattered relationships between tables in telecommunications operations and maintenance databases. This makes it difficult to accurately map natural language queries to the database structure, and cross-table relationships are prone to ambiguity. Furthermore, the accuracy and stability of generated query statements are lacking.

Method used

Construct a schema attribute graph and a structured schema index library. Match entity information in user query requests using an entity recognition model to determine candidate table names and field names. Build a local structured index library, generate and validate structured query statements, and dynamically update the index library based on query results.

Benefits of technology

It improves the accuracy and maintainability of database structure modeling, reduces users' dependence on database structure, enhances the intelligence and accuracy of query request parsing, reduces error associations and query load, and improves the stability and adaptability of query execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121880369B_ABST
    Figure CN121880369B_ABST
Patent Text Reader

Abstract

The application belongs to the cross technical field of natural language processing and database query technology, and provides a method for generating a database query from a natural language. The method comprises the following steps: obtaining table names and field names of each data table, constructing a Schema attribute graph for describing the association relationship between tables based on the table names and the field names, and establishing a structured Schema index library; receiving a query request input by a user, calling an entity recognition model to identify entity information related to a business from the query request, and obtaining corresponding candidate table names and candidate field names; determining an associated subgraph structure, and constructing a local structured Schema index library; constructing a candidate association path set, determining a target association path according to a preset priority rule; performing syntax and logic checking on a structured query statement, and obtaining an executable structured query statement; and updating the target local structured Schema index library. The application improves the stability and accuracy of query execution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the interdisciplinary field of natural language processing and database query technology, and specifically relates to a method for generating database queries from natural language. Background Technology

[0002] With the increasing demand for big data and intelligent analytics, Text-to-SQL technology, or natural language to SQL technology, has received widespread attention. This technology parses users' query intent expressed in natural language and converts it into executable SQL statements, lowering the barrier to entry for database queries and providing business users with a more user-friendly query method.

[0003] Currently, although it is possible to generate SQL using LLM (Large Language Model), the current Text-to-SQL technology still faces many challenges: (i) Natural language is highly complex, which places higher demands on the parsing capabilities of LLM; (ii) Semantic ambiguity is serious, requiring accurate mapping of user intent to complex database structures, which makes it difficult to understand and parse query intent. In the telecommunications field, database structure description information is usually large and table structures are complex, with multiple layers of business logic and common names coexisting with technical terms, making the matching of field and table names highly ambiguous; (iii) Redundant contextual information leads to distraction, making it difficult for the model to focus on key elements, ignoring task-specific explanations and prompts, and weakening the accuracy of SLQ generation; (iv) The SQL generation process lacks interpretability, with a lack of explicit constraints and supervision on intermediate reasoning or logical steps.

[0004] Therefore, there is an urgent need for a method that can overcome the ambiguity of natural language, utilize domain knowledge, and combine key contextual information to accurately generate SQL statements that conform to the user's intent when facing complex scenarios. Summary of the Invention

[0005] The technical problem this invention aims to solve is that existing Text-to-SQL technologies suffer from complex table structures and implicitly dispersed relationships between tables in existing telecommunications operation and maintenance databases. This leads to difficulties in accurately mapping natural language queries to the database structure, ambiguity in cross-table relationships, and a lack of accuracy and stability in query generation. The invention provides a method for generating database queries from natural language.

[0006] The content of this invention includes:

[0007] A method for generating database queries from natural language is provided, including:

[0008] Obtain the table name and field name of each data table, construct a schema attribute diagram to describe the relationship between the tables based on the table name and field name, and establish a structured schema index library corresponding to the table name and field name based on the schema attribute diagram;

[0009] Based on the structured schema index library, a query request input by the user is received, and an entity recognition model is called to identify business-related entity information from the query request. The entity information is then matched with the table name and field name to obtain candidate table name and candidate field name corresponding to the entity information.

[0010] The candidate table names are mapped to table nodes, the subgraph structure associated with the candidate table names and candidate field names corresponding to the entity information is determined, and a local structured schema index library corresponding to the entity information is constructed based on the subgraph structure.

[0011] In the subgraph structure, a set of candidate association paths is constructed based on the association relationships between table nodes recorded in the local structured schema index. Based on the set of candidate association paths, a target association path for generating structured query statements is determined according to a preset priority rule.

[0012] Based on the target association path, the table name and field name are combined to generate a structured query statement, and the structured query statement is subjected to syntax and logic validation to obtain an executable structured query statement.

[0013] Execute the executable structured query statement, and dynamically update the local structured schema index based on the query execution result to obtain the target local structured schema index that matches the query request.

[0014] Further, the step of obtaining the table names and field names of each data table, constructing a schema attribute diagram based on the table names and field names to describe the relationships between tables, and establishing a structured schema index library corresponding to the table names and field names based on the schema attribute diagram includes:

[0015] Perform structural parsing on the target telecom operations and maintenance database to obtain the table names and field names of each data table;

[0016] Based on the table names and field names, construct a schema attribute diagram to describe the relationships between the data tables;

[0017] Based on the schema attribute diagram, the table names and field names are organized to create a structured schema index library corresponding to the table names and field names.

[0018] Further, based on the structured schema index library, the process of receiving a user-input query request, calling an entity recognition model to identify business-related entity information from the query request, and matching the entity information with the table name and field name to obtain candidate table names and candidate field names corresponding to the entity information includes:

[0019] Receive query requests input by users and perform normalization processing on the query requests;

[0020] The entity recognition model is invoked to analyze the normalized query request and identify the business-related entity information. The entity information consists of structured elements identified from the natural language query that correspond one-to-one with objects in the structured schema index, including table name, field name, field value and their constraint relationship.

[0021] The entity information is matched with the table names and field names in the structured schema index to obtain candidate table names and candidate field names corresponding to the entity information.

[0022] Further, the step of mapping the candidate table names to table nodes, determining the subgraph structure associated with the candidate table names and candidate field names corresponding to the entity information, and constructing a local structured schema index library corresponding to the entity information based on the subgraph structure includes:

[0023] In the schema attribute diagram, the candidate table names are mapped to table nodes, and the candidate field names are mapped to field nodes;

[0024] Based on the membership relationship between field nodes and table nodes, and the association relationship between table nodes, a subgraph structure associated with the candidate table name and candidate field name corresponding to the entity information is extracted from the schema attribute graph. A local structured schema index library corresponding to the entity information is constructed based on the subgraph structure. The association relationship between the table nodes includes foreign key connection relationship and field reference relationship.

[0025] Further, in the subgraph structure, a candidate association path set is constructed based on the association relationships between table nodes recorded in the local structured schema index. Based on the candidate association path set, a target association path for generating a structured query statement is determined according to a preset priority rule, including:

[0026] In the subgraph structure, based on the association relationships between table nodes recorded in the local structured schema index library, the candidate association path set is generated according to the preset path generation rules, wherein the preset path generation rules are rules that limit the connection direction, connection level and maximum number of connections of table nodes in the association path.

[0027] The validity of each candidate association path in the candidate association path set is verified, and candidate association paths that do not meet the connection integrity constraints, have circular references, or do not contain the target field are eliminated to obtain the candidate association paths that pass the verification.

[0028] Among the candidate association paths that have passed the verification, the target association path for generating the structured query statement is determined according to the preset priority rules, wherein the priority rules are rules for sorting the association path by length, number of table nodes or field coverage.

[0029] Further, the step of generating a structured query statement by combining the table name and field name according to the target association path, and performing syntax and logic checks on the structured query statement to obtain an executable structured query statement includes:

[0030] Based on the correspondence between table names and field names in the target association path, a query template containing table join conditions and field selection conditions is generated;

[0031] The table name, field name, join condition, and field selection condition in the query template are replaced with the corresponding actual identifiers in the database. The structured query statement is then subjected to syntax and logic validation to form the executable structured query statement. The actual identifier is the real name used in the database to uniquely locate the data object.

[0032] Further, the execution of the executable structured query statement, and the dynamic updating of the local structured schema index based on the query execution result to obtain a target local structured schema index that matches the query request, includes:

[0033] Execute the executable structured query statement to obtain the corresponding query execution result;

[0034] The local structured schema index is dynamically updated based on the query execution result to obtain the target local structured schema index that matches the query request.

[0035] Furthermore, in the set of candidate associated paths, when multiple candidate associated paths simultaneously meet the preset conditions, a confirmation operation for the candidate associated paths is triggered.

[0036] Furthermore, the confirmation operation includes displaying the table names and field names corresponding to all candidate association paths to the user, filtering the candidate association paths based on pre-configured selection parameters, and receiving the user's confirmation result to determine the target association path that is uniquely used to generate a structured database query statement.

[0037] Furthermore, updating the local structured schema index also includes: adjusting the association between the table name and field name in the table nodes of the local structured schema index based on the user's confirmation result.

[0038] Compared with the prior art, the beneficial effects achieved by the present invention are:

[0039] 1. This invention obtains the table names and field names of each data table, constructs a schema attribute diagram and a structured schema index library, and transforms the implicit relationship between tables in the database into an explicit structured representation, avoiding the inconsistency problem caused by table relationships and improving the accuracy and maintainability of database structure modeling;

[0040] 2. This invention processes user query requests by introducing an entity recognition model and matches the recognized entity information with table names and field names, thereby achieving an effective mapping between natural language queries and database structures. This reduces users' dependence on database structures and query languages ​​and improves the intelligence and accuracy of query request parsing.

[0041] 3. This invention filters relevant table and field names in the structured schema index of entity information and further determines the corresponding subgraph structure, thus limiting the query scope to the local database structure that is highly related to the business entity. This effectively reduces the interference of irrelevant tables and fields and improves the efficiency of association analysis and query generation.

[0042] 4. This invention constructs a set of candidate association paths within the subgraph structure and determines the target association path from it, transforming the process of determining multi-table association relationships from a full database search to a specific target association path. This avoids erroneous associations caused by ambiguity in association paths and improves the reliability and consistency of constructing multi-table query relationships.

[0043] 5. This invention generates structured query statements through target association paths, performs syntax and logic checks, and discovers potential structural errors before query execution, reducing the load on the database system caused by invalid or erroneous queries and improving the stability and accuracy of query execution;

[0044] 6. This invention executes validated structured query statements and updates the structured schema index based on the query execution results. This allows the system to dynamically adjust the index information based on actual query feedback, resulting in a target local structured schema index that matches the query request. This improves the consistency between the schema index and the real database and enhances the system's adaptability. Attached Figure Description

[0045] Figure 1 This is a flowchart illustrating a method for generating database queries from natural language, as provided by the present invention. Detailed Implementation

[0046] Figure 1 This is a flowchart illustrating a method for generating database queries from natural language, as provided by the present invention.

[0047] like Figure 1 As shown, the present invention provides a method for generating database queries from natural language, comprising:

[0048] S1. Obtain the table name and field name of each data table, construct a schema attribute diagram to describe the relationship between the tables based on the table name and field name, and establish a structured schema index library corresponding to the table name and field name based on the schema attribute diagram.

[0049] S11. Perform structure parsing on the target telecom operation and maintenance database to obtain the table name and field name of each data table;

[0050] In one embodiment, the database structure of the target telecommunications operations and maintenance database is parsed, and the structure information of each defined data table in the database is read to obtain the table name and corresponding field names of each data table. For example, the telecommunications operations and maintenance database may include a "Base Station Information Table" for storing base station information, an "Alarm Information Table" for storing alarm information, and a "User Information Table" for storing user information, etc. Each data table contains multiple fields, such as base station number, base station name, alarm time, user number, etc. By parsing this database structure, without relying on specific business query content, the basic structural information of the queryable data tables and their fields in the database can be completely obtained, clarifying which tables are included and what fields are in each table.

[0051] S12. Based on the table names and field names, construct a schema attribute diagram to describe the relationships between the data tables;

[0052] In one embodiment, the schema attribute graph uses data tables as nodes and the relationships between data tables as edges to depict the connections between them. For example, when the base station number field in the "Alarm Information Table" has a foreign key relationship with the base station number field in the "Base Station Information Table," a corresponding data table connection is established in the schema attribute graph. By constructing the schema attribute graph, the structural relationships between the various data tables in the database are intuitively reflected.

[0053] S13. Based on the Schema attribute diagram, organize the table names and field names to establish a structured Schema index library corresponding to the table names and field names.

[0054] In one embodiment, a structured schema index is used to store index information about data tables, fields, and relationships between tables. Based on the schema attribute diagram, and according to the structural relationships defined in the schema attribute diagram, table names and field names are transformed into structured index units that can be quickly retrieved and invoked by algorithms, thus establishing a structured schema index and enabling rapid organization and access to database structure information.

[0055] S2. Based on the structured schema index library, receive the query request input by the user, call the entity recognition model to identify business-related entity information from the query request, and match the entity information with the table name and field name to obtain the candidate table name and candidate field name corresponding to the entity information;

[0056] Among them, entity recognition models include large language models. Large language models (LLMs) are deep learning models trained with a large amount of text data. These models can generate natural language text or understand language text.

[0057] S21. Receive a query request input by the user and perform normalization processing on the query request;

[0058] In one embodiment, a query request is received from a user. The query request is in natural language form, such as "Query alarm information of base stations in the Beijing area for the past three days." Because different users have different input methods, expression order, and symbol formats, the query request is standardized to facilitate identification. This includes: removing irrelevant stop words and redundant words; unifying synonymous or equivalent expressions into a standard, analyzable form; and standardizing the format of common conditions such as time and region. For example, expressions such as "past three days" and "last three days" are uniformly converted into a time range parameter format that the system can recognize. This standardization process is not about reasoning or understanding the query semantics, but rather about standardizing the input format.

[0059] S22. The entity recognition model is invoked to analyze the normalized query request and identify the business-related entity information therein. The entity information is a structured element that corresponds one-to-one with the object in the structured schema index library and is identified from the natural language query, including table name, field name, field value and its constraint relationship.

[0060] In one embodiment, the query content may correspond to tables, fields, or field values ​​in a database. Specifically, a pre-configured entity recognition model is invoked to analyze the normalized query request and identify entity information related to business processing. Entity information is structured elements, and its source is limited to content that corresponds one-to-one with objects in the structured schema index, including: table names corresponding to entities, field names corresponding to entities, field values, and constraints between field values. For example, when the query request is: "Query base station information with a severe alarm level in the Beijing area," the entity information identified by the entity recognition model may include: "base station" corresponding to the base station information table in the database; "alarm level" corresponding to the alarm level field in the alarm information table; "severe" corresponding to the field value; and "Beijing area" corresponding to the area field and its value constraints. The output of the entity recognition model is limited to objects already existing in the structured schema index, avoiding the generation of abstract semantic results unrelated to the database structure.

[0061] S23. Match the entity information with the table names and field names in the structured schema index to obtain candidate table names and candidate field names corresponding to the entity information.

[0062] In one embodiment, for table name entities, the system matches table nodes in the schema index with the same name or identifier; for field name entities, it matches field nodes under their respective table nodes; and for field value entities, it records the constraint relationship between the field and its corresponding field. For example, when the entity identification result includes "alarm level" and "critical": the system locates the alarm information table containing the "alarm level" field in the schema index; and records "critical" as a candidate value condition for this field; thus, the alarm information table is obtained as a candidate table name, and the alarm level field is obtained as a candidate field name. Through the above matching process, the entity information in the natural language query is constrained within the scope of the structured schema index, providing a structural foundation for the generation of database query statements.

[0063] S3. Map the candidate table name to a table node, determine the subgraph structure associated with the candidate table name and candidate field name corresponding to the entity information, and construct a local structured schema index library corresponding to the entity information based on the subgraph structure;

[0064] S31. In the Schema attribute diagram, the candidate table name is mapped to a table node, and the candidate field name is mapped to a field node;

[0065] In one embodiment, based on the identified candidate table names and candidate field names, corresponding node representations are created in the schema attribute graph. This maps each candidate table name to a table node and each candidate field name to a field node. In this way, table names and field names, originally existing as strings, are uniformly transformed into node elements in the graph structure. For example, in a telecommunications operations and maintenance database scenario, if a natural language query involves information such as "alarm time" or "base station name," it is mapped to the corresponding alarm table node, base station table node, and related field nodes, respectively.

[0066] S32. Based on the membership relationship between field nodes and table nodes, and the association relationship between table nodes, extract the subgraph structure associated with the candidate table name and candidate field name corresponding to the entity information from the schema attribute graph, and construct a local structured schema index library corresponding to the entity information based on the subgraph structure, wherein the association relationship between the table nodes includes foreign key connection relationship and field reference relationship.

[0067] In one embodiment, the aforementioned method shrinks the originally large global schema attribute graph into a local structure relevant only to the current query, reducing the interference of irrelevant tables and fields on subsequent path search and query generation. For example, when the query only involves a certain type of alarm record and its associated device, only the local connectivity graph formed by the alarm table, device table, and their associated fields needs to be extracted.

[0068] S4. In the subgraph structure, a candidate association path set is constructed based on the association relationships between table nodes recorded in the local structured schema index library. Based on the candidate association path set, a target association path for generating structured query statements is determined according to a preset priority rule.

[0069] S41. In the subgraph structure, based on the association relationship between table nodes recorded in the local structured schema index library, the candidate association path set is generated according to the preset path generation rules, wherein the preset path generation rules are rules that limit the connection direction, connection level and maximum number of connections of table nodes in the association path.

[0070] In one embodiment, within the subgraph structure, based on the known relationships between table nodes recorded in the local structured schema index, and following preset path generation rules, possible association paths for table joins are enumerated to form a candidate association path set. The preset path generation rules constrain the path search process, for example, limiting the connection direction of table nodes, restricting the hierarchical depth of cross-table joins, and limiting the maximum number of table nodes allowed in a single association path, thus avoiding the generation of excessively long or unreasonable connection paths. In this way, several candidate table association paths matching the current query requirements can be generated while ensuring query executability. For example, in a telecommunications operations and maintenance database, for queries involving alarm information and equipment information, only paths connected through foreign key relationships between the alarm table and the equipment table are generated, without introducing historical log tables unrelated to the query.

[0071] S42. Perform a validity check on each candidate association path in the candidate association path set, and remove candidate association paths that do not meet the connection integrity constraints, have circular references, or do not contain the target field, to obtain the candidate association paths that pass the check;

[0072] In one embodiment, each candidate association path undergoes a validity check to eliminate paths that do not meet database structure constraints or query semantic requirements. Specifically, each candidate association path is checked to ensure it satisfies table join integrity constraints, avoids circular references, and contains the necessary field nodes for generating the target query. Candidate association paths that do not meet these conditions are removed from the candidate set, retaining only those that pass the validation. This validation process prevents the generation of queries that cannot be executed correctly or fail to return the target fields.

[0073] S43. Among the candidate association paths that have passed the verification, the target association path for generating the structured query statement is determined according to the preset priority rules, wherein the priority rules are rules for sorting the association path length, number of table nodes, or field coverage.

[0074] In one embodiment, based on a comprehensive evaluation of the length of the join path, the number of table nodes it contains, or the coverage of the target field, the path with a simpler structure and a more direct relationship is preferentially selected as the target join path. In this way, when multiple feasible table join schemes exist, the optimal or more reasonable join path, i.e., the target join path, is automatically determined.

[0075] S5. Based on the target association path, combine the table name and field name to generate a structured query statement, and perform syntax and logic verification on the structured query statement to obtain an executable structured query statement.

[0076] S51. Based on the correspondence between table names and field names in the target association path, generate a query template that includes table join conditions and field selection conditions;

[0077] In one embodiment, based on a determined target association path, the correspondence between table names and field names within that path is analyzed to generate a query template for query generation. However, the query template is not a directly executable query statement, but rather a structured intermediate representation that explicitly includes the join conditions between tables and the field selection conditions to be returned. For example, when the target association path involves an alarm table and a device table, the query template will explicitly record the join relationship between the two, such as using the device identifier field, and indicate the fields to be queried, such as the alarm time, alarm type, or device number, providing clear structural information for generating a complete query statement.

[0078] S52. Replace the table name, field name, join condition, and field selection condition in the query template with the corresponding actual identifier in the database, and perform syntax and logic verification on the structured query statement to form the executable structured query statement, wherein the actual identifier is the real name used in the database to uniquely locate the data object.

[0079] In one embodiment, the actual identifier is the real name used to uniquely locate data objects in the database, such as a specific table name, field code, or field identifier defined internally by the system. After the replacement is completed, the generated structured query statement is subjected to syntax and logic validation to ensure that the query statement conforms to the database syntax specifications and that the table joins and field references are logically complete and consistent, ultimately resulting in a structured query statement that can be directly executed in the target database.

[0080] S6. Execute the executable structured query statement, and dynamically update the local structured schema index library based on the query execution result to obtain the target local structured schema index library that matches the query request.

[0081] S61. Execute the executable structured query statement to obtain the corresponding query execution result;

[0082] In one embodiment, executing the generated executable structured query statement is essentially running a query operation in the database. This process is similar to entering an SQL query in a database management system and clicking execute. After the query is executed, the database returns the query results. For example, suppose the query is to retrieve alarm information for a specific device over the past month. After execution, the database will return alarm records that meet the criteria, including values ​​for fields such as device number, alarm time, and alarm type. This result is the corresponding query execution result.

[0083] S62. Based on the query execution result, dynamically update the local structured schema index to obtain a target local structured schema index that matches the query request.

[0084] In one embodiment, the local structured schema index adjusts and improves its table names, field names, and relationships based on new data in the query results. For example, assuming the query returns data containing newly added fields or updated field values ​​in certain tables, these new data modifications are dynamically added to the local structured schema index to obtain a target local structured schema index that matches the query request, thus maintaining the index's up-to-dateness and accuracy. This process is like updating a database "map," ensuring that future queries can efficiently locate the correct tables and fields. The updated index helps the system more accurately identify and match data in subsequent queries, improving query efficiency.

[0085] For example, query execution results: When a user submits a query request, the system executes the query based on the constructed query statement, retrieving information from the database. Based on the query execution results, the system may find that the relationships between certain table names and field names are inaccurate or incomplete. For instance, suppose a field appears in the query results that did not correctly reflect its relationship with a certain table in the index. In this case, the system needs to adjust this relationship in the schema index. For example, suppose a user queries the fields "Device Name" and "Device Status". After executing the query, the system finds that the "Device Status" field is actually associated with the "Device ID" field in another table, not the "Device ID" field in the current table. The system then needs to update the association relationship to associate these two fields with the correct tables.

[0086] In the set of candidate associated paths, when multiple associated paths simultaneously meet the preset conditions, a confirmation operation for the candidate associated paths is triggered.

[0087] In one embodiment, the candidate association path set is a collection of multiple candidate paths, each representing a different method of association through different tables and fields. Each path represents a way to extract information from certain data tables. For example, in a telecommunications operations and maintenance database, multiple tables store device data, network status, alarm information, etc. Multiple different "paths," or candidate association paths, are constructed based on the relationships between these tables to retrieve the desired results. For instance, if a user queries "all alarm information for device A in the past month," multiple candidate association paths may be available to retrieve this information. These could be through a foreign key association path between the device table and the alarm table; or through a multi-level association path between the device table and the status table, and then the alarm table. If all these paths meet the query criteria (i.e., correctly find device A and its alarm records), a confirmation operation is triggered, allowing the user to select the most suitable path. For example, the system displays two query paths: Path 1: Device table -> Alarm table; Path 2: Device table -> Status table -> Alarm table, allowing the user to choose which path best suits their query needs.

[0088] The confirmation operation includes displaying the table names and field names corresponding to all candidate association paths to the user, filtering the candidate association paths based on pre-configured selection parameters, and receiving the user's confirmation result to determine the target association path that is uniquely used to generate a structured database query statement.

[0089] In one embodiment, when multiple candidate paths meet the query criteria, the user is shown detailed information about these paths, including the table names and field names involved in each path. This information helps the user understand the query logic of each path. For example, two candidate paths might be displayed: Path 1: Device table -> Alarm table (Device ID -> Alarm ID), Path 2: Device table -> Status table -> Alarm table (Device ID -> Status ID -> Alarm ID). All candidate paths are filtered based on pre-configured selection parameters. These pre-configured parameters include confidence level and threshold, which are used to measure the accuracy and reliability of the paths. Confidence level represents the system's confidence in the correctness of a candidate associated path, while the threshold sets a minimum standard; only paths exceeding this threshold are considered. For example, if path 1 has a low confidence level while path 2 has a high confidence level, the system will prioritize path 2.

[0090] The above information is presented to the user, who then selects the final query path. The user chooses the most suitable path based on business needs, data accuracy, or other criteria. For example, suppose a user prioritizes accuracy in device alarm queries, and path 2 provides more information related to device status with higher confidence; in this case, the user might choose path 2 as the final query path. Once the user confirms, the target association path is determined, and a final structured query statement is generated based on this path for database query operations.

[0091] The formula for confidence level is as follows:

[0092]

[0093] Decision logic: Set a global confidence threshold And ambiguity interval threshold .

[0094] (1) If : This indicates that the system cannot match the field, triggering the "manual search" interaction. (2) If This indicates the existence of two semantically very similar fields (such as "Actual Amount Received" and "Accounts Receivable"). The system automatically extracts the comment description for each field and pushes it to the user for candidate confirmation. For confidence level, For semantic field 1, This is the semantic field 2.

[0095] The update of the local structured schema index also includes: adjusting the association between the table name and field name in the table nodes of the local structured schema index based on the user's confirmation result.

[0096] In one embodiment, the association between table names and field names in the local structured schema index is updated based on the user's confirmation. In other words, if the system needs to confirm certain details with the user when generating a query path—for example, if multiple candidate association paths exist, and the user selects a candidate association path—the system will update the relationship between table names and field names in the index based on the user's selection. This adjusts the association between table nodes in the schema index to ensure more accurate database queries.

[0097] This invention obtains the table names and field names of each data table, constructs a schema attribute graph and a structured schema index library, and transforms the implicit relationships between tables in the database into an explicit structured representation, avoiding inconsistencies caused by table relationships and improving the accuracy and maintainability of database structure modeling. By introducing an entity recognition model to process user query requests and matching the identified entity information with table names and field names, it achieves an effective mapping between natural language queries and database structure, reducing users' dependence on database structure and query language, and improving the intelligence and accuracy of query request parsing. Furthermore, by filtering relevant table names and field names in the structured schema index library based on entity information and further determining the corresponding subgraph structure, the query scope is limited to local database structures highly related to business entities, effectively reducing interference from irrelevant tables and fields and improving association analysis and query generation. The system improves efficiency by constructing a set of candidate association paths within the subgraph structure and determining the target association path from them. This transforms the process of determining multi-table associations from a full database search to a specific target association path, avoiding erroneous associations caused by ambiguity in association paths and improving the reliability and consistency of multi-table query relationship construction. It generates structured query statements through target association paths, performs syntax and logic checks, and identifies potential structural errors before query execution, reducing the load on the database system caused by invalid or erroneous queries and improving the stability and accuracy of query execution. By executing validated structured query statements and updating the structured schema index based on the query execution results, the system dynamically adjusts the index information according to actual query feedback, obtaining a target local structured schema index that matches the query request. This improves the consistency between the schema index and the real database and enhances the system's adaptability.

[0098] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of protection of this application is limited to these examples; under the concept of this application, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of one or more embodiments of this application as described above, which are not provided in detail for the sake of brevity.

[0099] One or more embodiments in this application are intended to cover all such substitutions, modifications, and variations that fall within the broad scope of this application. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of one or more embodiments in this application should be included within the protection scope of this application.

Claims

1. A method for generating database queries from natural language, characterized in that, include: Obtain the table name and field name of each data table, construct a schema attribute diagram to describe the relationship between the tables based on the table name and field name, and establish a structured schema index library corresponding to the table name and field name based on the schema attribute diagram; Based on the structured schema index library, a query request input by the user is received, and an entity recognition model is called to identify business-related entity information from the query request. The entity information is then matched with the table name and field name to obtain candidate table name and candidate field name corresponding to the entity information. The candidate table names are mapped to table nodes, the subgraph structure associated with the candidate table names and candidate field names corresponding to the entity information is determined, and a local structured schema index library corresponding to the entity information is constructed based on the subgraph structure. In the subgraph structure, a set of candidate association paths is constructed based on the association relationships between table nodes recorded in the local structured schema index. Based on the set of candidate association paths, a target association path for generating structured query statements is determined according to a preset priority rule. Based on the target association path, the table name and field name are combined to generate a structured query statement, and the structured query statement is subjected to syntax and logic validation to obtain an executable structured query statement. Execute the executable structured query statement, and dynamically update the local structured schema index based on the query execution result to obtain the target local structured schema index that matches the query request.

2. The method for generating database queries from natural language as described in claim 1, characterized in that, The steps include obtaining the table names and field names of each data table, constructing a schema attribute diagram based on the table names and field names to describe the relationships between tables, and establishing a structured schema index library corresponding to the table names and field names based on the schema attribute diagram. Perform structural parsing on the target telecom operations and maintenance database to obtain the table names and field names of each data table; Based on the table names and field names, construct a schema attribute diagram to describe the relationships between the data tables; Based on the schema attribute diagram, the table names and field names are organized to create a structured schema index library corresponding to the table names and field names.

3. The method for generating database queries from natural language as described in claim 1, characterized in that, Based on the structured schema index library, the system receives user-input query requests, calls an entity recognition model to identify business-related entity information from the query requests, and matches the entity information with the table names and field names to obtain candidate table names and candidate field names corresponding to the entity information, including: Receive query requests input by users and perform normalization processing on the query requests; The entity recognition model is invoked to analyze the normalized query request and identify the business-related entity information. The entity information consists of structured elements identified from the natural language query that correspond one-to-one with objects in the structured schema index, including table name, field name, field value and their constraint relationship. The entity information is matched with the table names and field names in the structured schema index to obtain candidate table names and candidate field names corresponding to the entity information.

4. The method for generating database queries from natural language as described in claim 1, characterized in that, The step of mapping the candidate table names to table nodes, determining the subgraph structure associated with the candidate table names and candidate field names corresponding to the entity information, and constructing a local structured schema index library corresponding to the entity information based on the subgraph structure includes: In the schema attribute diagram, the candidate table names are mapped to table nodes, and the candidate field names are mapped to field nodes; Based on the membership relationship between field nodes and table nodes, and the association relationship between table nodes, a subgraph structure associated with the candidate table name and candidate field name corresponding to the entity information is extracted from the schema attribute graph. A local structured schema index library corresponding to the entity information is constructed based on the subgraph structure. The association relationship between the table nodes includes foreign key connection relationship and field reference relationship.

5. The method for generating database queries from natural language as described in claim 1, characterized in that, In the subgraph structure, a candidate association path set is constructed based on the association relationships between table nodes recorded in the local structured schema index. Based on the candidate association path set, a target association path for generating a structured query statement is determined according to a preset priority rule, including: In the subgraph structure, based on the association relationships between table nodes recorded in the local structured schema index library, the candidate association path set is generated according to the preset path generation rules, wherein the preset path generation rules are rules that limit the connection direction, connection level and maximum number of connections of table nodes in the association path. The validity of each candidate association path in the candidate association path set is verified, and candidate association paths that do not meet the connection integrity constraints, have circular references, or do not contain the target field are eliminated to obtain the candidate association paths that pass the verification. Among the candidate association paths that have passed the verification, the target association path for generating the structured query statement is determined according to the preset priority rules, wherein the priority rules are rules for sorting the association path by length, number of table nodes or field coverage.

6. The method for generating database queries from natural language as described in claim 1, characterized in that, The step of generating a structured query statement by combining the table name and field name according to the target association path, and performing syntax and logic validation on the structured query statement to obtain an executable structured query statement includes: Based on the correspondence between table names and field names in the target association path, a query template containing table join conditions and field selection conditions is generated; The table name, field name, join condition, and field selection condition in the query template are replaced with the corresponding actual identifiers in the database. The structured query statement is then subjected to syntax and logic validation to form the executable structured query statement. The actual identifier is the real name used in the database to uniquely locate the data object.

7. The method for generating database queries from natural language as described in claim 1, characterized in that, The execution of the executable structured query statement, and the dynamic updating of the local structured schema index based on the query execution result to obtain a target local structured schema index that matches the query request, includes: Execute the executable structured query statement to obtain the corresponding query execution result; The local structured schema index is dynamically updated based on the query execution result to obtain the target local structured schema index that matches the query request.

8. The method for generating database queries from natural language as described in claim 1, characterized in that, In the set of candidate associated paths, when multiple candidate associated paths simultaneously meet the preset conditions, a confirmation operation for the candidate associated paths is triggered.

9. The method for generating database queries from natural language as described in claim 8, characterized in that, The confirmation operation includes displaying the table names and field names corresponding to all candidate association paths to the user, filtering the candidate association paths based on pre-configured selection parameters, and receiving the user's confirmation result to determine the target association path that is uniquely used to generate a structured database query statement.

10. The method for generating database queries from natural language as described in claim 9, characterized in that, The update of the local structured schema index also includes: adjusting the association between the table name and field name in the table nodes of the local structured schema index based on the user's confirmation result.