NL2SQL database table dynamic screening method and system based on multi-strategy fusion

By employing a multi-strategy NL2SQL approach, utilizing semantic encoders and database schema graph analysis, and combining table content features, the problem of low accuracy and poor robustness in table filtering in large databases is solved, achieving efficient and accurate table filtering and SQL generation.

CN121807973APending Publication Date: 2026-04-07INFORMATION & COMM SHARING SERVICE BRANCH OF STATE GRID INFORMATION & COMM IND GRP CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing NL2SQL technology cannot efficiently and accurately filter out the set of tables that are truly relevant to the user's problem from a massive number of tables when dealing with large databases. This results in low accuracy, poor robustness, and a tendency to miss key tables or introduce irrelevant tables, leading to subsequent SQL generation failures.

Method used

A multi-strategy fusion approach is adopted. A preliminary candidate set is generated through a semantic encoder. In-depth analysis and re-ranking are performed by combining the database schema graph and table content features. The fusion model is used to comprehensively evaluate the semantic similarity of the tables, the tightness of the graph relationships, and the content relevance, and outputs the final set of relevant tables.

Benefits of technology

It achieves high accuracy and high recall in table filtering, reduces the search space for SQL generation, improves generation speed and system robustness, and adapts to complex and fuzzy user queries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121807973A_ABST
    Figure CN121807973A_ABST
Patent Text Reader

Abstract

The invention provides an NL2SQL database table dynamic screening method and system based on multi-strategy fusion. The method comprises the steps that a preliminary candidate set is generated, a semantic encoder is used for encoding a user natural language problem and table and column information in a database into vectors, the semantic similarity is calculated, a preset number of tables are screened out from a whole database table based on the similarity, and a preliminary candidate table set is formed; performing deep analysis and reordering, performing multi-dimensional analysis on the tables in the preliminary candidate table set, and calculating a graph relationship compactness score and a content correlation score of each table; and performing fusion decision, inputting the semantic similarity score, the graph relationship compactness score and the content correlation score of each table into a fusion model to obtain a final comprehensive score of each table, and screening out a final correlation table set based on the final comprehensive score. The method has high accuracy and high recall rate, the generation speed and response efficiency of the NL2SQL system are improved, meanwhile, the robustness is high, and the practicability and generalization ability of the system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and more specifically, to a method and system for dynamic filtering of NL2SQL database tables based on multi-strategy fusion. Background Technology

[0002] Natural Language to SQL (NL2SQL) technology enables users to access databases using everyday language, greatly improving the convenience of data interaction. However, existing NL2SQL technologies experience a significant performance drop when dealing with large databases containing hundreds or even thousands of tables. One of the core bottlenecks lies in the inability to efficiently and accurately filter out the set of tables truly relevant to the user's problem from a massive number of tables.

[0003] Existing technologies mostly employ simple keyword matching methods, such as string matching of words in user questions with table names and column names, or simple cosine similarity calculations. This approach has several inherent drawbacks: (1) Low accuracy: It heavily relies on the naming conventions of table and column names. In cases of abbreviations, synonyms, and fuzzy queries (such as when a user asks "this year's revenue", but the column name in the table is "year_2024_income"), it is easy to miss key tables or introduce a large number of irrelevant tables.

[0004] (2) Ignoring structural information: The rich structural information contained in the database schema, such as primary and foreign key constraints, is completely ignored. This often leads to the omission of "bridge tables" or "dimension tables" that are not directly matched semantically but are closely connected through foreign key relationships and are crucial for constructing correct SQL join conditions. For example, when a user queries "sales revenue in Shanghai", the Sales table, Store table (via store_id), and Region table (via region_id) need to be joined to get the answer, while a simple semantic match may only find the Sales table.

[0005] (3) Causes subsequent generation failure: Incorrect table filtering results will be passed to the downstream SQL generation module, causing its search space to explode, resulting in low generation efficiency and easy generation of SQL statements with syntax or logic errors.

[0006] Therefore, there is an urgent need for a comprehensive solution that can deeply integrate semantic information, database schema structure, and table content characteristics to solve the table filtering problem in large database environments. Summary of the Invention

