SQL generation method and system based on multi-agent interaction clarification, terminal and medium

By employing a multi-agent interactive clarification method, the system identifies and clarifies user intent and data ambiguity, generating accurate SQL statements. This solves the problem of error generation caused by unclear user questions and improves the accuracy of table retrieval and SQL execution.

CN122086930APending Publication Date: 2026-05-26BEIJING NORMAL UNIV AT ZHUHAI
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING NORMAL UNIV AT ZHUHAI
Filing Date
2026-04-24
Publication Date
2026-05-26

Smart Images

  • Figure CN122086930A_ABST
    Figure CN122086930A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of natural language processing, and discloses an SQL generation method and system based on multi-agent interaction clarification, a terminal and a medium, and the method comprises the steps: obtaining original information of a user, obtaining an intention result of the user according to the original information, if the intention result is intention fuzziness, receiving a first clarification reply of the user, updating the original information according to the first clear reply until the intention result is normal; performing validity verification on the original information to obtain a verification result of the user, if the verification result is data fuzzy, receiving a second clear reply of the user, updating the original information according to the second clear reply until the verification result is valid, and obtaining historical information; generating matching data according to the historical information; and generating an SQL statement according to the historical information and the matching data. According to the method, the table retrieval accuracy and the SQL execution accuracy under the fuzzy query scene are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing technology, and in particular to SQL generation methods, systems, terminals and media based on multi-agent interaction clarification. Background Technology

[0002] Large Language Models (LLMs) have driven the development of tabular question answering (QA). Existing technologies mainly fall into two categories: Firstly, there are closed-domain Text-to-SQL (Text-to-Structured Query Language) techniques, such as those used in the Spider and WikiSQL datasets. These assume the target table is predetermined, and users need to ask questions for a specific table. Secondly, there are open-domain table question-answering techniques, such as RETQA (Real Estate Tabular Question Answering dataset), which require manually retrieving relevant tables from large-scale databases to answer questions.

[0003] Existing technologies struggle to handle queries with "underspecification": real-world user questions often contain spelling errors, unclear expressions, or incomplete information (e.g., asking only "neighborhood environment" without specifying "which city"). Existing Text-to-SQL methods typically assume the question is clear, and when faced with ambiguous questions, they generate incorrect SQL statements, leading to incorrect answers.

[0004] Therefore, existing technologies still need to be improved and developed. Summary of the Invention

[0005] The main purpose of this application is to provide a SQL generation method, system, terminal and medium based on multi-agent interaction clarification, aiming to solve the problem in the prior art that user queries contain spelling errors, unclear expressions or incomplete information, resulting in the generation of incorrect SQL.

[0006] The first aspect of this application provides a SQL generation method based on multi-agent interaction clarification, the SQL generation method based on multi-agent interaction clarification includes the following steps: Obtain the user's original information and obtain the user's intent result based on the original information. If the intent result is ambiguous, receive the user's first clarification response and update the original information based on the first clarification response until the intent result is normal. The original information is validated to obtain the user's validation result. If the validation result is that the data is ambiguous, the user's second clarification response is received, and the original information is updated according to the second clarification response until the validation result is valid, thus obtaining the historical information. Generate matching data based on the historical information; SQL statements are generated based on the historical information and the matching data.

[0007] Optionally, in one embodiment of this application, obtaining the user's intent fuzzy result based on the original information specifically includes: Identify the user's intent and slot based on the original information; The user's stated intent is detected, resulting in an ambiguous result.

[0008] Optionally, in one embodiment of this application, the verification result includes a first result and a second result; The step of validating the original information to obtain the user's verification result specifically includes: Missing information is detected in the slots identified by the original information to obtain a first result; The actual value of the slot is retrieved from the database, and a second result is obtained based on the actual value.

[0009] Optionally, in one embodiment of this application, the step of receiving a second clarification response from the user if the verification result is ambiguous specifically includes: When the first result is ambiguous, a clarification question is asked to the user, and a second clarification response is received from the user. If the first result is complete, and the second result is an existence ambiguity or a combination conflict ambiguity, then a clarification question is sent to the user, and the user's second clarification response is received.

