A method for improving the accuracy of database query based on large models

CN122925408APending Publication Date: 2026-10-16ZHEJIANG AEROSPACE HENGJIA DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610734543.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-26
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

首先,由于该技术方案依赖关键词匹配或语义相似度检索来获取相关DDL信息,在面对复杂查询需求时,难以保证能够完整、准确地检索到与查询任务相关的全部表结构信息,尤其是在涉及多表关联查询的场景中,容易出现关键表未被检索命中的情况

Benefits of technology

本发明通过引入数据查询主题划分机制以及库表摘要文件的结构化表达方式,使大模型在处理查询任务时能够基于语义理解与结构信息进行数据表定位,从而避免因信息缺失导致的理解偏差,在多表关联场景下仍可准确识别完整的数据表集合,进而生成逻辑正确的SQL查询语句,整体提升数据查询结果的准确性,同时增强复杂查询任务下的稳定性与可用性,使系统在实际应用过程中能够持续输出符合用户需求的查询结果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122925408A_ABST
    Figure CN122925408A_ABST
Patent Text Reader

Abstract

The application discloses a method for improving database query accuracy based on a large model, and relates to the field of artificial intelligence. The target database is divided according to business scenarios, multiple data query topics are constructed, and corresponding data query tools are established for each data query topic. Meanwhile, a library table abstract file is generated based on the DDL information of each data table in the database. The library table abstract file includes table coding, table name, table summary, associated table and necessary table information. Through data query topic division and library table abstract structured expression, the large model can accurately locate the relevant data table and generate correct SQL, thereby improving the accuracy and stability in complex query scenarios. Meanwhile, through data query tools and tool abstract design, the query process is converted into intent-driven decision-making, the dependence on vector databases and embedded models is reduced, the system complexity and construction cost are reduced, and the engineering application and promotion value are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence, and more specifically to a method for improving the accuracy of database queries based on large models. Background Technology

[0002] With the development of artificial intelligence technology, the ability to understand and generate natural language based on large-scale language models (LLMs) is constantly improving, making database queries via natural language a hot research and application area. Current technologies typically employ Retrieval-Augmented Generation (RAG) combined with Text2SQL methods, and utilize an agent framework to achieve conversational interactive queries between users and the database.

[0003] Specifically, existing technologies generally include the following processing flow: First, based on the database's DDL (Data Definition Language) information, the table structure in the database is organized, and a database table structure knowledge base supporting keyword retrieval and semantic similarity matching is constructed; second, based on the natural language query input by the user, relevant DDL information is retrieved from the knowledge base through keyword matching or vector similarity calculation; then, the retrieved DDL content is injected as context information into the large model's prompt, guiding the large model to generate the corresponding SQL query statement; finally, the generated SQL statement is submitted to the database for execution, and the query results are returned to the user.

[0004] The aforementioned technical solutions have advantages such as clear implementation paths, short development cycles, and low human resource costs, and therefore have been promoted to a certain extent in practical applications. However, in specific applications, this type of technical solution still has the following shortcomings: First, since this technical solution relies on keyword matching or semantic similarity retrieval to obtain relevant DDL information, it is difficult to guarantee that all table structure information related to the query task can be retrieved completely and accurately when facing complex query requirements. Especially in scenarios involving multi-table join queries, key tables may not be retrieved.

[0005] Secondly, when the retrieved DDL information is incomplete or biased, it will directly affect the large model's understanding of the database structure, resulting in inaccurate SQL statements or even the inability to generate valid query statements, which in turn will cause query failures or incorrect returned results, reducing the overall query accuracy and stability of the system.

[0006] Furthermore, the aforementioned technical solutions typically rely on vector databases and embedding models to achieve semantic retrieval functions. This increases the infrastructure construction cost and operational complexity of the system to some extent, which is not conducive to the large-scale deployment and widespread application of the system.