[0007] To address the problems of low accuracy, poor robustness, and neglect of database structure information in existing technologies when processing large-scale databases, this invention provides a dynamic NL2SQL database table filtering method and system based on multi-strategy fusion. This method and system have high accuracy and high recall, improving the generation speed and response efficiency of the entire NL2SQL system. At the same time, it has strong robustness, improving the system's practicality and generalization ability.

[0008] To achieve the above objectives, a first aspect of the present invention provides a method for dynamic filtering of NL2SQL database tables based on multi-strategy fusion, the method comprising: A preliminary candidate set is generated by using a semantic encoder to encode the user's natural language question and the table and column information in the database into vectors, calculating semantic similarity, and selecting a predetermined number of tables from the entire database based on the similarity to form a preliminary candidate table set. In-depth analysis and re-ranking are performed on the tables in the preliminary candidate table set. Multi-dimensional analysis is conducted to calculate the graph relationship tightness score and content relevance score for each table. The fusion decision involves inputting the semantic similarity score, graph relationship density score, and content relevance score of each table into the fusion model to obtain the final comprehensive score for each table, and then selecting the final set of relevant tables based on the final comprehensive score.

[0009] Preferably, generating a preliminary candidate set includes: A pre-trained language model finely tuned on natural language and database semantic pairs is used as the semantic encoder; The user's natural language question Q, the table name t_i of each table, and the set of column names {c_i1, c_i2, ...} are encoded into high-dimensional vectors respectively; Calculate the cosine similarity between the question vector and the vector of each table / column pair; For each table, the maximum similarity among all columns is taken as the semantic similarity score Score_sem(t_i) for that table; Sort the tables in descending order based on their semantic similarity scores Score_sem(t_i), and select the top N tables to form a preliminary candidate table set C_sem.

[0010] Preferably, when performing in-depth analysis and reordering, calculating the graph relation tightness score for each table includes: The database schema is abstracted as a schema graph G=(V,E) with tables as nodes and foreign key relationships as edges; where node V represents a data table and edge E represents the foreign key relationship between tables. Using the initial candidate table set C_sem as the seed node, a restricted random walk or community detection algorithm is performed on the pattern graph G to explore and incorporate structurally closely related neighbor tables. Calculate the graph relation tightness score based on the distance of the candidate table to the seed node and / or the weight of the connection path in the graph.

[0011] Preferably, according to formula (1), the graph relation density score is calculated based on the distance between the candidate table and the seed node in the graph and the weight of the connection path. (1) Where t_i is the target term in the query, D is the node to be scored, t_k is all the terms that appear in document D, Weight(D,t_k) is the importance weight of term t_k in document D, and R(t_i,t_k) is the association strength between terms t_i and t_k.

[0012] Preferably, when performing in-depth analysis and reordering, the calculation of the content relevance score for each table includes: Data content sampling is performed on the tables in the preliminary candidate table set C_sem; The text feature extraction method is applied to convert the sampled content data into feature vectors, and at the same time, the user's natural language question is also converted into feature vectors; The correlation between the feature vector of the problem and the feature vector of the content of each table is calculated to obtain the content relevance score.

[0013] Preferably, according to formula (2), the correlation between the feature vector of user question Q and the feature vector of each table content is calculated to obtain the content relevance score Score_content(t_i). (2) Where A represents the feature vector of question Q, and B represents the feature vector of each table content; the dot product of vectors A and B reflects the extent to which the two vectors point in similar directions; ||A||||B|| represents the Euclidean norm of vectors A and B, representing the magnitude of the vectors.

[0014] Preferably, the fusion model is a linear weighted formula or a nonlinear machine learning model, and the fusion decision includes: According to formula (3), the scores of the three dimensions of candidate table t_i, Score_sem, Score_graph, and Score_content, are input into the fusion model for comprehensive evaluation. (3) Where α, β, and γ are learnable weight parameters; Then, sort all candidate tables in descending order of their final score Final_Score(t_i), and select the Top-K tables with the highest scores as the final output set of relevant tables.

