SQL statement generation system
By leveraging the collaborative retrieval capabilities of a multi-source knowledge base cluster and a vector engine module, the accuracy and security issues of SQL statement generation in existing technologies are resolved. This approach adapts to heterogeneous environments with multiple data sources at the enterprise level, enabling efficient and secure SQL statement generation.
Patent Information
- Application Number
- CN202511114568.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-11
- Publication Date
- 2025-11-11
AI Technical Summary
Existing technologies suffer from problems such as incorrect table names, incorrect field mappings, incorrect business logic, insufficient retrieval accuracy, and insufficient security when generating SQL statements, which are particularly difficult to handle in heterogeneous enterprise-level multi-data source environments.
It employs a multi-source knowledge base cluster module, including a schema vector library, a business knowledge vector library, a security tag vector library, a dialect knowledge vector library, and a historical case vector library. Through structural, semantic, and text encoders, it converts data of different data types into vector representations, and uses a vector engine module for collaborative retrieval. Combined with an LLM generator and SQL optimizer, it generates accurate SQL statements and implements fine-grained access control and security filtering.
It improves the accuracy and security of SQL statement generation, adapts to heterogeneous environments with multiple data sources, supports domestic databases, and achieves continuous self-optimization and security compliance.
Smart Images

Figure CN120929481A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to an SQL statement generation system. Background Technology
[0002] In some data query scenarios, users often use natural language to query relevant databases to obtain the data query results they need. With the rapid development of big data and artificial intelligence technologies, natural language to SQL (Text-to-SQL) technology has become an important means to lower the threshold for data querying. However, related technologies often use a single vector space to process all types of information and lack sufficient understanding of specific domain terminology and business logic. This results in the generated SQL statements often having problems such as incorrect table names, incorrect field mapping, incorrect business logic, and insufficient retrieval precision, thereby reducing the accuracy of the generated SQL statements. Summary of the Invention
[0003] The purpose of this invention is to provide an SQL statement generation system to improve the accuracy of generated SQL statements.
[0004] This invention provides an SQL statement generation system, comprising: a query understanding module, a vector engine module, a multi-source knowledge base cluster module, and an SQL generation module. The multi-source knowledge base cluster module includes multiple vector libraries, each storing data vectors of a data type corresponding to that library. The query understanding module receives natural language query questions input by a user, parses and processes the natural language query questions to obtain a processed query question, and sends the processed query question to the vector engine module. The vector engine module performs a collaborative retrieval of at least one vector library based on the processed query question to obtain target data information associated with the processed query question; the target data information is then sent to the SQL generation module. The SQL generation module generates a target SQL statement based on the target data information.
[0005] Furthermore, multiple vector libraries include: a schema vector library, a business knowledge vector library, a security tag vector library, a dialect knowledge vector library, and a historical case vector library. The multi-source knowledge base cluster module also includes a vectorization processing module, which is used to: encode the first original data of the first data type using a structure encoder to obtain a data vector of the first data type, and save the data vector of the first data type to the schema vector library; wherein, the first data type includes: table structure type, field type, relation constraint type, and index type; and to encode the second original data of the second data type and the third original data of the third data type respectively using a semantic encoder to obtain data vectors of the second data type and the third data type, and save the data vector of the second data type to the schema vector library. The data vectors of the third data type are saved to the business knowledge vector library, and the data vectors of the third data type are saved to the dialect knowledge vector library. The second data type includes domain terms, calculation indicators, business rules, and data lineage from various fields. The third data type includes syntax, functions, and optimization strategies. The fourth raw data of the fourth data type and the fifth raw data of the fifth data type are encoded using a text encoder to obtain data vectors of the fourth and fifth data types respectively. The data vectors of the fourth data type are saved to the security tag vector library, and the data vectors of the fifth data type are saved to the historical case vector library. The fourth data type includes user permissions, sensitive data security levels, and access policies. The fifth data type includes successful SQL statement cases and failed SQL statement cases.
[0006] Furthermore, the query understanding module also includes: a language parsing unit, an intent recognition unit, a context processing unit, and a preprocessing unit; the language parsing unit is used to parse and process the natural language query question to obtain the parsing result; the intent recognition unit is used to recognize the parsing result and output the intent recognition result; the context processing unit is used to perform context analysis based on the intent recognition result and output the context analysis result; the preprocessing unit is used to preprocess the context analysis result and output the processed query question.
[0007] Furthermore, the SQL generation module also includes: a fusion unit, a prompt word engineer, an LLM generator, and an SQL optimizer; the fusion unit is used to integrate and process the received target data information to obtain the processing result; the prompt word engineer is used to generate target prompt words based on the processing result; the LLM generator is used to generate an initial SQL statement based on the target prompt words; and the SQL optimizer is used to optimize the initial SQL statement to obtain the target SQL statement.
[0008] Furthermore, the system also includes a user access module and a security control module; the security control module includes an identity authentication unit and a permission verification unit; the user access module is used to receive user access instructions through a preset input interface; the user access instructions carry user login information and natural language query questions; the identity authentication unit is used to authenticate the accessing user based on the user login information, and if the authentication is successful, the user login information is sent to the permission verification unit; the permission verification unit is used to verify the accessing user's user permissions based on the user login information and natural language query questions, and if the verification is successful, the natural language query questions are sent to the query understanding module.
[0009] Furthermore, the security control module also includes: a security level tagging engine unit; the security level tagging engine unit pre-stores information on users allowed to access the system, as well as the allowed access permissions of the users corresponding to that information; the security level tagging engine unit is used to determine whether the user belongs to the user corresponding to the allowed access information based on the user login information after the user's identity is authenticated by the identity authentication unit; if the user belongs to the user corresponding to the allowed access information, the access permissions of the user are sent to the permission verification unit; the permission verification unit is used to verify the user's permissions based on a natural language query question and the user's allowed access permissions.
[0010] Furthermore, the security level labeling engine unit pre-stores multiple sensitivity labels and the sensitive data categories corresponding to each sensitivity label; wherein, the sensitivity label is used to indicate whether access to the data corresponding to the corresponding sensitive data category is allowed; the security level labeling engine unit is also used to obtain the intent recognition result and determine the target sensitive data category to which the intent recognition result belongs; determine the corresponding target sensitivity label according to the target sensitive data category, and determine whether context analysis based on the intent recognition result is allowed through the context processing unit according to the target sensitivity label.
[0011] Furthermore, the vector engine module is also used to: obtain security-related data from the security-level tagging engine unit; wherein, the security-related data includes at least one of the following: allowed access user information, and the allowed access permissions of the users corresponding to the allowed access user information, multiple sensitivity tags, and the sensitive data categories corresponding to each sensitivity tag; based on the processed query question, perform collaborative retrieval on at least one vector library to obtain initial data information associated with the processed query question; wherein, the initial data information includes multiple sub-information; filter the initial data information based on the security-related data to obtain filtered initial data information; and sort the multiple sub-information in the filtered initial data information according to a preset sorting method to obtain target data information.
[0012] Furthermore, the system includes an adapter module and a quality assessment module. The adapter module includes multiple adapters that match various vector libraries. The quality assessment module is used to: perform syntax checks on the target SQL statement and obtain syntax check results; obtain the execution results corresponding to the execution of the target SQL statement, evaluate the execution results, and obtain evaluation results; analyze the syntax check results and evaluation results to obtain a first analysis result; wherein the first analysis result includes at least one of the following: success pattern analysis result, error pattern analysis result, query intent analysis result, and user behavior analysis result; and send the first analysis result to the multi-source knowledge base cluster module to update the various vector libraries in the multi-source knowledge base cluster module.
[0013] Furthermore, the SQL generation module is also used to: update specified parameters based on specified input information; wherein, the specified input information includes: the validation result corresponding to the LLM generator, the updated multiple vector libraries, and the evaluation result; the specified parameters include at least one of the following: the parameters of the prompt word engineer and the parameters of the LLM generator.
[0014] The SQL statement generation system provided by this invention includes multiple vector libraries in a multi-source knowledge base cluster module. Each vector library stores data vectors of the data type corresponding to that library. After receiving the natural language query question input by the user, the query understanding module can parse and process it to obtain the processed query question. The vector engine module can then perform collaborative retrieval of at least one vector library based on the processed query question to obtain the target data information. Since multiple data types are stored in different vector libraries, only the vector library related to the processed query question needs to be retrieved, which improves the retrieval accuracy. Furthermore, the multiple vector libraries corresponding to multiple data vector types help improve the accuracy of the generated SQL statement. Attached Figure Description
[0015] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0016] Figure 1 This is a schematic diagram of an SQL statement generation system provided in an embodiment of the present invention; Figure 2 A schematic diagram of another SQL statement generation system provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the architecture of a multi-source knowledge base cluster module provided in an embodiment of the present invention; Figure 4 A relational connection diagram of a security level tagging engine unit provided in an embodiment of the present invention; Figure 5 A flowchart illustrating an adaptive learning mechanism provided in an embodiment of the present invention. Detailed Implementation
[0017] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] With the rapid development of big data and artificial intelligence technologies, Text-to-SQL (SQL) technology has become an important means of lowering the barrier to data querying. However, existing technologies still have significant limitations when facing enterprise-level applications. From the current state of technological development, existing technical solutions mainly include the following types: 1. Traditional Text-to-SQL models use neural network models based on the Seq2Seq architecture, such as various methods on standard datasets like Spider and WikiSQL, such as RAT-SQL (Relation-Aware Training for Text-to-SQL, a text-to-SQL conversion model), NatSQL (a text-to-SQL conversion model), and DIN-SQL (Decomposed In-Context Learning for Text-to-SQL, a decomposed text-to-SQL model). These solutions mainly focus on SQL generation capabilities in general scenarios.
[0019] 2. The direct application of large language models utilizes the few-shot capabilities of general large models such as GPT (Generative Pre-trained Transformer), Claude (a large language model), and Wenxin Yiyan to generate SQL statements through prompt word engineering.
[0020] 3. The simple RAG (Retrieval-Augmented Generation) enhancement scheme injects database schema information as context into the large language model to improve the relevance of the generated results.
[0021] 4. Knowledge graph-based solutions: By constructing a knowledge graph of database metadata, the system can be assisted in understanding the relationships between tables and business logic.
[0022] Through in-depth analysis of existing technical solutions, several significant shortcomings were found in their practical enterprise applications, as detailed below: 1. At the technical architecture level, existing solutions mostly use a single vector space to process all types of information, which cannot effectively distinguish and utilize knowledge from different dimensions such as schema structure, business rules, and security policies. Existing RAG solutions mix all information (schema, documents, examples, etc.) in the same vector space, resulting in insufficient retrieval accuracy and the inability to accurately locate the most relevant knowledge fragments.
[0023] 2. Regarding accuracy and learning ability, insufficient understanding of domain-specific terminology and business logic leads to frequent issues in generated SQL statements, such as incorrect table names, incorrect field mappings, and business logic errors. Traditional solutions lack self-optimization mechanisms and cannot learn from execution results, making recurring errors difficult to avoid and hindering continuous improvement in system accuracy. Existing technologies also fall short in integrating domain knowledge, exhibiting limited understanding of industry-specific business terminology, calculation rules, and data relationships, often resulting in generated SQL statements that do not conform to business logic.
[0024] 3. In terms of security, the lack of fine-grained access control mechanisms makes it impossible to dynamically filter sensitive data based on user identity, posing a risk of data leakage. Security controls also suffer from coarse-grained issues, lacking dynamic access control based on user identity and data sensitivity, thus failing to meet the security compliance requirements of government and enterprise clients.
[0025] 4. In terms of adaptability to multiple data sources, existing solutions are mainly designed for single databases and are difficult to handle heterogeneous environments with multiple data sources at the enterprise level. In particular, they lack support for domestic databases, have difficulty handling grammatical differences between different database dialects, have weak support for the domestic database ecosystem, and are difficult to meet the requirements of information technology innovation.
[0026] Comprehensive analysis reveals the following fundamental problems with existing solutions: First, the knowledge representation architecture is flawed, as a single vector space cannot effectively distinguish the characteristics of different types of knowledge, such as structured schema information, unstructured business rules, and security policies. Second, the retrieval strategies are limited, as simple vector similarity retrieval cannot handle the mixed requirements of precise matching (such as table names and field names) and semantic matching (such as business terms). Third, the learning mechanism is lacking, as there is no mechanism to optimize the knowledge base from the execution results of SQL statements, thus failing to form a closed loop of continuous improvement. Fourth, the ecosystem adaptability is insufficient, with limited support for heterogeneous environments with multiple data sources and domestic databases.
[0027] Based on this, embodiments of the present invention provide an SQL statement generation system, which can be applied to application scenarios that require generating SQL statements for relevant data queries.
[0028] To facilitate understanding of this embodiment, an SQL statement generation system disclosed in this invention will first be introduced, such as... Figure 1 As shown, the system includes: a query understanding module 10, a vector engine module 11, a multi-source knowledge base cluster module 12, and an SQL generation module 13. The multi-source knowledge base cluster module 12 includes multiple vector libraries, each used to store data vectors of the data type corresponding to that library. The number of different types of vector libraries can be set according to actual needs. Different vector libraries typically store data vectors of different data types. For example, if there are five vector libraries, they can be used to store data vectors of five different data types. By using multiple vector libraries to store data vectors of different data types, it helps to distinguish between various data types, making data classification clearer and thus improving subsequent query efficiency.
[0029] The query understanding module 10 receives natural language query questions input by the user, parses and processes the natural language query questions to obtain the processed query questions, and sends the processed query questions to the vector engine module 11. The natural language query questions can be understood as the natural language expressions input by the user. In actual implementation, the user can input natural language query questions into the query understanding module 10. After receiving the natural language query questions, the query understanding module 10 can parse and process the natural language query questions. For example, it can preprocess the natural language query questions to convert them into data formats suitable for subsequent query processing, and then send the processed query questions to the vector engine module 11.
[0030] The vector engine module 11 is used to perform collaborative retrieval of at least one vector library based on the processed query question to obtain target data information associated with the processed query question; and send the target data information to the SQL generation module 13. In actual implementation, when the vector engine module 11 receives the above-mentioned processed query question, it can query the required target data information from one or more relevant vector libraries according to the data type associated with the processed query question, and send it to the SQL generation module 13. For example, if the processed query question only involves table structure, the relevant target data information can be queried from the vector library corresponding to the table structure, without needing to query other vector libraries. This solution can divide different data types into different vector spaces. When relevant information needs to be retrieved, only the relevant vector space needs to be retrieved, thereby reducing the server's operating pressure and improving data query efficiency.
[0031] The SQL generation module 13 is used to generate target SQL statements based on target data information. SQL is a database query and programming language used to access data and query, update and manage relational database systems. After receiving the target data information, the SQL generation module 13 can generate the target SQL statement corresponding to the natural language query question based on the target data information.
[0032] The aforementioned SQL statement generation system includes multiple vector libraries in its multi-source knowledge base cluster module. Each vector library stores data vectors of the data type corresponding to that library. After receiving the natural language query question input by the user, the query understanding module can parse and process it to obtain the processed query question. The vector engine module can then perform collaborative retrieval of at least one vector library based on the processed query question to obtain the target data information. Since multiple data types are stored in different vector libraries, only the vector library related to the processed query question needs to be retrieved, which improves retrieval accuracy. Furthermore, the multiple vector libraries corresponding to multiple data vector types help improve the accuracy of the generated SQL statements.
[0033] Furthermore, the construction of the multi-source knowledge base cluster module is a core component of the system. In this embodiment, there are five different vector libraries, specifically including: a schema vector library, a business knowledge vector library, a security tag vector library, a dialect knowledge vector library, and a historical case vector library. The multi-source knowledge base cluster module also includes a vectorization processing module, which is used for: The first original data of the first data type is encoded by a structure encoder to obtain a data vector of the first data type, and the data vector of the first data type is saved to the schema vector library. The first data type includes: table structure type, field type, relation constraint type, and index type. The structure encoder can be understood as a model that captures structural information in structured data to convert structured data into vector representation. In actual implementation, when the first original data is structured data such as table structure, field semantics, relation constraints, and index information, the structure encoder can encode the first original data to obtain the corresponding data vector and save it to the schema vector library. That is, in this embodiment, the schema vector library is responsible for storing the deeply vectorized table structure, field semantics, relation constraints, index information, etc.
[0034] The second original data of the second data type and the third original data of the third data type are encoded by a semantic encoder to obtain data vectors of the second data type and the third data type. The data vector of the second data type is saved to the business knowledge vector library, and the data vector of the third data type is saved to the dialect knowledge vector library. The second data type includes domain terms, calculation indicators, business rules, and data lineages from various fields. The third data type includes syntax, functions, and optimization strategies. The aforementioned semantic encoder can be understood as a model that captures semantic information in natural language text and converts it into a low-dimensional vector representation. In practical implementation, when the second original data is natural language text containing domain terms, computational indicators, business rules, data lineage relationships, etc., from various domains, the semantic encoder can encode the second original data to obtain corresponding data vectors, which are then saved to the business knowledge vector library. When the third original data is natural language text containing syntax, functions, optimization strategies, etc., the semantic encoder can encode the second original data to obtain corresponding data vectors, which are then saved to the dialect knowledge vector library. That is, in this embodiment, the business knowledge vector library is responsible for storing the vectorized domain terms, computational indicators, business rules, data lineage relationships, etc., from various domains; the dialect knowledge vector library is responsible for storing the vectorized unique syntax, functions, optimization strategies, etc.
[0035] The fourth original data of the fourth data type and the fifth original data of the fifth data type are encoded by a text encoder to obtain data vectors of the fourth data type and the fifth data type, respectively. The data vector of the fourth data type is saved to the security tag vector library, and the data vector of the fifth data type is saved to the historical case vector library. The fourth data type includes: user permissions, sensitive data security level, and access policy; the fifth data type includes: successful SQL statement cases and failed SQL statement cases.
[0036] The aforementioned text encoder can be understood as a model that captures syntactic information in natural language text to convert it into a vector representation. In practical implementation, when the fourth raw data is natural language text such as user permissions, sensitive data classification, and access policies, the text encoder can encode the fourth raw data to obtain the corresponding data vector, which is then saved to the security tag vector library. When the fifth raw data is natural language text such as successful SQL statement examples or failed SQL statement examples, the text encoder can encode the fifth raw data to obtain the corresponding data vector, which is then saved to the historical case vector library. That is, in this embodiment, the security tag vector library is responsible for storing vectorized multi-dimensional security tags such as user permissions, sensitive data classification, and access policies; the historical case vector library is responsible for storing vectorized successful SQL statement examples (which can be understood as an answer book) and failed SQL statement examples (which can be understood as an error book).
[0037] For ease of understanding, see Figure 2 The diagram shown is of another SQL statement generation system. It should be noted that in the following figures, solid lines represent calling relationships and dashed lines represent signal transmission directions. Figure 2 This includes a query understanding layer (corresponding to the query understanding module mentioned above), a core vector engine (corresponding to the vector engine module mentioned above), a multi-source knowledge base cluster (corresponding to the multi-source knowledge base cluster module mentioned above), and an SQL generation engine (corresponding to the SQL generation module mentioned above). See [link to documentation]. Figure 3 The diagram shown illustrates the architecture of a multi-source knowledge base cluster module. Figure 2 and Figure 3 As can be seen, the multi-source knowledge base cluster includes: a schema vector library, a business knowledge base (corresponding to the aforementioned business knowledge vector library), a security tag library (corresponding to the aforementioned security tag vector library), a dialect knowledge base (corresponding to the aforementioned dialect knowledge vector library), and a historical case library (corresponding to the aforementioned historical case vector library). Among these, the schema vector space in the schema vector library is primarily responsible for storing vector representations of table structure information, field information, and relational information; the business vector space in the business knowledge base is primarily responsible for storing vector representations of calculation metrics, business rules, and business attributes; the dialect vector space in the dialect knowledge base is primarily responsible for storing vector representations of SQL syntax, built-in functions, and optimization strategies; the case vector space in the historical case library is primarily responsible for storing vector representations of successful cases, error cases, and query templates; and the security vector space in the security tag library is primarily responsible for storing vector representations of user permissions, sensitive data security levels, and access policies. This can be achieved through... Figure 3The structural encoder, semantic encoder, and text encoder in the vectorization processing engine encode the corresponding raw data to obtain corresponding data vectors. For details, please refer to the relevant descriptions in the preceding embodiments, which will not be repeated here. By performing multimodal fusion on multiple data vectors, the aforementioned multi-source knowledge base cluster can be formed; furthermore, from... Figure 3 It can be seen that a unified vector retrieval layer is usually included in a multi-source knowledge base cluster. When the vector engine module retrieves data from the multi-source knowledge base cluster, the unified vector retrieval layer inside the multi-source knowledge base cluster can first perform a mixed indexing of multiple vector databases based on the processed query question to obtain the mixed index results. Semantic similarity calculation can be performed based on the mixed index results. Through a multi-way recall mechanism, data results related to the processed query question can be obtained. The data results can be fused to obtain the fused result. It can be determined whether to use the fused result as a supplement to the target data information obtained by the vector engine module according to actual needs.
[0038] Should Figure 3 This document details the internal structure and vectorization mechanisms of five vector libraries: Schema Vector Library, Business Knowledge Base, Dialect Knowledge Base, Historical Case Library, and Security Tag Library. It also demonstrates the vector representation methods for different data types and their interrelationships. Figure 3 The unified vector retrieval layer can adopt a three-layer architecture design: by combining a hybrid index with a multi-path recall mechanism that integrates precise matching, semantic similarity, and structured constraints, it helps to improve the accuracy of the obtained fusion results.
[0039] Furthermore, such as Figure 2 As shown, the query understanding module also includes: a language parsing unit, an intent recognition unit, a context processing unit, and a preprocessing unit. The language parsing unit parses and processes the natural language query question to obtain the parsing result. Specifically, the language parsing unit can convert the natural language query question into a machine-understandable format, including word segmentation, part-of-speech tagging, and syntactic parsing. This parsing process improves the accuracy of subsequent processing. The intent recognition unit identifies the parsing result and outputs the intent recognition result. This unit can identify the core requirements of the natural language query question from the parsing result. The context processing unit performs context analysis based on the intent recognition result and outputs the context analysis result. In actual implementation, the natural language query question may be in the form of a multi-turn dialogue. Therefore, after obtaining the intent recognition result, it is necessary to further combine it with the context, integrating historical dialogue content to clarify the current intent and obtain the context analysis result. The preprocessing unit preprocesses the context analysis result and outputs the processed query question. In actual implementation, the context analysis result can be cleaned and transformed, including removing punctuation and lowercase text, to obtain the processed query question for subsequent data retrieval.
[0040] Furthermore, such as Figure 2 As shown, the SQL generation module also includes: a fusion unit, a prompt word engineer, an LLM (Large Language Model) generator, and an SQL optimizer. The fusion unit integrates the received target data information to obtain the processing result. In practical applications, since the target data information can come from multiple different vector libraries, the target data information can be merged to facilitate comprehensive analysis and improve the accuracy of the subsequently generated target SQL statement. The prompt word engineer generates target prompt words based on the processing result. Specifically, it can design and optimize input prompts based on the processing result to guide the LLM generator to generate the expected SQL statement. The LLM generator generates the initial SQL statement based on the target prompt words. The role of the LLM generator in the SQL statement generation process is to use the pre-trained large language model to generate the corresponding initial SQL statement based on the target prompt words. The SQL optimizer optimizes the initial SQL statement to obtain the target SQL statement. By improving the initial SQL statement, execution efficiency can be improved to ensure that the query can be executed efficiently.
[0041] Furthermore, the system also includes: a user access module and a security control module; corresponding to, respectively, as follows: Figure 2The system comprises a user access layer and a security control layer. The security control module includes an identity authentication unit and a permission verification unit. The user access module receives user access commands through a preset input interface. These user access commands carry user login information and a natural language query question. The preset access interface can be a web interface, API interface, or mobile terminal interface. The user login information can include the user's login account and password. In practice, users can input their login information and a natural language query question through a relevant operation page to generate a user access command, which the user access module can receive. The identity authentication unit authenticates the accessing user based on their login information. If authentication is successful, the user login information is sent to the permission verification unit. Specifically, the identity authentication unit verifies the user's login information to confirm the accessing user's identity and determine if the user is a legitimate user. If authentication is successful, the user is considered legitimate. After confirming the user's legitimacy, it is necessary to further verify whether the user has permission to access system resources. In this case, the user login information can be sent to the permission verification unit. The permission verification unit verifies the user's permissions based on the user's login information and the natural language query question. If the verification passes, the natural language query question is sent to the query understanding module. In actual implementation, after receiving the user's login information, the permission verification unit can determine whether the user has permission to access the system resources corresponding to the natural language query question. If the verification passes, the user is considered permitted to access the system resources for that natural language query question, and the natural language query question can then be sent to the query understanding module.
[0042] Furthermore, such as Figure 2As shown, the security control module also includes an audit log, which can be used to statistically record the actions performed by relevant personnel throughout the SQL statement generation process. The security control module also includes a security level tagging engine unit; this unit pre-stores allowed access user information and the corresponding allowed access permissions for each user. This allowed access user information can be represented by job title, job level, etc. Different allowed access user information typically corresponds to different allowed access permissions. For example, if the allowed access user is a senior manager, the allowed access permissions for a senior manager could be access to all resource information in the system; if the allowed access user is a product engineer, the allowed access permissions for a product engineer could be access only to product-related resource information in the system. The security level tagging engine unit, after the identity authentication unit has verified the accessing user's identity, determines whether the accessing user belongs to the user corresponding to the allowed access user information based on the user's login information. If the accessing user belongs to the user corresponding to the allowed access user information, the allowed access permissions for the accessing user are sent to the permission verification unit. The permission verification unit verifies the accessing user's user permissions based on the natural language query question and the accessing user's allowed access permissions. In actual implementation, after the identity authentication unit determines that the accessing user is a legitimate user, the security level tagging engine unit can further determine whether the accessing user belongs to the user information corresponding to the allowed access user information based on the user login information. If it is determined that the accessing user does not belong to the user information corresponding to the allowed access user information, the accessing user is prohibited from accessing system resources, and the SQL statement generation process ends. If it is determined that the accessing user belongs to the user information corresponding to the allowed access user information, the allowed access permissions corresponding to the accessing user can be obtained and sent to the permission verification unit. The permission verification unit can determine whether the natural language query question sent by the accessing user belongs to the accessing user's allowed access permissions. If the natural language query question belongs to the accessing user's allowed access permissions, the accessing user's user permission verification is considered successful, and the natural language query question can continue to be sent to the query understanding module. If the natural language query question does not belong to the accessing user's allowed access permissions, the accessing user's user permission verification is considered unsuccessful, that is, the accessing user does not have the right to query the resource corresponding to the natural language query question, and the SQL statement generation process ends.
[0043] Furthermore, the security classification labeling engine unit pre-stores various sensitivity labels and the corresponding sensitive data categories for each label. Sensitivity labels indicate whether access to data corresponding to a specific sensitive data category is permitted. Sensitivity labels can be set according to actual needs, such as "Top Secret," "Confidential," "Internal," and "Public." The sensitive data categories corresponding to each sensitivity label can be pre-defined; for example, "Top Secret" might include ID card numbers and phone numbers. Generally, the higher the security level of a sensitivity label, the higher the security level of its corresponding sensitive data category, requiring enhanced protection to prevent leakage. Therefore, access to data corresponding to this sensitive data category is usually prohibited. The security classification labeling engine unit also acquires intent recognition results and determines the target sensitive data category to which the intent recognition results belong. Based on the target sensitive data category, it determines the corresponding target sensitivity label and, based on the target sensitivity label, determines whether context analysis based on the intent recognition results is permitted through the context processing unit. In practical implementation, the security level labeling engine unit can obtain the intent recognition result output by the intent recognition unit. Based on the intent recognition result, it determines the target sensitive data category to which the data belongs, and then confirms the target sensitivity label corresponding to the target sensitive data category. Based on the target sensitivity label, it determines whether to allow the continued execution of the subsequent query process. For example, if a user wants to query "ID number" or "phone number" information, since the target sensitivity label corresponding to this information is "top secret", in order to ensure that the information is not leaked, the user can be prohibited from querying this information. In this case, the subsequent context analysis performed by the context processing unit based on the intent recognition result can be prohibited. It can be understood that the security level labeling engine unit pre-sets multiple sensitive data categories with different security levels. Some sensitive data categories allow users to access them, while others do not. Through this security level labeling engine unit, natural language query questions that are not allowed to be accessed can be filtered.
[0044] Furthermore, the vector engine module is also used to: obtain security-related data from the security-level tagging engine unit; wherein, the security-related data includes at least one of the following: allowed access user information, and the allowed access permissions of the users corresponding to the allowed access user information, multiple sensitivity tags, and the sensitive data categories corresponding to each sensitivity tag; based on this security-related data, the allowed access permissions of the accessing users can be clearly defined, and it can also be determined which data is highly sensitive, that is, data that is not allowed to be queried at a high level of confidentiality, etc.; based on the processed query question, perform collaborative retrieval on at least one vector library to obtain initial data information associated with the processed query question; wherein, the initial data information includes multiple sub-information; filter the initial data information based on the security-related data to obtain filtered initial data information; sort the multiple sub-information in the filtered initial data information according to a preset sorting method to obtain target data information.
[0045] In practical implementation, after the vector engine module obtains the processed query question, it can retrieve the required initial data information from one or more relevant vector libraries based on the data types involved in the processed query question. This data typically includes multiple sub-information. Specifically, the initial data information can be retrieved through a vector retrieval engine using a hybrid search algorithm. This involves similarity calculation (e.g., calculating semantic similarity between the processed query question and successful or incorrect cases in the historical case library to determine if similar cases exist) and a multi-path recall mechanism. To further ensure data security, the initial data information can be further filtered based on the security association data obtained above. For example, highly sensitive information such as "ID numbers" and "phone numbers" can be removed from the initial data information, as well as information that the accessing user does not have permission to access. The filtered initial data information can then be sorted according to a preset sorting method to obtain the target data information. This preset sorting method can be set according to actual needs. For example, corresponding weights can be set for each vector library in advance. Since multiple sub-information may come from multiple vector libraries, the multiple sub-information can be sorted in descending order of the weights of the vector libraries corresponding to the various sub-information.
[0046] like Figure 4The diagram illustrates the relationship between security-level tagging engine units. It describes the security-related processing of these units throughout the entire process, including key steps such as user identity vectorization, query intent analysis, multi-path vector retrieval, real-time permission verification, and result security filtering. This demonstrates how security control permeates the entire retrieval process. During intent recognition, the security-level tagging engine unit can be invoked to filter insecure information. The vector engine module receives security dimensions from the security-level tagging engine and verifies and filters the initial data. After generating the target SQL statement through the SQL generation module and executing it to output the retrieval results, the results processing layer summarizes the results. The summarized results undergo security compliance verification. Upon successful verification, sensitive information is anonymized, and the final retrieval results are output. Throughout the entire process, the security compliance verification process can be monitored and audited by an audit supervisor. Permission usage logs are recorded based on the access permissions of the users. Additionally, when the identity authentication unit authenticates users, it also records user access behavior. A compliance audit report can be generated based on the security audit monitoring, permission usage logs, and access behavior records. Security-aware filtering applies security policies in real time during the retrieval process to ensure that the returned results meet permission requirements.
[0047] Furthermore, such as Figure 2 As shown, the system includes: an adapter module and a quality assessment module; as Figure 2 As shown, the overall system architecture demonstrates the overall architecture of the intelligent SQL generation system based on the vector database RAG, including eight core modules and their interaction relationships: user access layer, security control layer, query understanding layer, core vector engine, multi-source knowledge base cluster, SQL generation engine, quality assurance layer (corresponding to the quality assessment module mentioned above), and multi-data source adaptation layer (corresponding to the adapter module mentioned above).
[0048] The adapter module includes multiple adapters compatible with various vector libraries. This embodiment sets up dedicated adapters based on the characteristics of the data types corresponding to each vector library to ensure correct connection and access to the data vectors in the corresponding vector library. When adding or removing vector libraries from the multi-source knowledge base cluster module, the corresponding adapters can be added or removed in the adapter module, making the application more flexible. Unified adaptation to multiple data sources is achieved through three key mechanisms: an independent adapter architecture that creates dedicated syntax conversion and optimization modules for each data source; a smooth switching mechanism that automatically selects the most suitable data source based on query intent; and deep support for domestic databases with dedicated optimizations.
[0049] like Figure 5The flowchart shown illustrates an adaptive learning mechanism. The quality assessment module is used for: performing syntax checks on the target SQL statement to obtain syntax check results, such as checking for syntax errors, logical errors, etc.; obtaining the execution results corresponding to the executed target SQL statement, evaluating the execution results, and obtaining evaluation results; in actual implementation, the target SQL statement can be executed through an SQL execution monitor, and the execution results can be collected. During execution, relevant performance indicators can be monitored, and error information can be captured. The quality assessment module can obtain the execution results and evaluate them to obtain evaluation results, such as: execution efficiency evaluation results, business logic verification results, data accuracy check results, etc.; analyzing the syntax check results and evaluation results to obtain a first analysis result; wherein the first analysis result includes at least one of the following: success pattern analysis result, error pattern analysis result, query intent analysis result, user behavior analysis result; and sending the first analysis result to the multi-source knowledge base cluster module to update various vector libraries in the multi-source knowledge base cluster module. In practical implementation, the quality assessment module can intelligently analyze the obtained syntax checking and assessment results to obtain first-level analysis results such as success pattern analysis, error pattern analysis, query intent analysis, and user behavior analysis. These first-level analysis results can be sent to the multi-source knowledge base cluster module to update various vector libraries, such as updating the answer book, maintaining the error book, adjusting vector weights, and optimizing retrieval strategies. This embodiment can also verify the learning effect, specifically by performing accuracy statistics on the target SQL statement, monitoring the performance improvement of the LLM generator, evaluating user satisfaction, and obtaining continuous improvement suggestions for the LLM generator.
[0050] Furthermore, the SQL generation module is also used to: update specified parameters based on specified input information; wherein, the specified input information includes: the validation result corresponding to the LLM generator, the updated multiple vector libraries, and the evaluation result; the specified parameters include at least one of the following: the parameters of the prompt word engineer and the parameters of the LLM generator.
[0051] In this embodiment, the SQL generation module can adaptively learn based on specified input information such as the validation results corresponding to the LLM generator, updated vector libraries, and evaluation results. Specifically, it can update the parameters of the prompt word engineer and the LLM generator to achieve continuous self-improvement of the SQL generation module. Figure 5 In this process, based on continuous improvement suggestions for the LLM generator, updated vector libraries, and evaluation results, the retrieval algorithm can be optimized, the parameters of the prompt word engineer can be optimized, and the parameters of the LLM generator can be tuned to achieve personalized recommendation of target SQL statements. For example... Figure 5As shown, the adaptive learning mechanism demonstrates a complete feedback loop from SQL execution to knowledge base optimization, including execution result monitoring, multi-dimensional quality assessment, error pattern recognition, and dynamic knowledge base updates, illustrating the process of continuous self-improvement of the system.
[0052] The adaptive learning mechanism constructs a complete feedback optimization loop: the execution result feedback is evaluated from multiple dimensions based on SQL execution success rate, query efficiency, and business logic correctness; error pattern mining automatically identifies common error types, updates the error notebook, and prevents repeated errors; the knowledge base is dynamically updated and automatically adjusts vector representation and retrieval strategies based on the feedback results.
[0053] In practical applications, this solution is primarily used in the following typical scenarios: In enterprise intelligent data query scenarios, employees from various business departments (sales, finance, HR, operations, etc.) can quickly obtain the required data analysis results by querying the enterprise data warehouse and business system databases using natural language. In industry-specific data analysis scenarios, in vertical fields such as finance, healthcare, manufacturing, and e-commerce, business experts use domain terminology to query industry databases to gain professional data insights. In unified query scenarios for multi-source heterogeneous data, enterprises typically have multiple data sources such as MySQL, PostgreSQL, Oracle, and domestic databases, requiring users to use a unified query interface. In security-sensitive data access scenarios, government agencies, financial institutions, and other scenarios with extremely high data security requirements need to dynamically control the scope of data access based on user identity and permissions.
[0054] In summary, regarding the detailed technical implementation scheme, this system adopts four core technical modules, as follows: 1. The multidimensional vector space design divides the vector space into four specialized domains: the structural vector space is responsible for the geometric representation of schema information, the semantic vector space handles the semantic embedding of business terms and rules, the security vector space manages the embedding of permissions and sensitivity tags, and the execution vector space records SQL execution patterns and performance characteristics.
[0055] 2. The intelligent retrieval algorithm follows a complete retrieval process: after the user query is analyzed for intent, it performs multi-vector retrieval, and then completes the context construction through permission filtering and relevance ranking.
[0056] 3. A comprehensive security strategy system has been established for the security control mechanism: user identity vectorization covers dimensions such as role, department, and security level; data sensitivity tags are divided into four levels: public, internal, confidential, and top secret; and dynamic permission calculation is based on user vectors and data tags to achieve real-time permission judgment.
[0057] 4. The feedback optimization system constructs a complete learning loop: starting from SQL execution, through result evaluation, error classification, and pattern extraction, it finally achieves closed-loop improvement in vector update and retrieval optimization.
[0058] The key technology implementation details mainly cover the following three important aspects: 1. The innovative vector coding technology adopts a multi-level coding strategy: structured information coding encodes table relationships, field types, and constraints into geometric vectors; business semantic coding uses domain pre-trained models to map business terms to semantic space; and security label coding realizes a hierarchical vector representation of multi-dimensional security attributes.
[0059] 2. The hybrid retrieval strategy combines three retrieval methods: exact match retrieval performs string matching based on table names and field names, semantic similarity retrieval achieves semantic understanding based on vector similarity, and structured constraint retrieval considers table relationships and data types for structured search.
[0060] 3. The adaptive optimization algorithm achieves continuous improvement through three mechanisms: an online learning mechanism that updates vector representations and retrieval weights in real time, error pattern recognition that can automatically identify error types based on failed SQL execution, and success pattern reuse that can transform successful cases into reusable query templates.
[0061] The technical benefits of this solution are mainly reflected in five aspects.
[0062] 1. Significantly improved accuracy: Through collaborative retrieval from multiple knowledge bases, the accuracy of SQL statement generation is improved by 60-80% compared to existing technologies, especially in complex business scenarios.
[0063] 2. In terms of comprehensive security protection, a vectorized security tag system is used to achieve fine-grained access control, ensuring that users can only access authorized data and meeting the security requirements of Level 3 or above of the Information Security Protection System.
[0064] 3. Significantly enhanced adaptability: It supports unified access to mainstream databases and domestic databases, and the access time for new data sources is shortened from several weeks to several days, significantly reducing deployment costs.
[0065] 4. In terms of self-optimization capability, through the feedback learning mechanism, the system accuracy continues to improve with the time of use, and can reach more than 95% SQL generation accuracy within 6 months.
[0066] 5. In terms of multi-source heterogeneous support, it supports mainstream databases such as MySQL and PostgreSQL, and implements a unified query interface.
[0067] In terms of the effectiveness of quantitative techniques, the main results are as follows: 1. Improved accuracy: SQL syntax accuracy: increased from 70% in traditional methods to over 95%; Business logic accuracy improved from 60% to over 90%. Complex query processing capabilities: Supports the generation of complex queries involving 3-5 table joins; Domain terminology comprehension accuracy: over 92% in vertical domains; 2. Performance optimization effect: Query response time: Average response time should be controlled within 2 seconds; Concurrency handling capability: Supports simultaneous queries from 1000+ concurrent users; Vector retrieval efficiency: Retrieval time for a million-level vector database is controlled within 100ms; Knowledge base update delay: Supports incremental updates at the minute level; 3. Security assurance effectiveness: Access control accuracy: Over 99.9% accuracy in access control decisions; Data breach risk: The risk of data breaches is reduced by more than 95% through multi-layered security mechanisms; Audit integrity: 100% of query operations are traceable and auditable; Compliance support: Meets mainstream security compliance requirements such as Level 3 Information Security Protection and GDPR; 4. Improved operational efficiency: Reduced deployment time: Deployment time for new customer environments has been reduced from 3-4 weeks to 3-5 days; Reduced maintenance costs: Automation reduces manual maintenance work by 60%; User training costs: Reduce user training time by 80% through natural language interfaces; Improved development efficiency: Data analysts can query efficiency by 3-5 times; The following table, Table 1, compares the effectiveness of this solution with existing technical solutions: Table 1
[0068] In addition, it should be noted that the following alternative technical solutions can be provided in this embodiment: 1. Alternative to vector database architecture: (1) Vector storage engine replacement: A. Different vector databases such as Pinecone, Weaviate, Milvus, and Qdrant can be used; B. Supports a self-developed vector storage engine, optimizing performance for specific scenarios; C. A distributed vector storage architecture can be adopted to improve scalability; (2) Vector encoding scheme alternative: A. Different embedding models such as OpenAI, BGE, and M3E can be used; B. Supports self-trained domain-specific vector coding models; C. Multimodal vector encoding can be used to support structured data such as tables and graphs; 2. Alternatives to the retrieval algorithm: (1) Alternative to similarity calculation: A. Cosine similarity can be replaced by Euclidean distance and Manhattan distance; B. A learning-to-rank algorithm can be used; C. Supports similarity calculation based on graph neural networks; (2) Hybrid retrieval strategy alternative: A. The BM25 algorithm can be replaced by TF-IDF and Okapi BM25 variants. B. Reinforcement learning-based retrieval strategies can be used for optimization. C. Supports personalized search weight adjustment based on user feedback 3. Alternative security mechanisms (1) Replacement of access control model: A. The RBAC model can be replaced by the ABAC and DAC models; B. A blockchain-based authorization verification mechanism can be used; C. Support privacy protection schemes based on zero-knowledge proofs; (2) Security tag system replacement: A. Hierarchical labels can be replaced by label trees or label graph structures; B. A dynamic tag generation and update mechanism can be adopted; C. Supports automatic label classification based on machine learning; 4. Data source adaptation alternatives (1) Adapter architecture replacement: A. A plug-in architecture can be replaced by a microservice architecture; B. A unified ORM layer can be used for data source abstraction; C. Supports containerized dynamic adapter deployment; (2) SQL dialect processing alternative: A. The rule engine can be replaced by AST-based syntax transformation; B. Large models can be transformed using specialized SQL; C. Supports template-based SQL generation mechanism; All of the above alternative solutions can achieve the same or similar technical effects, thus providing a broad scope of protection for this solution.
[0069] Based on in-depth technical analysis, the key innovations of this solution are as follows: 1. Vectorization architecture for multi-source heterogeneous knowledge bases: A. This paper proposes for the first time to construct dedicated vector spaces for schema structure, business rules, security policies, and execution modes. B. A vector space association mapping mechanism was designed to achieve collaborative retrieval of multi-dimensional knowledge; C. Supports hot-plugging and dynamic expansion of the knowledge base, adapting to complex enterprise-level environments; The specific implementation is as follows: A. Schema Vector Space: Graph neural network encoding of table relationship graphs; B. Business Vector Space: Semantic encoding based on domain pre-trained models; C. Security Vector Space: A hierarchical vector representation of multidimensional security attributes; D. Execution Vector Space: Vectorization of SQL execution patterns and performance characteristics; 2. Security-aware vector retrieval mechanism: A. Move security controls forward to the vector retrieval stage, rather than post-filtering. B. An access control algorithm based on user identity vectors and data tag vectors was designed. C. Real-time security policy application was implemented during the retrieval process. The specific implementation is as follows: A. User identity vectorization: role_vector = f(role, department, clearance_level) B. Permission calculation: access_score = cosine_similarity(user_vector, data_label_vector) C. Dynamic filtering: A real-time filtering mechanism based on the access_score threshold; This solution features the following improvements in architectural design: 1. Adaptive Feedback Learning System: A. A complete feedback loop was constructed, from SQL execution results to knowledge base optimization. B. A multi-dimensional execution quality assessment system was designed. C. Implemented an automatic error mode identification and prevention mechanism. The specific technical implementation is as follows: A. Execution result evaluation: syntax correctness, execution efficiency, and accuracy of business logic; B. Error Pattern Mining: Automatic classification of error types based on clustering algorithms; C. Knowledge base update: incremental vector update and retrieval weight adjustment; 2. Unified architecture for adapting to multiple data sources: A. Design independent adapters for each data source to achieve plug-and-play functionality; B. A vectorized representation of data source characteristics has been constructed, supporting intelligent routing; C. Specifically adapted to the syntax characteristics of domestic databases; The specific technical implementation is as follows: A. Adapter plug-in architecture: standardized adapter interfaces and lifecycle management; B. Intelligent routing: Automatic selection based on query characteristics and data source capabilities; C. Supports domestic databases: dedicated syntax libraries for DM, Kingbase, and OceanBase; This scheme has the following improvements in algorithm optimization: 1. Hybrid retrieval algorithm: A. Multi-path recall combining precise matching, semantic similarity, and structured constraints. B. A dynamic weight adjustment mechanism based on query intent was designed. C. Implemented multi-dimensional sorting and deduplication of search results. The resulting technical effects are as follows: A. Search accuracy improved by over 40%; B. Supports complex multi-table join queries; C. Retrieval latency is controlled within 100ms; 2. Contextual intelligence fusion technology: A. A structured fusion algorithm for multi-source information was designed; B. Implemented dynamic context length adjustment based on query complexity; C. An automatic assessment mechanism for context quality was constructed; This solution has the following improvements in terms of application scenarios: 1. Enterprise-level security compliance support: A. Meets the security requirements of government and enterprise clients at or above Level 3 of the Information Security Protection Scheme; B. Supports fine-grained data access control and auditing; C. It enables visual configuration and management of security policies; 2. Compatibility with domestic database ecosystems: A. It fills the technological gap in the field of intelligent querying for domestic databases; B. Support the requirements of information technology innovation and promote the development of the domestic database ecosystem; C. It lowers the technical threshold for enterprises' digital transformation; The value of the aforementioned key technologies is specifically reflected in the following aspects: 1. Technological advancement: It is the first in the RAG+Text-to-SQL field to propose a multi-source knowledge base vectorization architecture; 2. Highly practical: It solves the core pain points of enterprise-level SQL generation; 3. Safe and controllable: Meets the stringent security requirements of government and enterprise clients; 4. Eco-friendly: Supports domestic databases, aligning with the development trend of information technology innovation; 5. Scalability: The architecture design supports flexible functional expansion and technological evolution; The technical standards and specifications involved in this invention mainly include database standards, security standards, vector database standards, and AI standards. Regarding database standards, this involves SQL-92 / 99 / 2003 / 2008 / 2011 standards and the dialect specifications of various database vendors. Regarding security standards, it follows GB / T 22239-2019 (Level 2.0) and ISO 27001 information security management standards. Regarding vector database standards, it adopts vector retrieval algorithm standards such as FAISS (Facebook AI Similarity Search, a vector retrieval algorithm) and HNSW (Hierarchical Navigable Small World, a vector retrieval algorithm). Regarding AI standards, it references the IEEE 2857 AI Systems Engineering standard and the ISO / IEC 23053 AI Risk Management Framework.
[0070] Currently, RAG and Text-to-SQL technologies are developing in several important directions. Multimodal fusion is becoming an important trend, supporting unified processing of various data types such as text, tables, and graphs. Real-time learning capabilities are constantly improving, and the technology is evolving from static knowledge bases to dynamic adaptive systems. Secure and trustworthy AI is receiving increasing attention, requiring stronger security, interpretability, and auditability. Edge computing support is also becoming a development focus, with the technology moving towards lightweight and localized deployment.
[0071] This technology has broad market application prospects. In terms of target market size, the global Text-to-SQL market is projected to reach $1.5 billion by 2025, while the Chinese enterprise-level AI market is growing at an annual rate exceeding 30%, with continued growth in demand for digital transformation from government and enterprises. Regarding key application areas, government agencies primarily use it for government data querying and decision support analysis; financial institutions focus on risk analysis, regulatory reports, and customer profiling; manufacturing enterprises focus on production data analysis, quality control, and supply chain optimization; and e-commerce platforms emphasize user behavior analysis, marketing effectiveness evaluation, and inventory management.
[0072] The productization of this technology is characterized by its versatility. The technology platform is based on a cloud-native architecture, supporting private cloud, public cloud, and hybrid cloud deployment modes. Product forms include SaaS (Software as a Service), private deployment, API (Application Programming Interface), and SDK (Software Development Kit) components. In terms of integration capabilities, it supports seamless integration with mainstream BI (Business Intelligence) tools and data analysis platforms, providing users with flexible technology access solutions.
[0073] This solution proposes an intelligent SQL generation system based on the RAG vector database. By constructing a multi-source heterogeneous knowledge base cluster and an innovative vector retrieval engine, it achieves high accuracy, strong security, and adaptive optimization capabilities for enterprise-level SQL generation. Through its innovative multi-source knowledge base vectorization architecture, security-aware retrieval mechanism, and adaptive learning system, it effectively solves key problems of existing technologies in enterprise-level applications.
[0074] The core technological advantages of this solution are reflected in several aspects. In terms of technological innovation, it proposes for the first time a vectorized unified architecture for multi-source heterogeneous knowledge bases, providing a completely new technical path for the RAG+Text-to-SQL field. Regarding security and controllability, it achieves enterprise-level fine-grained security access control, meeting the stringent security requirements of government and enterprise clients. In terms of self-optimization, it constructs a closed-loop system for continuous learning and improvement, with system accuracy continuously improving over time. Regarding ecosystem adaptability, it fully supports domestic databases and multi-source heterogeneous environments, aligning with the development trend of domestic IT innovation. In terms of practical feasibility, it has been verified through real-world applications, demonstrating significant technical effectiveness and commercial value.
[0075] The expected application value of this solution is mainly reflected in four aspects: significantly reducing the technical threshold and usage cost of enterprise data query, enabling non-technical personnel to easily perform complex data queries; improving the work efficiency of data analysts and business personnel by automating repetitive SQL writing tasks; ensuring enterprise data security and compliance requirements by ensuring data access security through fine-grained access control; and promoting the intelligent development of the domestic database ecosystem by providing intelligent query capabilities for domestic databases.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention 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; and these 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 the present invention.
Claims
1. An SQL statement generation system, characterized in that, The system includes: a query understanding module, a vector engine module, a multi-source knowledge base cluster module, and an SQL generation module; wherein, the multi-source knowledge base cluster module includes multiple vector libraries, each of which is used to store data vectors of the data type corresponding to that vector library; The query understanding module is used to receive natural language query questions input by the user, parse and process the natural language query questions to obtain processed query questions, and send the processed query questions to the vector engine module. The vector engine module is used to perform collaborative retrieval of at least one vector library based on the processed query question to obtain target data information associated with the processed query question; and send the target data information to the SQL generation module. The SQL generation module is used to generate target SQL statements based on the target data information.
2. The system according to claim 1, characterized in that, The various vector libraries include: a schema vector library, a business knowledge vector library, a security tag vector library, a dialect knowledge vector library, and a historical case vector library; the multi-source knowledge base cluster module also includes a vectorization processing module, which is used for: The first original data of the first data type is encoded by a structure encoder to obtain a data vector of the first data type, and the data vector of the first data type is saved to the schema vector library; wherein, the first data type includes: table structure type, field type, relation constraint type, and index type; The second original data of the second data type and the third original data of the third data type are encoded by a semantic encoder to obtain data vectors of the second data type and the third data type. The data vector of the second data type is saved to the business knowledge vector library, and the data vector of the third data type is saved to the dialect knowledge vector library. The second data type includes domain terms, calculation indicators, business rules, and data lineage relationships from various fields. The third data type includes syntax, functions, and optimization strategies. The fourth original data of the fourth data type and the fifth original data of the fifth data type are encoded by a text encoder to obtain data vectors of the fourth data type and the fifth data type, respectively. The data vector of the fourth data type is saved to the security tag vector library, and the data vector of the fifth data type is saved to the historical case vector library. The fourth data type includes: user permissions, sensitive data security level, and access policy; the fifth data type includes: successful SQL statement cases and failed SQL statement cases.
3. The system according to claim 1, characterized in that, The query understanding module further includes: a language parsing unit, an intent recognition unit, a context processing unit, and a preprocessing unit; The language parsing unit is used to parse and process the natural language query question to obtain the parsing result; The intent recognition unit is used to recognize the parsing result and output the intent recognition result; The context processing unit is used to perform context analysis based on the intent recognition result and output the context analysis result; The preprocessing unit is used to preprocess the context analysis results and output the processed query question.
4. The system according to claim 1, characterized in that, The SQL generation module also includes: a fusion unit, a prompt word engineer, an LLM generator, and an SQL optimizer; The fusion unit is used to integrate and process the received target data information to obtain a processing result; The prompt word engineer is used to generate target prompt words based on the processing results; The LLM generator is used to generate an initial SQL statement based on the target prompt words; The SQL optimizer is used to optimize the initial SQL statement to obtain the target SQL statement.
5. The system according to claim 3, characterized in that, The system further includes: a user access module and a security management module; wherein the security management module includes: an identity authentication unit and an authorization verification unit; The user access module is used to receive user access instructions through a preset input interface; wherein, the user access instructions carry user login information and the natural language query question; The identity authentication unit is used to authenticate the identity of the accessing user based on the user login information. If the authentication is successful, the user login information is sent to the permission verification unit. The permission verification unit is used to verify the user's permissions based on the user login information and the natural language query question. If the verification is successful, the natural language query question is sent to the query understanding module.
6. The system according to claim 5, characterized in that, The security management module also includes: a security level tagging engine unit; the security level tagging engine unit pre-stores information on users allowed to access the system, as well as the allowed access permissions of the users corresponding to the information on users allowed to access the system. The security level tag engine unit is used to determine whether the accessing user belongs to the user corresponding to the allowed access user information based on the user login information after the identity authentication unit has successfully authenticated the accessing user's identity. If the accessing user belongs to the user corresponding to the allowed access user information, the allowed access permissions of the accessing user are sent to the permission verification unit. The permission verification unit is used to verify the user's permissions based on the natural language query question and the user's allowed access permissions.
7. The system according to claim 6, characterized in that, The security level tagging engine unit pre-stores multiple sensitivity tags and the sensitive data category corresponding to each sensitivity tag; wherein, the sensitivity tag is used to indicate whether access to the data corresponding to the corresponding sensitive data category is allowed; The security level labeling engine unit is also used to obtain the intent recognition result and determine the target sensitive data category to which the intent recognition result belongs; Based on the target sensitive data category, a corresponding target sensitivity label is determined, and based on the target sensitivity label, it is determined whether context analysis is allowed through the context processing unit based on the intent recognition result.
8. The system according to claim 7, characterized in that, The vector engine module is also used for: Security-related data is obtained from the security-level tagging engine unit; wherein, the security-related data includes at least one of the following: user information that is allowed to access, and the user's allowed access permissions corresponding to the user information that is allowed to access, multiple sensitivity tags, and the sensitive data category corresponding to each sensitivity tag; Based on the processed query question, a collaborative retrieval is performed on at least one vector library to obtain initial data information associated with the processed query question; wherein, the initial data information includes multiple sub-information. The initial data information is filtered based on the security association data to obtain the filtered initial data information. According to a preset sorting method, the various sub-information in the filtered initial data information are sorted to obtain the target data information.
9. The system according to claim 4, characterized in that, The system includes an adapter module and a quality assessment module; the adapter module includes multiple adapters that match the multiple vector libraries; the quality assessment module is used for: Perform a syntax check on the target SQL statement and obtain the syntax check result; Obtain the execution result corresponding to the target SQL statement, evaluate the execution result, and obtain the evaluation result; The syntax check results and the evaluation results are analyzed to obtain a first analysis result; wherein, the first analysis result includes at least one of the following: success pattern analysis result, error pattern analysis result, query intent analysis result, and user behavior analysis result; The first analysis result is sent to the multi-source knowledge base cluster module to update the various vector libraries in the multi-source knowledge base cluster module.
10. The system according to claim 9, characterized in that, The SQL generation module is also used for: Based on specified input information, update specified parameters; wherein, the specified input information includes: the verification result corresponding to the LLM generator, the updated multiple vector libraries, and the evaluation result; the specified parameters include at least one of the following: the parameters of the prompt word engineer and the parameters of the LLM generator.
Citation Information
Cited By
Database query and visualization method and system based on large language model
CN121387948A
Water conservancy intelligent question-answering system and method based on knowledge enhancement and data driving
CN121860062A