Low-sample NL2SQL intelligent generation method and device

Through dynamic sample expansion, clause dependency chain generation and multi-agent collaboration platform, the semantic mapping and complex query problems of traditional NL2SQL systems in small sample scenarios are solved, and efficient and secure SQL generation and optimization are achieved.

CN120632074AInactive Publication Date: 2025-09-12SHANDONG INSPUR CLOUD GOVERNMENT INFORMATION TECHNOLOGY CO LTD
View PDF 0 Cites 6 Cited by

Patent Information

Application Number
CN202510782415.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-12
Publication Date
2025-09-12
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional NL2SQL systems cannot effectively learn the mapping relationship between semantics and SQL in small sample scenarios, have difficulty processing complex queries, lack automated evaluation mechanisms, and have insufficient processing capabilities for domain-specific terminology.

Method used

It adopts dynamic sample expansion modules, clause dependency chain generation architecture, multi-agent collaboration platform and automated evaluation mechanism, combined with domain knowledge graph for semantic parsing and SQL generation, through technical means such as intent clarification, data enhancement, multi-source heterogeneous encoding, and security enhancement.

Benefits of technology

It significantly improves the accuracy of SQL generation in small sample scenarios, supports complex query processing, achieves continuous iterative optimization of the system, adapts to specific fields, and ensures data access security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120632074A_ABST
    Figure CN120632074A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence, and particularly provides a low-sample NL2SQL intelligent generation method and device, and the method comprises the following steps: S1, enabling a dynamic sample extension module to solve a training data sparse problem in a small sample scene through an intention clarification and data enhancement technology; s2, the clause dependency chain type generation framework converts natural language query into structured query language (SQL) statements with clear structures through semantic analysis, clause generation and dependency modeling; s3, the multi-agent cooperation platform performs iterative optimization through intention recognition, SQL generation and code execution; s4, enabling an automatic evaluation and iteration mechanism to pass a standardized test and continuous optimization; and S5, carrying out field adaptation and security enhancement. Compared with the prior art, the complex query processing capacity can be improved, and the stability and safety of the system are guaranteed through automatic evaluation and a safety mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and specifically provides a low-sample NL2SQL intelligent generation method and device. Background Art

[0002] With the advancement of digital transformation, NL2SQL technology has become the core of achieving efficient human-computer database interaction. However, traditional NL2SQL systems face the following technical bottlenecks.

[0003] Sample dependency: Existing systems typically rely on large-scale labeled data for training. In small sample scenarios, data sparsity prevents the model from fully learning the mapping relationship between semantics and SQL. This makes it difficult to achieve accurate modeling with limited samples, leading to increased SQL generation errors.

[0004] High Module Coupling: Traditional systems' semantic parsing and SQL generation modules are highly coupled, resulting in insufficient processing capabilities for complex queries (such as multi-table joins and nested subqueries). For example, while public datasets such as WikiSQL and Spider have driven technological development, in practice, the diversity of table structures and the complexity of query intent often lead to parsing failures, making it difficult for traditional systems to accurately decompose multi-table joins and aggregation logic.

[0005] Lack of automated evaluation mechanisms: Existing systems lack standardized evaluation processes, making it impossible to continuously optimize model performance. In scenarios where data accuracy is crucial, manual evaluation is costly and inefficient, making it difficult to meet real-time optimization requirements. Furthermore, traditional systems lack the ability to process domain-specific terminology, preventing accurate mapping to database fields and leading to SQL generation errors.

[0006] In summary, the traditional NL2SQL system has significant shortcomings in low sample adaptability, complex query processing, and automated optimization. There is an urgent need for an intelligent generation system that can operate efficiently under small sample conditions and adapt to diverse business scenarios. Summary of the Invention

[0007] The present invention aims to address the above-mentioned deficiencies in the prior art and provides a highly practical low-sample NL2SQL intelligent generation method.

[0008] A further technical task of the present invention is to provide a rationally designed, safe and applicable low-sample NL2SQL intelligent generation device.

[0009] The technical solution adopted by the present invention to solve its technical problem is:

[0010] A low-sample NL2SQL intelligent generation method has the following steps:

[0011] S1. The dynamic sample expansion module solves the problem of sparse training data in small sample scenarios through intent clarification and data enhancement technology;

[0012] S2, clause dependency chain generation architecture converts natural language queries into clearly structured SQL statements through semantic parsing, clause generation, and dependency modeling;