[0007] Therefore, how to improve the accuracy of obtaining relevant table structure information during database queries based on large models, while reducing system complexity and construction costs, thereby improving the accuracy of SQL generation and the overall availability of the system, has become a technical problem that urgently needs to be solved by those skilled in the art.

[0008] The information disclosed in the background section is only intended to enhance the understanding of the background of this disclosure, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0009] The purpose of this invention is to provide a method for improving the accuracy of database queries based on large models, thereby solving the problems mentioned in the background art.

[0010] To achieve the above objectives, the present invention provides the following technical solution: a method for improving the accuracy of database queries based on large models, comprising the following steps: The target database is divided according to business scenarios, multiple data query topics are constructed, and corresponding data query tools are built for each data query topic. At the same time, a database table summary file is generated based on the DDL information of each data table in the database. The database table summary file includes table code, table name, table overview, related tables and necessary table information. It receives query descriptions input by users, performs semantic parsing on the query descriptions using a large model, determines matching data query tools based on pre-built tool summary files, and generates corresponding tool task descriptions. For data query tools, locate the target table code corresponding to the query task in the database table summary file according to the tool task description, and read the corresponding DDL information; Input the DDL information, tool task description, and query example into the large model to generate an SQL query statement, and execute the SQL query statement to obtain the query results; When an SQL query statement execution error occurs or the query description does not meet the preset data query theme, the query description or SQL query statement is analyzed and correction information is generated to update the query description or regenerate the SQL query statement until the query result is obtained.

[0011] Preferably, the association table information in the database table summary file is obtained by extracting and organizing the foreign key relationships between various data tables in the database and the preset business association rules, and stored in the database table summary file in the form of structured relationships. This enables the large model to perform multi-level reasoning based on the association table information when locating the target table encoding, thereby improving the completeness and accuracy of target data table location in scenarios involving multi-table association queries.

[0012] Preferably, the tool summary file further includes data query scope boundary information and query restriction information, which are used to determine whether the query description belongs to the preset data query topic when performing semantic parsing of the query description, and to generate restrictive prompt information when the query description exceeds the data query scope, thereby improving the accuracy of matching between the query description and the data query tool and avoiding the execution of invalid query tasks.

[0013] Preferably, in the process of semantic parsing of query descriptions using a large model, the query descriptions are standardized by introducing a pre-defined set of query use cases and synonym mapping rules, converting natural language expressions into structured query task descriptions. This improves the consistency and stability of the large model in recognizing query intent and reduces the bias in the selection of data query tools caused by differences in expression.

[0014] Preferably, in the process of locating the target table code according to the tool task description, the core data table is determined first based on the necessary table information in the database table summary file, and the relevant data table set is gradually expanded in combination with the related table information to form a complete target table code set, thereby ensuring the integrity of the data tables participating in SQL generation in complex query scenarios.

[0015] Preferably, in the process of generating SQL query statements, the DDL information, tool task description, and query examples are hierarchically organized and multiple prompt words are input into the large model. This allows the large model to first determine the query fields and conditions, then determine the data table relationships, and finally generate a complete SQL statement, thereby improving the logical correctness and structural standardization of SQL generation.

[0016] Preferably, after executing the SQL query statement, the query results are further input into the large model for semantic consistency verification with the original query description. When an inconsistency is detected between the query results and the query description, correction information is generated and the SQL generation process is retried to improve the matching degree between the final query results and the user's query intent.

[0017] Preferably, when an SQL query statement execution exception occurs, the error type is classified and identified by parsing the error information returned by the database and combining it with the field definitions and table structure relationships in the DDL information. This includes field non-existence, table association errors, and query condition conflicts. Corresponding correction strategies are generated for different error types, thereby improving the pertinence and effectiveness of SQL statement correction.

[0018] Preferably, during the analysis of the query description, when it is detected that the query description lacks key constraints, multiple candidate query directions are generated and fed back to the user for selection, thereby guiding the user to improve the query description, making the generated tool task description clearer, and thus improving the accuracy of subsequent SQL generation.