[0015] Secondly, the present invention provides a dynamic filtering system for NL2SQL database tables based on multi-strategy fusion for implementing the above-mentioned method, comprising: The semantic matching module is used to perform the initial candidate set generation step; The graph structure analysis module is used to calculate the graph relationship density score of candidate tables; The content analysis module is used to calculate the content relevance score of the candidate tables; The multi-strategy fusion decision module is used to execute fusion decision steps and output the final set of related tables.

[0016] Thirdly, the present invention provides a computing device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described above.

[0017] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described above.

[0018] The above technical solution first utilizes a fine-tuned semantic encoder to generate a preliminary candidate table set with high recall based on the semantic similarity between user questions and table / column names. Second, it performs in-depth analysis and re-ranking of the candidate table set, including: graph traversal and community discovery based on the database schema graph, mining structurally related tables and calculating graph relationship density; and calculating content relevance scores based on table content sampling and feature extraction. Finally, a fusion model linearly or non-linearly fuses the scores from the three dimensions of semantics, graph structure, and content to obtain a final comprehensive score, which is then used to output the most relevant set of tables. In this way, the method accurately and efficiently identifies the most relevant set of data tables through a multi-stage, multi-strategy fusion screening framework, laying the foundation for subsequent high-quality SQL generation.

[0019] Other features and advantages of the embodiments of the present invention will be described in detail in the following detailed description section. Attached Figure Description

[0020] The accompanying drawings are provided to further illustrate embodiments of the present invention and form part of the specification. They are used together with the following detailed description to explain the embodiments of the present invention, but do not constitute a limitation thereof. In the drawings: Figure 1 This is a simplified flowchart of the NL2SQL database table dynamic filtering method based on multi-strategy fusion provided by the present invention; Figure 2 This is a detailed flowchart of the NL2SQL database table dynamic filtering method based on multi-strategy fusion provided by the present invention. Detailed Implementation

[0021] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the scope of the present invention.

[0022] It should be noted that the acquisition, transmission, storage, use, and processing of data in the technical solution of this application all comply with relevant laws and regulations. In the embodiments of this application, certain existing industry solutions such as software, components, and models may be mentioned. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solution of this application, and do not imply that the applicant has already used or necessarily used such solutions.

[0023] See Figure 1 The first aspect of this invention provides a dynamic filtering method for NL2SQL database tables based on multi-strategy fusion, the method comprising: A preliminary candidate set is generated by using a semantic encoder to encode the user's natural language question and the table and column information in the database into vectors, calculating semantic similarity, and selecting a predetermined number of tables from the entire database based on the similarity to form a preliminary candidate table set. In-depth analysis and re-ranking are performed on the tables in the preliminary candidate table set. Multi-dimensional analysis is conducted to calculate the graph relationship tightness score and content relevance score for each table. The fusion decision involves inputting the semantic similarity score, graph relationship density score, and content relevance score of each table into the fusion model to obtain the final comprehensive score for each table, and then selecting the final set of relevant tables based on the final comprehensive score.

[0024] Specifically, the goal of the preliminary candidate set generation (recall phase) is to rapidly recall all potentially relevant tables from all database tables T, forming a broad candidate set C_sem, striving for a high recall rate. This includes: 1. Semantic Encoder: A pre-trained language model (such as BERT, RoBERTa, or Sentence-Transformer) fine-tuned on natural language and database semantic pairs serves as a dual encoder. This encoder encodes the user's natural language question Q and each table name t_i and its set of column names {c_i1, c_i2, ...} into high-dimensional vectors. The fine-tuning process uses triples of (question, positive list, negative list) to teach the model to associate relevant questions with relevant tables / columns in the vector space.

[0025] 2. Similarity Calculation: Calculate the cosine similarity between the question vector and each pair of vectors (table, column). The formula is:

[0026] Here, A represents the feature vector of the problem, and B represents the feature vector of each table content. The dot product of the numerator vectors A and B reflects the degree to which the two vectors point in similar directions. The denominator ||A|| and ||B|| represent the Euclidean norms of vectors A and B, also called the length or magnitude of the vectors, representing their magnitude. Dividing the dot product by the product of the two norms is equivalent to normalizing the dot product.