[0013] S3, a multi-agent collaboration platform, is optimized through iterative intent recognition, SQL generation, and code execution.

[0014] S4, automated evaluation and iteration mechanism through standardized testing and continuous optimization;

[0015] S5. Perform domain adaptation and security enhancement.

[0016] Furthermore, in step S1, it includes:

[0017] S1-1. Build an intent clarification adapter based on a deep pre-trained language model, perform word segmentation and vectorization on the original business samples, input them into the pre-trained language model, obtain contextual semantic representation, identify possible ambiguous words or expressions in the samples through the attention mechanism and semantic alignment technology, and perform semantic disambiguation in combination with the domain knowledge graph, and output the corrected standardized samples.

[0018] S1-2, dynamic template generation uses a preset template library and rule engine to expand a single expression into a multi-dimensional sample;

[0019] S1-3. Introduce a quality assessment mechanism to evaluate the semantic consistency between the extended samples and the original samples through semantic similarity calculation, use domain expert annotation or pre-trained model scoring to screen high-quality samples for model training.

[0020] Furthermore, in step S2, it includes:

[0021] S2-1, the semantic parsing module uses a multi-source heterogeneous encoder to combine text semantics and database metadata for joint modeling;

[0022] S2-2, the clause generation adapter group includes SELECT, FROM and WHERE. Each adapter independently processes the semantic representation and generates the corresponding clause;

[0023] S2-3. The clause dependency graph represents the logical order between clauses through a directed acyclic graph (DAG).

[0024] Furthermore, in step S2-1, the text encoder encodes the natural language query and extracts semantic features; the database metadata encoder encodes the table structure, column names, and constraint metadata of the database;

[0025] Multi-source heterogeneous fusion: Through attention mechanisms or graph neural networks, text and metadata features are integrated to achieve alignment of semantics with database structure. The output of semantic parsing is a structured semantic representation consisting of an entity set E, an attribute set A, and a condition set C.

[0026] In step S2-2, the ELECT adapter converts natural language attributes into database column names based on the attribute set A through the predefined attribute-column mapping table. The FROM adapter determines the relevant table names based on the entity set E through the entity-table mapping table, analyzes the relationship between entities, and generates table connection conditions. The WHERE adapter converts the natural language conditions into SQL expressions.

[0027] In step S2-3, the clause generation order is determined, the logical relationship in the semantic representation is analyzed, the predecessor and successor clauses are determined for each clause, and the clauses are assembled in sequence according to the order of the clause dependency graph to form a complete SQL statement.

[0028] Furthermore, in step S3, it includes:

[0029] S3-1. The intent recognition agent is built on the Large Language Model (LLM). It is responsible for parsing the user's natural language query, extracting key parameters, and inputting the natural language query. Through the contextual understanding capabilities of the LLM, it identifies the user's core intent.

[0030] Use named entity recognition (NER) and relation extraction (RE) techniques to extract entities, time, and condition numbers from queries;

[0031] S3-2: The SQL generation agent combines database metadata and the clause dependency model to generate candidate SQL statements, obtain key parameters extracted by the intent recognition agent, and obtain database metadata. Using the clause dependency model, it generates SELECT, FROM, and WHERE clauses in a logical order and assembles them into complete SQL statements. The generated SQL statements are then syntax-checked and semantically validated.

[0032] S3-3. The code execution agent is responsible for verifying the validity of candidate SQL statements and providing optimization feedback. It executes candidate SQL statements through the database connection interface and captures errors that occur during the execution process. It analyzes the causes of errors, generates optimization suggestions, and feeds them back to the SQL generation agent, triggering iterative optimization. It also records the execution results and optimization process for subsequent model training and strategy optimization.

[0033] Furthermore, in step S4, it includes:

[0034] S4-1. The evaluation dataset contains natural language queries and their corresponding standard SQL answers, covering different complexities and domain scenarios. We collect query logs from real business scenarios and invite domain experts to annotate the standard answers.

[0035] S4-2. Call the API of the system under test, input a natural language query, and obtain the generated SQL statement; standardize the generated SQL statement; match the standardized SQL with the standard answer, calculate the accuracy and recall rate indicators; generate an evaluation report, and analyze the system's performance in different query types and fields;

[0036]

[0037] S4-3. Based on the evaluation results, the system adopts the following optimization strategies: using the gradient descent algorithm to adjust the parameters of the clause dependency model, dynamically adjusting the template library and data augmentation algorithm to generate more relevant training samples based on the weak links found in the evaluation; optimizing the parameters of the intent recognition agent or the rules of the SQL generation agent to improve the accuracy of key parameter extraction and clause generation.

