Industrial report SQL query generation method and system based on large model
Through the SQL query generation method based on large models, using technologies such as Hairuo large model and graph neural network, we solve the problem that existing SQL query methods are difficult to understand complex queries, achieve efficient and accurate database queries, lower the technical threshold and Applicable to multiple database types.
Patent Information
- Application Number
- CN202410926753.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-10-15
AI Technical Summary
Existing SQL query methods are expensive to learn and difficult to use for non-professional users, and have limitations in processing complex queries, multi-table joins and deep semantic understanding, limiting their practical application scenarios.
Adopt a large model-based SQL query generation method for industry reports. By constructing similarity matching between database table feature vectors and user question vectors, Hairuo large model, graph neural network and deep learning model are used for intent recognition, keyword extraction and semantic roles. Annotate, generate SQL statements, and adjust model parameters according to the execution results through the optimization module to ensure that the generated SQL statements can be correctly executed by the database.
It significantly improves query efficiency and semantic understanding, improves the accuracy of query results and system robustness, and lowers the technical threshold, allowing non-professional users to easily perform database queries. It is suitable for relational and non-relational databases.
Smart Images

Figure CN118779335A_ABST
Abstract
Description
Technical Field
[0001] The invention discloses a method and a system, and relates to the field of artificial intelligence technology, in particular to a method and a system for generating industry report SQL queries based on a large model. Background Art
[0002] In the era of big data, how to quickly and accurately extract the required information from massive databases? Although the existing SQL query method has powerful data processing capabilities, for non-professional users, its learning cost and difficulty of use are relatively high, which undoubtedly increases the difficulty of obtaining information. Even though NL2SQL can convert the user's natural language query into SQL statements to achieve interaction with the database. However, the existing NL2SQL method still has certain limitations in processing complex queries, multi-table joins, and deep semantic understanding, which further limits the actual application scenarios. Summary of the invention
[0003] In view of the problems of the prior art, the present invention provides a method and system for generating industry report SQL queries based on a large model, which overcomes the shortcomings of the existing methods and provides users with a more convenient and efficient database query experience.
[0004] The specific scheme proposed by the present invention is:
[0005] The present invention provides a method for generating industry report SQL query based on a large model, comprising:
[0006] Step 1: Build the table feature vector of the database, obtain the user question vector, calculate the similarity between the user question vector and the table feature vector, and locate the database table most relevant to the user query.
[0007] Step 2: Use the Hairuo model to analyze the user's question, including intent recognition, keyword extraction, and semantic role labeling. Use the graph neural network model to convert the database's schema information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the relationship between database tables.
[0008] Step 3: Use the deep learning model to analyze the intent of the user question and the graph structure, obtain the mapping result of the database schema information corresponding to the intent and the graph structure, and generate SQL statements according to the SQL query template based on the mapping result.
[0009] Step 4: Optimize the generated SQL statements: Select and simplify SQL statements according to the query plan, send the SQL statements to the database for execution, feedback the execution results, and adjust the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results.
[0010] Furthermore, in the step 1 of the method for generating SQL queries for industry reports based on a large model, the Chroma-DB word vector database is used to extract features of the database table to be queried, and the features of the database table are converted into vectorized representations to construct table feature vectors. At the same time, the BGE vectorization method is used to convert the natural query language input by the user into a vector representation to obtain the user question vector.
[0011] Furthermore, in step 3 of the method for generating industry report SQL queries based on a large model, a deep learning model is used to analyze the intention of the user's question and the graph structure, including: using a deep learning model to apply an attention mechanism and a graph convolution operation to analyze the intention of the user's question and the graph structure.
[0012] Furthermore, in step 3 of the method for generating SQL queries for industry reports based on a big model, the Hairuo big model fine-tuned by nl2sql performs query intent analysis on the generated SQL statements to ensure that the generated SQL statements are correctly executed by the database system.
[0013] The present invention also provides an industry report SQL query generation system based on a large model, including a vectorized matching engine module, an intention and pattern analysis module, an SQL conversion generation module and an optimization module.
[0014] The vectorized matching engine module constructs the table feature vector of the database, obtains the user question vector, calculates the similarity between the user question vector and the table feature vector, and locates the database table most relevant to the user query.
[0015] The intent and pattern analysis module uses the Hairuo model to analyze user questions, including intent recognition, keyword extraction, and semantic role labeling. It uses the graph neural network model to convert the database pattern information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the associations between database tables.
[0016] The SQL conversion generation module uses a deep learning model to analyze the intent of the user question and the graph structure, obtains a mapping result of the database schema information corresponding to the intent and the graph structure, and generates an SQL statement according to the SQL query template based on the mapping result.
[0017] The optimization module optimizes the generated SQL statements: selects and simplifies SQL statements according to the query plan, sends the SQL statements to the database for execution, feeds back the execution results, and adjusts the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results.
[0018] Furthermore, the vectorized matching engine module of the industry report SQL query generation system based on a large model uses the Chroma-DB word vector database to extract features of the database table to be queried, and converts the features of the database table into vectorized representations to construct table feature vectors. At the same time, the BGE vectorization method is used to convert the natural query language input by the user into a vector representation to obtain the user question vector.
[0019] Furthermore, the SQL conversion generation module of the industry report SQL query generation system based on a large model uses a deep learning model to analyze the intention of the user question and the graph structure, including: using the deep learning model to apply the attention mechanism and graph convolution operation to analyze the intention of the user question and the graph structure.
[0020] Furthermore, the SQL conversion generation module of the industry report SQL query generation system based on a big model performs query intent analysis on the generated SQL statements through the Hairuo big model fine-tuned by nl2sql to ensure that the generated SQL statements are correctly executed by the database system.
[0021] The benefits of the present invention are:
[0022] (1) Improve query efficiency: Chroma-DB technology is used to vectorize database tables, and BGE vectorization technology is used to convert natural language queries into high-dimensional vectors, which can quickly match user queries with database tables and significantly improve query efficiency.
[0023] (2) Enhanced semantic understanding capabilities: Using advanced NLP models to deeply understand user queries and combining them with graph neural networks to capture the complex structure and relationships of database schemas, it can more accurately understand user intent and database schemas, thereby generating more accurate SQL statements.
[0024] (3) Optimizing query results: Using attention mechanism and graph convolution operation to perform intelligent intent and pattern mapping, which not only improves the efficiency of mapping, but also greatly improves the accuracy of query results.
[0025] (4) Continuous performance optimization: By executing the generated SQL statements and adjusting the model parameters based on the execution result feedback, it has the ability of adaptive learning and can continuously optimize its performance to adapt to the ever-changing query requirements and database environment.
[0026] (5) Wide applicability: It is applicable not only to relational databases but also to non-relational databases. It has good versatility and customizability and can be optimized according to different database types and user needs.
[0027] (6) Enhanced system robustness: Through the structured representation method of graph neural networks, it can better handle multi-table joins and complex queries, and enhance the robustness when facing complex database models.
[0028] (7) Lowering the technical threshold: It enables non-professional users to easily query the database, which lowers the technical threshold for using the database and makes information extraction from the database more popular and convenient. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 It is a schematic flow chart of the method of the present invention.
[0030] Figure 2 It is a schematic diagram of the feature vector acquisition process in the present invention.
[0031] Figure 3 It is a schematic diagram of the graphical structure analysis process of user questions and database model information in the present invention.
[0032] Figure 4 It is a schematic diagram of the SQL conversion generation process in the present invention. DETAILED DESCRIPTION
[0033] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0034] Example 1
[0035] The present invention provides a method for generating industry report SQL query based on a large model, comprising:
[0036] Step 1: Build the table feature vector of the database, obtain the user question vector, calculate the similarity between the user question vector and the table feature vector, and locate the database table most relevant to the user query.
[0037] In step 1, the Chroma-DB word vector database can be further used to extract features from the database table to be queried, and the features of the database table can be converted into vector representations to construct table feature vectors. At the same time, the BGE vectorization method can be used to convert the natural query language input by the user into vector representations to obtain the user question vector. This process not only improves the matching efficiency, but also enhances the matching accuracy, laying a solid foundation for subsequent query generation.
[0038] Step 2: Use the Hairuo model to analyze the user's questions, including intent recognition, keyword extraction, and semantic role labeling. Use the graph neural network model to convert the database schema information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the relationship between database tables.
[0039] The task involves deep semantic analysis and intent recognition of natural language queries input by users, and constructing a graphical representation of the database schema in order to more accurately capture and express the structure and relationships of the database. First, the natural language processing (NLP) model Hairuda model is used to perform a detailed analysis of the query statements of user questions, including intent recognition, keyword extraction, and semantic role annotation to ensure that the user's real query needs can be accurately grasped. Subsequently, the database schema information is converted into a graph structure through a graph neural network model, where the nodes of the graph structure represent tables or fields in the database, and the edges represent the associations between tables, such as foreign key constraints, or functional dependencies between fields. The graph structure representation method can not only reveal the intrinsic connections of the database schema, but also provide rich contextual information for further query generation, making the entire system more accurate and efficient in processing complex queries.
[0040] Step 3: Use a deep learning model to analyze the intent of the user question and the graph structure, obtain a mapping result of the database model information corresponding to the intent and the graph structure, and generate an SQL statement based on the SQL query template based on the mapping result.
[0041] The deep learning model uses the attention mechanism and graph convolution operation to analyze the intention of the user's question and the graph structure, and obtains the mapping result of the database model information corresponding to the intention and the graph structure, ensuring that the user's real needs can be accurately captured by the system and converted into a language that the database can understand.
[0042] Based on the mapping results, we enter the SQL template generation stage. In this stage, we can further use the Hairuoda model after fine-tuning the nl2sql capabilities to ensure that the generated SQL statements not only meet the user's query intentions, but can also be correctly executed by the database system.
[0043] Step 4: Optimize the generated SQL statements: Select and simplify SQL statements according to the query plan, send SQL statements to the database for execution, feedback the execution results, and adjust the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results. This feedback-based learning mechanism enables the system to continuously learn from actual execution results, automatically adjust and optimize the generation strategy, and continuously improve overall accuracy and efficiency.
[0044] Example 2
[0045] The present invention also provides an industry report SQL query generation system based on a large model, including a vectorized matching engine module, an intention and pattern analysis module, an SQL conversion generation module and an optimization module.
[0046] The vectorized matching engine module constructs the table feature vector of the database, obtains the user question vector, calculates the similarity between the user question vector and the table feature vector, and locates the database table most relevant to the user query.
[0047] The intent and pattern analysis module uses the Hairuo model to analyze user questions, including intent recognition, keyword extraction, and semantic role labeling. It uses the graph neural network model to convert the database pattern information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the associations between database tables.
[0048] The SQL conversion generation module uses a deep learning model to analyze the intent of the user question and the graph structure, obtains a mapping result of the database schema information corresponding to the intent and the graph structure, and generates an SQL statement according to the SQL query template based on the mapping result.
[0049] The optimization module optimizes the generated SQL statements: selects and simplifies SQL statements according to the query plan, sends the SQL statements to the database for execution, feeds back the execution results, and adjusts the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results.
[0050] As the information interaction and execution process between the modules in the above-mentioned system are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.
[0051] Likewise, the system of the present invention is beneficial in that:
[0052] (1) Improve query efficiency: Chroma-DB technology is used to vectorize database tables, and BGE vectorization technology is used to convert natural language queries into high-dimensional vectors, which can quickly match user queries with database tables and significantly improve query efficiency.
[0053] (2) Enhanced semantic understanding capabilities: Using advanced NLP models to deeply understand user queries and combining them with graph neural networks to capture the complex structure and relationships of database schemas, it can more accurately understand user intent and database schemas, thereby generating more accurate SQL statements.
[0054] (3) Optimizing query results: Using attention mechanism and graph convolution operation to perform intelligent intent and pattern mapping, which not only improves the efficiency of mapping, but also greatly improves the accuracy of query results.
[0055] (4) Continuous performance optimization: By executing the generated SQL statements and adjusting the model parameters based on the execution result feedback, it has the ability of adaptive learning and can continuously optimize its performance to adapt to the ever-changing query requirements and database environment.
[0056] (5) Wide applicability: It is applicable not only to relational databases but also to non-relational databases. It has good versatility and customizability and can be optimized according to different database types and user needs.
[0057] (6) Enhanced system robustness: Through the structured representation method of graph neural networks, it can better handle multi-table joins and complex queries, and enhance the robustness when facing complex database models.
[0058] (7) Lowering the technical threshold: It enables non-professional users to easily query the database, which lowers the technical threshold for using the database and makes information extraction from the database more popular and convenient.
[0059] It should be noted that not all steps and modules in the above-mentioned processes and system structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0060] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A method for generating SQL queries for industry reports based on a large model, characterized by: include: Step 1: Build the table feature vector of the database, obtain the user question vector, calculate the similarity between the user question vector and the table feature vector, and locate the database table most relevant to the user query. Step 2: Use the Hairuo model to analyze the user's question, including intent recognition, keyword extraction, and semantic role labeling. Use the graph neural network model to convert the database's schema information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the relationship between database tables. Step 3: Use the deep learning model to analyze the intent of the user question and the graph structure, obtain the mapping result of the database schema information corresponding to the intent and the graph structure, and generate SQL statements according to the SQL query template based on the mapping result. Step 4: Optimize the generated SQL statements: Select and simplify SQL statements according to the query plan, send the SQL statements to the database for execution, feedback the execution results, and adjust the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results.
2. According to the large model-based industry report SQL query generation method described in claim 1, it is characterized in that in step 1, the Chroma-DB word vector database is used to extract features of the database table to be queried, and the features of the database table are converted into vectorized representations to construct table feature vectors. At the same time, the BGE vectorization method is used to convert the natural query language input by the user into a vector representation to obtain the user question vector.
3. The method for generating industry report SQL query based on a large model according to claim 1 is characterized by: In step 3, the intention of the user question and the graph structure are analyzed using a deep learning model, including: using the deep learning model to analyze the intention of the user question and the graph structure using an attention mechanism and a graph convolution operation.
4. The method for generating industry report SQL query based on a large model according to claim 1 is characterized by: In step 3, the query intent of the generated SQL statement is analyzed by the Hairuo model fine-tuned by nl2sql to ensure that the generated SQL statement is correctly executed by the database system.
5. A large model-based industry report SQL query generation system, characterized by It includes vectorized matching engine module, intent and pattern analysis module, SQL conversion generation module and optimization module. The vectorized matching engine module constructs the table feature vector of the database, obtains the user question vector, calculates the similarity between the user question vector and the table feature vector, and locates the database table most relevant to the user query. The intent and pattern analysis module uses the Hairuo model to analyze user questions, including intent recognition, keyword extraction, and semantic role labeling. It uses the graph neural network model to convert the database pattern information into a graph structure based on the database table most relevant to the user's query. The nodes in the graph structure represent tables or fields in the database, and the edges represent the associations between database tables. The SQL conversion generation module uses a deep learning model to analyze the intent of the user question and the graph structure, obtains a mapping result of the database schema information corresponding to the intent and the graph structure, and generates an SQL statement according to the SQL query template based on the mapping result. The optimization module optimizes the generated SQL statements: selects and simplifies SQL statements according to the query plan, sends the SQL statements to the database for execution, feeds back the execution results, and adjusts the parameters of the Hairuo model, graph neural network model, and deep learning model based on the execution results.
6. The industry report SQL query generation system based on a large model according to claim 5 is characterized by: The vectorized matching engine module uses the Chroma-DB word vector database to extract features of the database table to be queried, converts the features of the database table into vectorized representations, and constructs table feature vectors. At the same time, it uses the BGE vectorization method to convert the natural query language input by the user into a vector representation to obtain the user question vector.
7. The industry report SQL query generation system based on a large model according to claim 5 is characterized in that SQL The conversion generation module uses a deep learning model to analyze the intention of the user's question and the graph structure, including: using the deep learning model to apply an attention mechanism and a graph convolution operation to analyze the intention of the user's question and the graph structure.
8. According to the large model-based industry report SQL query generation system of claim 5, its characteristic SQL conversion The generation module uses the Hairuo model fine-tuned by nl2sql to analyze the query intent of the generated SQL statements to ensure that the generated SQL statements are correctly executed by the database system.
Citation Information
Patent Citations
Graph structure generation method of database logic relationship and data query method and device
CN111831626A
Database query result generation method and device, equipment and storage medium
CN115062050A
NL2SQL generation method based on graph neural network
CN117235108A
SQL statement generation method and system based on deep learning
CN118132592A
Question and answer method and device based on RAG and GNN and electronic equipment
CN118210906A
Cited By
Deep learning-based one-key table establishment and model processing task generation method
CN119441218A
One-click table building and model processing task generation method based on deep learning
CN119441218B
Cross-system data retrieval method and device, terminal and medium
CN120596681A
Visual report display method and system and electronic equipment
CN121681635A