[0010] Optionally, in one embodiment of this application, the historical information includes original information, intent, slot, and full range information; The step of generating matching data based on the historical information specifically includes: The original information, the intent, the slot, and the complete range information are input into a large language model to generate a natural language summary. A table search is performed based on the natural language summary to obtain matching data.

[0011] Optionally, in one embodiment of this application, the matching data includes a predicted target table; the step of performing table retrieval based on the natural language summary to obtain the matching data specifically includes: The comparison results of the tables are obtained by comparing the natural language summary with all the actual table names in the database one by one. If the comparison result meets the matching requirements, the corresponding table will be used as the prediction target table; If the comparison result does not meet the matching requirements, the relevance score between the natural language summary and each table is calculated, and the table with the highest relevance score is used as the prediction target table.

[0012] Optionally, in one embodiment of this application, generating an SQL statement based on the historical information and the matching data specifically includes: The original information, the slot, and the prediction target table are input into the large language model, and the initial statement is output. The initial statement is executed in a real data environment database to obtain the execution result; If the execution result is empty, a clarification question is sent to the user, and a third clarification response is received from the user. The historical information is updated according to the third clarification response until the execution result is valid. Then, the corresponding initial statement is used as an SQL statement.

[0013] A second aspect of this application also provides a SQL generation system based on multi-agent interaction clarification, wherein the SQL generation system based on multi-agent interaction clarification is used to implement the SQL generation method based on multi-agent interaction clarification as described in any of the above solutions; the SQL generation system based on multi-agent interaction clarification includes: The intent detection module is used to obtain the user's original information and obtain the user's intent result based on the original information. If the intent result is ambiguous, the module receives the user's first clarification response and updates the original information based on the first clarification response until the intent result is normal. The range verification module is used to verify the validity of the original information and obtain the user's verification result. If the verification result is that the data is ambiguous, the module receives the user's second clarification response and updates the original information according to the second clarification response until the verification result is valid, thereby obtaining the historical information. The table retrieval module is used to generate matching data based on the historical information; The SQL generation and validation module is used to generate SQL statements based on the historical information and the matching data.

[0014] A third aspect of this application also provides a terminal, wherein the terminal includes: a memory, a processor, and a SQL generation program based on multi-agent interaction clarification stored in the memory and executable on the processor, wherein when the SQL generation program based on multi-agent interaction clarification is executed by the processor, it implements the steps of the SQL generation method based on multi-agent interaction clarification as described above.

[0015] A fourth aspect of this application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores an SQL generation program based on multi-agent interaction clarification, and the SQL generation program based on multi-agent interaction clarification, when executed by a processor, implements the steps of the SQL generation method based on multi-agent interaction clarification as described above.

[0016] Beneficial effects: This application provides a SQL generation method, system, terminal, and medium based on multi-agent interactive clarification. This invention can proactively identify missing or erroneous information in user questions, initiate targeted follow-up questions to users through multi-round dialogue, and integrate user feedback into the context, thereby achieving accurate table retrieval and SQL generation, improving the accuracy of table retrieval and the correctness of SQL execution in fuzzy query scenarios. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart of a preferred embodiment of the SQL generation method based on multi-agent interaction clarification in this application; Figure 2 This is a structural diagram of a preferred embodiment of the SQL generation system based on multi-agent interaction clarification of this application; Figure 3 This is a structural diagram of a preferred embodiment of the terminal of this application.

[0019] Explanation of reference numerals in the attached figures: 100. Intent Detection Module; 200. Range Validation Module; 300. Table Retrieval Module; 400. SQL Generation and Validation Module. Detailed Implementation

[0020] To make the objectives, technical solutions, and effects of this application clearer and more explicit, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. The described embodiments are only possible technical implementations of this application and not all possible implementations. Based on the embodiments in this application, those skilled in the art can obtain other embodiments without creative effort, and these embodiments are also within the protection scope of this application.