[0038] Furthermore, in step S5, it includes:

[0039] S5-1. Domain knowledge graphs are used to store the mapping relationship between professional terms and database fields, as well as domain-specific business rules. Professional terms and business rules are collected and constructed using a graph database. Nodes represent entities and terms, and edges represent the relationships between them.

[0040] In the process of semantic parsing and clause generation, knowledge graphs are used to enhance the understanding of professional terminology;

[0041] S5-2, security enhancement mechanisms include database connection verification and SQL injection detection;

[0042] Database connection verification: Use OAuth2.0 protocol or pre-shared key to verify database access rights;

[0043] SQL injection detection: Through regular expression matching and semantic analysis, it detects whether SQL statements contain dangerous operations and filters malicious input.

[0044] A low-sample NL2SQL intelligent generation device includes: at least one memory and at least one processor;

[0045] The at least one memory is configured to store a machine-readable program;

[0046] The at least one processor is configured to call the machine-readable program to execute a low-sample NL2SQL intelligent generation method.

[0047] Compared with the prior art, the low-sample NL2SQL intelligent generation method and device of the present invention has the following outstanding beneficial effects:

[0048] This invention significantly improves SQL generation accuracy in small sample scenarios through dynamic sample expansion and multi-source heterogeneous data fusion, reducing reliance on labeled data. The clause-dependent chain generation architecture supports complex operations such as multi-table joins and nested subqueries. Multi-agent collaboration and automated evaluation mechanisms enable continuous system iteration, optimizing model performance without manual intervention. Combined with domain knowledge graphs, the system can quickly adapt to specific domains, ensuring data access security through database connection verification and SQL injection detection, meeting the needs of scenarios with high security requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0050] Figure 1 This is a schematic diagram of the architecture of a low-sample NL2SQL intelligent generation method;

[0051] Figure 2 It is a clause dependency chain generation flowchart in the low-sample NL2SQL intelligent generation method;

[0052] Figure 3 It is an interactive flow chart of a multi-agent collaboration platform in a low-sample NL2SQL intelligent generation method. DETAILED DESCRIPTION

[0053] In order to enable those skilled in the art to better understand the solutions of the present invention, the present invention will be further described in detail below in conjunction with specific embodiments. Obviously, the embodiments described are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0054] A best embodiment is given below:

[0055] like Figure 1-3 As shown, a low-sample NL2SQL intelligent generation method in this embodiment has the following steps:

[0056] S1. The dynamic sample expansion module solves the problem of sparse training data in small sample scenarios through intent clarification and data augmentation technology. The core of this module is to generate high-quality and diverse training samples through semantic correction and template expansion. The steps are as follows:

[0057] S1-1, intent clarification adapter;

[0058] The intent clarification adapter is built on deep pre-trained language models (such as BERT and GPT series) and is designed to eliminate semantic ambiguity in raw samples.

[0059] The workflow is as follows: The original business samples are segmented and vectorized, then fed into a pre-trained language model to obtain contextual semantic representations. Attention mechanisms and semantic alignment techniques are used to identify potentially ambiguous words or expressions in the samples, and semantic disambiguation is performed by integrating with the domain knowledge graph. Corrected, standardized samples are then output to ensure semantic accuracy and consistency.

[0060] S1-2, dynamic template generation;

[0061] Dynamic template generation uses a pre-defined template library and rule engine to expand single expressions into multi-dimensional samples. The template library includes templates for various purposes, such as time ranges, entity types, and aggregation functions. The generation process is as follows: the modified sample is semantically combined with templates in the template library to generate a diverse set of expanded samples. Data augmentation algorithms (such as synonym replacement and sentence structure transformation) are used to further increase sample diversity while maintaining semantic consistency.

[0062] S1-3, sample quality assessment;

[0063] To ensure the effectiveness of the extended samples, the module introduces a quality assessment mechanism: the semantic consistency between the extended samples and the original samples is evaluated through semantic similarity calculation (such as cosine similarity); domain expert annotation or pre-trained model scoring is used to screen high-quality samples for model training.

[0064] The S2, clause dependency chain generation architecture converts natural language queries into clearly structured SQL statements through semantic parsing, clause generation, and dependency modeling. The core of this architecture is to break down complex queries into independent clauses and ensure the logical accuracy of the generated SQL through dependency relationships.

