A database schema graph construction and retrieval method

CN122733892APending Publication Date: 2026-09-11TSINGHUA UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610823088.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-06-09
Publication Date
2026-09-11

AI Technical Summary

Technical Problem

然而,该类方法在实际应用中存在明显局限,Schema 图的构建过程依赖领域专家经验,人工成本高、维护难度大,难以适配不同数据库或频繁变化的业务场景;另一方面,其语义匹配过程往往需要在大规模列空间中进行高维向量比对,当表行数和列数显著增加时,计算开销迅速上升,检索效率难以保障

Benefits of technology

[0020] The database pattern graph construction and retrieval method of this invention can improve the construction accuracy and retrieval efficiency of database pattern graphs, reduce the computational overhead of large-scale column value matching, and achieve dynamic optimization of the graph structure through reinforcement learning, thereby improving the accuracy and stability of downstream SQL generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122733892A_ABST
    Figure CN122733892A_ABST
Patent Text Reader

Abstract

This invention proposes a database pattern graph construction and retrieval method, relating to the interdisciplinary fields of data table management and artificial intelligence. The method first calculates the correlation coefficients between database fields, then constructs weighted edges based on the maximum correlation values ​​of column pairs between two tables, generating a weighted pattern graph of the data tables. For user natural language queries, the text is encoded and the search fields are used to obtain a seed table, which is then breadth-expanded and sorted in the graph, outputting an ordered set of candidate tables. A reinforcement learning agent is constructed based on historical queries and standard SQL. Using the original query and local subgraphs of the candidate tables as input, the agent outputs graph edge addition / deletion and weight modification actions. The reward is calculated based on the query results, and iterative optimization is performed to dynamically correct the pattern graph. This solution leverages reinforcement learning to continuously iterate and optimize the graph structure, improving the matching accuracy of natural language table lookups.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data table management and artificial intelligence, and in particular to a method for constructing and retrieving database pattern graphs. Background Technology

[0002] With the continuous development of enterprise information systems and data warehouses, databases are expanding in scale, and a single database often contains a large number of data tables with complex structures and heterogeneous semantics. To support applications such as natural language to structured query (Text-to-SQL), existing methods typically need to retrieve a set of data tables most relevant to the user's query from the database schema.

[0003] In their paper "Is Table Retrieval a Solved Problem? Exploring Join-Aware Multi-Table Retrieval," Chen et al. proposed a join-aware multi-table retrieval method that improves retrieval performance by analyzing the join relationships between tables. This paper was published at ACL 2024, with pages 2687–2699. However, this approach typically treats the schema graph as an offline, static structure that remains fixed once constructed, making it difficult to dynamically adjust as database content changes or query distribution shifts. Furthermore, updating the graph structure relies on re-statistically analyzing or reconstructing the entire graph, resulting in high computational costs and hindering real-time or incremental optimization requirements in continuously evolving scenarios.

[0004] In their paper "Plugging Schema Graph into Multi-Table QA: A Human-Guided Framework for Reducing LLM Reliance," Wang et al. proposed a method to assist multi-table question answering by introducing schema graphs. This method constructs and introduces schema graphs through manual guidance to reduce the dependence of large language models on multi-table reasoning. The paper was published at EMNLP 2025, with pages 5829–5842. However, this type of method has significant limitations in practical applications. The construction of schema graphs relies on domain expert experience, resulting in high manual costs, high maintenance difficulties, and difficulty in adapting to different databases or frequently changing business scenarios. Furthermore, its semantic matching process often requires high-dimensional vector comparisons in a large column space. When the number of rows and columns in a table increases significantly, the computational cost rises rapidly, making it difficult to guarantee retrieval efficiency.

[0005] The above methods and other existing technologies still have obvious shortcomings in practical applications: (1) Methods based on rules or foreign keys rely heavily on the quality of database design and are difficult to discover implicit semantic relationships; (2) When directly relying on large models to process complete schemas, the reasoning cost increases significantly with the increase in the number of tables and is easily limited by the length of the context; (3) Existing schema diagram construction methods mostly use table-level or simple column matching, which do not fully depict the decisive role of "key column pairs" in table joins; (4) The schema diagrams constructed by most methods are static structures and fail to utilize the real table join information contained in historical queries and known SQL for continuous optimization.

[0006] Existing schema graph construction and retrieval methods suffer from several technical problems in practical applications. At the graph construction level, existing methods often employ table-level rule matching or simple column name similarity calculations, failing to finely characterize the "key column pairs that determine table join relationships." This coarse-grained modeling approach easily introduces noisy joins, resulting in a dense but low-information-density schema graph, impacting subsequent retrieval accuracy. Secondly, existing schema graph construction processes rely solely on one-time offline construction. When database size changes, business semantics evolve, or query distribution changes, a full graph reconstruction is often required, failing to meet the continuously evolving needs of real-world systems. This "static graph" cannot absorb the real table join knowledge inherent in historical queries and known SQL, causing the graph structure to remain in an initial, coarse state for extended periods. Furthermore, during column-level matching, real database tables often contain a large number of columns with numerous rows. Directly calculating similarity based on column instances incurs high time costs, becoming a performance bottleneck in the schema construction and retrieval phase, affecting the overall system availability and stability.

[0007] In summary, existing technologies have the following problems: how to construct a high-quality schema graph that can accurately depict the key table join relationships; how to enable the graph structure to continuously and dynamically evolve based on historical queries without repeating the full construction; and how to significantly reduce the computational overhead of column-level semantics and instance matching when facing columns with a huge number of rows and large-scale schemas. Summary of the Invention

[0008] The main objective of this invention is to provide a method for constructing and retrieving database schema graphs. This method constructs a table-level schema graph, using tables in the database as nodes and inter-table correlations as weighted edges. Efficient table retrieval is achieved through column-level correlation modeling, graph retrieval, and personalized ranking. A reinforcement learning agent is introduced to dynamically optimize the graph structure. Finally, the selected set of highly correlated tables, along with the user query, is input into a large model to generate the final SQL statement.

[0009] To achieve the above objectives, a first aspect of the present invention proposes a method for constructing and retrieving a database pattern graph, comprising:

