An intelligent SQL generation system based on multi-level intent recognition and a generation method thereof

The intelligent SQL generation system with multi-level intent recognition solves the problems of field ambiguity and insufficient semantic understanding in complex database queries, realizes efficient and accurate database operations, and improves user experience and system adaptability.

CN120910240BActive Publication Date: 2026-04-10SICHUAN ZHONGLI JIAHUA INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-24
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing technologies suffer from problems such as field ambiguity, insufficient semantic understanding, difficulty in understanding the entire database, and poor interpretability in complex database queries, leading to inaccurate queries and low user trust.

Method used

An intelligent SQL generation system based on multi-level intent recognition is adopted. Through vector matching, multi-layer structured knowledge base, dual-tower model and large language model, combined with user input, it generates SQL statements that conform to the syntax rules, dynamically configures database table and field information, and provides a self-learning optimization mechanism.

Benefits of technology

It improves the accuracy and efficiency of database queries, enabling non-technical personnel to easily perform database operations, ensuring the correctness of generated SQL statements, and continuously improving system performance through self-learning optimization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120910240B_ABST
    Figure CN120910240B_ABST
Patent Text Reader

Abstract

The application discloses a kind of intelligent SQL generation method and system based on multistage intention recognition, comprising: receiving user natural language query;Vector matching step: vector matching is carried out based on knowledge base, obtain Top-K candidate query object, and knowledge base contains multi-layer structure description information;Large language model intention understanding step: determine final query object in combination with candidate query object description;Load branch workflow, parse field and table structure, dynamically configure database table and field information;SQL generation step: generate SQL sentence in accordance with syntax rule, including automatically adding field, time condition conversion, field priority matching operation;Execute SQL sentence and return result, and record log if it fails to prompt correction.The application provides an efficient, accurate and user-friendly database query solution by natural language processing technology combined with database knowledge base.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, natural language processing (NLP) and database query, in particular to an intelligent SQL generation system based on multi-level intent recognition and an implementation method thereof, and is especially suitable for intelligent conversion and execution of database query through natural language in complex business scenarios. BACKGROUND

[0002] In the current big data environment, users are facing the challenge of quickly extracting specific information from complex databases. Traditional methods require users to have SQL writing ability, which is often difficult to accurately match fields and table structures when facing ambiguous or colloquial questions. Although existing intelligent search tools have solved this problem to some extent, they still have some significant defects.

[0003] Firstly, the field ambiguity problem is serious. In multiple tables, we often encounter the same or similar field names, such as "CPU utilization", "memory utilization" and "vCPU utilization". In the resource pool query object and the host group query object, there may be a "CPU utilization" field, which leads to the inaccuracy of SQL generation.

[0004] Secondly, semantic understanding is also a key problem. Existing single large models cannot effectively combine specific business knowledge, which makes them prone to misinterpretation when understanding user intent.

[0005] Thirdly, it is difficult to understand the whole database. Due to the large number of data tables and the large number of fields, the lack of flexible workflow mechanism, existing tools can only process the whole database, and cannot dynamically select the appropriate data processing path.

[0006] Finally, the explainability is poor. The process of generating SQL is not transparent, which reduces the trust of users and requires users to understand the relationship between field names and business names.

[0007] Therefore, in order to improve the accuracy of natural language query, an intelligent SQL generation system that combines knowledge base and multi-stage reasoning with large model capabilities is urgently needed. Such a system can better understand the user's query intent, reduce ambiguity, and provide a more transparent and explainable query process. SUMMARY

[0008] The purpose of the present application is to overcome the shortcomings of the prior art and provide an intelligent SQL generation system based on multi-level intent recognition and a generation method thereof, which enables non-technical personnel to easily perform database operations through natural language query, while improving query efficiency and intent recognition accuracy, and ensuring the correctness of the generated SQL statements.

[0009] The object of the present application is achieved by the following technical solutions:

[0010] An intelligent SQL generation method based on multi-level intent recognition, comprising the following steps:

[0011] Receiving a user natural language query;

[0012] Vector matching step: vector matching based on a knowledge base to obtain Top-K candidate query objects, the knowledge base containing multi-layer structure description information of the query objects, including query object name, field information, typical question sentence, enumeration value and special rule;

[0013] Large language model intent understanding step: using a large language model to determine the final query object in combination with the candidate query object description, the large language model performing intent understanding according to a preset prompt word;

[0014] Loading the branch workflow corresponding to the final query object, parsing the field and table structure, the branch workflow dynamically configuring database table and field information according to query object classification;

[0015] SQL generation step: generating an SQL statement conforming to the syntax rules based on the multi-layer structure knowledge base and rule description, the SQL statement including automatic field addition, time condition conversion, field priority matching operation;

[0016] Executing the SQL statement and returning the result, if the execution fails, recording the error log and prompting the user to correct and recording in the self-learning optimization module as learning optimization materials.

[0017] As a preferred mode, the vector matching step comprises:

[0018] Using a double-tower model to perform semantic vector matching on the user question and the typical question sentence, field alias, field abbreviation, professional term, etc. in the knowledge base;

[0019] The double-tower model comprises two independent encoders, which respectively perform semantic encoding on the user input question and the candidate query object in the knowledge base, and calculate the semantic matching degree through cosine similarity.

[0020] As a preferred mode, the large language model intent understanding step comprises:

[0021] Inputting the original user question and the candidate query object description;

[0022] According to the role (such as "senior business expert") and task chain description set by the prompt word, in combination with the context information, judging the real query intent of the user;

[0023] Output the final determined query object and classification information, or return "Unable to determine" if unable to confirm.

[0024] As a preferred mode, the SQL generation step includes:

[0025] Generating SQL statements that meet business requirements based on the table structure and field information of the query object;

[0026] Automatically adding default fields (such as "statistical date" and "resource pool name");

[0027] Converting time conditions (such as "last week" and "this week") into specific date ranges;

[0028] Matching and returning relevant fields based on field priority (such as "CPU utilization" while returning average and peak values);

[0029] Ensuring that the generated SQL statements meet the target database syntax specifications (such as PostgreSQL).

[0030] As a preferred mode, it also includes a SQL syntax verification step:

[0031] Building a SQL syntax tree to verify the existence of fields and the correctness of the syntax;

[0032] Automatically fixing issues such as keyword case, special character escaping, etc.

[0033] If a syntax error is detected, it will be intercepted and the user will be prompted to correct it.

[0034] As a preferred mode, it also includes a self-learning optimization step: based on user feedback and execution results, optimize the model and rule library to form a self-learning closed loop; the self-learning optimization step includes:

[0035] Collecting user feedback and execution results;

[0036] Optimizing large language model parameters through reinforcement learning mechanism;