[0019] Preferably, the data query tool supports combined calls according to a preset call order. In query scenarios involving multiple data query topics, the call order is determined according to the logical relationship between the task descriptions of each tool, and intermediate query results are obtained step by step through sequential calls to achieve joint queries across data query topics.

[0020] The technical effects and advantages provided by the present invention in the above technical solution are as follows: This invention introduces a data query topic partitioning mechanism and a structured expression method for database table summary files, enabling large models to locate data tables based on semantic understanding and structural information when processing query tasks. This avoids misunderstandings caused by missing information and can accurately identify complete data table sets even in multi-table join scenarios, thereby generating logically correct SQL query statements. This improves the overall accuracy of data query results and enhances the stability and usability of complex query tasks, allowing the system to continuously output query results that meet user needs in practical applications.

[0021] This invention transforms the query process from one reliant on similarity retrieval to one based on intent recognition through the design of data query tools and tool summary files. This reduces reliance on vector databases and word embedding models, thereby lowering resource consumption and maintenance complexity during system deployment and operation. Simultaneously, it simplifies the overall technical architecture, reduces construction costs while ensuring query performance, and makes the method more suitable for engineering applications in large-scale database scenarios, thus enhancing the system's promotional value. Attached Figure Description

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

[0023] Figure 1 This diagram illustrates a use case for querying large model data in this invention.

[0024] Figure 2 This is a usage scenario diagram of the data query tool of the present invention. Detailed Implementation

[0025] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the description of this disclosure will be more complete and fully convey the concept of the exemplary embodiments to those skilled in the art.

[0026] This invention provides, for example Figures 1 to 2 The method shown here can be used to improve the accuracy of database queries based on large models, and includes the following steps: The target database is divided according to business scenarios, multiple data query topics are constructed, and corresponding data query tools are built for each data query topic. At the same time, a database table summary file is generated based on the DDL information of each data table in the database. The database table summary file includes table code, table name, table overview, related tables and necessary table information. It receives query descriptions input by users, performs semantic parsing on the query descriptions using a large model, determines matching data query tools based on pre-built tool summary files, and generates corresponding tool task descriptions. For data query tools, locate the target table code corresponding to the query task in the database table summary file according to the tool task description, and read the corresponding DDL information; Input the DDL information, tool task description, and query example into the large model to generate an SQL query statement, and execute the SQL query statement to obtain the query results; When an SQL query statement execution error occurs or the query description does not meet the preset data query theme, the query description or SQL query statement is analyzed and correction information is generated to update the query description or regenerate the SQL query statement until the query result is obtained.

[0027] Implementation Method 1: In this implementation method, a data query method based on a large model proposed in this invention is described in detail using the database of a risk management platform in a chemical industrial park as a specific application scenario. This platform database is large, involving more than 100 data tables and over 10,000 data fields. The data structure is complex, with diverse relationships between tables. Especially in hazardous source management, it involves data from multiple dimensions, including basic hazardous source information, hazardous substance information, storage status information, and related regulatory information. Therefore, traditional keyword-based retrieval or semantic similarity matching techniques struggle to accurately and completely locate all data tables relevant to the query task, easily leading to errors in query statement generation or inaccurate query results.

[0028] To address the aforementioned issues, this implementation first performs a structured decomposition of the database at the business level. Specifically, the entire database is divided into multiple independent data query topics according to actual business scenarios. All data tables related to hazard sources are uniformly grouped into the "Hazard Source Management" data query topic, and a unique data query tool code A is assigned to this topic. This approach decouples the originally highly coupled large-scale database structure, allowing each data query tool to focus only on data within a specific business scope, thereby reducing the complexity of subsequent queries.