[0010] S1 calculates the correlation score between columns of each data table in the database; S2, for any two data tables, determine the correlation between the tables based on the maximum correlation score of all column pairs between the two tables, and establish weighted edges when the correlation exceeds a preset threshold, and construct a weighted pattern graph with data tables as nodes and inter-table correlation as edge weights. S3 receives the user's natural language query, decomposes the query into semantic units and encodes them into query vectors, searches for matching columns in the column vector index, determines the seed table set based on the matching score, performs breadth-first expansion in the weighted pattern graph starting from the seed table, runs a personalized sorting algorithm to sort the candidate tables, and outputs the sorted target table set. S4 constructs a reinforcement learning agent based on historical queries and their corresponding real structured query statements. With the current query and the candidate table subgraph in the sorted target table set as the state, it outputs actions such as establishing, deleting, or adjusting the weights of edges in the pattern graph. It calculates the reward based on the impact of the actions on the real query results and optimizes the agent through a relative advantage update strategy within the group to dynamically update the pattern graph structure.

[0011] In one embodiment of the present invention, the relevance score integrates the instance similarity of the column value set, the semantic similarity of the column name context, and the uniqueness index of the column; the calculation of the relevance score between columns includes: A fixed-length signature fingerprint is generated using the MinHash algorithm on the column value set of the data table. The Jaccard similarity between the column value sets is approximately estimated by comparing the collision probability of the signature fingerprints, and the instance similarity score is obtained. The column name, the name of the table to which it belongs, and the names of other columns in the same table are concatenated into the context text, which is then input into a pre-trained semantic encoding model to generate column-level semantic vectors. The semantic similarity score is obtained by calculating the cosine similarity between the column-level semantic vectors. The number of non-empty rows and the number of different values ​​in the statistical column are counted, and the ratio of the number of different values ​​to the number of non-empty rows is used as a uniqueness indicator. The instance similarity score, the semantic similarity score, and the uniqueness index are weighted and fused to obtain the relevance score between columns.

[0012] In one embodiment of the present invention, generating a fixed-length signature fingerprint by applying the MinHash algorithm to the column value set of the data table includes: applying a set of independent hash functions to each element in the column value set, recording the minimum hash value of each hash function, and combining the minimum hash values ​​into a fixed-length signature vector; The method of approximating the Jaccard similarity between column value sets by comparing the collision probabilities of signature fingerprints includes: calculating the proportion of corresponding positions with equal hash values ​​in the two signature vectors, and using this proportion as an unbiased estimate of the Jaccard similarity of the column value sets; The step of concatenating the column name, the table name, and other column names in the same table into context text includes: concatenating the column name of the current column, the table name of the data table to which the current column belongs, and the column names of other columns in the data table containing the current column in a preset order into a string sequence; The process of generating column-level semantic vectors by inputting the pre-trained semantic coding model includes: inputting the string sequence into a pre-trained language model based on the Transformer architecture, and extracting the vector representation of the corresponding column name position in the last hidden state as the column-level semantic vector; The uniqueness index is calculated by taking the ratio of the number of non-empty rows and the number of distinct values ​​in the statistical column. This ratio includes the total number of non-empty rows and the distinct number of distinct values ​​in the statistical column. The uniqueness index is calculated using the formula uniqueness = distinct / total.

[0013] In one embodiment of the present invention, the determination of inter-table correlation based on the maximum correlation score of all column pairs between the two tables includes: for the first data table TableA and the second data table TableB, obtaining the correlation scores between all columns in TableA and all columns in TableB, and taking the maximum value of the correlation scores of all column pairs as the overall correlation score S_AB of the two tables; The step of establishing a weighted edge when the correlation exceeds a preset threshold includes: when the overall correlation score S_AB is greater than the preset threshold, establishing an edge between TableA and TableB, and using S_AB as the weight of the edge; The step of decomposing the query into semantic units and encoding them into query vectors includes: performing word segmentation and dependency parsing on the user's natural language query, extracting noun phrases, verb phrases and entities in the query as semantic units, and inputting each semantic unit into a semantic encoding model to generate a corresponding query vector; The process of searching for matching columns in the column vector index includes: calculating the cosine similarity between each query vector and the column-level semantic vectors in the pre-built column vector index, recalling columns with similarity exceeding a preset threshold as matching columns, and recording the similarity score of each matching column.

[0014] In one embodiment of the present invention, determining the seed table set based on the matching score includes: For each data table, the sum of the similarity scores of all matching columns in the data table is used as the initial score (InitialScore) for that data table. Sort all data tables from highest to lowest based on their initial scores, and select the top N data tables as the seed table set.

[0015] In one embodiment of the present invention, the breadth-first expansion in the weighted pattern graph starting from the seed table includes: starting from each data table in the seed table set, performing a 1-hop breadth-first search in the weighted pattern graph, expanding only along connections with edge weights higher than a preset threshold, and forming candidate subgraphs from all data tables and their connecting edges visited during the expansion process. The process of running a personalized ranking algorithm to sort the candidate tables includes: running a personalized PageRank algorithm on the candidate subgraph, using the initial score of the seed table as a personalized vector, iteratively calculating the PageRank score of each candidate table, and outputting the Top-K data table and its associated paths and key column explanations according to the PageRank score from high to low.

[0016] In one embodiment of the present invention, constructing the reinforcement learning agent includes: A dual-tower encoding structure is constructed, in which a text encoder is used to encode the current query to obtain query features, and a graph encoder is used to encode the sorted candidate table subgraph to obtain graph structure features. The query features and graph structure features are fused through a gating attention mechanism to obtain a state representation. The action output by the agent is defined as a quadruple, which includes action type, source node, target node, and weight adjustment value. Action type includes creating an edge, deleting an edge, adjusting weight, or keeping it unchanged.

[0017] In one embodiment of the present invention, the calculation of reward based on the impact of the action on the real query result includes: obtaining the set of real target tables involved in the real structured query statement corresponding to the historical query, determining whether the action has enhanced the connection strength between the data tables in the set of real target tables, and if so, giving a positive reward; otherwise, giving a negative reward. The optimization of the agent through updating the strategy using relative advantage within the group includes: using the GRPO algorithm to calculate the relative advantage value of each action within each group of sampled trajectories, and updating the agent's policy network parameters based on the relative advantage value.

[0018] In one embodiment of the present invention, the method further includes: During the inference phase, the policy network of the reinforcement learning agent and the graph structure of the weighted pattern graph are frozen and used only for retrieving and sorting candidate lists. During the offline phase, the weighted pattern graph is updated in batches based on batch historical queries and their corresponding real structured query statements; During the online phase, graph structure updates are triggered at a lower frequency than preset, and version management is performed on the graph structure after each update.