[0021] First, let's introduce the terms used in the embodiments of this application: MAIC-TQA, Multi-Agent Interactive Clarification for Tabular QA, is a tabular question-answering method based on multi-agent interactive clarification (i.e., a SQL generation method based on multi-agent interactive clarification). SLU, Spoken Language Understanding, is a module responsible for parsing user queries. SV Agent, Scope Validator Agent; TR Agent, Table Retrieval Agent; SGV Agent, SQL Generation and Validation Agent; Intent, meaning what the user wants to do, belongs to the category of vague intent. Scope, range (which table to look up, belonging to the fuzzy range category); Condition, the criteria for the query (belonging to the category of fuzzy conditions); Slot (a key information segment in a user query, such as location or name); Domain, field (such as knowledge fields like real estate and healthcare); LLM, Large Language Model; BERT, Bidirectional Encoder Representations from Transformers, is a pre-trained language model based on bidirectional encoder representations from Transformers. SQL, Structured Query Language (used for database operations). FROM is the SQL clause specifying a table (corresponding to the question of "which table to query"). WHERE, a conditional clause in SQL (corresponding to filter conditions); BM25, Best Match 25, is a relevance ranking function for text retrieval. Recall (a metric for evaluating search performance); F1, F1 Score (harmonic mean), F1 score (an evaluation metric that combines precision and recall). In-Context Learning (learning from context) allows the model to understand the task based on the provided examples or context. Tabular QA, Tabular Question Answering; Text-to-SQL (the task of converting natural language into SQL statements). Underspecification refers to unclear or insufficiently described questions (i.e., vague questions asked by users). Missing, meaning missing (referring to the absence of essential information); Unmatch, mismatch or conflict (such as the geographical combination error "City A has District B", where City A has District A and City B has District B).

[0022] In related technologies, there is a lack of dynamic clarification mechanisms: existing research (such as Bhaskar et al., 2023) mainly focuses on detecting ambiguity or using pre-set static dialogues (such as PRACTIQ), which cannot clarify user intent through dynamic multi-turn dialogues like a real person. Furthermore, there is a lack of effective integration of multi-turn information: existing methods struggle to handle various types of ambiguity (table range ambiguity, intent ambiguity, condition ambiguity) while retrieving tables from large-scale databases, and to continuously refine the retrieval and result generation based on information obtained from multi-turn dialogues.

[0023] To address the problem that existing technologies cannot effectively handle ambiguous or unclear user queries in open-domain environments, leading to inaccurate table retrieval and answer generation, this invention proposes a table question-answering method based on multi-agent interactive clarification (MAIC-TQA). This invention subdivides ambiguous questions into three categories: intent ambiguity, scope ambiguity, and condition ambiguity, and designs a collaborative framework including an SLU module, a scope verification agent, a table retrieval agent, and an SQL generation verification agent. Through a closed-loop mechanism of "detection-clarification-re-detection," the system can proactively identify missing or erroneous information in user questions, initiate targeted follow-up questions to the user through multiple rounds of dialogue, and integrate user feedback into the context, thereby achieving accurate table retrieval and SQL generation. Technical effects: Significantly improves table retrieval accuracy (Recall / F1) and SQL execution correctness rate in fuzzy query scenarios, solving the problem of traditional models "forcing answers" to fuzzy questions, which leads to errors.

[0024] The technical solutions of this application will be described in detail below with reference to specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0025] The SQL generation method based on multi-agent interaction clarification described in the preferred embodiment of this application, such as... Figure 1 As shown, the SQL generation method based on multi-agent interaction clarification includes the following steps: In step S101, the user's original information is obtained, and the user's intent result is obtained based on the original information. If the intent result is ambiguous, the user's first clarification response is received, and the original information is updated based on the first clarification response until the intent result is normal.

[0026] In one possible implementation, step S101 specifically includes: identifying the user's intent and slot based on the original information; detecting the user's intent to obtain a fuzzy result of the user's intent.