[0065] include:

[0066] S2-1, semantic parsing module;

[0067] The semantic parsing module uses a multi-source heterogeneous encoder to jointly model text semantics and database metadata. The text encoder encodes natural language queries and extracts semantic features. The database metadata encoder encodes database metadata, such as table structures, column names, and constraints. Multi-source heterogeneous fusion uses an attention mechanism or graph neural network to fuse text and metadata features, aligning semantics with database structure. The output of semantic parsing is a structured semantic representation consisting of an entity set E, an attribute set A, and a condition set C.

[0068] S2-2, semantic parsing module;

[0069] The clause generation adapter group includes generation modules for clauses such as SELECT, FROM, and WHERE. Each module independently processes semantic representations and generates corresponding clauses. SELECT adapter: Based on the attribute set A, it converts natural language attributes into database column names through a predefined attribute-column mapping table. FROM adapter: Based on the entity set E, it determines the relevant table names through the entity-table mapping table, analyzes the relationships between entities (such as foreign key constraints), and generates table join conditions. WHERE adapter: Converts natural language conditions into SQL expressions. This adapter contains a rule engine and a semantic parser, and can handle various condition types such as numerical comparison and string matching.

[0070] S2-3, Clause Dependency Graph (CDG) modeling;

[0071] The clause dependency graph represents the logical order between clauses through a directed acyclic graph (DAG).

[0072] The construction process is as follows: Determine the order in which clauses are generated: For example, the SELECT clause typically depends on the tables specified in the FROM clause, and the WHERE clause depends on the columns and tables in both the SELECT and FROM clauses. Establish dependencies: By analyzing the logical relationships in the semantic representation, determine the predecessor and successor clauses for each clause.

[0073] Generate SQL statements: Assemble each clause in sequence according to the order of the clause dependency graph to form a complete SQL statement.

[0074] S3, a multi-agent collaboration platform, improves the accuracy and robustness of SQL generation through iterative optimization of intent recognition, SQL generation, and code execution. The core of this platform lies in the information exchange and feedback mechanism between multiple agents.

[0075] include:

[0076] S3-1, Intent Recognition Agent;

[0077] The intent recognition agent is built on the Large Language Model (LLM) and is responsible for parsing users' natural language queries and extracting key parameters: inputting a natural language query, through the context understanding capability of the LLM, identifying the user's core intent (such as query, statistics, filtering, etc.); using named entity recognition (NER) and relation extraction (RE) technology, extracting key parameters such as entities, time, and conditions in the query.

[0078] S3-2, SQL generates Agent;

[0079] The SQL generation agent combines database metadata and the clause dependency model to generate candidate SQL statements. It obtains the key parameters extracted by the intent recognition agent, as well as metadata such as the database table structure and column names. It uses the clause dependency model to generate clauses such as SELECT, FROM, and WHERE in a logical order and assembles them into complete SQL statements. The generated SQL statements are then syntax-checked and semantically verified to ensure that they comply with the database's grammatical rules.

[0080] S3-3, Code Execution Agent;

[0081] The code execution agent is responsible for verifying the validity of candidate SQL statements and providing optimization feedback. It executes candidate SQL statements through database connection interfaces (such as JDBC and ODBC) and captures errors that occur during execution (such as syntax errors, table non-existence, and insufficient permissions). It analyzes the causes of errors, generates optimization suggestions (such as correcting table names and adjusting conditional expressions), and feeds these suggestions back to the SQL generation agent to trigger iterative optimization. It also records the execution results and optimization process for subsequent model training and strategy optimization.

[0082] S4. Automated evaluation and iteration mechanism ensures the stability and improvement of system performance through standardized testing and continuous optimization. The core of this mechanism lies in the automated testing process and iterative optimization based on evaluation indicators;

[0083] include:

[0084] S4-1. The evaluation dataset contains natural language queries and their corresponding standard SQL answers, covering various complexities and domain scenarios. Data source: Query logs from real business scenarios are collected, and standard answers are annotated by domain experts. Data diversity: This includes a variety of query types, including single-table queries, multi-table joins, and nested subqueries.

[0085] S4-2, automated testing process;

[0086] The automated testing process includes the following steps: calling the API of the system under test, entering a natural language query, and obtaining the generated SQL statement; standardizing the generated SQL statement (such as unifying uppercase and lowercase letters and removing redundant spaces); matching the standardized SQL with the standard answer, and calculating indicators such as accuracy and recall rate; generating an evaluation report and analyzing the system's performance in different query types and fields.