[0019] In one embodiment of the present invention, the method further includes: The sorted target table set and the user's natural language query are input into the large language model, which then generates a corresponding structured query statement based on the table structure information in the target table set and the user's natural language query.

[0020] The database pattern graph construction and retrieval method of this invention can improve the construction accuracy and retrieval efficiency of database pattern graphs, reduce the computational overhead of large-scale column value matching, and achieve dynamic optimization of the graph structure through reinforcement learning, thereby improving the accuracy and stability of downstream SQL generation.

[0021] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0022] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 This is a flowchart illustrating a database pattern graph construction and retrieval method provided in an embodiment of the present invention; Figure 2 This is an architecture diagram of a database pattern graph construction and retrieval method provided in an embodiment of the present invention; Figure 3 Comparison diagram of ablation experiments provided in embodiments of the present invention; Figure 4 The figure provided in this embodiment of the invention shows a Sota result on two datasets, comparing the accuracy of downstream tasks with existing methods. Detailed Implementation

[0023] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0024] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0025] The following describes a database pattern graph construction and retrieval method according to an embodiment of the present invention, with reference to the accompanying drawings.

[0026] Example 1 This embodiment provides a method for constructing and retrieving database pattern graphs. For example... Figure 1 As shown, it includes: S1 calculates the correlation score between columns of each data table in the database.

[0027] Specifically, in the process of constructing a database schema graph, the first step is to perform correlation analysis on the columns in the various data tables that constitute the database to quantify the possible semantic or structural relationships between different columns. This method evaluates the correlation score between any two columns by comprehensively considering features across multiple dimensions. This score aims to reflect the degree of matching between the two columns in terms of data content, semantic meaning, and structural characteristics.

[0028] Specifically, the relevance score calculation integrates instance similarity of column value sets, semantic similarity of column name context, and column uniqueness metrics. Instance similarity measures the degree of overlap between two columns in terms of specific data values, capturing direct relationships based on data content. Semantic similarity assesses the closeness of two columns in terms of business meaning by analyzing column naming information and the context of their respective tables. The uniqueness metric characterizes the distinctiveness of values ​​within a column, highlighting the crucial role of columns with primary or foreign key characteristics in table joins. By integrating these multi-dimensional features, a comprehensive relevance score is generated for each pair of columns, serving as the basis for subsequent determination of relationships between tables.

[0029] As one implementation method, instance similarity can be represented by the MinHash algorithm to fingerprint the set of column values. By comparing signature similarity, Jaccard similarity can be approximately estimated, thereby transforming high-dimensional column value comparison into low-dimensional signature comparison. Semantic similarity can be achieved by concatenating the column name, the name of the table to which it belongs, and the names of other columns in the same table as context into text, inputting it into a semantic encoding model to obtain column-level semantic vectors, and measuring semantic relevance through cosine similarity. The uniqueness index can be calculated by the ratio of the number of non-empty rows in the column to the number of different values.

[0030] This step, by fusing multidimensional features to quantitatively evaluate the correlation between columns, can effectively identify potentially related column pairs, providing an accurate column-level correlation measurement basis for the subsequent construction of high-quality pattern maps, thereby avoiding the noise and accuracy loss caused by relying solely on table-level rules or simple column name matching.

[0031] S2. For any two data tables, determine the correlation between the tables based on the maximum correlation score of all column pairs between the two tables, and establish weighted edges when the correlation exceeds a preset threshold, thus constructing a weighted pattern graph with data tables as nodes and inter-table correlation as edge weights.

[0032] Specifically, when constructing a database schema graph, the graph structure needs to be built based on the inherent relationships between data tables. To this end, for any two data tables, all possible column pairs between them are first obtained. Then, using the calculated relevance scores of each column pair, a maximum value is determined and used as the basis for measuring the overall relevance between the two tables. This method of determining table relationships based on the maximum relevance of column pairs can accurately capture the key column pairs that determine table join relationships in the database. This is because, in actual database schemas, the join between two tables is often dominated by one or a few pairs of strongly related columns (such as primary / foreign key relationships or semantically highly matched columns), rather than the average or cumulative effect of all column pairs. When the maximum relevance score exceeds a preset threshold, a valid relationship is determined between the two data tables, and a weighted edge is established between them. The weight of this edge is the determined maximum relevance score. By traversing all data table pairs in the database and repeating the above determination and edge construction process, a weighted schema graph with data tables as nodes and inter-table relevance scores as edge weights is finally constructed.

[0033] As one implementation method, the overall correlation score between the two tables can be expressed as: ,in This is the relevance score between column k in table A and column l in table B. This score can be calculated by combining the instance similarity of the column value set, the semantic similarity of the column name context, and the uniqueness index of the column.

[0034] This step effectively avoids noise introduced by irrelevant column pairs by using the maximum relevance of column pairs as the criterion for determining inter-table associations. This results in a sparser and more information-dense pattern graph structure, thereby improving the accuracy of the graph and subsequent retrieval efficiency. Simultaneously, the edge-building mechanism based on preset thresholds provides adjustable flexibility for graph construction, adapting to the size and semantic complexity of different databases.

[0035] S3 receives the user's natural language query, decomposes the query into semantic units and encodes them into query vectors, searches for matching columns in the column vector index, determines the seed table set based on the matching score, performs breadth-first expansion in the weighted pattern graph starting from the seed table, runs a personalized sorting algorithm to sort the candidate tables, and outputs the sorted target table set.

[0036] Specifically, upon receiving a query from a user expressed in natural language, the query is first semantically decomposed into multiple smaller, more basic semantic units, which can independently reflect column-level concepts or attributes in the database.

[0037] Subsequently, a pre-trained semantic encoding model is used to encode each semantic unit into a query vector in a high-dimensional space. By performing a similarity search between each query vector and a pre-built column vector index, a set of semantically most matching candidate columns and their corresponding similarity scores are retrieved for each query vector. Based on this, for each data table in the database, the similarity scores of all matched candidate columns in that table are aggregated, thus assigning an initial relevance score to the table. This score reflects the overall semantic relevance of the table to the user's query. Based on this initial score, several tables with the highest scores are selected from all data tables as a seed table set, which forms the starting point for subsequent graph retrieval.

[0038] Next, using each table in the seed table set as a starting node, a breadth-first expansion is performed on a pre-constructed weighted pattern graph. This expansion process proceeds along edges in the graph with weights higher than a preset threshold, thereby including tables with strong correlations to the seed table in the candidate scope, forming a candidate subgraph. Finally, a personalized ranking algorithm is run on this candidate subgraph. This algorithm uses the initial score of the seed table as a personalized vector to reorder all table nodes in the candidate subgraph, outputting a sorted target table set. The tables in this set are arranged from high to low in terms of comprehensive relevance to the user query, and include the association path and key column information between them and the seed table to provide interpretable search results.