[0037] Error logs automatically trigger the update process of knowledge base field aliases.

[0038] As a preferred mode, the knowledge base includes:

[0039] The name, classification information, and field list of the query object (including Chinese meaning, unit, alias, and abbreviation, etc.);

[0040] Typical question sentences (for training and matching);

[0041] Enumerated value explanations (such as resource pool name enumeration);

[0042] Special rules (such as time granularity judgment, default fields, sorting, etc.).

[0043] As a preferred mode, the dynamic branch workflow comprises:

[0044] Load the branch process corresponding to the query object classification;

[0045] Configure the table and field information of the query object to ensure consistency with the database structure;

[0046] Support multiple query object branches. When a new query object is added, only the new process configuration needs to be added to take effect. A smart SQL generation system based on multi-level intent recognition, see Figure 1 , comprising:

[0047] A user interaction module for receiving natural language input from a user and returning generated SQL statements and query results; The user interaction module receives natural language input from the user (such as "memory usage rate of trusted 3 resource pool in the last week"). Return the generated SQL statement and the query result (SQL statement code / table / chart form). Including result display module, the result display module displays the generated SQL statement code and the formatted result, or the chart (SQL statement code / table / chart) required by the user.

[0048] A knowledge base module for storing multi-level structure description information of query objects, including query object name, field information, typical question sentence, enumeration value and special rule, professional term, etc.

[0049] The knowledge base module stores multi-level structure knowledge base information:

[0050] Query objects (such as "resource pool performance data", "switch performance data", and "host performance data").

[0051] Field list (including Chinese meaning, unit, alias, abbreviation, etc., such as "port utilization rate this week peak value (TOR) (%)", two-layer network receiving average rate (Mbps), two-layer network sending average rate (Mbps), number of computing servers, number of storage servers, number of data and security devices, average CPU utilization rate (%), CPU average utilization rate (%), average CPU utilization rate peak value (%), CPU average utilization rate peak value (%), memory utilization rate peak value (%), average memory utilization rate (%), memory average utilization rate (%), TOR, EOR, switch performance routing, etc.).

[0052] Typical question sentences (for training and matching, such as: EOR matching router, port utilization rate of matching route, number of used ports, etc.).

[0053] Enumerated value description (e.g. resource pool name enumeration: DMZ, Trusted 1, Trusted 2... Trusted 13; 01A, 02A... 13A, etc. Special enumeration description).

[0054] Special rules (e.g. time granularity judgment, default field, sorting, etc.).

[0055] Vector matching module, for vector matching based on knowledge base, obtaining Top-K candidate query objects;

[0056] The vector matching module uses a double tower model (e.g. Sentence-BERT) to perform semantic vector matching on user questions and question statements in the knowledge base.

[0057] Return Top-K possible query object candidates.

[0058] The double tower model training data contains manually annotated sample pairs, the vector dimension is 1024 dimensions, and the Top-K value dynamic adjustment strategy is based on user roles (e.g. administrator K=5, ordinary user K=3).

[0059] The double tower model includes two independent encoders for semantic encoding of user input questions and candidate query objects in the knowledge base, and calculates semantic matching degree through cosine similarity method.

[0060] Intention understanding module, for determining the final query object by using a large language model combined with candidate object description;

[0061] Input: original question and candidate object description.

[0062] Output: final confirmed query object and classification information.

[0063] This module is completed by a large model, and the prompt words are as follows:

[0064] You are a senior business expert, your task is to understand the user's query intent, read the information in the following XML tags

[0065] <context>< / context> , and infer the most likely query object and classification information from it, giving priority to the query object classification at the top.

[0066] If the user input contains specific fields or objects, it should be combined with <context>The fields in the description of the semantics of the match.

[0067] Only output query objects and categories, no explanation.

[0068] Cannot find any query objects or categories, please return "Unable to determine".

[0069] <context>

[0070] A plurality of possible candidate query object descriptions, input from the preceding vector matching module results.

[0071] < / context>

[0072] <example>

[0073] Output:

[0074] Query object: Resource pool

[0075] Category: Resource pool performance data

[0076] < / example>

[0077] The resource pool name is an enumeration type, with values including (DMZ, trusted 1, trusted 2, trusted 3, trusted 4, trusted 5, trusted 6, trusted 7, network management 8, DMZ 9, network management 10, trusted 11, trusted 12, provincial 13).

[0078] Prompt word engineering includes role setting (such as "You are a senior business expert") and thought chain task description.

[0079] Workflow routing module, used to load the branch workflow corresponding to the query object, parse the field and table structure;

[0080] According to the query object confirmed by the intention understanding module, load the corresponding processing flow branch (such as resource pool performance data, firewall performance data, switch performance data, storage pool performance data, host performance data, etc. 14 kinds of data branch processing flow).

[0081] Configure the field and table structure (such as the day / week statistics table, accurately configure the table and field name of the corresponding query object for different data processing branches, consistent with the database, used to provide accurate table and field reference for the next step of generating SQL statement by the large model).

[0082] SQL generation module, used to generate SQL statements that meet the syntax rules based on multi-layer structure knowledge base and rule description;

[0083] Based on the large model and context reference data and rule description, generate SQL statements that meet the business requirements:

[0084] Through the output results of the previous workflow configuration, accurately obtain the table and field information needed for this natural language query; let the large model understand the user's problem, refer to the context data, and generate SQL statements that meet the business requirements in combination with some special descriptions.

[0085] Automatically add fields (such as "statistical date" "resource pool name").

[0086] Time condition conversion (such as "last week" "this week" "this week" mapped to a specific date range).

[0087] Field priority matching (e.g., "CPU utilization" returns average and peak values).

[0088] Database type determination (e.g., requires generated SQL statements to conform to PostgreSQL syntax).

[0089] User does not set the number of restrictions, and by default adds LIMIT 20.

[0090] After the SQL statement is generated, a SQL syntax tree verification module is added to detect the legality of the generated SQL and the validity of field references, and to handle special characters.

[0091] A database execution module is used to execute the SQL statement and return the result, and if the execution fails, an error log is recorded and the user is prompted to correct it.

[0092] The SQL statement generated by the SQL generation module is passed to this module, which calls the database to execute the generated SQL and returns the result. If an error occurs, the user is prompted to correct it and an error log is recorded.

[0093] As a preferred mode, the vector matching module comprises:

[0094] A double tower model is used to perform semantic vector matching on user questions and typical question statements in the knowledge base.

[0095] A dynamic adjustment unit is used to dynamically adjust the Top-K value according to the user's role.

[0096] The present application has at least the following beneficial effects: by receiving the user's natural language query, it can be closer to the user's daily communication method, reduce the user's professional knowledge requirement of SQL language, so that non-technical personnel can easily perform database query operation.