[0027] 3. Aggregation and Filtering: For each table, take the maximum value of the similarity between all its columns and the question as the semantic similarity score between that table and the question, Score_sem(t_i). Sort all tables in descending order of Score_sem(t_i), and select the top N tables (N is a large threshold, such as 20 or 10% of the total number of tables) to form the initial candidate table set C_sem.

[0028] Next, the process moves to in-depth analysis and re-ranking (fine-tuning stage). This stage involves a more in-depth, multi-dimensional analysis of the candidate tables in C_sem, followed by precise ranking and filtering. This includes: 1. Construct a schema graph using the schema graph analysis module: Abstract the database schema into a directed or undirected graph structure G=(V, E), where nodes V represent data tables and edges E represent foreign key relationships between tables. Weights can be assigned to edges, such as the strength of foreign key references (whether a reference is mandatory) or weights based on historical query frequency.

[0029] 2. Graph traversal expansion using the pattern graph analysis module: Using tables in the initial candidate set C_sem as seed nodes, perform restricted, weighted random walks or employ community detection algorithms (such as the Louvain algorithm) on the pattern graph G to explore its closely connected neighbor nodes (tables). This step aims to discover "bridging tables" that are not semantically directly matched but are structurally indispensable.

[0030] 3. Scoring using the pattern graph analysis module: For each candidate table (including the seed node and its extended neighbor nodes), a graph relation density score, Score_graph(t_i), is obtained based on its importance relative to the seed node set, calculated using the shortest path length to the seed node in the graph, the cumulative weight of the connecting paths, or a personalized PageRank algorithm. In an extended implementation, the calculation formula can be expressed as:

[0031] Where t_i is the target term in the query, i.e., the term whose relationship score with document D needs to be calculated; D is the node to be scored; t_k is all terms (or entities) appearing in document D, which are the "related terms" of t_i; Weight(D,t_k) is the importance weight of term t_k in document D. Specifically, it can be a simple value, such as: Term frequency (TF): The number of times t_k appears in D; TF-IDF: It takes into account both term frequency and inverse document frequency, and is more representative of the importance of terms; Binary value: 1 if t_k appears in D, otherwise 0 (rarely used).

[0032] 4. Use the content saliency analysis module for data sampling and preprocessing: For candidate tables in C_sem, randomly sample a certain number of table content data (records). For non-text fields (such as dates and numbers), they can be converted to strings or bucketed.

[0033] 5. Use the content saliency analysis module for feature extraction: Apply text feature extraction methods (such as TF-IDF or Doc2Vec) to convert the sampled content data into an aggregated feature vector to represent the overall content features of the table.

[0034] 6. Use the content saliency analysis module to calculate relevance: Similarly, convert the user question Q into a feature vector. Then, calculate the cosine similarity between the question feature vector and the content feature vector of each table, or use the BM25 algorithm to calculate the relevance, obtaining the content relevance score Score_content(t_i):

[0035] Here, A represents the feature vector of problem Q, and B represents the feature vector of each table content. The dot product of the numerator vectors A and B reflects the degree to which the two vectors point in similar directions. The denominator ||A|| and ||B|| represent the Euclidean norms of vectors A and B, also called the length or magnitude of the vectors, representing their magnitude. Dividing the dot product by the product of the two norms is equivalent to normalizing the dot product.

[0036] This step can effectively solve the problem of tables with misleading names but relevant content. For example, a table named T_001 may contain "customer address information". This module can effectively identify such tables when a user queries "customer distribution".

[0037] Then, we move on to the integration decision-making phase: For a candidate table t_i, its scores in its three dimensions (Score_sem, Score_graph, Score_content) are normalized and then input into a fusion model for comprehensive evaluation.

[0038] In one implementation, the above fusion model is a linear weighted formula:

[0039] Here, α, β, and γ are learnable weight parameters that can be optimized using grid search or linear regression on labeled (relevant / irrelevant) datasets.

[0040] In another implementation, a lightweight machine learning model (such as a gradient boosting tree (GBDT) or a small neural network) is used for nonlinear fusion. This model is trained with three scores as features and table relevance as labels, enabling it to learn more complex decision boundaries.