[0029] After defining the data query themes, corresponding table summary files are constructed based on the DDL (Data Definition Language) information of each data table in the database related to hazard source management. The table summary files describe the data tables in a structured manner, including but not limited to the following fields: table code, table name, table overview, related tables, and necessary tables. Specifically, the table code uniquely identifies the data table for quick subsequent location; the table name intuitively expresses the business meaning of the data table; the table overview describes the main content of the data stored in the table; the related tables indicate other related data tables that may be involved in the query process; and the necessary tables identify the core data tables that must participate in the query in a specific query task. By constructing these table summary files, the large model can understand the relationships between data tables through structured semantic information instead of directly parsing the complex raw DDL structure when processing query tasks, thus significantly improving understanding efficiency and accuracy.

[0030] When a user inputs a query request via natural language, such as "query the types and distribution of current hazards in the park," the system first inputs this query description into a query intent recognition module built on a large-scale model. This module, combined with a pre-built tool summary file, performs semantic parsing of the user input. The tool summary file contains information such as the tool code, tool name, function description, data scope, and precautions for each data query tool. By matching the user input with the tool summary information, the large-scale model can identify that the current query request belongs to the "hazard management" data query topic, thereby determining that the data query tool with tool code A should be invoked. At the same time, the large-scale model generates a corresponding tool task description based on the user's query content, such as "query the types of hazards and their spatial distribution," to clarify the specific target of the subsequent query.

[0031] After determining the tool code and tool task, the system invokes a pre-designed large model prompt template, taking the tool task, database summary file, and preset query examples as input to guide the large model in further analyzing the target data tables involved in the query. Specifically, the large model, through understanding the table overview and related table information in the database summary file, gradually filters out the set of table codes related to the query task and determines the relationships between the data tables. For example, when querying the types and distribution of hazard sources, multiple data tables may be involved, such as the hazard source basic information table, the hazard source type table, and the location information table. Through this method, a precise mapping from the "query task" to the "target data table set" is achieved.

[0032] After determining the target table code, the system uses the DDL reading module to read the corresponding table structure definition information from the database or a pre-stored DDL file based on the table code and name. The DDL information includes detailed structural information such as field names, field types, primary key constraints, and foreign key relationships. Subsequently, the DDL information, along with the tool task description and query examples, is injected into the SQL generation prompts to construct a complete large-scale model input context. This context not only contains structured table information but also example query logic and synonyms, guiding the large-scale model to generate SQL statements that conform to database syntax and meet query requirements.

[0033] After generating the SQL statement, the system submits it to the database for execution via the data query execution module. The database performs the data query operation based on the SQL statement and returns the query results to the system. The system further formats the query results and provides feedback to the user, achieving a complete closed loop from natural language input to data result output.

[0034] Compared to existing RAG-based database query solutions, this implementation transforms the original passive retrieval method, which relies on keywords or semantic matching, into a proactive decision-making method driven by query intent by introducing a data query topic partitioning mechanism, a database table summary file structure, and a tool-based query process. Especially in multi-table join scenarios, the explicit definition of join and necessary tables in the database table summary allows the large model to progressively determine the required data tables in a manner similar to human problem analysis, effectively avoiding SQL generation errors caused by incomplete DDL retrieval.

[0035] Furthermore, since this implementation no longer relies on vector databases or embedding models for semantic retrieval, but instead achieves data table location through the collaborative design of structured summary files and large model prompts, it can significantly reduce the system's infrastructure construction costs and simplify the system architecture. Simultaneously, the structured decomposition and step-by-step reasoning of the query task also improves the interpretability and controllability of the query process.

[0036] This implementation method constructs a database query system centered on data query tools, and combines database table summary files and large model prompts to achieve efficient parsing and accurate querying of complex database structures under a single data query topic, thereby improving the accuracy of database queries based on large models and the availability of the system.

[0037] Implementation Method Two: In this implementation method, a joint query scenario involving two data query themes—"hazard source management" and "agile emergency management"—in a risk management platform of a chemical industrial park is used as an example to illustrate the database query method based on a large model proposed in this invention. This platform's database is quite large, containing over 100 data tables and more than 10,000 data fields, with complex data relationships between different business modules. For example, in actual operations, the information on stored hazardous materials is often closely related to the status of emergency material reserves, requiring joint analysis and querying across business modules. Therefore, to address this complex query requirement across data query themes, this implementation method constructs a collaborative working mechanism for multiple data query tools to achieve efficient integration and accurate querying of multi-theme data.