[0027] It should be noted that in the SLU module (spoken language comprehension module) and intent detection process, it is responsible for initially parsing the user's natural language query and extracting the user's intent and slot information.

[0028] Specifically, the system receives user queries and uses a classifier (such as a BERT-based method) to detect intent and slots. It then performs intent ambiguity detection: if the classifier output indicates unclear user intent (e.g., using ambiguous column names), the system generates a "fuzzy intent" label. Next, it performs clarification interaction: if ambiguity is detected, the system triggers follow-up questions generated by a preset template or a large model (e.g., "Your question is unclear, please provide more details"). After the user replies, the system concatenates the original query with the reply, updates the context, and performs intent recognition again.

[0029] Furthermore, firstly, the system receives the user's original natural language query and parses it using a classifier based on models such as BERT; it identifies the user's current intent (what they want to do, such as querying house prices) and slots (key information, such as city and neighborhood name). Secondly, it performs ambiguity determination (intent level), assessing the confidence or completeness of the parsing results from the first step; it checks for unclear references, overly broad expressions, or missing key intents; if normal, it proceeds to the next step (S102 range verification); if ambiguous, the system generates a special "ambiguous intent" label. Next, it actively clarifies the interaction. When the system is labeled "ambiguous intent," it does not continue executing SQL generation but instead switches to "dialogue management," calling a preset follow-up question template or using a large model to generate a natural follow-up question (e.g., "Which neighborhood's house price are you referring to? Please provide the specific name."); it waits for the user's response to the follow-up question; it concatenates the "original query and the user's clarification response" to update the entire dialogue context; with the updated context, it jumps back to the initial step to perform intent recognition again.

[0030] This invention ensures that the information entering subsequent processes is clear and unambiguous through a cycle of parsing, judging, questioning, and re-parsing, thereby reducing the error rate of subsequent steps.

[0031] In step S102, the original information is validated to obtain the user's validation result. If the validation result is that the data is ambiguous, the user's second clarification response is received, and the original information is updated according to the second clarification response until the validation result is valid, thus obtaining historical information.

[0032] In one possible implementation, the verification result includes a first result and a second result. Step S102 specifically includes: performing missing detection on the slots identified by the original information to obtain a first result; retrieving the actual value of the slot from the database, and obtaining a second result based on the actual value. When the first result is ambiguous in scope, a clarification question is raised to the user, and a second clarification response is received from the user; when the first result is complete, if the second result is ambiguous in existence or in combination, a clarification question is raised to the user, and a second clarification response is received from the user.

[0033] It should be noted that the Scope Validator Agent (SV Agent) resolves the ambiguity related to the FROM clause (i.e., the question of "which table to look up"), ensuring that the correct table range is locked.

[0034] Specifically, the system receives the query and prediction domain and the extracted slots. Missing slot detection: It compares the slots with those required for the domain (e.g., the real estate domain must include "city"). If a slot is missing, it generates a "Missing" type fuzzy label for the range. Validity verification: It calls the slotSearchTool to retrieve slot values ​​from the database. If a slot value does not exist (Error) or there is a combination conflict (Unmatch, e.g., "B District of City A," where City A has District a, and only City B has District b), it generates a corresponding fuzzy label. Clarification interaction: For detected range issues, it initiates clarification to the user (e.g., "This community was not found; please confirm the name").