[0041] Finally, all candidate tables are sorted in descending order of their final score Final_Score(t_i), and the Top-K (e.g., K=5) tables with the highest scores are selected as the final output set of related tables and passed to the downstream SQL generation module.

[0042] Furthermore, the present invention also provides a dynamic filtering system for NL2SQL database tables based on multi-strategy fusion for implementing the method described above, comprising: The semantic matching module is used to perform the preliminary candidate set generation step; The graph structure analysis module is used to calculate the graph relationship density score of candidate tables; The content analysis module is used to calculate the content relevance score of the candidate tables; The multi-strategy fusion decision module is used to execute the fusion decision steps and output the final set of related tables.

[0043] And a computing device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method described above.

[0044] Another type of computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described above.

[0045] Based on the above technical solutions, the present invention provides the following methods, systems, devices, and storage media: 1. It achieves a dual improvement in screening precision and recall, fundamentally solving the problems of "missed selection" and "false selection." This includes: High recall rate guarantee: Through the initial candidate set generation step based on fine-tuning semantic encoder, it can deeply understand the semantic relationship between user query intent and table / column names, rather than simple keyword matching. This effectively addresses synonyms, business slang, and non-standard naming issues, ensuring that the vast majority of relevant tables are successfully "recalled," laying a solid foundation for subsequent fine-tuning.

[0046] High accuracy is guaranteed by an innovative multi-dimensional ranking mechanism. Through schema graph analysis, it identifies and introduces "bridging tables" that are semantically incompatible but structurally essential, solving the problem of missing connections caused by neglecting database schemas in existing technologies. Through content saliency analysis, it penetrates table name restrictions to directly reveal the relevance of data within the table to the problem, solving the challenge of identifying tables with misleading names. Finally, a fusion decision model comprehensively evaluates the evidence from these three dimensions, achieving accurate noise reduction and outputting a highly clean set of relevant tables.

[0047] 2. Significant performance optimizations have been achieved in the end-to-end NL2SQL system, including: Explosive compression of search space: The search space of the SQL generation module decreases from combinatorial order, significantly reducing computational complexity and memory usage.

[0048] Improved generation efficiency and speed: Due to fewer computational units and a simpler pattern, the inference speed of SQL generation is increased by orders of magnitude, enabling a rapid response to user queries.

[0049] Improved success and accuracy: Provides the SQL generation module with accurate and complete context, avoiding the construction of incorrect joins or query conditions on irrelevant tables, thereby directly reducing the generation of SQL statements with syntax and logical errors, and improving the availability and reliability of the entire NL2SQL system.

[0050] 3. A significant enhancement in system robustness and usability has been achieved, including: Strong adaptability to fuzzy and complex queries: The fusion of three strategies allows the system to operate independently of any single feature. When semantic matching fails due to naming inconsistencies, content analysis can fill the gap; when directly related tables are missing, graph structure analysis can discover indirectly related tables through relational chains. This complementary mechanism enables the system to readily handle various complex and fuzzy user natural language expressions.

[0051] Generalization capability to diverse database schemas: Whether it is a database designed in accordance with specifications or a complex and outdated system with a large number of abbreviations and historical legacy names, the multi-strategy framework of this invention can capture relevant evidence through different analysis dimensions, demonstrating strong generalization capability and engineering practical value.

[0052] In summary, this invention, through an organic "recall-ranking" framework, deeply integrates technologies from fields such as natural language processing (semantic encoding), graph computing (pattern graph analysis), and information retrieval (content analysis), generating a synergistic effect of "1+1+1>3". This provides a complete, efficient, and reliable solution to address the core bottleneck problem of NL2SQL in large database environments.

[0053] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0054] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0055] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0056] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0057] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0058] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0059] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0060] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0061] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A dynamic filtering method for NL2SQL database tables based on multi-strategy fusion, characterized in that, The method includes: A preliminary candidate set is generated by using a semantic encoder to encode the user's natural language question and the table and column information in the database into vectors, calculating semantic similarity, and selecting a predetermined number of tables from the entire database based on the similarity to form a preliminary candidate table set. In-depth analysis and re-ranking are performed on the tables in the preliminary candidate table set. Multi-dimensional analysis is conducted to calculate the graph relationship tightness score and content relevance score for each table. The fusion decision involves inputting the semantic similarity score, graph relationship density score, and content relevance score of each table into the fusion model to obtain the final comprehensive score for each table, and then selecting the final set of relevant tables based on the final comprehensive score.

2. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 1, characterized in that, The generation of the preliminary candidate set includes: A pre-trained language model finely tuned on natural language and database semantic pairs is used as the semantic encoder; The user's natural language question Q, the table name t_i of each table, and the set of column names {c_i1, c_i2, ...} are encoded into high-dimensional vectors respectively; Calculate the cosine similarity between the question vector and the vector of each table / column pair; For each table, the maximum similarity among all columns is taken as the semantic similarity score Score_sem(t_i) for that table; Sort the tables in descending order according to their semantic similarity scores Score_sem(t_i), and select the top N tables to form a preliminary candidate table set C_sem.

3. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 2, characterized in that, When performing deep analysis and reordering, the calculation of the graph relationship tightness score for each table includes: The database schema is abstracted as a schema graph G=(V,E) with tables as nodes and foreign key relationships as edges; where node V represents a data table and edge E represents the foreign key relationship between tables. Using the initial candidate table set C_sem as the seed node, a restricted random walk or community detection algorithm is performed on the pattern graph G to explore and incorporate structurally closely related neighbor tables. Calculate the graph relation tightness score based on the distance of the candidate table to the seed node and / or the weight of the connection path in the graph.

4. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 3, characterized in that, According to formula (1), the graph relation density score is calculated based on the distance between the candidate table and the seed node in the graph and the weight of the connection path. ,(1) Where t_i is the target term in the query, D is the node to be scored, t_k is all the terms that appear in document D, Weight(D,t_k) is the importance weight of term t_k in document D, and R(t_i,t_k) is the association strength between terms t_i and t_k.

5. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 2, characterized in that, When performing in-depth analysis and reordering, the calculation of the content relevance score for each table includes: Data content sampling is performed on the tables in the preliminary candidate table set C_sem; The text feature extraction method is applied to convert the sampled content data into feature vectors, and at the same time, the user's natural language question is also converted into feature vectors; The correlation between the feature vector of the problem and the feature vector of the content of each table is calculated to obtain the content relevance score.

6. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 2, characterized in that, According to formula (2), the correlation between the feature vector of user question Q and the feature vector of each table content is calculated to obtain the content relevance score Score_content(t_i). ,(2) Where A represents the feature vector of question Q, and B represents the feature vector of each table content; the dot product of vectors A and B reflects the extent to which the two vectors point in similar directions; ||A||||B|| represents the Euclidean norm of vectors A and B, representing the magnitude of the vectors.

7. The NL2SQL database table dynamic filtering method based on multi-strategy fusion according to claim 1, characterized in that, The fusion model is a linear weighted formula or a nonlinear machine learning model, and the fusion decision includes: According to formula (3), the scores of the three dimensions of candidate table t_i, Score_sem, Score_graph, and Score_content, are input into the fusion model for comprehensive evaluation. ,(3) Where α, β, and γ are learnable weight parameters; Then, sort all candidate tables in descending order of their final score Final_Score(t_i), and select the Top-K tables with the highest scores as the final output set of relevant tables.

8. A dynamic filtering system for NL2SQL database tables based on multi-strategy fusion for implementing the method as described in any one of claims 1-7, characterized in that, include: The semantic matching module is used to perform the preliminary candidate set generation step; The graph structure analysis module is used to calculate the graph relationship density score of candidate tables; The content analysis module is used to calculate the content relevance score of the candidate tables; The multi-strategy fusion decision module is used to execute the fusion decision steps and output the final set of related tables.

9. A computing device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-7.

Citation Information

Cited By

  • Method and system for generating Text2SQL (Structured Query Language) based on mixed view retrieval

    CN121996663A

  • A Text2SQL Generation Method and System Based on Hybrid View Retrieval

    CN121996663B