[0038] First, the database is divided according to business scenarios. Data tables related to hazard sources are assigned to the "Hazard Source Management" data query topic and assigned data query tool code A; data tables related to emergency resources, emergency supplies, and emergency response are assigned to the "Agile Emergency Management" data query topic and assigned data query tool code B. For each data query tool, a corresponding tool summary file is constructed. The tool summary file adopts a structured design and includes at least the tool code, tool name, function description, data scope, and precautions. The function description explains the query types supported by the tool, such as hazard source information query or emergency resource dispatch query; the data scope limits the range of data tables accessible by the tool; and the precautions indicate potential constraints or special rules during the query process. By constructing these tool summary files, the large model can accurately understand the functional boundaries and applicable scenarios of different tools when identifying query intent.

[0039] When a user inputs a complex query, such as "query the storage of hazardous materials in the park and the corresponding emergency supplies reserves," the system first passes the natural language input to a query intent recognition module built on a large model. This module, combining a pre-built tool summary file and preset query use cases, performs multi-level semantic parsing of the user input. On one hand, by analyzing key entities in the query statement (such as "hazardous source," "storage material," and "emergency supplies") and their semantic relationships, it identifies that the query involves two data query topics: hazardous source management and agile emergency management. On the other hand, by combining the data scope and functional description in the tool summary file, it determines that two data query tools, tool code A and tool code B, need to be invoked. Simultaneously, the large model further generates task descriptions for each tool; for example, it generates a task description for "obtaining information on hazardous source storage materials" for tool A and a task description for "obtaining emergency supplies reserves" for tool B. Based on the logical relationships between tasks, it determines the invocation order; for example, it first obtains hazardous source-related information and then queries the corresponding emergency resource data.

[0040] After determining the toolset and its invocation order, the system enters the data table location phase. For each tool task, the corresponding data query tool is invoked, and data tables are filtered based on their respective database table summary files. Specifically, for tool A, by analyzing the table overview, related tables, and necessary table information in the database table summary file corresponding to hazard source management, the target table code set related to "hazardous source stored substances" is filtered out, such as the hazard source basic information table and the hazardous substance information table; for tool B, by analyzing the database table summary file corresponding to agile emergency management, data tables related to "emergency material reserves" are filtered out, such as the emergency material inventory table and the material classification table. Through the above method, a precise mapping from tool tasks to data table sets is achieved.

[0041] After acquiring the data table sets corresponding to each tool, the system uses the DDL reading module to read the corresponding data table structure definition information one by one according to the table code, including field names, field types, primary and foreign key relationships, and constraints. Subsequently, the large model integrates the data table information from different data query tools, focusing on analyzing the relationships between different data tables. For example, through foreign key relationships or business semantics, it determines the association path between the hazard source table and the emergency supplies table, thereby constructing a complete data association network. Based on this, the large model combines the user's original query description, the task descriptions of each tool, and example query cases to comprehensively reason about the query conditions, output fields, and association methods, generating SQL query statements that include multi-table join operations. These SQL statements typically include multi-table JOIN operations, condition filtering, and field selection, capable of simultaneously meeting cross-topic data query needs.

[0042] After generating the SQL statement, the system submits it to the database for execution via the data query execution module. During execution, the database performs data queries based on the SQL statement and returns the results. The system then performs structured processing on the returned results and provides the final result back to the user, thus completing a complex query task across multiple data topics.

[0043] Furthermore, in this embodiment, a query result verification mechanism can be incorporated to validate the validity of the query results. Specifically, a large-scale model is used to compare and analyze the query results with the user's original query intent to determine whether the results meet the user's needs. When a deviation is found in the results, the query conditions can be further adjusted or the SQL statement can be regenerated to improve the accuracy of the query results.