[0097] By using the vector matching step, combined with the multi-layer structure description information in the knowledge base, the most matched candidate query object with the user's query intention can be quickly screened out. Not only improves the query efficiency, but also enhances the understanding depth of the user's query intention through the rich information of the knowledge base.

[0098] Through the large language model intention understanding step, the system can use advanced natural language processing technology combined with context information to further accurately determine the user's final query intention. This step significantly improves the accuracy and intelligence of intention recognition.

[0099] Load branch workflow and parse field and table structure, so that the system can dynamically configure database table and field information according to the classification of the query object, which not only improves the flexibility of SQL generation, but also ensures that the generated SQL statement can accurately reflect the user's query requirements.

[0100] In the SQL generation step, based on the multi-layer structure knowledge base and rule description, the system can generate SQL statements that conform to the syntax rules. This includes automatically adding necessary fields, converting time conditions, and performing field priority matching operations, ensuring the correctness and efficiency of the SQL statements.

[0101] Finally, the SQL statement is executed and the results are returned. If the execution fails, an error log is recorded and the user is prompted to make corrections. This feedback mechanism not only helps users understand the reasons for query failure in a timely manner, but also provides data support for continuous optimization of the system.

[0102] In summary, the intelligent SQL generation method and system provide an efficient, accurate and user-friendly database query solution by combining natural language processing technology and database knowledge base. BRIEF DESCRIPTION OF DRAWINGS

[0103] In order to further illustrate the technical features of the embodiments of the present application, the drawings involved in the embodiments will be briefly introduced below. It should be particularly pointed out that these drawings only show some embodiments of the present application and should not be regarded as limiting the scope of protection of the present application. For those skilled in the art, other related drawings can be derived from these drawings without creative efforts.

[0104] Figure 1 is a system overall architecture diagram;

[0105] Figure 2 is a knowledge base structure diagram;

[0106] Figure 3 is a vector matching and semantic retrieval flowchart;

[0107] Figure 4 is a branch workflow scheduling flowchart;

[0108] Figure 5 is a SQL generation and execution flowchart. DETAILED DESCRIPTION

[0109] In the following, the technical solutions of the present application will be described in more detail in conjunction with the drawings, but it should be noted that the scope of protection of the present application is not limited to the following descriptions.

[0110] The terms used in the present disclosure are intended to illustrate specific embodiments and are not limiting to the disclosure. In this context, the use of singular forms also includes plural forms unless otherwise explicitly stated. In the description, the words "comprise" or "have" are intended to mean that there are certain features, quantities, steps, operations, structural components, parts or combinations thereof, and do not exclude the possibility of existence of other one or more features, quantities, steps, operations, structural components, parts or combinations thereof or addition.

[0111] It is to be expressly understood that, however, the descriptions and illustrations herein are provided merely as examples of the example embodiments and should not be construed as limiting upon the scope of the example embodiments. For example, the systems can be shown in block diagram form to avoid obscuring the examples. In other instances, well-known processes, structures, and techniques have been omitted so as not to obscure the examples in unnecessary detail.

[0112] An intelligent SQL generation method based on multi-level intent recognition, comprising the following steps:

[0113] Receiving a user natural language query, which contains time range, enumeration value, and index name, etc. Key information;

[0114] The system receives the user's natural language input through the user interaction module, such as: "Memory usage of Trusted 3 resource pool last week". The input can contain time range (such as "last week"), enumeration value (such as "Trusted 3 resource pool"), index name (such as "memory usage") and other key information. These information will be gradually parsed and mapped to the fields and conditions in the database in the subsequent processing.

[0115] Vector matching step: vector matching based on knowledge base, obtaining Top-K candidate query objects, the knowledge base contains multi-layer structure description information of query objects, including query object name, field information, typical question sentence, enumeration value and special rules, etc.

[0116] Large language model intent understanding step: using large language model combined with candidate query object description to determine the final query object, the large language model performs intent understanding according to the preset prompt word;

[0117] Load the branch workflow corresponding to the final query object, parse the field and table structure, the branch workflow dynamically configures the database table and field information according to the query object classification;

[0118] SQL generation step: based on multi-layer structure knowledge base and rule description, generate SQL statement conforming to syntax rules, the SQL statement includes automatic adding field, time condition conversion, field priority matching and other operations;

[0119] Execute the SQL statement and return the result, if the execution fails, record the error log and prompt the user to correct and record in the self-learning optimization module as learning optimization materials.

[0120] The core of the intelligent SQL generation method based on multi-level intent recognition proposed in this embodiment is to automatically convert the natural language query input by the user into a structured SQL statement through the combination of various technical means such as knowledge base, vector matching, large model understanding, dynamic workflow routing, and rule-driven generation, and to perform the corresponding database query operation. The entire processing flow can be divided into seven closely connected main stages: first, the system receives the natural language query input by the user; then, through the vector matching and candidate object screening mechanism, the possible involved database objects are preliminarily located; on this basis, the semantic understanding ability of the large model is combined to further complete the intent understanding and object confirmation; next, according to the confirmed information, the system performs workflow routing and table field configuration to clarify the subsequent processing path; then, it enters the SQL generation and optimization stage to generate efficient and accurate SQL statements; next, the system automatically executes the generated SQL statements and obtains the query results, which are returned to the user; finally, the system also has the self-learning and updating ability, which can continuously optimize its recognition and generation performance according to the historical interaction data, thereby continuously improving the overall effect.

[0121] In a preferred embodiment, the vector matching step comprises:

[0122] The semantic vector matching of the user question and the typical question statement in the knowledge base is performed using a double tower model (such as Sentence-BERT);

[0123] The double tower model includes two independent encoders that perform semantic encoding on the user input question and the candidate query object in the knowledge base, respectively, and calculates the semantic matching degree through cosine similarity;

[0124] The Top-K value is dynamically adjusted according to the user role, for example, K=5 for administrators and K=3 for ordinary users.

[0125] The system uses a double tower model to perform semantic vector matching of the user input question and the pre-stored typical question statement in the knowledge base. The user question is encoded into a high-dimensional semantic vector (1024 dimensions); the description, field alias, and common questions of each query object in the knowledge base are also pre-encoded into a semantic vector; by calculating the cosine similarity, the Top-K most matched candidate query objects are found.

[0126] Suppose the user input is: "Memory usage of the trusted 3 resource pool last week", after vector matching, the following Top-3 candidate objects are returned: 1. Resource pool performance data; 2. Host performance data; 3. Storage pool performance data. The role of this stage is to narrow the search space and avoid ambiguity problems caused by full database field matching.