[0039] In one implementation, the semantic decomposition breaks down the user query into independent words or phrases; the column vector index is constructed based on the semantic vectors of column names and their context text; the initial score is obtained by summing the similarity scores of each hit column; the breadth-first expansion adopts a 1-hop strategy; and the personalized ranking algorithm adopts a personalized PageRank algorithm.

[0040] This step significantly improves retrieval accuracy by decomposing natural language queries into fine-grained semantic units and matching them at the column level. It can accurately locate columns that are highly relevant to the query semantics, thereby accurately identifying key data tables. Simultaneously, by combining breadth-first expansion and personalized sorting of the graph, it not only utilizes the structural relationships between tables but also fully considers the personalized needs of the query. This ensures comprehensive retrieval results while achieving efficient and accurate sorting of candidate tables, effectively reducing the computational overhead of subsequent processing.

[0041] S4 constructs a reinforcement learning agent based on historical queries and their corresponding real structured query statements. With the current query and the candidate table subgraph in the sorted target table set as the state, it outputs actions such as establishing, deleting, or adjusting the weights of edges in the pattern graph. It calculates the reward based on the impact of the actions on the real query results and optimizes the agent through a relative advantage update strategy within the group to dynamically update the pattern graph structure.

[0042] Specifically, a reinforcement learning agent is constructed based on historical queries and their corresponding real structured query statements. This agent uses the current user query and the sorted candidate table subgraph as its state representation. By perceiving the semantic and structural relationships between the current query and the candidate subgraph, it outputs operation actions on the edges in the pattern graph. These actions include at least creating new edges, deleting existing edges, or adjusting the weights of existing edges, thereby achieving dynamic adjustment of the pattern graph structure. The agent's optimization process calculates reward signals based on the impact of the actions on the real query results. These reward signals are used to evaluate whether the actions help improve the accuracy of subsequent retrievals. An intra-group relative advantage update strategy is used to iteratively optimize the agent's policy network, enabling the agent to continuously learn effective graph structure adjustment patterns from historical queries. This allows the pattern graph to be dynamically updated with the evolution of query distribution and database semantics, maintaining the efficiency and accuracy of the graph structure.

[0043] As one implementation method, the agent can use a dual-tower encoding structure to process the query text and candidate subgraphs separately, and perform feature fusion through a gated attention mechanism. An action can be defined as a quadruple containing operation type, source node, target node, and adjusted weight. The reward signal can be calculated based on the consistency between the target table set in the real structured query statement and the retrieval results after the action. For example, an Oracle-Guided reward mechanism can be used. If the action enhances the connection between the real target tables, a positive reward is given; otherwise, a negative reward is given. The optimization algorithm can use Group Relative Policy Optimization (GRPO) to improve training stability and efficiency.

[0044] This step introduces a reinforcement learning agent to dynamically optimize the pattern graph, enabling the graph structure to continuously learn from historical queries and adaptively adjust. This avoids the high cost of full reconstruction required by traditional static graphs and significantly improves the graph's adaptability to changes in query distribution. At the same time, the relative advantage update strategy within groups ensures the efficiency and stability of agent training, thereby achieving continuous evolution and performance improvement of the pattern graph while reducing manual maintenance costs.

[0045] Example 2 Based on the above embodiments, this embodiment provides a detailed description of the specific implementation of calculating the correlation score between columns of each data table in the database. The specific steps are as follows: In this embodiment, the calculation of the correlation score between columns in step S1 is implemented through the following sub-steps. First, for the column value sets of each data table in the database, a fixed-length signature fingerprint is generated using the MinHash algorithm. Specifically, an independent set of hash functions is applied to each element in the column value set, the minimum hash value of each hash function is recorded, and these minimum hash values ​​are combined into a fixed-length signature vector. By comparing the proportion of equal hash values ​​at corresponding positions in two signature vectors, this proportion is used as an unbiased estimate of the Jaccard similarity of the column value sets, thereby obtaining the instance similarity score. This process transforms high-dimensional column value comparison into low-dimensional signature comparison, significantly reducing computational overhead. Second, the column name of the current column, the table name of the data table to which the current column belongs, and the column names of other columns in the data table to which the current column belongs, are concatenated into a string sequence in a preset order as context text. This string sequence is input into a pre-trained language model based on the Transformer architecture, and the vector representation of the corresponding column name position in the last hidden state is extracted as a column-level semantic vector. By calculating the cosine similarity between two column-level semantic vectors, the semantic similarity score is obtained. Next, the number of non-empty rows (total) and the number of distinct values ​​(distinct) in the column are counted. The uniqueness index is calculated using the formula uniqueness = distinct / total. This index amplifies the weight of column pairs with primary key or foreign key characteristics. Finally, the instance similarity score, semantic similarity score, and uniqueness index are weighted and fused to obtain the relevance score between columns. This fusion process can adjust the weight coefficients of each component according to the actual application scenario to balance the contributions of instance matching, semantic matching, and column uniqueness to the final relevance. Through these steps, a fine-grained quantification of inter-column relevance is achieved, providing an accurate column-level foundation for subsequent inter-table relevance determination.

[0046] This specific implementation effectively solves the computational bottleneck of large-scale column value instance matching and column name semantic understanding by introducing the MinHash algorithm and a pre-trained semantic coding model. At the same time, it enhances the identification capability of key column pairs by utilizing uniqueness indicators, thereby improving the accuracy and efficiency of column correlation calculation and laying a solid foundation for building a high-quality pattern graph.