[0044] Compared to existing RAG-based solutions, this implementation introduces a multi-data query tool collaboration mechanism to break down complex query tasks into multiple sub-tasks. It also achieves precise data table location through tool-level semantic abstraction, effectively avoiding the problem of incomplete DDL information retrieval in multi-table join scenarios, a common issue with traditional keyword or semantic similarity-based retrieval methods. Furthermore, the two-layer structured design of tool summary files and database / table summary files allows the large model to analyze the query task step-by-step, similar to human problem-solving, thus improving the accuracy of SQL generation.

[0045] Furthermore, this implementation reduces reliance on vector databases and embedding models, lowering system infrastructure construction costs and improving system deployment flexibility. Simultaneously, the multi-tool collaboration mechanism enables the system to possess excellent scalability; when new business scenarios are added, only corresponding data query tools and summary files need to be added, without requiring large-scale adjustments to the overall system architecture.

[0046] This implementation method achieves efficient support for complex cross-business data query tasks by constructing a joint query mechanism based on multiple data query topics. While improving query accuracy, it also enhances the system's availability, scalability, and engineering implementation efficiency.

[0047] Implementation Method 3: In this implementation method, the specific implementation of the query error correction module designed in this invention in practical applications is described in detail. This query error correction module works collaboratively with the query intent recognition module, the data query tool system, and the SQL generation and execution module, permeating the entire data query process. It is used to identify, analyze, and correct potential errors at multiple stages, including user input, query task parsing, SQL generation, and execution, thereby improving the accuracy, stability, and user interaction experience of the overall query system.

[0048] In this implementation, we still use the database of a risk management platform in a chemical industrial park as the application background. This database contains more than 100 data tables and over 10,000 fields, with a complex business structure and dense relationships between data. In such a complex data environment, when users initiate query requests using natural language, they often encounter problems such as non-standard expression, ambiguous semantics, or unclear query scope, which can easily lead to errors in query intent recognition or SQL generation failure. Therefore, this implementation introduces a multi-stage error correction mechanism based on a large model to dynamically optimize the entire query process.

[0049] First, during the user's query description input stage, the system uses a query intent recognition module to perform preliminary analysis of the user input and, in conjunction with a tool summary file, determines whether a matching data query tool exists. The tool summary file contains information such as tool codes, function descriptions, data ranges, and precautions, clearly defining the applicable scope of each data query tool. When the system detects that the user's input query description exceeds the data range of any tool, or cannot find a specific tool code, it determines that the query request falls under the "incorrect query scope" or "no matching tool" category. In this case, the system generates guiding prompts through a large model, indicating to the user that the current query content exceeds the system's supported scope. It also automatically generates several example query statements that conform to the current system's capabilities, based on the existing function descriptions in the tool summary file. For example, when a user inputs "Query all historical accident responsible persons and future risk predictions in the park," the system can prompt "The current system only supports hazard source management and emergency resource queries; please adjust the query scope," and provide examples such as "Query the current hazard source distribution" or "Query emergency material reserves," thereby guiding the user to modify the query description to conform to the system's supported scope.

[0050] Secondly, during the query intent parsing phase, when user input, while not exceeding the data range, exhibits semantic ambiguity or incomplete information, the system performs fine-grained analysis of the query description using a large model to identify whether key constraints are missing. For example, for a user inputting "query about hazard sources," the system determines the query intent to be unclear because the query dimension (such as time range, regional range, or specific fields) is not specified. In this case, the error correction module generates multiple rounds of prompts to guide the user to supplement necessary information, such as prompting the user to select the query scope (e.g., "whether to limit to a certain region") or query content (e.g., "whether to query the type, quantity, or distribution of hazard sources"). Simultaneously, multiple candidate query directions can be provided for the user to choose from, thereby gradually transforming the original fuzzy query into a clearly structured and executable query description, improving the accuracy of subsequent SQL generation.