[0127] To further improve the accuracy of the vector matching step, in one embodiment, especially when dealing with professional terms and ambiguous fields, a hybrid weighted semantic matching model is introduced. This model significantly improves the accuracy and robustness of matching by integrating semantic similarity and field relevance. The specific technical details are as follows:

[0128] Based on the original double-tower model, the invention proposes a hybrid weighted matching algorithm that combines semantic similarity (S f ) and field relevance (R f ). The final matching degree of field f in the knowledge base and user question q is calculated as follows:

[0129] Match(f, q) = alpha * S f (q) + beta * R f (q)

[0130] Where S f (q) represents the semantic vector cosine similarity between user question q and field f, ranging from -1 to 1. R f (q) represents the relevance of field f in the knowledge base to the problem keywords, ranging from 0 to 1. alpha and beta are weight coefficients, satisfying alpha + beta = 1, and are dynamically adjusted through reinforcement learning.

[0131] Field relevance calculation: To more accurately measure the relevance between fields and user problem keywords, a field co-occurrence network is constructed based on historical query logs. The field co-occurrence network is a statistical model based on historical query logs, used to measure the relevance between fields and keywords. Its main function is to analyze the frequency and co-occurrence relationship of fields in historical queries to enhance the accuracy of semantic matching. The field co-occurrence network provides co-occurrence frequency data between fields and keywords, which is the basis for calculating field relevance. Field relevance is calculated based on data in the field co-occurrence network, used to measure the relevance between fields and user query keywords. Historical query logs contain user query text and corresponding field selection. Field co-occurrence network construction: Tokenize each query in the historical query log to extract keywords. Count the number of co-occurrences of each field and each keyword in historical queries. Calculate the co-occurrence frequency of fields and keywords, and normalize it to the [0, 1] interval.

[0132] The calculation formula of field relevance R f (q) is as follows:

[0133]

[0134] Where K q This is the set of keywords for the user's question q. CoOccur(f, k) is the co-occurrence frequency of field f and keyword k in historical queries, normalized to [0, 1]. |K q | is the cardinality of the keyword set.

[0135] Suppose a user queries "memory usage", and the keyword set is K. q ={Memory, Memory Usage}. Assume that in the historical query logs: the co-occurrence frequency of the fields "Memory Usage" and "Memory" is 0.8, and the co-occurrence frequency of "Memory Usage" and "Memory Utilization" is 0.2. The co-occurrence frequency of the fields "Memory Usage" and "Memory" is 0.7, and the co-occurrence frequency of "Memory Usage" and "Memory Utilization" is 0.9. Then the field correlation is calculated as follows:

[0136]

[0137] To dynamically adjust the weight coefficients α and β, this invention employs a reinforcement learning method, using the SQL execution success rate as the reward signal r. The weight update formula is:

[0138] Δα=η×r×(S f -R f )

[0139] Δβ=-Δα

[0140] Where η is the learning rate, with a default value of 0.01. r is the reward value, r = 1 when the SQL executes successfully, and r = -1 when it fails.

[0141] By introducing a hybrid weighted semantic matching model, this invention demonstrates a significant performance improvement in handling specialized terminology matching. For example, when a user queries "memory usage":

[0142] Semantic similarity S f "Memory usage" = 0.8, "Memory occupancy" = 0.75. These values ​​were calculated using a dual-tower model, specifically based on the cosine similarity between the semantic vectors of the user's input question and the field descriptions in the knowledge base.

[0143] Field correlation R f Field correlation is calculated based on a field co-occurrence network. Assume that in the historical query log, the co-occurrence frequency of the field "memory usage" and the keyword "occupancy rate" is 0.2. This is obtained by counting the number of times the field "memory usage" and the keyword "occupancy rate" appear simultaneously in historical queries and normalizing it to the [0,1] interval. The co-occurrence frequency of the field "memory usage" and the keyword "occupancy rate" is 0.9. This indicates that "memory usage" and "occupancy rate" frequently co-occur in historical queries, therefore their correlation is high.

[0144] Final matching result (assuming α = 0.4, β = 0.6):

[0145] Memory usage: 0.4 x 0.8 + 0.6 x 0.2 = 0.44

[0146] Memory usage: 0.4 x 0.75 + 0.6 x 0.9 = 0.84

[0147] Through this mixed weighting method, professional terms can be more accurately identified and matched, thereby improving the accuracy of the query and user experience.

[0148] Self-learning closed loop: When SQL execution fails, the reward value r = -1 triggers Δα reverse adjustment, reducing the weight of error matching. The weight update rule is: α new = α old + Δα, β new = 1 - α new .

[0149] Through the above optimization, not only the identification accuracy of professional terms and ambiguous fields is improved, but also the weight coefficient is dynamically adjusted through reinforcement learning, further enhancing the adaptability and robustness of the system. This improvement significantly improves the performance of the original vector matching step, providing more accurate candidate query objects for the subsequent large language model intent understanding step, thereby improving the query accuracy and user experience of the entire system.

[0150] In a preferred embodiment, the large language model intent understanding step includes:

[0151] Inputting the original user question and candidate query object description;

[0152] Determining the user's real query intent according to the role set by the prompt word (such as "senior business expert") and the task chain description, combined with context information;

[0153] Outputting the final determined query object and classification information, and returning "unable to determine" if it cannot be confirmed.

[0154] On the basis of the candidate object, the large language model (LLM) further performs intent understanding and object confirmation. The input includes the original user question and candidate object description; the LLM determines the user's real query intent according to the role set by the prompt word (such as "senior business expert"), combined with context information; the output is the final determined query object and classification information. For example, the output query object is: resource pool; classification: resource pool performance data. If the LLM cannot confirm, it returns "unable to determine", which is intervened by human or prompts the user to supplement information.

[0155] In a preferred embodiment, the dynamic branching workflow includes:

[0156] Load the branch process corresponding to the query object category;

[0157] Configure the table and field information of the query object to ensure consistency with the database structure;

[0158] Support multiple query object branches. When adding a new query object, simply add a new process configuration to take effect.

[0159] According to the query object confirmed in the previous step (such as "resource pool performance data"), load the corresponding branch processing process, which includes: database table structure (such as weekly statistical table, daily statistical table); field list (such as "average memory utilization (%)", "resource pool name", "statistical date"); special rules (such as default sorting field, time granularity priority). This stage ensures that the fields and table structures used in the subsequent SQL generation process are accurate and error-free, avoiding large model "hallucinations".

[0160] In a preferred embodiment, the SQL generation step includes:

[0161] Generate SQL statements that meet business requirements according to the table structure and field information of the query object;

[0162] Automatically add default fields (such as "statistical date" "resource pool name");