[0035] Further, it receives the raw query text from the SLU module, the predicted domain (e.g., real estate, education), and the extracted slots (e.g., city = "A", region = "a"). Missing detection is performed, checking against a predefined "list of required slots" in the domain knowledge base. For example, the real estate domain must contain "city," and the education and training domain may require "course name." If a required slot is missing from the currently extracted slots, it is considered "missing." A range-based fuzzy label of type "Missing" is generated, and the specific missing slot name (e.g., "city") is recorded. Note that this step only checks if the slot exists, not if the value is correct. Then, validity validation is performed, calling an underlying tool (e.g., slotSearchTool) to retrieve the actual values ​​of existing slots from the database. Errors include: a slot value that does not exist in the database (e.g., a user says "city = 'xyz'," but this city does not exist in the database); and unmatches where multiple slot values ​​are combined in an unreasonable way. For example, a user might say "City = 'City A', Region = 'Block B'", but Block B actually belongs to City B. This combination cannot match any data. If a problem is found, a corresponding fuzzy label ("Error" or "Unmatch") is generated, along with specific error information (such as "City 'xyz' not found" or "No region 'b' under City 'City A'"). Clarification occurs when any fuzzy label (Missing / Error / Unmatch) is generated in the previous two steps. The system then stops passing information to subsequent modules and instead redirects to the dialogue management module to ask the user a targeted clarification question. This is done using a preset template or a large model to generate natural language follow-up questions, such as: for missing values: "Which city's real estate information do you want to query?"; for non-existent values: "City 'xyz' not found. Please confirm the city name is correct."; for combination conflicts: "No region b under City A. Do you mean City B, Block b?". After the user replies, the system concatenates the original query with the clarification response, updates the context, and restarts processing from the SLU module until the range validation passes.

[0036] This invention, through range verification, can correct deviations in data range at the earliest stage, greatly improving the accuracy of the entire process and the user experience.

[0037] In step S103, matching data is generated based on the historical information.

[0038] In one possible implementation, the historical information includes original information, intent, slot, and full range information. Step S103 specifically includes: inputting the original information, intent, slot, and full range information into a large language model to generate a natural language summary; and performing a table search based on the natural language summary to obtain matching data.

[0039] In one possible implementation, the matching data includes a prediction target table. The natural language summary is compared one-to-one with all actual table names in the database to obtain table comparison results. If the comparison result meets the matching requirements, the corresponding table is used as the prediction target table. If the comparison result does not meet the matching requirements, the relevance score between the natural language summary and each table is calculated, and the table with the highest relevance score is used as the prediction target table.

[0040] It should be noted that the Table Retrieval Agent (TR Agent) retrieves the most relevant tables from a large-scale database based on the clarified and complete information.

[0041] Specifically, the system integrates the original query and all historical conversations (including user clarification). A large model is used to generate a "summary" of the target table as the predicted table title. A two-stage retrieval process is employed: first, an exact match is attempted between the generated summary and the database table names; if no match is found, the BM25 algorithm is used for similarity retrieval, returning a list of the most relevant tables.

[0042] Furthermore, the system receives and integrates all historical information, including: the user's original query (e.g., "What are the newly opened residential communities in District a of City A?"), the intent and slot extracted by the SLU module, the complete scope information confirmed after clarification by the SV Agent (e.g., domain = real estate, city = City A, district = District a), and the user's clarification responses throughout the dialogue. The integrated contextual information is then input into the Large Language Model (LLM), which generates a natural language summary of the target table. This summary is an abstract description of the expected table content; it is not necessarily the actual table name in the database, but rather an "ideal table title" used to guide subsequent retrieval. In the two-stage table retrieval process, the first stage involves exact matching, comparing the generated summary with each actual table name in the database. If an exact match (or a match ignoring case and spaces) is found for a table name, that table is returned directly as the result. The second stage, similarity retrieval (BM25), proceeds if an exact match fails (the actual table name may not contain words from the "Summary," or the naming convention may be inconsistent). Then, the BM25 algorithm is activated to perform text similarity retrieval. BM25 calculates the relevance score between the summary and each table name (along with possible table comments and field descriptions), returning the top-scoring tables as a candidate list. Finally, the most relevant one or a few tables (usually the Top-1 or Top-K tables) are returned for use by subsequent modules.

[0043] This invention, by generating and matching summaries, can handle discrepancies between table names and natural language descriptions, significantly improving the accuracy of table lookup. The success of this step directly determines whether subsequent SQL queries can be executed on the correct data source.

[0044] In step S104, an SQL statement is generated based on the historical information and the matching data.