[0051] Furthermore, after identifying the query intent and generating the SQL statement, when an error occurs during the SQL statement's execution in the database, the error correction module enters the execution error analysis phase. Specifically, the system first obtains the error information returned by the database, such as syntax errors, field non-existence errors, table non-existence errors, or join condition errors. Subsequently, the error information, along with the corresponding DDL structure information and query task context, is input into the large model for analysis. Through semantic parsing of the error information by the large model, the specific cause of the error can be identified, such as misspelled field names, missing join tables, unreasonable JOIN conditions, or conflicting query conditions.

[0052] After identifying the cause of the error, the system further generates targeted correction suggestions. For example, when a field is found to be missing, the system can recommend similar field names based on DDL information; when a table join error is detected, it can suggest supplementing or modifying the join path based on the join table information in the database table summary file; when an unreasonable query condition is detected, the system can prompt the user to adjust the filter conditions or range. Furthermore, in some cases, the system can automatically adjust the SQL generation prompts based on the correction suggestions and re-invoke the large model to generate a new SQL statement, thereby achieving an automatic error correction and retry mechanism.

[0053] Furthermore, during the query result return phase, this implementation can further introduce a query result intent verification mechanism. Specifically, the query results are re-inputted into the large model for comparison and analysis against the user's original query description to determine whether the results satisfy the user's query intent. For example, when a user queries "distribution of hazardous sources," but the returned results only contain some fields or are incomplete, the system can identify the result deviation and prompt the user or automatically trigger a re-query process, thereby further improving the accuracy of the query results.

[0054] It is worth noting that in each of the above stages, the error correction module uses both database table summary files and tool summary files for auxiliary judgment. The database table summary files provide information on the structural relationships between data tables, which helps in analyzing SQL errors and recommending correction paths; the tool summary files are used to determine the query scope and provide user guidance information. Through the synergistic effect of these two types of structured summary files and the large model's prompts, the error correction process not only possesses semantic understanding capabilities but also structured reasoning capabilities, thereby significantly improving the error correction effect.

[0055] Compared to existing technologies, traditional RAG-based database query systems typically lack a systematic error handling mechanism. Once a query fails, they only return error messages, failing to effectively guide users in making corrections. This implementation, however, constructs a multi-stage error correction mechanism covering the entire process of "query input, intent recognition, SQL generation, execution feedback, and result verification." This enables the system to possess interactive guidance capabilities similar to human experts, not only analyzing the causes of errors but also proactively guiding users to optimize their query expressions, thereby significantly improving the query success rate.

[0056] Furthermore, since this implementation method uses a large model for error analysis and guidance, it eliminates the need for complex rule engines or additional machine learning models, thus reducing system development and maintenance costs. Simultaneously, by continuously accumulating user query and error correction data, the design of prompt words and the example library can be further optimized, thereby continuously improving system performance.

[0057] This implementation method achieves dynamic optimization of the entire database query process by constructing a multi-stage query correction mechanism based on a large model. It not only effectively solves the query failure problem caused by non-standard user input or SQL generation errors, but also improves the system's availability, robustness, and user experience, providing an efficient and reliable solution for intelligent querying in complex database environments.

[0058] This invention introduces a data query topic partitioning mechanism and a structured expression method for database table summary files, enabling large models to locate data tables based on semantic understanding and structural information when processing query tasks. This avoids misunderstandings caused by missing information and can accurately identify complete data table sets even in multi-table join scenarios, thereby generating logically correct SQL query statements. This improves the overall accuracy of data query results and enhances the stability and usability of complex query tasks, allowing the system to continuously output query results that meet user needs in practical applications.

[0059] This invention transforms the query process from one reliant on similarity retrieval to one based on intent recognition through the design of data query tools and tool summary files. This reduces reliance on vector databases and word embedding models, thereby lowering resource consumption and maintenance complexity during system deployment and operation. Simultaneously, it simplifies the overall technical architecture, reduces construction costs while ensuring query performance, and makes the method more suitable for engineering applications in large-scale database scenarios, thus enhancing the system's promotional value.