[0163] Convert time conditions (such as "last week" "this week") into specific date ranges;

[0164] Match and return relevant fields according to field priority (such as "CPU utilization" returns both average and peak values);

[0165] Ensure that the generated SQL statements meet the target database syntax specifications (such as PostgreSQL).

[0166] Further, it also includes a SQL syntax verification step:

[0167] Build a SQL syntax tree to verify whether the fields exist and the syntax is correct;

[0168] Automatically fix issues such as keyword case, special character escaping, etc.

[0169] If a syntax error is detected, it will be intercepted and the user will be prompted to correct it.

[0170] On the basis of explicit table structure and field information, the SQL statement is generated by the large model. The key points of this stage include: field matching: such as "memory usage" corresponding to "average memory utilization (%)"; time condition conversion: such as "last week" converted to specific start and end dates (such as 2025 June 5 to 2025 June 11); enumeration value conversion: such as "trusted 3" converted to the actual resource pool name "trusted 3"; default field addition: such as automatically adding "statistical date", "resource pool name"; SQL syntax checking: through AST to build syntax tree, detect and correct SQL syntax errors.

[0171] Special rule application: wrap fields containing special characters with double quotes; default descending order by "statistical date"; if the number of restrictions is not specified, default "LIMIT20" (default 20) is added; select weekly / daily statistical table according to query type; field priority processing (such as returning "average CPU utilization" and "peak value" at the same time).

[0172] Example SQL generation result:

[0173] SELECT"statistical date", "resource pool name", "average memory utilization (%)"

[0174] FROM"resource pool performance data_weekly statistics"

[0175] WHERE"statistical date"BETWEEN'2025-06-05'AND'2025-06-11'

[0176] AND"resource pool name"='trusted 3'

[0177] ORDERBY"statistical date"DESC

[0178] LIMIT20;

[0179] The generated SQL statement is transmitted to the database execution module, and the database interface is called to execute the query, and the success: returns the formatted result (table / chart); failure: record error log, prompt user to correct, and trigger self-learning mechanism. The SQL syntax checking module intercepts syntax errors in advance to improve the success rate of execution.

[0180] In a preferred embodiment, it also includes a self-learning optimization step: based on user feedback and execution results, optimize the model and rule library, form a self-learning closed loop; the self-learning optimization step includes:

[0181] Collecting user feedback and execution results;

[0182] Optimizing large language model parameters through reinforcement learning mechanism;

[0183] Error log automatically triggers the update process of the field alias of the knowledge base.

[0184] In a preferred embodiment, the self-learning optimization further comprises:

[0185] When adding a query object, automatically annotate typical question sentences, and support dynamic expansion.

[0186] Field alias management uses a synonym network relationship graph, supporting cross-field alias association.

[0187] In a preferred embodiment, the knowledge base comprises:

[0188] Two-layer structure of the knowledge base segment:

[0189] The first layer stores the complete information of the query object description, including the name of the query object, enumeration value description, special rules, field list, etc.

[0190] The second layer is hung under the first layer storage, and the scattered information related to the query object is included, including detailed field names, field aliases, field abbreviations, typical question sentences, professional terms, and colloquial names in the field list.

[0191] When vector matching, the second layer of scattered information is matched with the user's question, and the first layer of query object complete information is brought out through the second layer of scattered information.

[0192] In a preferred embodiment, the SQL generation step further comprises:

[0193] Automatically add LIMIT limit (such as the user does not set the number of limits, and default to add LIMIT 20);

[0194] According to the query type, select the weekly / daily statistical table;

[0195] By default, arrange the "statistical date" in descending order.

[0196] By default, output the "resource pool name" field.

[0197] In an embodiment, the following process is performed:

[0198] 1. Receive user input and get natural language query (such as "Memory usage rate of trusted 3 resource pool last week").

[0199] 2. Vector matching and candidate query object filtering. Encode the user's question into a semantic vector, and calculate the similarity with the query object field and the question sentence vector in the knowledge base, and return the Top-K candidate query objects. The similarity calculation adopts the cosine similarity calculation method, and the formula is as follows:

[0200] Given two n-dimensional vectors:

[0201]

[0202] The cosine similarity between them is defined as:

[0203]

[0204] where, is the first n-dimensional vector (such as embedding vector), is the second n-dimensional vector, a i is the value of the i-th dimension of the vector , b i is the value of the i-th dimension of the vector , a i b i is the product of the i-th dimension of the vectors and is the dot product of the vectors and , a is the length of the vector (L2 norm), is the length of the vector (L2 norm). The output range is: [-1, 1], 1: the two vector directions are exactly the same (most similar), 0: the two vectors are orthogonal (irrelevant), -1: the two vector directions are completely opposite (least similar). In practical applications, the vector matching module uses a vector model (a special model that converts information into numerical form for expression, used in natural language processing. Simply put, it converts text data into a string of numbers (called "vectors"), which can reflect the similarity or relationship between data) such as the bge-m3 model to vectorize the user's question and the segmented knowledge in the knowledge base, and get the vector and the vector perform similarity calculation in turn, the closer the value is to 1, the more similar it is, and get the top few query candidate query object related information.

[0205] 3. Intent understanding and object confirmation

[0206] Input: original question and candidate object description, which is obtained from the previous step.

[0207] Output: re-understand the intent through the large model, and finally confirm the query object (such as "resource pool performance data").

[0208] 4. Workflow routing and table field configuration

[0209] The large model understands the user's intent and routes the correct branch process combined with the finally confirmed query object. ​

[0210] The specific branch flow handles the fixed query object related business, configures the table and field information of the query object, and obtains all the accurate database field information required by the query object.

[0211] 5. SQL generation and optimization

[0212] Large model understands business: the large model understands user problems, references context data, and generates SQL statements that meet business requirements in combination with some special instructions.

[0213] Time condition conversion: dynamically calculate specific date ranges based on the current date.

[0214] Example: "Last week" is converted to specific start and end dates (e.g., June 2, 2025 to June 8, 2025).

[0215] Field priority matching: if the user queries "CPU utilization", both the average value and the peak value are returned; by default, add a data return limit of 20.

[0216] Special instructions: the field "resource pool name" is an enumeration type, and possible values include: DMZ, trusted 1, trusted 2, trusted 3, trusted 4, trusted 5, trusted 6, trusted 7, network management 8, DMZ 9, network management 10, trusted 11, trusted 12, and provincial 13.

[0217] The user did not set the number limit, and by default, LIMIT 20 is added.

[0218] Other more detailed prompt word instructions provide precise instructions to assist the large model in generating SQL statements.

[0219] 6. Execution and feedback

[0220] Call the query interface to execute SQL and return the results.