[0045] In one possible implementation, step S104 specifically includes: inputting the original information, the slot, and the prediction target table into the large language model and outputting an initial statement; executing the initial statement in a real data environment database to obtain an execution result; if the execution result is empty, initiating a clarification question to the user and receiving the user's third clarification reply, updating the historical information according to the third clarification reply, until the execution result is valid, and then using the corresponding initial statement as an SQL statement.

[0046] It should be noted that the SQL Generation and Validation Agent (SGV Agent) generates executable SQL statements and resolves ambiguities related to the WHERE clause.

[0047] Specifically, input the complete conversation history, predicted table title, and slots. Based on In-Context Learning, use the LLM to generate SQL statements. Execution and feedback verification: Execute the generated SQL in the database. Empty result detection (fuzzy conditions): If the execution result is empty or incomplete, the system infers that there may be an error in the query conditions (such as abbreviations in the project name causing no match). The system generates a "fuzzy conditions" label and initiates clarification with the user again. After obtaining the user's correction, regenerate the SQL and return the final answer.

[0048] Furthermore, receive the complete information processed by all previous modules (SLU, SV, TR), including: the complete conversation history (including all clarification interactions), the predicted target table (table name or table structure), and the confirmed slot key-value pairs (such as city = A, price < Y million). Based on In-Context Learning, use the large language model (LLM) to generate SQL statements. Usually, provide several few-shot examples or database Schema information in the prompt to guide the LLM to write the correct SQL according to the current requirements, and output a theoretically correct SQL query statement that conforms to the user's intention. Execution and feedback verification: Execute the generated SQL in a real database environment, obtain the actual query result, and observe the status of the result set. Empty result detection (fuzzy condition determination): If the result set returned after the SQL execution is empty, or the result is significantly incomplete (for example, the user asks for "all communities", but only a few are returned), the system determines that there may be an error in the query conditions, generates a "fuzzy conditions" label, and records the possible error reasons. Clarification interaction and loop: Initiate clarification with the user. After the user replies, the system splices the new information (the conditions corrected by the user) into the conversation history, processes it again to generate the SQL and verify it until a valid result is returned or the user terminates.

[0049] Through actual execution of SQL and detection of empty results, the system of the present invention can actively discover these fine-grained fuzzy conditions and correct them through clarification interactions, thus ensuring the accuracy and integrity of the final answer.

[0050] It is worth noting that this invention employs a fine-grained fuzziness classification and processing architecture. The fuzziness in open-domain table-based question answering is explicitly divided into three levels, each processed according to a different clause of the SQL statement: Intent / SELECT: handled by the SLU module. Scope / FROM: handled by the scope verification agent, a step that is easily overlooked in existing technologies but crucial for table selection. Condition / WHERE: handled by the SQL generation verification agent through "execution feedback." This hierarchical architecture, with dedicated agents configured for detection and clarification of different SQL components (SELECT / FROM / WHERE), is noteworthy.

[0051] This invention employs a closed-loop clarification mechanism based on execution feedback (Detection-Clarification-Redetection): Unlike traditional single-generation methods, this invention establishes a dynamic closed loop: ambiguity is detected, generation is paused, multi-round dialogue clarification is initiated, information is acquired, and detection or generation is repeated. Specifically, it utilizes the mechanism of using SQL execution results (e.g., empty results) to trigger the clarification process in reverse. Intermediate verification results (range verification tool results, empty SQL execution results) are used to dynamically trigger the human-computer multi-round dialogue clarification control process.

[0052] This invention is a multi-agent collaborative table-based question-and-answer workflow: by connecting four specialized agents—SLU, SV, TR, and SGV—it solves the end-to-end ambiguity problem from natural language understanding to database operations.

[0053] It is understood that this invention mentions the use of BERT for classification and Qwen / GPT for generation. Alternative solutions can replace the underlying LLM with any other large model capable of following instructions (such as Llama, Claude, etc.), or use a lighter, dedicated small model.