[0047] Example 3 Based on the above embodiments, this embodiment describes in detail the specific implementation of "for any two data tables, determining the correlation between the tables based on the maximum correlation score of all column pairs between the two tables, and establishing weighted edges when the correlation exceeds a preset threshold, constructing a weighted pattern graph with data tables as nodes and inter-table correlation as edge weights". The specific steps are as follows: In this embodiment, the specific implementation of determining the inter-table correlation based on the maximum correlation score of all column pairs between the two tables in step S2 is as follows. For any two data tables, denoted as the first data table TableA and the second data table TableB, firstly, obtain the column correlation scores between all columns in TableA and all columns in TableB calculated in step S1. These scores are stored in matrix form, where each element... This represents the relevance score between column k of Table A and column l of Table B. Subsequently, the relevance scores of all column pairs are extracted from this matrix, and the maximum value is taken as the overall relevance score between the two tables. Its mathematical expression is This maximum value operation effectively identifies the key column pairs that determine the join relationship between two tables, avoiding underestimation of the true relationship between tables due to interference from a large number of low-correlation column pairs. This is achieved by obtaining the overall relevance score. Then, it is compared with a preset threshold. This threshold can be determined through validation set tuning based on database size or business needs, for example, set to 0.5 or 0.6. When When the value exceeds the preset threshold, it is determined that there is a correlation between TableA and TableB, and a weighted edge is established between them. The weight of the edge is... By traversing all table pairs in the database and repeating the above process, a weighted pattern graph is finally constructed, with data tables as nodes and inter-table correlations as edge weights. This construction method ensures that each edge in the graph corresponds to at least one pair of highly correlated columns, thus accurately depicting the key connections between tables while maintaining the sparsity of the graph structure.

[0048] The beneficial effects of the above specific implementation method are as follows: by taking the maximum value of the correlation score of the column pair as the inter-table correlation, the key column pairs that determine the table join can be accurately captured, and noisy joins can be effectively filtered out, thereby constructing a weighted pattern graph with high information density and sparse structure, providing a high-quality basic structure for subsequent graph retrieval and dynamic optimization.

[0049] Example 4 Based on the above embodiments, this embodiment describes in detail the specific implementation of receiving a user's natural language query, decomposing the query into semantic units and encoding them into query vectors, searching for matching columns in the column vector index, determining a seed table set based on the matching score, performing breadth-first expansion in the pattern graph starting from the seed table, running a personalized ranking algorithm to sort the candidate tables, and outputting the sorted target table set. The specific steps are as follows: In this embodiment, the process of decomposing the query into semantic units and encoding them into query vectors in step S3 is as follows: First, the user-input natural language query statement is received. The query statement is then segmented and subjected to dependency parsing. The core semantic components in the query are identified through syntactic structure, including noun phrases, verb phrases, and entity names. These components are treated as independent semantic units. For example, for the query "Query customers whose sales revenue in 2023 is greater than 1 million and their orders," dependency parsing can extract semantic units such as "2023," "sales revenue," "greater than 1 million," "customers," and "orders." Subsequently, each semantic unit is input into a pre-trained semantic encoding model. This model can employ a pre-trained language model based on the Transformer architecture, such as BERT or its lightweight variant, mapping each semantic unit to a dense vector of fixed dimensions, thereby generating the corresponding query vector. Each query vector retains the positional information of the semantic unit in the semantic space for subsequent similarity matching.

[0050] The process of searching for matching columns in the column vector index is as follows. The pre-built column vector index stores the column-level semantic vectors of each column in the database. These vectors are generated in step S1 by concatenating the column name, the name of the table to which it belongs, and the names of other columns in the same table into context text, and then inputting this text into the same semantic encoding model. The cosine similarity is calculated between each query vector and all column-level semantic vectors in the column vector index to obtain a similarity score between each query vector and each column vector. A preset threshold is set, for example, 0.6, and only columns with similarities exceeding this threshold are retained as matching columns, and the similarity score corresponding to each matching column is recorded. In cases where the same column may be matched by multiple query vectors, the highest similarity score is taken as the final matching score for that column.

[0051] The specific method for determining the seed table set based on the matching score is as follows: For each data table in the database, the sum of the similarity scores of all matching columns in that data table is calculated, and this sum is defined as the initial score of that data table, i.e. ,in Representation Table The set of all matching columns in the set. For example The matching score. Sort all data tables from highest to lowest according to the initial score, and select the top N data tables as the seed table set, where N is a preset parameter, for example, a value of 10.

[0052] The process of breadth-first expansion in the pattern graph, starting from the seed table, is as follows: Each data table in the seed table set is used as a starting node, and a 1-hop breadth-first search is performed in the weighted pattern graph constructed in step S2. During the expansion, only connections with edge weights higher than a preset threshold are traversed. This edge weight threshold can be consistent with the threshold used to establish the edges in step S2, for example, 0.5. All data tables visited during the expansion and the connecting edges between them together constitute a candidate subgraph. This candidate subgraph includes neighboring tables that are strongly correlated with the seed table, while eliminating weak connection noise.

[0053] The process of running the personalized ranking algorithm on the candidate subgraph is as follows: A personalized PageRank algorithm is used to sort all data tables in the candidate subgraph. The initial scores of the seed tables are normalized and used as personalized vectors; that is, the personalized weight of each seed table is its initial score divided by the sum of the initial scores of all seed tables. The PageRank score of each data table is iteratively calculated on the candidate subgraph using the following formula: ,in This is the damping coefficient, typically taken as 0.85. For nodes The personalized vector value (this value is 0 for non-seed table nodes). Pointing to a node The set of neighboring nodes, For nodes The out-degree of the target table is determined. After iteration to convergence, the Top-K data table is output in descending order of PageRank score. At the same time, the association path (i.e. the edge sequence traversed) between each target table and the seed table is output, along with the explanation of the key columns. The explanation of the key columns is the column pair that contributes the most to the matching process and its similarity score.

[0054] Through the aforementioned semantic decomposition and column-level matching mechanism, this invention can accurately locate the semantic units involved in the user query, efficiently recall relevant columns using column vector indexes, and then significantly reduce computational overhead while ensuring retrieval accuracy through initial score aggregation and personalized PageRank sorting, thus achieving efficient retrieval and sorting of large-scale database patterns.