[0087]

[0088] S4-3, iterative optimization strategy;

[0089] Based on the evaluation results, the system adopted the following optimization strategies: Model parameter optimization: Using algorithms such as gradient descent, we adjusted the parameters of the clause dependency model to improve the accuracy of complex query generation. Sample expansion strategy adjustment: Based on weaknesses discovered during the evaluation, we dynamically adjusted the template library and data augmentation algorithm to generate more relevant training samples. Multi-agent collaboration optimization: We optimized the parameters of the intent recognition agent or the rules of the SQL generation agent to improve the accuracy of key parameter extraction and clause generation.

[0090] S5, the domain adaptation and security enhancement module improves the system's professionalism and security through domain knowledge graphs and security mechanisms, ensuring its reliable application in specific fields;

[0091] include:

[0092] S5-1, construction of domain knowledge graph;

[0093] Domain knowledge graphs are used to store the mapping between specialized terminology and database fields, as well as domain-specific business rules. Knowledge acquisition: Gathering specialized terminology and business rules through interviews with domain experts and literature analysis. Graph construction: Using graph databases (such as Neo4j) to build knowledge graphs, where nodes represent entities and terms, and edges represent the relationships between them. Graph application: During semantic parsing and clause generation, knowledge graphs are leveraged to enhance understanding of specialized terminology and ensure the accuracy of SQL generated.

[0094] S5-2, security enhancement mechanism;

[0095] Security enhancement mechanisms include database connection verification and SQL injection detection: Database connection verification: Use the OAuth2.0 protocol or pre-shared keys to verify database access rights to ensure that only authorized users can execute queries; SQL injection detection: Through regular expression matching and semantic analysis, detect whether SQL statements contain dangerous operations and filter malicious input.

[0096] Based on the above method, a low-sample NL2SQL intelligent generation device in this embodiment includes: at least one memory and at least one processor;

[0097] The at least one memory is configured to store a machine-readable program;

[0098] The at least one processor is configured to call the machine-readable program to execute a low-sample NL2SQL intelligent generation method.

[0099] Through the above technical solution, the present invention realizes efficient NL2SQL generation in low-sample scenarios, improves complex query processing capabilities, and ensures the stability and security of the system through automated evaluation and security mechanisms.

[0100] The above-mentioned specific implementation methods are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementation methods. Any technical solutions that conform to the above-mentioned specific implementation methods of the present invention and any appropriate changes or substitutions made thereto by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.

[0101] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.

Claims

1. A low-sample NL2SQL intelligent generation method, characterized by: The steps are as follows: S1. The dynamic sample expansion module solves the problem of sparse training data in small sample scenarios through intent clarification and data enhancement technology; S2, clause dependency chain generation architecture converts natural language queries into clearly structured SQL statements through semantic parsing, clause generation, and dependency modeling; S3, a multi-agent collaboration platform, is optimized through iterative intent recognition, SQL generation, and code execution. S4, automated evaluation and iteration mechanism through standardized testing and continuous optimization; S5. Perform domain adaptation and security enhancement.

2. The low-sample NL2SQL intelligent generation method according to claim 1, characterized in that: In step S1, it includes: S1-1. Build an intent clarification adapter based on a deep pre-trained language model, perform word segmentation and vectorization on the original business samples, input them into the pre-trained language model, obtain contextual semantic representation, identify possible ambiguous words or expressions in the samples through the attention mechanism and semantic alignment technology, and perform semantic disambiguation in combination with the domain knowledge graph, and output the corrected standardized samples. S1-2, dynamic template generation uses a preset template library and rule engine to expand a single expression into a multi-dimensional sample; S1-3. Introduce a quality assessment mechanism to evaluate the semantic consistency between the extended samples and the original samples through semantic similarity calculation, use domain expert annotation or pre-trained model scoring to screen high-quality samples for model training.

3. The low-sample NL2SQL intelligent generation method according to claim 2, characterized in that: In step S2, it includes: S2-1, the semantic parsing module uses a multi-source heterogeneous encoder to combine text semantics and database metadata for joint modeling; S2-2, the clause generation adapter group includes SELECT, FROM and WHERE. Each adapter independently processes the semantic representation and generates the corresponding clause; S2-3. The clause dependency graph represents the logical order between clauses through a directed acyclic graph (DAG).