[0221] If there is an error, prompt the user to correct it and record the error log.

[0222] Add a SQL syntax checking step, build a database syntax parser based on AST, intercept syntax errors and prompt for correction suggestions.

[0223] 7. Self-learning update

[0224] Collect user feedback and execution results to optimize the model and rule library.

[0225] The key technical points are as follows:

[0226] 1. Knowledge base construction (see Figure 2 )

[0227] Two-layer classification structure of query object and field:

[0228] The name of the query object, classification information, and complete field information are taken as the first layer data.

[0229] Each field name, field name alias, abbreviation, professional term, colloquial name, conventional special name, and some predictable common problems and special problems of the query object are taken as the second layer data.

[0230] The vector precise matching association brings out the complete query object:

[0231] The double tower model (such as Sentence-BERT) is used for semantic vector matching of the user question and the second layer data in the knowledge base, and the first layer complete query object and field data are brought out. The matching range is narrowed to improve the precision while not losing complete information.

[0232] Meanwhile, the second layer data can be infinitely expanded, and new special problems can be directly added for subsequent matching expansion learning.

[0233] Referring to Figure 2 , the construction form of the knowledge base is shown, which adopts a double-layer design and is divided into a first layer: query object classification and a second layer: field and question mapping. The first layer includes query object names, field lists, enumerated value explanations, and special rules, providing complete business definitions and field structures for each query object; the second layer realizes the bidirectional mapping relationship between natural language and database fields through field names, field aliases, field abbreviations, and typical question sentences. The two layers are associated through shared fields to ensure that the user input can be accurately matched to the corresponding complete query object information. This design brings out the complete information of the query object through the field and question mapping of the second layer after matching the user question.

[0234] Vector retrieval parameter configuration:

[0235] According to the test results, the Top-K parameter is flexibly adjusted to adapt to the appropriate threshold value for filtering the text fragments with the highest similarity to the user question, realizing query object candidate filtering.

[0236] Dynamic update mechanism:

[0237] When a new query object is added, typical question sentences are automatically labeled (based on business terminology library generation + template filling); field alias management adopts a synonym network relationship graph, supporting cross-field alias association (such as bidirectional mapping of "memory usage rate" and "memory occupancy rate").

[0238] 2. Workflow routing and table field configuration

[0239] Query object classification routing configuration:

[0240] Through the screened query object and classification, the large model understands the user's intent again and infers the appropriate branch routing.

[0241] The specific branch routing processes the business data of the specific query object, configures the corresponding table and field information, and is consistent with the table structure in the database, ensuring the consistency and accuracy of the subsequent generated SQL statements, and avoiding the illusion of the large model.

[0242] 3. SQL generation and optimization

[0243] Large model understanding business to generate SQL statement:

[0244] The large model understands the user's intent again, references the context data, and generates SQL statements that meet the business requirements in combination with some special instructions; At this time, the context has been obtained after multiple levels of intent understanding in the previous context, and the context content has been highly matched with business, database information and field instructions. Therefore, the large model can accurately generate SQL statements that meet the business requirements.

[0245] The syntax checking module ensures that the generated SQL conforms to the syntax specifications of the target database through AST analysis, and automatically corrects known problems such as keyword case and special characters.

[0246] Special rule explanation prompt words:

[0247] 1. If the field or table name contains special characters (such as %, (), space, etc.), wrap the field in double quotes " and do not use backticks ` or other escape symbols.

[0248] 2. Only output one executable SQL statement, do not add additional instructions or descriptive text.

[0249] 3. If the user query does not specify detailed index fields, query all fields in the table by default, and the field name is strictly extracted according to the content of "Database table and field information" in the xml tag.

[0250] 4. If the user does not require sorting, the default is to sort the "statistical date" field in descending order.

[0251] 5. The "statistical date" condition needs to be calculated to a specific statistical date based on the "current date", and dynamic constants or variables (such as CURRENT_DATE or INTERVAL) should not be used in SQL. For example:

[0252] If the "current date" is January 15, 2025 (Wednesday), it is less than Thursday, so it belongs to this week, and "last week" is from January 2, 2025 (Thursday) to January 8, 2025 (Wednesday).

[0253] If "current date" is January 16, 2025 (Thursday) and equals Thursday, "last week" is January 9, 2025 (Thursday) to January 15, 2025 (Wednesday).

[0254] 6. If the user does not specify the year, the query condition is generated according to the current year by default.

[0255] 7. If the user does not set the number limit, LIMIT 20 is added by default.

[0256] 8. A space needs to be added before the SQL keywords such as WHERE, LIMIT, FROM, AND, etc.

[0257] 9. The query semantics need to be understood according to the user's needs, and the SQL statement is generated by selecting the fields that meet the needs. Note that the fields are separated by commas, for example: "Port utilization rate this week peak (TOR) (%)" is a field; as many relevant fields as possible are returned, for example: the user searches for "CPU utilization rate" or "memory utilization rate", and needs to return "average CPU utilization rate" and "average CPU utilization rate peak value" at the same time. Note to check.

[0258] 10. If the keywords such as "this week", "last week", "the xth week" appear in the user's question, the table for weekly statistics needs to be used first.

[0259] 11. The default output fields are all with statistical dates, resource pool names or resource pool names. Note that the field names need to be matched and must be existing fields. The date column and the name related column are displayed in the front by default.

[0260] 12. The field "resource pool name" is an enumeration type, and the possible values include: DMZ, trusted 1, trusted 2, trusted 3, trusted 4, trusted 5, trusted 6, trusted 7, network management 8, DMZ 9, network management 10, trusted 11, trusted 12, and provincial 13.

[0261] 13. The resource pool has an alias: DMZ (00A), trusted 1 (01A), trusted 2 (02A), trusted 3 (03A), trusted 4 (04A), trusted 5 (05A), trusted 6 (06A), trusted 7 (07A), network management 8 (08A), DMZ 9 (09A), network management 10 (10A), trusted 11 (11A), trusted 12 (12A), and provincial 13 (13A). If the user mentions the alias, please convert the alias to the real resource pool name in the SQL statement.

[0262] The system has six innovations: first, a multi-level intent recognition mechanism is adopted to improve recognition accuracy through the process of "user question, vector matching candidate object, LLM precise positioning target object"; second, a dynamic branch workflow is introduced to automatically trigger the corresponding data processing process according to different query objects, and configure its table and field information, so as to obtain accurate database field data and improve accuracy; third, SQL generation and query object deep matching are realized, based on understanding of user intent, combined with data context of business table fields, to improve the accuracy of SQL statement field syntax; fourth, a rule mixing generation method is adopted, combined with the context data of the query object and special rules, to generate SQL statements that meet business needs by large models, enhancing the understanding and expression ability of business logic; fifth, an exception detection and feedback mechanism is established to record and feedback SQL execution errors, forming a continuous optimization closed loop; sixth, a synonym network relationship graph is constructed to support bidirectional mapping of field aliases, strengthening the semantic association matching ability across fields and businesses.