[0055] Example 5 Based on the above embodiments, this embodiment constructs a reinforcement learning agent based on historical queries and their corresponding real structured query statements. The agent takes the current query and the sorted candidate table subgraph as its state, outputs actions such as creating, deleting, or adjusting the weights of edges in the pattern graph, and calculates rewards based on the impact of the actions on the real query results. The agent is optimized through a relative advantage update strategy within the group. The specific implementation of dynamically updating the pattern graph structure is described in detail below: In this embodiment, the specific implementation of constructing the reinforcement learning agent in step S4 is as follows. First, a dual-tower encoding structure is constructed, which includes a text encoder and a graph encoder. The text encoder receives the user's current natural language query q as input and encodes it into a query feature vector using a pre-trained language model (e.g., BERT). This vector captures the semantic information of the query. The graph encoder receives the sorted candidate table subgraph G_k as input. This subgraph is composed of the Top-K candidate tables output in step S3 and their associated paths and key columns. The graph encoder uses a graph neural network (e.g., GCN or GAT) to encode the features of each node in the subgraph and the edge weights between nodes, outputting a graph structure feature vector. This vector reflects the topological relationships and connection strengths between the candidate tables. Subsequently, a gated attention mechanism is used to fuse query features with graph structure features. Specifically, the gated attention mechanism calculates the attention weight of the query features on each node feature in the graph structure features, and performs a weighted summation of the graph structure features based on this weight. A gating unit is introduced to control the fusion ratio of the query features and the weighted graph structure features, ultimately yielding a state representation vector. This vector integrates the query intent and the structural information of the current subgraph, serving as the basis for the agent's decision-making. The action output by the agent is defined as a quadruple (Type, Src, Dst, Weight), where Type represents the action type, including creating an edge, deleting an edge, adjusting weights, or keeping it unchanged; Src and Dst represent the source and target nodes involved in the action, i.e., the data table in the candidate subgraph; Weight represents the weight adjustment value. When Type is adjusting weights, this value specifies the new value of the edge weight; when Type is creating an edge, this value specifies the initial weight of the new edge; when Type is deleting an edge or keeping it unchanged, this value is set to invalid. For reward calculation, the set of real target tables (Gold Tables) involved in the real structured query statements (i.e., real SQL) corresponding to historical queries is obtained. It is then determined whether the agent's output action strengthens the connection strength between the data tables in this set of real target tables. Specifically, if the action establishes a new edge between Gold Tables or increases the weight of an existing edge, it is considered to have strengthened the connection strength and is given a positive reward; if the action deletes an edge between Gold Tables or reduces its weight, a negative reward is given; if the action does not affect the connection between Gold Tables, the reward is zero. For policy updates, the GRPO algorithm is used. This algorithm calculates the relative advantage value of each action within each set of sampled trajectories. Specifically, for multiple sampled trajectories within the same set, the cumulative reward of each trajectory is calculated. Using the average reward within the set as a baseline, the advantage value of each action is equal to the cumulative reward of its trajectory minus the average reward within the set. Based on this relative advantage value, the agent's policy network parameters are updated using the policy gradient method, thereby improving learning efficiency while ensuring training stability.Through the above mechanism, the intelligent agent can dynamically adjust the edge structure of the pattern graph based on historical query knowledge, so that the graph evolves from a static structure into a continuously optimized dynamic knowledge carrier.

[0056] This implementation achieves deep integration of query and graph structure through dual-tower coding and gated attention mechanism. Combined with Oracle-Guided reward and GRPO algorithm, it enables the agent to accurately optimize the graph structure based on the real query results, significantly improving the retrieval accuracy and adaptability of the pattern graph, while reducing manual maintenance costs.

[0057] In this embodiment, the specific operational strategies for different operational stages are further refined for the dynamic optimization process of the weighted pattern graph by the reinforcement learning agent. Specifically, the system divides the operation process into an inference stage, an offline stage, and an online stage, and adopts differentiated processing logic in each stage to balance retrieval efficiency, update cost, and graph structure stability.

[0058] During the inference phase, the system receives the current natural language query input by the user and obtains the weighted pattern graph structure at the current time. At this point, the policy network of the reinforcement learning agent is completely frozen, its network parameters are no longer updated, and the graph structure of the weighted pattern graph remains fixed. The system uses only this frozen policy network and fixed graph structure to perform retrieval and ranking operations on the candidate table. Specifically, the system first decomposes the user query into semantic units and encodes them into query vectors, searches for matching columns in the column vector index, and determines the seed table set based on the matching score. Then, starting from the seed table, it performs breadth-first expansion in the frozen weighted pattern graph and runs a personalized PageRank algorithm to rank the candidate tables, outputting the ranked target table set. No graph structure modifications or policy network updates are performed during this phase, thus ensuring the stability and low latency of the retrieval process.

[0059] In the offline phase, the system collects a batch of historical queries and their corresponding real structured query statements (e.g., SQL statements) to form batch training data. Using these historical queries as input, the system combines them with the current weighted pattern graph to construct the state of the reinforcement learning agent, which consists of the current query and the sorted candidate table subgraph. The agent outputs actions based on its policy network. These actions are defined as quadruples, including type, source node, target node, and weight, supporting operations such as creating edges, deleting edges, or adjusting weights. The system calculates rewards based on the Gold Tables in the real structured query statements; a positive reward is given if the action strengthens the connections between Gold Tables, otherwise a negative reward is given. Subsequently, the agent's policy network is optimized using the Relative Advantage Update (GRPO) algorithm, and the weighted pattern graph is updated in batches based on the optimized policy, i.e., the existence or weight of multiple edges are adjusted simultaneously. This phase allows for significant modifications to the graph structure to incorporate real table join knowledge contained in the historical queries.

[0060] During the online phase, the system triggers graph structure updates at a lower-than-preset frequency. For example, an update can be triggered every 24 hours or after processing 1000 queries. When the triggering condition is met, the system collects a small amount of historical query data accumulated since the last update and performs a reinforcement learning update process similar to the offline phase, but with a smaller update scope, only fine-tuning the graph structure. After each update, the system performs version management on the updated weighted pattern graph, assigning a unique version identifier to each version of the graph structure and recording the update timestamp, a summary of changes, and the set of queries that triggered the update. Version management supports graph structure rollback and comparative analysis, ensuring rapid recovery to the previous stable version in case of update anomalies.

[0061] Through the aforementioned phased processing mechanism, the system ensures the efficiency and stability of retrieval during the reasoning phase, achieves batch optimization of the graph structure during the offline phase, continuously absorbs new knowledge through low-frequency fine-tuning during the online phase, and ensures the traceability and reliability of the graph structure through version management.

[0062] This implementation effectively reduces the computational overhead of online retrieval by adopting a phased freezing and updating strategy, avoiding performance fluctuations caused by frequent updates. At the same time, by combining offline batch updates with online low-frequency fine-tuning, the weighted pattern map can continuously absorb historical query knowledge, achieving a smooth transition from a static structure to a dynamic evolutionary carrier, and significantly improving the system's adaptability and stability in continuously evolving scenarios.