[0054] The current implementation is primarily based on real estate and financial data. This method can be seamlessly migrated to other vertical fields such as medical record queries, e-commerce product filtering, and industrial equipment maintenance log queries, simply by replacing the field-specific slot schema.

[0055] The table search currently uses BM25, which can be replaced with vector-based (Dense Retrieval) semantic search. The slot search tool can be replaced with fuzzy matching, pinyin matching, or a knowledge graph-based entity linking tool to enhance tolerance for spelling errors.

[0056] The current clarification is based on text-based dialogue. Alternative solutions could design the clarification interaction as a GUI (e.g., a pop-up tab allowing users to select the correct city or neighborhood) or as a voice interaction.

[0057] Next, referring to the accompanying drawings, a SQL generation system based on multi-agent interaction clarification proposed according to an embodiment of this application is described, which is used to implement the SQL generation method based on multi-agent interaction clarification as described in any of the above schemes.

[0058] Figure 2 This is a structural diagram of the SQL generation system based on multi-agent interaction clarification according to an embodiment of this application.

[0059] like Figure 2 As shown, the SQL generation system based on multi-agent interaction clarification includes: an intent detection module 100, a range verification module 200, a table retrieval module 300, and an SQL generation and verification module 400.

[0060] Specifically, the intent detection module 100 is used to obtain the user's original information and obtain the user's intent result based on the original information. If the intent result is ambiguous, it receives the user's first clarification response and updates the original information based on the first clarification response until the intent result is normal. The range verification module 200 is used to verify the validity of the original information and obtain the user's verification result. If the verification result is that the data is ambiguous, the module receives the user's second clarification reply and updates the original information according to the second clarification reply until the verification result is valid, thereby obtaining historical information. Table retrieval module 300 is used to generate matching data based on the historical information; SQL generation and validation module 400 is used to generate SQL statements based on the historical information and the matching data.

[0061] Figure 3 A structural diagram of a terminal provided in an embodiment of this application. The terminal may include: The memory 501, the processor 502, and the computer program stored on the memory 501 and capable of running on the processor 502.

[0062] When the processor 502 executes the program, it implements the SQL generation method based on multi-agent interaction clarification provided in the above embodiments.

[0063] Furthermore, the terminal also includes: Communication interface 503 is used for communication between memory 501 and processor 502.

[0064] The memory 501 is used to store computer programs that can run on the processor 502.

[0065] Memory 501 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.

[0066] If the memory 501, processor 502, and communication interface 503 are implemented independently, then the communication interface 503, memory 501, and processor 502 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EIS) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 3 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0067] Optionally, in a specific implementation, if the memory 501, processor 502, and communication interface 503 are integrated on a single chip, then the memory 501, processor 502, and communication interface 503 can communicate with each other through an internal interface.

[0068] Processor 502 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.

[0069] This embodiment also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the SQL generation method based on multi-agent interaction clarification as described above.

[0070] One embodiment of this application provides a computer program product, including a computer program that, when executed by a processor, implements the features described in this application. Figure 1 The SQL generation method based on multi-agent interaction clarification provided in any of the corresponding embodiments.

[0071] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. 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.

[0072] 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 application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0073] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.

[0074] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable storage medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable storage medium could be paper or other suitable media on which the program can be printed, since the program can be obtained electronically by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.

[0075] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0076] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0077] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0078] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.

[0079] It should be understood that the application of this application is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.