[0263] An intelligent SQL generation system based on multi-level intent recognition, referring to Figure 1 , comprising:

[0264] A user interaction module for receiving natural language input from users and returning generated SQL statements and query results;

[0265] A knowledge base module for storing multi-layer structure description information of query objects, including query object name, field information, typical question statement, enumeration value and special rules, etc.

[0266] A vector matching module for vector matching based on the knowledge base to obtain Top-K candidate query objects;

[0267] An intent understanding module, referring to Figure 4 , for determining the final query object using a large language model (such as qwen3-32b model) combined with candidate query object description;

[0268] A workflow routing module, referring to Figure 4 , for loading the branch workflow corresponding to the query object (according to the query object output by the intent understanding module, dynamically loading the corresponding branch workflow), parsing the field and table structure; loading the branch process includes determining the target branch (resource pool performance data, firewall performance data, storage pool performance data, and host performance data, etc.), parsing the field / table structure according to the loaded branch process, including field list, table structure and special rules, etc., after obtaining complete business description, database table structure and field information, and related business context, triggering the SQL generation module, and calling the large language model Qwen3-32B to generate the corresponding SQL statement.

[0269] SQL generation module, for generating SQL statements that meet syntax rules and business requirements based on multi-layer structure knowledge base and rule description; the SQL generation module first performs field matching, time condition conversion, field priority matching, default field addition, etc., and then generates SQL statements according to rule-driven, and the entire process will be submitted to the large language model Qwen3-32B in the form of prompt words to complete. In addition, the SQL statement will also be subjected to SQL syntax checking, and after verification of legality, it will be submitted to the database execution module for execution, and after successful execution, the data will be returned and displayed by the result display module. When the verification is not legal and the execution is not successful, error logs are recorded to form a material set for the self-learning optimization module, which is then fed back to the SQL generation module for feedback and update, further improving the accuracy of SQL generation. If the syntax is legal, the database execution module (see Figure 5 ) is performed.

[0270] Database execution module, for executing the SQL statement and returning the result, and recording error logs and prompting the user to correct if the execution fails; that is, if the execution is successful, the result display module is entered to display the result. If the execution fails, error logs are recorded and the user is prompted to correct.

[0271] Self-learning optimization module (see Figure 5 ), the core logic is to build a closed-loop feedback mechanism, continuously monitor the legality of SQL generation results and execution effects, collect illegal SQL and execution failure cases, and form structured error logs. These logs, together with the original input description, error type, execution result, etc., are built into a material set for model optimization. Subsequently, the material set is fed back to the SQL generation module to guide the iterative training of the large language model Qwen3-32B and adjust the generation strategy, so as to continuously correct common errors and improve the generation accuracy. The entire process realizes a complete closed loop from error identification, data sedimentation, model optimization to effect improvement, ensuring the adaptive and continuous evolution ability of the system in complex business scenarios.

[0272] In a preferred embodiment, the vector matching module comprises:

[0273] Double tower model, for performing semantic vector matching on user questions and typical question statements in the knowledge base;

[0274] Dynamic adjustment unit, for dynamically adjusting the Top-K value according to the user role.

[0275] As Figure 3 As shown, the input question is preprocessed, and the preprocessing module is responsible for cleaning and standardizing the user input, mainly including removing noise (extraneous punctuation, html tags, meaningless words, etc.), text segmentation, stop word filtering, case unification, etc. The purpose is to convert the original input into a structured and standardized form, improve the accuracy of the subsequent double tower model in semantic matching and similarity calculation, and ensure consistency with the standard statements in the knowledge base, providing high-quality input basis for Top-K screening and SQL generation. The knowledge base statement loading is divided into knowledge base typical question statement and field alias / professional term, query object description, etc. to obtain the knowledge base segmentation. After double tower model coding, the vector of the user question generated and the vector of the knowledge base segment generated are obtained, and then similarity calculation is performed, and cosine similarity calculation method is adopted to realize, and Top-K candidate is obtained, and Top-K is screened. According to the dynamic K value adjustment, the candidate query object is output.

[0276] In a preferred embodiment, the intent understanding module comprises:

[0277] The prompt word setting unit is used to set the role and task chain description of the large language model; and the reference candidate query object and the user question.

[0278] The output control unit is used to ensure that the finally determined query object and classification information are output.

[0279] In a preferred embodiment, the SQL generation module further comprises:

[0280] The syntax checking unit is used to construct an SQL syntax tree, and verify whether the field exists and the syntax is correct.

[0281] The automatic repair unit is used to automatically repair problems such as keyword case and special character escape.

[0282] In a preferred embodiment, the self-learning optimization module further comprises:

[0283] The new configuration unit is used to automatically annotate the typical question statement when adding a query object.

[0284] The field alias management unit is used to adopt a synonym network relationship graph, and support cross-field alias association.

[0285] The present application has the following key technologies.

[0286] 1. Double tower model training and deployment

[0287] Model Architecture: Based on Sentence-BERT (SBERT) design, adopts a double-tower structure, two shared parameter encoders respectively map user input and knowledge base sentences into semantic vectors, and match and sort through cosine similarity.

[0288] Vector Dimension: 1024 dimensions;

[0289] Training Data: Artificially labeled question-query object sample pairs;

[0290] Top-K Strategy: Dynamically adjusted according to different user roles (e.g. administrator K=5, ordinary user K=3);

[0291] Deployment: Local model service inference.

[0292] 2. Large Model Intent Understanding

[0293] Prompt Word Engineering: Contains role setting (e.g. "You are a senior business expert") and task chain description;

[0294] Context Enhancement: Provides complete field descriptions, enumerated values, special rules, etc.;

[0295] Output Control: Requires only the target query object and classification to be output, avoiding lengthy explanations.

[0296] 3. Dynamic Workflow Engine

[0297] Number of Branch Processes: Supports dozens of different query object branches;

[0298] Configuration File: Each branch is bound to specific table structure and field information;

[0299] Trigger Mechanism: Dynamically loads corresponding processes according to query object classification;

[0300] Extensibility: When adding new query objects, simply add new process configurations to take effect.

[0301] 4. SQL Syntax Verification and Optimization (see Figure 1 SQL Verification)

[0302] Build AST syntax tree, verify if fields exist and syntax is correct;

[0303] Automatically fix issues such as keyword case, special character escaping, etc.;