4. The low-sample NL2SQL intelligent generation method according to claim 3 is characterized in that: In step S2-1, the text encoder encodes the natural language query and extracts semantic features; the database metadata encoder encodes the database table structure, column names, and constraint metadata; Multi-source heterogeneous fusion: Through attention mechanisms or graph neural networks, text and metadata features are integrated to achieve alignment of semantics with database structure. The output of semantic parsing is a structured semantic representation consisting of an entity set E, an attribute set A, and a condition set C. In step S2-2, the ELECT adapter converts natural language attributes into database column names based on the attribute set A through the predefined attribute-column mapping table. The FROM adapter determines the relevant table names based on the entity set E through the entity-table mapping table, analyzes the relationship between entities, and generates table connection conditions. The WHERE adapter converts the natural language conditions into SQL expressions. In step S2-3, the clause generation order is determined, the logical relationship in the semantic representation is analyzed, the predecessor and successor clauses are determined for each clause, and the clauses are assembled in sequence according to the order of the clause dependency graph to form a complete SQL statement.

5. The low-sample NL2SQL intelligent generation method according to claim 4 is characterized in that: In step S3, it includes: S3-1. The intent recognition agent is built on the Large Language Model (LLM). It is responsible for parsing the user's natural language query, extracting key parameters, and inputting the natural language query. Through the contextual understanding capabilities of the LLM, it identifies the user's core intent. Use named entity recognition (NER) and relation extraction (RE) techniques to extract entities, time, and condition numbers from queries; S3-2: The SQL generation agent combines database metadata and the clause dependency model to generate candidate SQL statements, obtain key parameters extracted by the intent recognition agent, and obtain database metadata. Using the clause dependency model, it generates SELECT, FROM, and WHERE clauses in a logical order and assembles them into complete SQL statements. The generated SQL statements are then syntax-checked and semantically validated. S3-3. The code execution agent is responsible for verifying the validity of candidate SQL statements and providing optimization feedback. It executes candidate SQL statements through the database connection interface and captures errors that occur during the execution process. It analyzes the causes of errors, generates optimization suggestions, and feeds them back to the SQL generation agent, triggering iterative optimization. It also records the execution results and optimization process for subsequent model training and strategy optimization.

6. The low-sample NL2SQL intelligent generation method according to claim 5, characterized in that: In step S4, it includes: S4-1. The evaluation dataset contains natural language queries and their corresponding standard SQL answers, covering different complexities and domain scenarios. We collect query logs from real business scenarios and invite domain experts to annotate the standard answers. S4-2. Call the API of the system under test, input a natural language query, and obtain the generated SQL statement; standardize the generated SQL statement; match the standardized SQL with the standard answer, calculate the accuracy and recall rate indicators; generate an evaluation report, and analyze the system's performance in different query types and fields; S4-3. Based on the evaluation results, the system adopts the following optimization strategies: using the gradient descent algorithm to adjust the parameters of the clause dependency model, dynamically adjusting the template library and data augmentation algorithm to generate more relevant training samples based on the weak links found in the evaluation; optimizing the parameters of the intent recognition agent or the rules of the SQL generation agent to improve the accuracy of key parameter extraction and clause generation.

7. The low-sample NL2SQL intelligent generation method according to claim 6, characterized in that: In step S5, it includes: S5-1. Domain knowledge graphs are used to store the mapping relationship between professional terms and database fields, as well as domain-specific business rules. Professional terms and business rules are collected and constructed using a graph database. Nodes represent entities and terms, and edges represent the relationships between them. In the process of semantic parsing and clause generation, knowledge graphs are used to enhance the understanding of professional terminology; S5-2, security enhancement mechanisms include database connection verification and SQL injection detection; Database connection verification: Use OAuth2.0 protocol or pre-shared key to verify database access rights; SQL injection detection: Through regular expression matching and semantic analysis, it detects whether SQL statements contain dangerous operations and filters malicious input.

8. A low-sample NL2SQL intelligent generation device, characterized in that: include: at least one memory and at least one processor; The at least one memory is configured to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Graph query processing method and system based on multi-agent collaboration

    CN121210525A

  • Method and system for processing graph query based on multi-intelligent agent cooperation

    CN121210525B

  • Intelligent data query system and method based on natural language processing

    CN121255832A

  • An intelligent data query system and method based on natural language processing

    CN121255832B

  • Multi-agent model self-evolution method for Text2SQL (Structured Query Language)

    CN121501816A