[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A SQL generation method based on multi-agent interaction clarification, characterized in that, The SQL generation method based on multi-agent interaction clarification includes: Obtain the user's original information and obtain the user's intent result based on the original information. If the intent result is ambiguous, receive the user's first clarification response and update the original information based on the first clarification response until the intent result is normal. The original information is validated to obtain the user's validation result. If the validation result is that the data is ambiguous, the user's second clarification response is received, and the original information is updated according to the second clarification response until the validation result is valid, thus obtaining the historical information. Generate matching data based on the historical information; SQL statements are generated based on the historical information and the matching data.

2. The SQL generation method based on multi-agent interaction clarification according to claim 1, characterized in that, The step of obtaining the user's intent fuzzy result based on the original information specifically includes: Identify the user's intent and slot based on the original information; The user's stated intent is detected, resulting in an ambiguous result.

3. The SQL generation method based on multi-agent interaction clarification according to claim 2, characterized in that, The verification results include a first result and a second result; The step of validating the original information to obtain the user's verification result specifically includes: Missing information is detected in the slots identified by the original information to obtain a first result; The actual value of the slot is retrieved from the database, and a second result is obtained based on the actual value.

4. The SQL generation method based on multi-agent interaction clarification according to claim 3, characterized in that, If the verification result is ambiguous, then a second clarification response from the user is received, specifically including: When the first result is ambiguous, a clarification question is asked to the user, and a second clarification response is received from the user. If the first result is complete, and the second result is an existence ambiguity or a combination conflict ambiguity, then a clarification question is sent to the user, and the user's second clarification response is received.

5. The SQL generation method based on multi-agent interaction clarification according to claim 4, characterized in that, The historical information includes original information, intent, slot, and full range information; The step of generating matching data based on the historical information specifically includes: The original information, the intent, the slot, and the complete range information are input into a large language model to generate a natural language summary. A table search is performed based on the natural language summary to obtain matching data.

6. The SQL generation method based on multi-agent interaction clarification according to claim 5, characterized in that, The matching data includes a prediction target table; The step of performing a table search based on the natural language summary to obtain matching data specifically includes: The comparison results of the tables are obtained by comparing the natural language summary with all the actual table names in the database one by one. If the comparison result meets the matching requirements, the corresponding table will be used as the prediction target table; If the comparison result does not meet the matching requirements, the relevance score between the natural language summary and each table is calculated, and the table with the highest relevance score is used as the prediction target table.

7. The SQL generation method based on multi-agent interaction clarification according to claim 6, characterized in that, The step of generating SQL statements based on the historical information and the matching data specifically includes: The original information, the slot, and the prediction target table are input into the large language model, and the initial statement is output. The initial statement is executed in a real data environment database to obtain the execution result; If the execution result is empty, a clarification question is sent to the user, and a third clarification response is received from the user. The historical information is updated according to the third clarification response until the execution result is valid. Then, the corresponding initial statement is used as an SQL statement.

8. A SQL generation system based on multi-agent interaction clarification, characterized in that, The SQL generation system based on multi-agent interaction clarification is used to implement the SQL generation method based on multi-agent interaction clarification as described in any one of claims 1-7, wherein the SQL generation system based on multi-agent interaction clarification comprises: The intent detection module is used to obtain the user's original information and obtain the user's intent result based on the original information. If the intent result is ambiguous, the module receives the user's first clarification response and updates the original information based on the first clarification response until the intent result is normal. The range verification module is used to verify the validity of the original information and obtain the user's verification result. If the verification result is that the data is ambiguous, the module receives the user's second clarification response and updates the original information according to the second clarification response until the verification result is valid, thereby obtaining the historical information. The table retrieval module is used to generate matching data based on the historical information; The SQL generation and validation module is used to generate SQL statements based on the historical information and the matching data.

9. A terminal, characterized in that, The terminal includes: a memory, a processor, and a SQL generation program based on multi-agent interaction clarification stored in the memory and executable on the processor. When the SQL generation program based on multi-agent interaction clarification is executed by the processor, it implements the steps of the SQL generation method based on multi-agent interaction clarification as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores an SQL generation program based on multi-agent interaction clarification, which, when executed by a processor, implements the steps of the SQL generation method based on multi-agent interaction clarification as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Artificial intelligence based search system optimization method and device

    CN106503189A

  • Natural language processing method and device, equipment and storage medium

    CN114186026A

  • Query method, electronic equipment and storage medium

    CN121326946A

  • Database query statement generation method and device, equipment and storage medium

    CN121326955A

  • Vehicle personal assistant

    US20140136187A1