[0304] Support for multiple database types (e.g. PostgreSQL, MySQL) adaptation.

[0305] In terms of application scenarios, take "host performance data" as an example to illustrate the system running process:

[0306] 1. User input: "Yesterday's CPU utilization of the host machine"

[0307] 2. Vector matching gets Top-K candidate objects, including "host performance data"

[0308] 3. Large model confirms that the query object is "host performance data"

[0309] 4. Load host branch process, get corresponding table and field, for example: table name: vim_host_usage_day_view, field: statistical date, CPU total, average CPU utilization (%), peak CPU utilization (%), total memory (TB), average memory utilization (%), memory utilization 24-hour peak (%), two-layer network receiving average rate (mbps), two-layer network sending average rate (mbps)

[0310] 5. Generate SQL statement and execute

[0311] 6. Show the result table

[0312] 7. If the user feedback result is not accurate, trigger knowledge base update and model fine-tuning.

[0313] The present application effectively solves the field ambiguity problem through a multi-level intent recognition mechanism, significantly improving accuracy. At the same time, it combines the capabilities of knowledge base and large model, enhancing system robustness and adapting to complex business scenarios. The introduction of dynamic workflow mechanism improves efficiency by reducing invalid calculations and speeding up response speed. In addition, SQL generation is based on actual table structure, ensuring consistency and avoiding large model hallucinations. The present application also has scalability, with knowledge base and process supporting dynamic updates to adapt to future business changes. The transparency and controllability of SQL generation enhance explainability and improve user trust. Finally, the closed-loop optimization mechanism ensures that the self-learning module continuously optimizes the model and rules, thereby improving the long-term performance of the system.

[0314] Although the preferred embodiments of the present application have been described in detail, once the basic innovative concept is understood by those skilled in the art, they can further adjust and improve these schemes. Therefore, the appended claims are intended to cover the preferred embodiments, as well as all modifications and improvements within the scope of the present application. The above is only an example of the preferred embodiments of the present application and does not constitute a limitation. It should be clear that any modification, equivalent replacement and improvement made under the guidance of the spirit and principles of the present application should be included in the protection scope of the present application.< / context>

Claims

1. A multi-level intent recognition-based intelligent SQL generation method, characterized in that, The method comprises the following steps: receiving a user natural language query; vector matching step: vector matching based on a knowledge base to obtain Top-K candidate query objects, the knowledge base containing multi-layer structure description information of the query objects, including query object name, field information, typical question sentence, enumeration value and special rule; large language model intent understanding step: determining the final query object by using a large language model in combination with the candidate query object description, the large language model performing intent understanding according to a preset prompt word; loading the branch workflow corresponding to the final query object, parsing the field and table structure, the branch workflow dynamically configuring the database table and field information according to the query object classification; SQL generation step: generating a SQL sentence conforming to the syntax rule based on the multi-layer structure knowledge base and rule description, the SQL sentence including automatic addition of fields, time condition conversion, field priority matching operation; executing the SQL sentence and returning the result, and recording an error log and prompting the user to correct if the execution fails; The vector matching step comprises: using a double-tower model to perform semantic vector matching on the user question and the typical question sentence in the knowledge base; the double-tower model comprising two independent encoders for performing semantic encoding on the user input question and the candidate query object in the knowledge base respectively, and calculating the semantic matching degree through cosine similarity; On the basis of the original double-tower model, the hybrid weighted matching algorithm of semantic similarity and field correlation is fused to calculate the final matching degree of the fields in the knowledge base and the user question: :​ wherein, represents the semantic vector cosine similarity of the user question and the field , ranging from [-1, 1]; represents the relevance of the field to the question keywords in the knowledge base, ranging from [0, 1]; and are weight coefficients, satisfying and are dynamically adjusted through reinforcement learning; Field correlation degree The calculation formula is: wherein, is a set of segmented keywords of the user question CoOccur is a field and keyword co-occurrence frequency in historical queries, normalized to [0, 1]; is the cardinality of the set of keywords; The large language model intent understanding step comprises: inputting the original user question and the candidate query object description; judging the real query intent of the user according to the role and task chain description set by the prompt word in combination with the context information; outputting the finally determined query object and classification information, and returning "unable to determine" if it cannot be confirmed; further comprising a self-learning optimization step: optimizing the model and rule base based on user feedback and execution result to form a self-learning closed loop; the self-learning optimization step comprises: collecting user feedback and execution result; optimizing the large language model parameters through a reinforcement learning mechanism in reverse; error log automatically triggering the update process of the knowledge base field alias. 2.The intelligent SQL generation method based on multi-level intent recognition of claim 1, wherein, further comprising a SQL syntax checking step: constructing a SQL syntax tree to verify whether the field exists and the syntax is correct; automatically repairing the keyword case, special character escaping problem; if a syntax error is detected, the original question user feedback and the error SQL sentence are recorded into the self-learning optimization module. 3.The intelligent SQL generation method based on multi-level intent recognition of claim 1, wherein, The knowledge base comprises: the name, classification information and field list of the query object; typical question sentence; enumeration value description; special rule. 4.The intelligent SQL generation method based on multi-level intent recognition of claim 1, wherein, The branch workflow comprises: loading the branch process corresponding to the query object classification; configuring the table and field information of the query object to ensure consistency with the database structure; supporting multiple query object branches, and adding a new process configuration to take effect when a new query object is added.

5. An intelligent SQL generation system based on multi-level intent recognition, used to implement the intelligent SQL generation method based on multi-level intent recognition in any one of claims 1-4. comprise: a user interaction module for receiving user natural language input and returning the generated SQL sentence and query result; a knowledge base module for storing multi-layer structure description information of the query object, including query object name, field information, typical question sentence, enumeration value and special rule; a vector matching module for vector matching based on the knowledge base to obtain Top-K candidate query objects; An intent understanding module is configured to determine a final query object by using a large language model in combination with a candidate object description; A workflow routing module is configured to load a branch workflow corresponding to the query object, and parse a field and a table structure; An SQL generation module is configured to generate an SQL statement in accordance with a syntax rule based on a multi-layer structure knowledge base and a rule description; A database execution module is configured to execute the SQL statement and return a result, and record an error log and prompt a user to correct if the execution fails. 6.The intelligent SQL generation system based on multi-level intent recognition of claim 5, wherein, The vector matching module includes: A double tower model is configured to perform semantic vector matching on a user question and a typical question statement in a knowledge base; A dynamic adjustment unit is configured to dynamically adjust a Top-K value according to a user role.

Citation Information

Patent Citations

  • Data processing method and device, readable storage medium and electronic equipment

    CN115982416A

  • SQL (Structured Query Language) statement generation method based on large model, related device and storage medium

    CN119166666A