[0060] The foregoing has only described certain exemplary embodiments of the present invention by way of illustration. Undoubtedly, those skilled in the art can modify the described embodiments in various ways without departing from the spirit and scope of the present invention. Therefore, the foregoing drawings and descriptions are illustrative in nature and should not be construed as limiting the scope of protection of the claims of the present invention.

Claims

1. A method for improving the accuracy of database queries based on large models, characterized in that, Includes the following steps: The target database is divided according to business scenarios, multiple data query topics are constructed, and corresponding data query tools are built for each data query topic. At the same time, a database table summary file is generated based on the DDL information of each data table in the database. The database table summary file includes table code, table name, table overview, related tables and necessary table information. It receives query descriptions input by users, performs semantic parsing on the query descriptions using a large model, determines matching data query tools based on pre-built tool summary files, and generates corresponding tool task descriptions. For data query tools, locate the target table code corresponding to the query task in the database table summary file according to the tool task description, and read the corresponding DDL information; Input the DDL information, tool task description, and query example into the large model to generate an SQL query statement, and execute the SQL query statement to obtain the query results; When an SQL query statement execution error occurs or the query description does not meet the preset data query theme, the query description or SQL query statement is analyzed and correction information is generated. The query description is then updated or the SQL query statement is regenerated until the query result is obtained.

2. The method for improving the accuracy of database queries based on large models according to claim 1, characterized in that, The association table information in the database table summary file is obtained by extracting and organizing the foreign key relationships between various data tables in the database and the preset business association rules, and stored in the database table summary file in the form of structured relationships, so that the large model can perform multi-level reasoning based on the association table information when locating the target table encoding.

3. A method for improving the accuracy of database queries based on large models, as described in claim 1, characterized in that... The tool summary file includes data query scope boundary information and query restriction information. It is used to determine whether the query description belongs to the preset data query topic when performing semantic parsing of the query description, and to generate limiting prompt information when the query description exceeds the data query scope.

4. A method for improving the accuracy of database queries based on large models, as described in claim 1, characterized in that... In the process of semantic parsing of query descriptions using large models, a pre-defined set of query use cases and synonym mapping rules are introduced to standardize and transform the query descriptions, converting natural language expressions into structured query task descriptions.

5. A method for improving the accuracy of database queries based on large models, as described in claim 1, characterized in that... In the process of locating the target table code based on the tool task description, the core data tables are determined first based on the necessary table information in the library table summary file, and the relevant data table set is gradually expanded by combining the related table information to form a complete target table code set.

6. A method for improving the accuracy of database queries based on large models, as described in claim 5, is characterized in that... In the process of generating SQL query statements, DDL information, tool task descriptions, and query examples are organized hierarchically and multiple prompt words are input into the large model. The large model first determines the query fields and conditions, then determines the data table relationships, and finally generates the complete SQL statement.

7. A method for improving the accuracy of database queries based on large models, as described in claim 5, characterized in that, After executing the SQL query statement, the query results are further compared with the original query description input into the large model for semantic consistency verification. When the query results are found to be inconsistent with the query description, correction information is generated and the SQL generation process is retried.

8. A method for improving the accuracy of database queries based on large models, as described in claim 5, characterized in that... When an SQL query execution exception occurs, the error information returned by the database is parsed and combined with the field definitions and table structure relationships in the DDL information to classify and identify the error type, including field non-existence, table join errors, and query condition conflicts, and corresponding correction strategies are generated for different error types.

9. A method for improving the accuracy of database queries based on large models, as described in claim 1, characterized in that... During the analysis of query descriptions, when it is detected that the query description lacks key constraints, multiple candidate query directions are generated and fed back to the user for selection, guiding the user to improve the query description and making the generated tool task description clearer.

10. A method for improving the accuracy of database queries based on large models, as described in claim 1, characterized in that, The data query tool supports combined calls according to a preset call order. In query scenarios involving multiple data query topics, the call order is determined based on the logical relationship between the task descriptions of each tool, and intermediate query results are obtained step by step through sequential calls.