[0063] In this embodiment, after step S4, the system further includes inputting the sorted target table set and the user's natural language query into a large language model. The large language model then generates a corresponding structured query statement based on the table structure information in the target table set and the user's natural language query. Specifically, after obtaining the sorted target table set through a personalized sorting algorithm, the system concatenates the schema information of each data table in the target table set, including table name, column name, column data type, primary and foreign key constraints, and the relationship paths and key column explanations between tables, with the user's original natural language query to form a structured prompt text. This prompt text is fed into the large language model, which utilizes its powerful semantic understanding and code generation capabilities to parse the user's query intent and, based on the provided table structure information, infers the required data columns, table join relationships, and filtering conditions, ultimately generating a structured query statement that conforms to SQL syntax. In one possible implementation, the number of tables in the target table set is limited to a preset Top-K, for example, K is 10, thereby effectively controlling the context length input to the large language model and avoiding increased inference costs and decreased generation stability due to excessive input of table structure information. The structured query statements output by the large language model are the final SQL statements used to perform data retrieval in the database. By using the set of highly relevant tables filtered through graph retrieval and sorting as input to the large language model, the range of patterns that the model needs to process is significantly reduced, and the difficulty of reasoning in a large number of irrelevant tables is reduced, thereby improving the accuracy and efficiency of SQL generation.

[0064] This specific implementation combines the set of highly relevant tables selected by graph retrieval with a large language model, which significantly reduces the range of patterns that the model needs to process, lowers the inference cost, and improves the accuracy and stability of generating structured query statements.

[0065] Example 6 Figure 2 This is an architecture diagram of the database pattern graph construction and retrieval method of the present invention, such as... Figure 2 As shown, this invention constructs a table-level pattern graph, using tables in a database as nodes and inter-table correlations as weighted edges. It achieves efficient table recall through column-level correlation modeling, graph retrieval, and personalized ranking, and introduces a reinforcement learning agent to dynamically optimize the graph structure. Finally, the selected set of highly correlated tables, along with the user query, is input into a large model to generate the final SQL statement.

[0066] Specifically, for any two data tables, Table A and Table B, a correlation is determined when they have at least one pair of "high-scoring join columns." To avoid meaningless calculations, the columns are first filtered to remove weakly discriminative columns such as timestamps and constant identifiers. Let Table A have N columns after filtering, and Table B have M columns. The overall correlation score between the two tables is defined as:

[0067] This design aligns with the common practice in databases where table joins are typically determined by a pair of primary and foreign keys or key semantic columns, effectively reducing interference from irrelevant column pairs and improving retrieval efficiency.

[0068] Column relevance is defined as:

[0069] in: Instance similarity: The MinHash algorithm is used to fingerprint the column value set, and the Jaccard similarity is approximately estimated by comparing signature similarity. This method utilizes the mathematical property that the minimum hash collision probability is equivalent to set similarity, transforming high-dimensional column value comparison into low-dimensional signature comparison, which is particularly suitable for database columns with a huge number of rows.

[0070] Semantic similarity: The column name, the name of the table to which it belongs, and the names of other columns in the same table are concatenated into text as context, input into the semantic encoding model to obtain column-level semantic vectors, and the semantic relevance is measured by cosine similarity.

[0071] Column Uniqueness: This metric amplifies the weight of column pairs with primary key or foreign key characteristics. It calculates the uniqueness index by counting the number of non-empty rows and the number of distinct values ​​in a column.

[0072] when When the threshold is exceeded, a weighted edge is created between table A and table B, and the edge weight is... This allows for the construction of a weighted schema graph.

[0073] Furthermore, the user's natural language query is broken down into smaller semantic units, each of which is encoded as a query vector. A similarity search is then performed in the column vector index to obtain candidate columns and their matching scores. Finally, the sum of the similarity scores of the matched columns in each table is calculated, and an initial score is defined:

[0074] The top-N tables with the highest scores are selected as the seed table set. Starting from the seed tables, a 1-hop breadth-first search is performed in the schema graph, expanding only along connections with edge weights higher than a threshold to form candidate subgraphs. A personalized PageRank algorithm is run on the candidate subgraphs, using the initialScore of the seed tables as a personalized vector to sort all candidate tables, outputting the top-K tables and their associated paths and key column explanations.

[0075] This invention designs a reinforcement learning feedback mechanism for dynamic graphs, constructing an agent whose state is determined by user query q and the current Top-K candidate subgraph. Composition. The agent employs a dual-tower coding structure, including a text encoder and a graph encoder, and uses a gated attention mechanism for feature fusion. The action output by the agent is defined as a quadruple. It supports operations such as creating edges, deleting edges, adjusting weights, or keeping them unchanged. It employs an Oracle-Guided Reward system, judging the merit of actions based on the Gold Tables in the actual SQL. Positive rewards are given for strengthening connections between Gold Tables, and negative rewards are given otherwise. The GRPO algorithm is used to update the strategy based on relative advantage within the group, improving learning efficiency while ensuring training stability. During the inference phase, the strategy and graph structure are frozen and used only for retrieval and ranking; batch updates of the graph structure are allowed in the offline phase; and updates are triggered infrequently and managed in a versioned manner in the online phase.

[0076] Compared with the prior art, the present invention has the following advantages: (1) Improves the accuracy and efficiency of table retrieval by modeling the maximum relevance at the column level; (2) Effectively solves the computational bottleneck of matching large-scale column value instances by using MinHash technology; (3) Continuously absorbs historical query knowledge through reinforcement learning mechanism, so that the schema diagram evolves from a static structure into a dynamic knowledge carrier; (4) Reduces the schema range of large model processing, thereby reducing inference costs and improving the stability of SQL generation.

[0077] Further Figure 3 This is a comparative effect of the ablation experiment of the present invention; Figure 4 This is a comparison of the accuracy of our method with existing methods in downstream tasks, achieving Sota results on both datasets.

[0078] The database pattern graph construction and retrieval method of this invention can improve the construction accuracy and retrieval efficiency of database pattern graphs, reduce the computational overhead of large-scale column value matching, and achieve dynamic optimization of the graph structure through reinforcement learning, thereby improving the accuracy and stability of downstream SQL generation.

[0079] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

[0080] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0081] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

Claims

1. A method for constructing and retrieving database pattern graphs, characterized in that, include: Calculate the correlation score between columns in each table of the database; For any two data tables, the correlation between the tables is determined based on the maximum correlation score of all column pairs between the two tables, and weighted edges are established when the correlation exceeds a preset threshold, thus constructing a weighted pattern graph with data tables as nodes and inter-table correlation as edge weights. The system receives natural language queries from users, decomposes the queries into semantic units and encodes them into query vectors, searches for matching columns in the column vector index, determines the seed table set based on the matching score, performs breadth-first expansion in the weighted pattern graph starting from the seed table, runs a personalized sorting algorithm to sort the candidate tables, and outputs the sorted target table set. Based on historical queries and their corresponding real structured query statements, a reinforcement learning agent is constructed. With the current query and the candidate table subgraph in the sorted target table set as the state, the agent outputs actions such as creating, deleting, or adjusting the weights of edges in the pattern graph. The reward is calculated based on the impact of the actions on the real query results. The agent is optimized through a relative advantage update strategy within the group to dynamically update the pattern graph structure.

