Mode linking method and device, electronic equipment and storage medium
By using intelligent agents to interact with databases in multiple rounds to filter pattern information, the problem of reduced response time and low accuracy of pattern linking in cross-domain database text-to-SQL conversion is solved, achieving efficient and accurate pattern linking and SQL generation.
Patent Information
- Application Number
- CN202511715274.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-20
- Publication Date
- 2026-02-24
AI Technical Summary
Existing technologies significantly reduce the response time of text-to-SQL conversion when dealing with cross-domain, heterogeneous, or ultra-large-scale databases, and the lack of dynamic exploration and feedback mechanisms in pattern linking algorithms leads to low accuracy and recall rates in pattern linking.
By interacting with the database in multiple rounds, the agent filters pattern information related to the text to be queried. Through exploration, retrieval, verification and addition actions, the pattern subset is dynamically updated to generate the SQL statement corresponding to the text to be queried, thus avoiding inputting the complete pattern information of the database into the SQL generation model.
It reduces the computational and memory pressure on SQL generation models, improves the accuracy and recall of schema linking, and enhances the efficiency and accuracy of text-to-SQL conversion, making it suitable for large-scale complex database scenarios.
Smart Images

Figure CN121560899A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of database technology, specifically to a schema linking method and apparatus, electronic device and storage medium. Background Technology
[0002] The Text-to-SQL task aims to enable systems to understand user queries presented in natural language and automatically convert them into corresponding structured database query statements (SQL) to retrieve relevant results from the database. This task requires algorithms to possess comprehensive capabilities including natural language understanding, database structure awareness, semantic alignment, and inference decision-making, representing a key direction for the deep integration of natural language processing and database technologies.
[0003] In related technologies, when performing text-to-SQL tasks, it is often necessary to input the query question in natural language form and the complete database schema information into the SQL generation model so that the SQL generation model can generate SQL statements to achieve the text-to-SQL conversion. However, this conversion method is difficult to cope with the computational and memory pressure brought about by the expansion of database size, especially in real-world applications when facing cross-domain, heterogeneous, or ultra-large-scale databases, the system response time drops significantly. Summary of the Invention
[0004] To overcome the problems existing in the related technologies, the present disclosure provides a pattern linking method and apparatus, electronic device and storage medium to solve the defects in the related technologies.
[0005] According to a first aspect of the present disclosure, a pattern linking method is provided, the method comprising: Based on the first version of the query text and the pattern subset, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database, and links the target version of the pattern subset obtained from the interaction with the query text, wherein the pattern subset includes some pattern information from the database; In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
[0006] In one possible embodiment of this disclosure, the set of actions generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action; The exploration action includes executing an SQL query against the data environment to determine at least one candidate column; The retrieval action includes performing a retrieval based on the text to be queried against the pattern environment to determine at least one candidate column; The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are related to the text to be queried. The adding action includes adding the candidate columns related to the text to be queried to the pattern subset, so as to update the version of the pattern subset; The termination action includes determining the current version of the pattern subset as the target version and determining the current round as the last round.
[0007] In one possible embodiment of this disclosure, the retrieval action includes retrieving the K columns with the highest similarity to the text to be queried within the pattern environment, and determining all K columns as candidate columns, wherein K is an integer greater than 0.
[0008] In one possible embodiment of this disclosure, the verification action further includes executing an SQL query against the data environment to determine whether the current version of the pattern subset satisfies the linking requirements of the text to be queried, and what fields are still missing in the current version of the pattern subset.
[0009] In one possible embodiment of this disclosure, if the execution result of the previous round indicates that the current version of the pattern subset has met the linking requirements of the text to be queried, then the agent generates a set of actions including a termination action in the current round.
[0010] In one possible embodiment of this disclosure, if the number of completed rounds meets a preset threshold, the agent generates a set of actions, including a termination action, in the current round.
[0011] In one possible embodiment of this disclosure, the agent generates a reasoning trajectory and a set of actions based on the historical information of the current round, executes the set of actions for the data environment and / or the mode environment and obtains the execution result, and adds the reasoning trajectory, the set of actions and the execution result to the historical information.
[0012] In one possible embodiment of this disclosure, the first version of controlling the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the data, based on the query text and a subset of patterns, includes: Based on all table names in the database, the text to be queried, and the first version of a subset of patterns, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database.
[0013] In one possible embodiment of this disclosure, the step of controlling the agent to perform multiple rounds of interaction with the database's data environment and / or pattern environment based on a first version of all table names, the text to be queried, and a subset of patterns in the database includes: The agent is input with all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instructions to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database. The prompting instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompting instruction as historical information for the first round. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result.
[0014] In one possible embodiment of this disclosure, the method further includes: Within the pattern environment, retrieve the N columns with the highest similarity to the text to be queried, and determine the N columns as the first version of the pattern subset, where N is an integer greater than 0.
[0015] In one possible embodiment of this disclosure, the method further includes: The schema environment is constructed based on the encoding results of information in all columns of the database.
[0016] In one possible embodiment of this disclosure, the method further includes: The completed link to the query text and the target version of the pattern subset are sent to the SQL generation model so that the SQL generation model generates an SQL statement related to the query text.
[0017] According to a second aspect of the present disclosure, a pattern linking apparatus is provided, the apparatus comprising: The linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on the first version of the query text and the pattern subset, and to link the target version of the pattern subset obtained by the interaction with the query text, wherein the pattern subset includes some pattern information of the database. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
[0018] In one possible embodiment of this disclosure, the set of actions generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action; The exploration action includes executing an SQL query against the data environment to determine at least one candidate column; The retrieval action includes performing a retrieval based on the text to be queried against the pattern environment to determine at least one candidate column; The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are related to the text to be queried. The adding action includes adding the candidate columns related to the text to be queried to the pattern subset, so as to update the version of the pattern subset; The termination action includes determining the current version of the pattern subset as the target version and determining the current round as the last round.
[0019] In one possible embodiment of this disclosure, the retrieval action includes retrieving the K columns with the highest similarity to the text to be queried within the pattern environment, and determining all K columns as candidate columns, wherein K is an integer greater than 0.
[0020] In one possible embodiment of this disclosure, the verification action further includes executing an SQL query against the data environment to determine whether the current version of the pattern subset satisfies the linking requirements of the text to be queried, and what fields are still missing in the current version of the pattern subset.
[0021] In one possible embodiment of this disclosure, if the execution result of the previous round indicates that the current version of the pattern subset has met the linking requirements of the text to be queried, then the agent generates a set of actions including a termination action in the current round.
[0022] In one possible embodiment of this disclosure, if the number of completed rounds meets a preset threshold, the agent generates a set of actions, including a termination action, in the current round.
[0023] In one possible embodiment of this disclosure, the agent generates a reasoning trajectory and a set of actions based on the historical information of the current round, executes the set of actions for the data environment and / or the mode environment and obtains the execution result, and adds the reasoning trajectory, the set of actions and the execution result to the historical information.
[0024] In one possible embodiment of this disclosure, the linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the data based on a first version of the query text and a subset of patterns, for the following purposes: Based on all table names in the database, the text to be queried, and the first version of a subset of patterns, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database.
[0025] In one possible embodiment of this disclosure, the linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on all table names of the database, the text to be queried, and a first version of a subset of patterns. The module is configured to: The agent is input with all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instructions to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database. The prompting instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompting instruction as historical information for the first round. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result.
[0026] In one possible embodiment of this disclosure, the apparatus further includes an initialization module for: Within the pattern environment, retrieve the N columns with the highest similarity to the text to be queried, and determine the N columns as the first version of the pattern subset, where N is an integer greater than 0.
[0027] In one possible embodiment of this disclosure, the apparatus further includes a building module for: The schema environment is constructed based on the encoding results of information in all columns of the database.
[0028] In one possible embodiment of this disclosure, the apparatus further includes an SQL generation module for: The completed link to the query text and the target version of the pattern subset are sent to the SQL generation model so that the SQL generation model generates an SQL statement related to the query text.
[0029] According to a third aspect of the present disclosure, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the method described in the first aspect.
[0030] According to a fourth aspect of the present disclosure, an electronic device is provided, the electronic device including a memory and a processor, the memory being configured to store computer instructions executable on the processor, and the processor being configured to implement the method of the first aspect when executing the computer instructions.
[0031] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.
[0032] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects: The pattern linking method provided in this disclosure, based on the query text and a first version of a pattern subset, controls an agent to perform multiple rounds of interaction with the data environment and / or pattern environment of a database, and links the target version of the pattern subset obtained from the interaction with the query text. In each round of interaction, the agent generates an action set based on historical information of the current round, executes the action set against the data environment and / or the pattern environment, obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action. In other words, this method controls an agent to perform multiple rounds of interaction with the data environment and / or pattern environment of a database to filter pattern information related to the query text during the interaction process, and uses the filtered model information as a pattern subset to generate the SQL statement corresponding to the query text. This reduces the computational and memory pressure on the SQL generation model and improves the efficiency of text-to-SQL conversion compared to the SQL generation method in related technologies that inputs the complete pattern information of the database into the SQL generation model.
[0033] In particular, this method controls the agent to interact with the data environment and / or pattern environment of the database in multiple rounds to filter pattern information related to the query text, which can ensure the matching degree between the obtained pattern subset and the query text, thereby improving the accuracy and recall of pattern linking. Attached Figure Description
[0034] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0035] Figure 1 This is a flowchart illustrating a pattern linking method in an exemplary embodiment of this disclosure; Figure 2 This is a schematic diagram illustrating the data environment and schema environment of a database according to an exemplary embodiment of this disclosure; Figure 3This is a logical schematic diagram illustrating a pattern linking method according to an exemplary embodiment of this disclosure; Figure 4 This is a schematic diagram of the structure of a mode linking device illustrated in an exemplary embodiment of this disclosure; Figure 5 This is a structural block diagram of an electronic device illustrated in an exemplary embodiment of the present disclosure. Detailed Implementation
[0036] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0037] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The singular forms “a,” “the,” and “the” as used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0038] It should be understood that although the terms first, second, third, etc., may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are used only to distinguish information of the same type from one another. For example, without departing from the scope of this disclosure, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0039] Some related technologies use pattern linking algorithms to link the database with the query text. This involves filtering the necessary pattern information from the complete pattern information in the database, allowing the SQL generation model to input only the pattern information from the linked results, reducing computational and memory pressure. However, these pattern linking algorithms often employ static matching or one-time retrieval, using string similarity, word vector matching, or lightweight semantic retrieval to locate tables and fields relevant to the user's question. These methods generally lack dynamic exploration and feedback mechanisms, failing to correct incomplete or erroneous pattern retrieval or proactively discover potentially relevant pattern information. This not only reduces the accuracy of pattern linking but also leads to incomplete or failed SQL queries.
[0040] To address the aforementioned technical problems, in a first aspect, at least one embodiment of this disclosure provides a pattern linking method. This method enables pattern linking between a query text described in natural language and a database. Specifically, it involves an agent interacting with the database in multiple rounds to filter out partial pattern information related to the query text from the database's complete pattern information. The filtered partial pattern information can then be used, along with the query text, as input to an SQL generation model to generate SQL corresponding to the query text, thus completing the conversion of the query text from text to SQL. This method reduces the memory and computational pressure on the SQL generation model and exhibits high recall and accuracy.
[0041] This method can be applied to a text-to-SQL conversion system, which is configured with an agent for pattern linking and an SQL generation model, both of which can be large language models.
[0042] Please refer to the appendix. Figure 1 The method includes append Figure 1 Step S101 in the process.
[0043] In step S101, based on the query text and a first version of the pattern subset, the agent is controlled to perform multiple rounds of interaction with the data environment and / or pattern environment of the database, and the target version of the pattern subset obtained from the interaction is linked with the query text. The pattern subset includes some pattern information from the database. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
[0044] The query text is a question described in natural language, such as Chinese or English. The answer to the query text can only be obtained by querying data within the database.
[0045] This disclosure does not limit the type of the intelligent agent, such as the intelligent agent being any large language model.
[0046] Among them, such as Figure 2 As shown, the data environment of the database ( This provides agents with the ability to directly access databases, supporting the execution of SQL queries to explore table structures, column information, key relationships, and data samples. Execution results. The returned data is structured text, including the first 5 rows of data from a successful query, an empty result message, or an execution timeout or error message, as shown in the following formula: Among them, such as Figure 2 As shown, the schema environment of the database ( This method provides agents with the ability to retrieve pattern information, which refers to information about tables and columns in a database. For example, the method can pre-construct the pattern environment based on the encoding results of information from all columns in the database. Column information may include column name, table name, data type, description, primary and foreign key information, etc. Alternatively, a pre-trained text encoder (such as bge-large-en-v1.5) can be used to encode the column information (text) into vectors and create a vector index (Faiss) to obtain a vector database index. This vector database index supports approximate nearest neighbor search and semantic retrieval, allowing input of questions described in natural language. Return the K most relevant columns and organize them into a structured pattern fragment, as shown in the following formula: In the above formula, These are the candidate columns that have already been retrieved. Candidate columns that have already been retrieved will be excluded from the vector database index. This is a subset of the retrieved structured patterns.
[0047] The first version of the pattern subset includes multiple columns within the database. For example, the method can pre-determine the first version of the pattern subset as follows: retrieve the N columns with the highest similarity to the text to be queried within the pattern environment, and determine the N columns as the first version of the pattern subset, where N is an integer greater than 0. For example, the pattern version of the pattern subset ( )pass Acquisition: This first version was obtained through the mode environment. Retrieval is achieved through a single non-agent-driven process. This means using the text to be queried. Use it as a query to retrieve an initial set of candidate columns, thereby creating the first version. = , where N is a relatively large hyperparameter (such as 50 or 100) to ensure that the first version is a set of elements that are highly relevant to the query text but may be incomplete.
[0048] Each round can be an iterative operation performed at each time step.
[0049] For example, in at least one round of interaction, the action set generated by the agent includes interactive actions for updating the version of the pattern subset. The target version of the pattern subset can be the version obtained after at least one version update of the first version of the pattern subset. As another example, if the pattern subset is not updated in any round of interaction, then the target version of the pattern subset is the same as the first version.
[0050] For example, in each round of interaction, the agent generates a reasoning trajectory and a set of actions based on the historical information of the current round, executes the set of actions for the data environment and / or the pattern environment, obtains the execution result, and adds the reasoning trajectory, the set of actions, and the execution result to the historical information. That is, each round of interaction includes the following stages: Agent decision-making: based on current history The agent generates inference trajectories. and action set As shown in the following formula: Where π represents the prompt-based LLM strategy. Encapsulated in <think>In the label (reasoning process) Encapsulated in <actions>In the label (action sequence).
[0051] Environment execution: Environment ε receives actions And return the execution result. As shown in the following formula: Among them, environment ε includes data environment and mode environment Execution is routed based on the action type.
[0052] Historical Updates: Triplets in the Current Round ( It is added to history to form a new history, as shown in the following formula: Among them, the initial history (i.e., the historical information in the first round) is the initial state of interaction, which is constructed by the system (such as the first version containing prompts, text to be queried, all table names and a subset of the schema, which will be described in detail below and will not be repeated here).
[0053] For example, the method may also include an appendix Figure 1 Step S102 shown: The target version of the query text and the pattern subset with the completed link is sent to the SQL generation model so that the SQL generation model generates an SQL statement related to the query text.
[0054] This step only requires inputting the target version of the pattern subset obtained in step S101 into the SQL generation model, without inputting the complete pattern information of the database into the SQL generation model. This reduces the computational and memory pressure on the SQL generation model and improves the efficiency and accuracy of SQL statement generation.
[0055] The pattern linking method provided in this disclosure, based on the query text and a first version of a pattern subset, controls an agent to perform multiple rounds of interaction with the data environment and / or pattern environment of a database, and links the target version of the pattern subset obtained from the interaction with the query text. In each round of interaction, the agent generates an action set based on historical information of the current round, executes the action set against the data environment and / or the pattern environment, obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action. In other words, this method controls an agent to perform multiple rounds of interaction with the data environment and / or pattern environment of a database to filter pattern information related to the query text during the interaction process, and uses the filtered model information as a pattern subset to generate the SQL statement corresponding to the query text. This reduces the computational and memory pressure on the SQL generation model and improves the efficiency of text-to-SQL conversion compared to the SQL generation method in related technologies that inputs the complete pattern information of the database into the SQL generation model. In particular, this method controls the agent to interact with the data environment and / or pattern environment of the database in multiple rounds to filter pattern information related to the query text, which can ensure the matching degree between the obtained pattern subset and the query text, thereby improving the accuracy and recall of pattern linking.
[0056] For example, the SQL generation method in related technologies, which inputs the complete schema information of the database into the SQL generation model, relies on pre-loaded complete schema information from the database, resulting in huge resource consumption and making it difficult to apply efficiently in large-scale database scenarios. This method introduces an agent decision-making process into the large language model inference framework, eliminating the dependence on pre-loading complete schema information from the database, fundamentally reducing computational resource consumption, and improving adaptability and generalization ability in cross-domain and complex database scenarios.
[0057] For example, pattern linking algorithms in related technologies lack autonomous exploration and verification mechanisms. The pattern linking process is static and unadjustable, leading to insufficient recall and error accumulation, which severely affects the performance of downstream SQL generation and query execution. This method utilizes a large language model-driven agent to perform autonomous iterative pattern retrieval and verification, thereby achieving efficient and accurate database pattern linking and significantly improving the recall rate and query generation quality of text-to-SQL in large-scale database scenarios. Moreover, the iterative completion strategy improves pattern coverage, making it particularly suitable for complex queries and cross-table operation scenarios.
[0058] In one possible embodiment, step S101 may control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on all table names of the database, the text to be queried, and a first version of a subset of patterns.
[0059] For example, all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instruction are input into the agent to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database; wherein, the prompt instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instruction as historical information for the first round, and in each round of interaction, an action set is generated based on the historical information of the current round, the action set is executed for the data environment and / or the pattern environment and the execution result is obtained, and the historical information is updated based on the action set and the execution result.
[0060] Among these, all table names T provide the agent with the necessary structural context. Hints define the agent's goals and available actions. The first version of the pattern subset provides the agent with the foundation for constructing the pattern subset.
[0061] This embodiment defines all table names, query text, first versions of pattern subsets, and prompt instructions in the database as historical information for the first round, i.e., the initial history. This provides a decision-making basis for the agent in the first round. The initial history includes prompt instructions to instruct the agent to interact, the first version of the pattern subset as the basis for the agent to construct the pattern subset, and the structural context of the database—table names and query text input by the user. This enables the agent to initiate interaction with the database environment and explore the pattern subset, thus completing the definition and initiation of the interaction process and improving the efficiency and convenience of the method's initiation.
[0062] In one possible embodiment, the set of actions generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action.
[0063] Among them, the exploration action, the retrieval action, and the verification action are actions that provide feedback.
[0064] The exploration action includes executing an SQL query against the data environment to determine at least one candidate column. This exploration action is used to explore the database structure and data samples, and does not directly answer user questions. For example, an agent can write a simple SQL query targeting a specific column name under a specific table name, and execute this simple SQL query against the data environment to determine whether the table exists in the database and whether the column exists within that table, thus completing a targeted exploration of the database structure.
[0065] The retrieval action includes performing a retrieval based on the query text within the pattern environment to determine at least one candidate column. For example, the retrieval action includes retrieving the K columns with the highest similarity to the query text within the pattern environment, and determining all K columns as candidate columns, where K is an integer greater than 0. It should be understood that the retrieval action can use the query text itself as the query to perform semantic retrieval within the pattern environment to retrieve the K columns with the highest similarity; it can also use extended content, virtual column names, abstract concepts, etc., of the query text to perform semantic retrieval within the pattern environment to retrieve the K columns with the highest similarity.
[0066] The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are relevant to the text to be queried. The verification action attempts to execute an SQL query to verify whether one or more candidate columns are relevant to the text to be queried, i.e., whether the candidate columns need to be retained.
[0067] Preferably, the verification action further includes executing an SQL query against the data environment to determine whether the current version of the pattern subset meets the linking requirements of the text to be queried, and what fields (i.e., columns) are missing in the current version of the pattern subset. The verification action attempts to execute a complete SQL query to verify whether the current version of the pattern subset is sufficient to answer the question, and error messages during the query can be used to identify missing tables, columns, or join paths, etc.
[0068] The addition action and the termination action are actions without feedback.
[0069] The addition action includes adding the candidate columns related to the query text to the pattern subset to update the pattern subset. This action can be paired with a feedback action to add newly discovered pattern elements relevant to the question. (i.e., candidate columns) are added to the current version of the pattern subset. As shown in the following formula: The termination action includes determining the current version of the pattern subset as the target version and the current round as the last round. For example, if the execution result of the previous round indicates that the current version of the pattern subset already meets the linking requirements of the queried text, then the agent generates an action set including the termination action in the current round. Alternatively, if the number of completed rounds meets a preset threshold, then the agent generates an action set including the termination action in the current round.
[0070] Based on the above descriptions of various action types, the process of the agent interacting with the database's data environment and / or pattern environment through multiple rounds can be as follows: Multiple candidate columns are determined through exploration and retrieval actions; candidate columns related to the text to be queried are identified from the obtained candidate columns through verification actions; and candidate columns related to the text to be queried are added to the current version of the pattern subset through addition actions. Verification actions determine whether the current version of the pattern subset meets the linking requirements of the text to be queried, and what fields the current version of the pattern subset is still missing. If the current version of the pattern subset does not meet the linking requirements of the text to be queried, candidate columns are further determined through exploration and retrieval actions based on the fields still missing in the current version of the pattern subset. This process continues until the current version of the pattern subset meets the linking requirements of the text to be queried or the number of rounds reaches a preset threshold. Finally, a termination action is executed to complete the interaction process and obtain the target version of the pattern subset.
[0071] The action types included in this embodiment enable the agent to progressively explore, verify, and complete database pattern information. After receiving a natural language query, the agent dynamically decides its next action based on the current retrieval status, historical verification feedback, and target information. This includes whether to further search for patterns, call SQL execution tools to verify some candidate patterns, or terminate the exploration. Through this closed-loop feedback mechanism, the system can complete pattern linking with high recall without loading the complete pattern.
[0072] In particular, pattern linking algorithms in related technologies often rely on only a single round of retrieval, which is easily affected by semantic drift and retrieval errors. However, the action types included in this embodiment combine pattern retrieval with SQL execution verification, forming a dual-constraint link. That is, by inserting candidate patterns into part of the SQL structure and verifying them, the agent can actively eliminate irrelevant patterns, thereby improving the accuracy and stability of the final link.
[0073] Combining the above embodiments, the following can be obtained: Figure 3 The pattern linking process is shown.
[0074] First, the first version of the pattern subset. The prompts, the text to be queried, and all table names are used as initial historical inputs to the agent.
[0075] Next, the agent interacts with the initial history and database environment (data environment and / or pattern environment) for at least one round. In each round of interaction, the agent generates an inference trajectory based on the historical information of the current round and selects one or more actions from exploration, retrieval, verification, addition, and termination actions as an action set. If the action set does not include the termination action, the agent executes the action set for the database environment, obtains the execution result, and adds the inference trajectory, action set, and execution result of that round to the historical information. If the action set includes the addition action, the agent updates the current version of the pattern subset. If the action set includes a termination action or the number of completed rounds reaches a preset threshold, the iteration terminates, and the current version of the pattern subset is output. For the target version.
[0076] To verify the performance of the pattern linking method provided in this disclosure, the performance of the method was evaluated using the Spider 2.0-Lite and Bird-Dev datasets, and the performance of pattern linking was evaluated using the following four evaluation metrics: Strict Recall (SRR): The percentage of tasks in the schema subset that contain all schema elements required for the actual SQL query. This metric is the most direct indicator for evaluating schema linking performance.
[0077] Average token consumption (Avg. Tokens): Measures the average number of tokens consumed by the algorithm per task, which can reflect the efficiency of the algorithm's inference.
[0078] Average number of columns recalled (Avg. C): The average number of columns contained in the recalled pattern.
[0079] Execution accuracy (EX): The percentage of tasks in which the SQL query generated based on a subset of the schema executes on the database with the same result as the actual SQL execution.
[0080] To ensure a fair comparison of the methods, the same large language model (any large language model will suffice) was used as the base model for all methods. As can be seen from the schema linking results in Tables 1 and 2, this disclosure significantly outperforms all baseline methods in strict recall (SRR), especially on the more challenging Spider 2.0-Lite dataset, where it achieved 91.2%, far exceeding other methods (such as SQL-to-Schema's 64.0% and MCS-SQL's 58.8%). On the Bird-Dev dataset, this disclosure achieved an even higher SRR of 97.4%, demonstrating its strong generalization ability across datasets. Notably, this disclosure does not require input of the complete database schema, yet maintains a high recall while keeping the average token consumption to a minimum (e.g., only 8.0K on Bird-Dev), far lower than methods that rely on full schema input or multiple sampling (such as RSL-SQL and MCS-SQL).
[0081] Table 1: Spider 2.0-Lite Dataset Pattern Linking Results Table 2. Bird-Dev dataset pattern linking results As shown in Tables 3 and 4, this disclosure demonstrates competitive performance in SQL generation with high execution accuracy (EX). On Spider 2.0-Lite, this disclosure achieves an EX of 34.92% using DeepSeek-R1, slightly lower than ReFoRCE (37.84%), but with a token consumption of only 38.0K, less than half that of ReFoRCE, exhibiting higher efficiency. On Bird-Dev, this disclosure achieves an EX of 68.71% using Gemini-1.5-pro, outperforming CHESS (68.31%) and RSL-SQL (67.21%). These results indicate that this disclosure provides sufficient and accurate context for subsequent SQL generation through high-quality schema linking, thereby achieving generation performance comparable to current state-of-the-art methods without significantly increasing computational costs, demonstrating stronger practicality and scalability, especially in large-scale complex databases.
[0082] Table 3. SQL generation results for the Spider 2.0-Lite dataset. Table 4. SQL generation results for the Bird-Dev dataset According to a second aspect of the present disclosure, a pattern linking device is provided, the device including an attached... Figure 4 The linking module 401 is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on the first version of the query text and the pattern subset, and to link the target version of the pattern subset obtained by the interaction with the query text, wherein the pattern subset includes some pattern information of the database. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
[0083] In one possible embodiment of this disclosure, the set of actions generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action; The exploration action includes executing an SQL query against the data environment to determine at least one candidate column; The retrieval action includes performing a retrieval based on the text to be queried against the pattern environment to determine at least one candidate column; The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are related to the text to be queried. The adding action includes adding the candidate columns related to the text to be queried to the pattern subset, so as to update the version of the pattern subset; The termination action includes determining the current version of the pattern subset as the target version and determining the current round as the last round.
[0084] In one possible embodiment of this disclosure, the retrieval action includes retrieving the K columns with the highest similarity to the text to be queried within the pattern environment, and determining all K columns as candidate columns, wherein K is an integer greater than 0.
[0085] In one possible embodiment of this disclosure, the verification action further includes executing an SQL query against the data environment to determine whether the current version of the pattern subset satisfies the linking requirements of the text to be queried, and what fields are still missing in the current version of the pattern subset.
[0086] In one possible embodiment of this disclosure, if the execution result of the previous round indicates that the current version of the pattern subset has met the linking requirements of the text to be queried, then the agent generates a set of actions including a termination action in the current round.
[0087] In one possible embodiment of this disclosure, if the number of completed rounds meets a preset threshold, the agent generates a set of actions, including a termination action, in the current round.
[0088] In one possible embodiment of this disclosure, the agent generates a reasoning trajectory and a set of actions based on the historical information of the current round, executes the set of actions for the data environment and / or the mode environment and obtains the execution result, and adds the reasoning trajectory, the set of actions and the execution result to the historical information.
[0089] In one possible embodiment of this disclosure, the linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the data based on a first version of the query text and a subset of patterns, for the following purposes: Based on all table names in the database, the text to be queried, and the first version of a subset of patterns, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database.
[0090] In one possible embodiment of this disclosure, the linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on all table names of the database, the text to be queried, and a first version of a subset of patterns. The module is configured to: The agent is input with all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instructions to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database. The prompting instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompting instruction as historical information for the first round. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result.
[0091] In one possible embodiment of this disclosure, the device further includes an attachment Figure 4 The initial module 402 shown is used for: Within the pattern environment, retrieve the N columns with the highest similarity to the text to be queried, and determine the N columns as the first version of the pattern subset, where N is an integer greater than 0.
[0092] In one possible embodiment of this disclosure, the device further includes an attachment Figure 4 The building block 403 shown is used for: The schema environment is constructed based on the encoding results of information in all columns of the database.
[0093] In one possible embodiment of this disclosure, the device further includes an attachment Figure 4 The SQL generation module 404 shown is used for: The completed link to the query text and the target version of the pattern subset are sent to the SQL generation model so that the SQL generation model generates an SQL statement related to the query text.
[0094] According to a third aspect of the present disclosure, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the method described in the first aspect.
[0095] According to a fourth aspect of the present disclosure, an electronic device is provided, the electronic device including a memory and a processor, the memory being configured to store computer instructions executable on the processor, and the processor being configured to implement the method of the first aspect when executing the computer instructions.
[0096] Please refer to the appendix. Figure 5 The diagram illustrates, for example, a block diagram of the device. For instance, device 500 could be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0097] Reference Figure 5 The device 500 may include one or more of the following components: processing component 502, memory 504, power supply component 506, multimedia component 508, audio component 510, input / output (I / O) interface 512, sensor component 514, and communication component 516.
[0098] Processing component 502 typically controls the overall operation of device 500, such as operations associated with display, telephone calls, data communication, optical camera operation, and recording. Processing component 502 may include one or more processors 520 to execute instructions to complete all or part of the steps of the methods described above. Furthermore, processing component 502 may include one or more modules to facilitate interaction between processing component 502 and other components. For example, processing component 502 may include a multimedia module to facilitate interaction between multimedia component 508 and processing component 502.
[0099] Memory 504 is configured to store various types of data to support the operation of device 500. Examples of this data include instructions for any application or method operating on device 500, contact data, phonebook data, messages, pictures, videos, etc. Memory 504 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0100] The power supply component 506 provides power to the various components of the device 500. The power supply component 506 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to the device 500.
[0101] Multimedia component 508 includes a screen that provides an output interface between the device 500 and the occupant. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the occupant. The touch panel includes one or more touch sensors to sense touch, swipe, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 508 includes a front-facing optical camera and / or a rear-facing optical camera. When the device 500 is in an operation column, such as a shooting column or a video column, the front-facing optical camera and / or the rear-facing optical camera may receive external multimedia data. Each front-facing and rear-facing optical camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0102] Audio component 510 is configured to output and / or input audio signals. For example, audio component 510 includes a microphone (MIC) configured to receive external audio signals when device 500 is in an operation column, such as a call column, recording column, or voice recognition column. The received audio signals may be further stored in memory 504 or transmitted via communication component 516. In some embodiments, audio component 510 also includes a speaker for outputting audio signals.
[0103] I / O interface 512 provides an interface between processing component 502 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0104] Sensor assembly 514 includes one or more sensors for providing status assessments of various aspects of device 500. For example, sensor assembly 514 may detect the on / off state of device 500, the relative positioning of components such as the display and keypad of device 500, changes in position of device 500 or a component of device 500, the presence or absence of occupant contact with device 500, orientation or acceleration / deceleration of device 500, and temperature changes of device 500. Sensor assembly 514 may also include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 514 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 514 may also include an accelerometer, a gyroscope, a magnetometer, a pressure sensor, or a temperature sensor.
[0105] Communication component 516 is configured to facilitate wired or wireless communication between device 500 and other devices. Device 500 can access Wi-Fi networks based on communication standards, such as WiFi, 2G or 3G, 4G or 5G, or combinations thereof. In one exemplary embodiment, communication component 516 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 516 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0106] In an exemplary embodiment, device 500 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to implement the method described in the first aspect.
[0107] Fifthly, in exemplary embodiments, this disclosure also provides a non-transitory computer-readable storage medium including instructions, such as a memory 504 including instructions, which can be executed by a processor 520 of device 500 to implement the method described in the first aspect. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0108] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0109] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.< / actions> < / think>
Claims
1. A pattern linking method, characterized in that, The method includes: Based on the first version of the query text and the pattern subset, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database, and links the target version of the pattern subset obtained from the interaction with the query text, wherein the pattern subset includes some pattern information from the database; In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
2. The pattern linking method according to claim 1, characterized in that, The action set generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action; The exploration action includes executing an SQL query against the data environment to determine at least one candidate column; The retrieval action includes performing a retrieval based on the text to be queried against the pattern environment to determine at least one candidate column; The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are related to the text to be queried. The adding action includes adding the candidate columns related to the text to be queried to the pattern subset, so as to update the version of the pattern subset; The termination action includes determining the current version of the pattern subset as the target version and determining the current round as the last round.
3. The pattern linking method according to claim 2, characterized in that, The retrieval action includes retrieving the K columns with the highest similarity to the text to be queried within the mode environment, and determining all K columns as candidate columns, where K is an integer greater than 0.
4. The pattern linking method according to claim 2, characterized in that, The verification action also includes executing an SQL query against the data environment to determine whether the current version of the pattern subset meets the linking requirements of the text to be queried, and what fields the current version of the pattern subset is still missing.
5. The pattern linking method according to claim 2, characterized in that, If the execution result of the previous round indicates that the current version of the pattern subset has met the linking requirements of the text to be queried, then the agent generates a set of actions including a termination action in the current round.
6. The pattern linking method according to claim 2, characterized in that, If the number of completed rounds meets a preset threshold, the agent generates a set of actions, including a termination action, in the current round.
7. The pattern linking method according to claim 1, characterized in that, The agent generates a reasoning trajectory and action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and adds the reasoning trajectory, the action set and the execution result to the historical information.
8. The pattern linking method according to claim 1, characterized in that, The first version, based on the query text and a subset of patterns, controls the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the data, including: Based on all table names in the database, the text to be queried, and the first version of a subset of patterns, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database.
9. The pattern linking method according to claim 8, characterized in that, The first version, based on all table names, the text to be queried, and a subset of patterns in the database, controls the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database, including: The agent is input with all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instructions to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database. The prompting instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompting instruction as historical information for the first round. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result.
10. The pattern linking method according to claim 1, characterized in that, The method further includes: Within the pattern environment, retrieve the N columns with the highest similarity to the text to be queried, and determine the N columns as the first version of the pattern subset, where N is an integer greater than 0.
11. The pattern linking method according to claim 1, characterized in that, The method further includes: The schema environment is constructed based on the encoding results of information in all columns of the database.
12. The pattern linking method according to claim 1, characterized in that, The method further includes: The completed link to the query text and the target version of the pattern subset are sent to the SQL generation model so that the SQL generation model generates an SQL statement related to the query text.
13. A pattern linking device, characterized in that, The device includes: The linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database based on the first version of the query text and the pattern subset, and to link the target version of the pattern subset obtained by the interaction with the query text, wherein the pattern subset includes some pattern information of the database. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and updates the historical information based on the action set and the execution result. The action set includes at least one interactive action.
14. The mode linking device according to claim 13, characterized in that, The action set generated by the agent in each round of interaction includes at least one of the following interaction actions: exploration action, retrieval action, verification action, addition action, and termination action; The exploration action includes executing an SQL query against the data environment to determine at least one candidate column; The retrieval action includes performing a retrieval based on the text to be queried against the pattern environment to determine at least one candidate column; The verification action includes executing an SQL query against the data environment to determine whether the candidate columns are related to the text to be queried. The adding action includes adding the candidate columns related to the text to be queried to the pattern subset, so as to update the version of the pattern subset; The termination action includes determining the current version of the pattern subset as the target version and determining the current round as the last round.
15. The mode linking device according to claim 14, characterized in that, The retrieval action includes retrieving the K columns with the highest similarity to the text to be queried within the mode environment, and determining all K columns as candidate columns, where K is an integer greater than 0.
16. The mode linking device according to claim 14, characterized in that, The verification action also includes executing an SQL query against the data environment to determine whether the current version of the pattern subset meets the linking requirements of the text to be queried, and what fields the current version of the pattern subset is still missing.
17. The mode linking device according to claim 14, characterized in that, If the execution result of the previous round indicates that the current version of the pattern subset has met the linking requirements of the text to be queried, then the agent generates a set of actions including a termination action in the current round.
18. The mode linking device according to claim 14, characterized in that, If the number of completed rounds meets a preset threshold, the agent generates a set of actions, including a termination action, in the current round.
19. The mode linking device according to claim 13, characterized in that, The agent generates a reasoning trajectory and action set based on the historical information of the current round, executes the action set for the data environment and / or the mode environment and obtains the execution result, and adds the reasoning trajectory, the action set and the execution result to the historical information.
20. The mode linking device according to claim 13, characterized in that, The linking module is used to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the data based on a first version of the query text and a subset of patterns, for the following purposes: Based on all table names in the database, the text to be queried, and the first version of a subset of patterns, the control agent performs multiple rounds of interaction with the data environment and / or pattern environment of the database.
21. The mode linking device according to claim 20, characterized in that, The linking module is used to control the agent to perform multiple rounds of interaction with the database's data environment and / or pattern environment based on all table names, the text to be queried, and a first version of a subset of patterns in the database. It is used for: The agent is input with all table names of the database, the text to be queried, the first version of the pattern subset, and the prompt instructions to control the agent to perform multiple rounds of interaction with the data environment and / or pattern environment of the database. The prompting instruction is used to prompt the agent to use all table names of the database, the text to be queried, the first version of the pattern subset, and the prompting instruction as historical information for the first round. In each round of interaction, the agent generates an action set based on the historical information of the current round, executes the action set for the data environment and / or the pattern environment and obtains the execution result, and updates the historical information based on the action set and the execution result.
22. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the method of any one of claims 1 to 12.
23. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory being used to store computer instructions that can be executed on the processor, and the processor being used to implement the method of any one of claims 1 to 12 when executing the computer instructions.
24. 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 of any one of claims 1 to 12.