2. The method as described in claim 1, characterized in that, The relevance score integrates instance similarity of column value sets, semantic similarity of column name context, and column uniqueness index; the calculation of the relevance score between columns includes: A fixed-length signature fingerprint is generated using the MinHash algorithm on the column value set of the data table. The Jaccard similarity between the column value sets is approximately estimated by comparing the collision probability of the signature fingerprints, and the instance similarity score is obtained. The column name, the name of the table to which it belongs, and the names of other columns in the same table are concatenated into the context text, which is then input into a pre-trained semantic encoding model to generate column-level semantic vectors. The semantic similarity score is obtained by calculating the cosine similarity between the column-level semantic vectors. The number of non-empty rows and the number of different values ​​in the statistical column are counted, and the ratio of the number of different values ​​to the number of non-empty rows is used as a uniqueness indicator. The instance similarity score, the semantic similarity score, and the uniqueness index are weighted and fused to obtain the relevance score between columns.

3. The method as described in claim 2, characterized in that, The step of generating a fixed-length signature fingerprint from the column value set of the data table using the MinHash algorithm includes: applying a set of independent hash functions to each element in the column value set, recording the minimum hash value of each hash function, and combining the minimum hash values ​​into a fixed-length signature vector; The method of approximating the Jaccard similarity between column value sets by comparing the collision probabilities of signature fingerprints includes: calculating the proportion of corresponding positions with equal hash values ​​in the two signature vectors, and using this proportion as an unbiased estimate of the Jaccard similarity of the column value sets; The step of concatenating the column name, the table name, and other column names in the same table into context text includes: concatenating the column name of the current column, the table name of the data table to which the current column belongs, and the column names of other columns in the data table containing the current column in a preset order into a string sequence; The process of generating column-level semantic vectors by inputting the pre-trained semantic coding model includes: inputting the string sequence into a pre-trained language model based on the Transformer architecture, and extracting the vector representation of the corresponding column name position in the last hidden state as the column-level semantic vector; The uniqueness index is calculated by taking the ratio of the number of non-empty rows and the number of distinct values ​​in the statistical column. This ratio includes the total number of non-empty rows and the distinct number of distinct values ​​in the statistical column. The uniqueness index is calculated using the formula uniqueness = distinct / total.

4. The method as described in claim 1, characterized in that, The method of determining the inter-table correlation based on the maximum correlation score of all column pairs between the two tables includes: for the first data table TableA and the second data table TableB, obtaining the correlation scores between all columns in TableA and all columns in TableB, and taking the maximum value of the correlation scores of all column pairs as the overall correlation score S_AB of the two tables; The step of establishing a weighted edge when the correlation exceeds a preset threshold includes: when the overall correlation score S_AB is greater than the preset threshold, establishing an edge between TableA and TableB, and using S_AB as the weight of the edge; The step of decomposing the query into semantic units and encoding them into query vectors includes: performing word segmentation and dependency parsing on the user's natural language query, extracting noun phrases, verb phrases and entities in the query as semantic units, and inputting each semantic unit into a semantic encoding model to generate a corresponding query vector; The process of searching for matching columns in the column vector index includes: calculating the cosine similarity between each query vector and the column-level semantic vectors in the pre-built column vector index, recalling columns with similarity exceeding a preset threshold as matching columns, and recording the similarity score of each matching column.

5. The method as described in claim 4, characterized in that, Determining the seed table set based on the matching score includes: For each data table, the sum of the similarity scores of all matching columns in the data table is used as the initial score (InitialScore) for that data table. Sort all data tables from highest to lowest based on their initial scores, and select the top N data tables as the seed table set.

6. The method as described in claim 4, characterized in that, The breadth-first expansion in the weighted pattern graph starting from the seed table includes: starting from each data table in the seed table set, performing a 1-hop breadth-first search in the weighted pattern graph, expanding only along connections with edge weights higher than a preset threshold, and forming candidate subgraphs from all data tables and their connecting edges visited during the expansion process. The process of running a personalized ranking algorithm to sort the candidate tables includes: running a personalized PageRank algorithm on the candidate subgraph, using the initial score of the seed table as a personalized vector, iteratively calculating the PageRank score of each candidate table, and outputting the Top-K data table and its associated paths and key column explanations according to the PageRank score from high to low.

7. The method as described in claim 1, characterized in that, The construction of the reinforcement learning agent includes: A dual-tower encoding structure is constructed, in which a text encoder is used to encode the current query to obtain query features, and a graph encoder is used to encode the sorted candidate table subgraph to obtain graph structure features. The query features and graph structure features are fused through a gating attention mechanism to obtain a state representation. The action output by the agent is defined as a quadruple, which includes action type, source node, target node, and weight adjustment value. Action type includes creating an edge, deleting an edge, adjusting weight, or keeping it unchanged.

8. The method as described in claim 10, characterized in that, The calculation of rewards based on the impact of actions on real query results includes: obtaining the set of real target tables involved in the real structured query statements corresponding to the historical queries, determining whether the action has enhanced the connection strength between data tables in the set of real target tables, and giving a positive reward if it has enhanced the connection strength, otherwise giving a negative reward. The optimization of the agent through updating the strategy using relative advantage within the group includes: using the GRPO algorithm to calculate the relative advantage value of each action within each group of sampled trajectories, and updating the agent's policy network parameters based on the relative advantage value.

9. The method as described in claim 1, characterized in that, The method further includes: During the inference phase, the policy network of the reinforcement learning agent and the graph structure of the weighted pattern graph are frozen and used only for retrieving and sorting candidate lists. During the offline phase, the weighted pattern graph is updated in batches based on batch historical queries and their corresponding real structured query statements; During the online phase, graph structure updates are triggered at a lower frequency than preset, and version management is performed on the graph structure after each update.

10. The method as described in claim 1, characterized in that, The method further includes: The sorted target table set and the user's natural language query are input into the large language model, which then generates a corresponding structured query statement based on the table structure information in the target table set and the user's natural language query.