Multi-table SQL (Structured Query Language) generation method and device based on large model and metadata knowledge graph

Through the multi-table SQL generation method based on large models and metadata knowledge graphs, the problem of the inability to generate accurate multi-table SQL query statements in the prior art is solved, and automatic conversion and efficient data access are achieved.

CN119719145APending Publication Date: 2025-03-28BEIJING HAIZHI TECH GRP CO LTD
View PDF 0 Cites 7 Cited by

Patent Information

Application Number
CN202411749553.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The existing technology cannot effectively consider the association relationship between data, resulting in the lack of inference ability of deep learning models and the inability to generate accurate multi-table SQL query statements.

Method used

A multi-table SQL generation method based on the big model and metadata knowledge graph is adopted. By receiving the user's natural language query request, semantic analysis is performed, the metadata knowledge graph is queried to obtain relevant meta information, and input it into the big model for analysis and processing to build an accurate SQL query statement.

Benefits of technology

It realizes automatic conversion from user intention to SQL queries, reduces the difficulty of users writing complex SQL, improves the efficiency of data access, and can generate accurate query statements that consider data association relationships.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119719145A_ABST
    Figure CN119719145A_ABST
Patent Text Reader

Abstract

The invention provides a multi-table SQL generation method and device based on a large model and a metadata knowledge graph, a storage medium and equipment, and the method comprises the steps: receiving a query request provided by a user in a natural language form, carrying out the semantic analysis of the query request, obtaining a semantic analysis result, and according to the semantic analysis result, generating a multi-table SQL according to the semantic analysis result; and querying the metadata knowledge graph to obtain meta-information related to the semantic analysis result, and inputting the meta-information corresponding to the query request into the large model for analysis processing to construct an SQL query statement corresponding to the query request. Therefore, automatic conversion from the user intention to the SQL query is realized, the difficulty of compiling a complex SQL by a user is reduced, the data access efficiency is improved, meanwhile, the incidence relation between the data can be considered, and the query statement with high accuracy can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a multi-table SQL generation method, device, storage medium and equipment based on a large model and metadata knowledge graph. Background Art

[0002] With the development of computer technology, more and more work and study tasks can be automated. Computer technology has gradually been applied to various daily education and learning activities. For example, computer technology can be used to realize data query, which greatly saves human resources.

[0003] At present, various tasks of natural language processing (NLP) technology can be significantly improved with the help of pre-trained models. However, this structure based entirely on deep learning models cannot effectively consider the correlation between data, resulting in the lack of reasoning ability of the model and the inability to generate accurate query statements (SQL, Structured Query Language). Therefore, there is an urgent need for a query statement generation solution that considers the correlation between data and has high accuracy. Summary of the invention

[0004] In view of this, the present invention provides a multi-table SQL generation method, device, storage medium and equipment based on a large model and metadata knowledge graph, which can consider the association relationship between data and generate query statements with high accuracy.

[0005] In a first aspect, an embodiment of the present invention provides a multi-table SQL generation method based on a large model and a metadata knowledge graph, the method comprising:

[0006] Receive a query request from a user in natural language, and perform semantic analysis on the query request to obtain a semantic analysis result;

[0007] According to the semantic analysis result, query the metadata knowledge graph to obtain meta information related to the semantic analysis result, wherein the meta information includes tables, fields, semantic information, business tags, classification information and blood relationship;

[0008] The meta information corresponding to the query request is input into the large model for analysis and processing to construct an SQL query statement corresponding to the query request.

[0009] Further, according to the semantic analysis result, querying the metadata knowledge graph to obtain meta-information related to the semantic analysis result includes:

[0010] According to the semantic analysis results, relevant table and field information is searched in the metadata knowledge graph, wherein the metadata knowledge graph includes table names, field names, field types, and the relationship between tables;

[0011] By querying the metadata knowledge graph, meta information related to the query request is obtained, and the meta information includes tables, fields, semantic information, business tags, classification information and blood relationships.

[0012] Further, the meta information corresponding to the query request is input into the large model for analysis and processing to construct an SQL query statement corresponding to the query request, including:

[0013] Write the metadata of the table in the database into the vector database in advance;

[0014] Inputting the meta information corresponding to the query request into the large model, and the large model searching and matching the meta information corresponding to the query request in the vector database;

[0015] The large model merges the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request;

[0016] The large model generates an SQL query statement corresponding to the query request according to the constructed prompt.

[0017] Furthermore, the method further comprises:

[0018] Performing rule verification on the SQL query statement;

[0019] The performance of the SQL query statement is optimized.

[0020] In a second aspect, an embodiment of the present invention provides a multi-table SQL generation device based on a large model and a metadata knowledge graph, the device comprising:

[0021] A receiving module is used to receive a query request from a user in a natural language form, and perform semantic analysis on the query request to obtain a semantic analysis result;

[0022] An analysis module, configured to query a metadata knowledge graph according to the semantic analysis result to obtain meta-information related to the semantic analysis result, wherein the meta-information includes tables, fields, semantic information, business tags, classification information and blood relationships;

[0023] The construction module is used to input the meta information corresponding to the query request into the large model for analysis and processing, so as to construct an SQL query statement corresponding to the query request.

[0024] Furthermore, the analysis module includes:

[0025] A search unit, used to search for relevant table and field information in a metadata knowledge graph according to the semantic analysis result, wherein the metadata knowledge graph includes table names, field names, field types, and relationships between tables;

[0026] The acquisition module is used to obtain meta information related to the query request by querying the metadata knowledge graph, and the meta information includes tables, fields, semantic information, business tags, classification information and blood relationships.

[0027] Furthermore, the building blocks include:

[0028] A writing unit, used for writing the metadata of the table in the database into the vector database in advance;

[0029] A matching unit, configured to input the meta information corresponding to the query request into the large model, and the large model searches and matches the meta information corresponding to the query request in the vector database;

[0030] A merging unit, used for the large model to merge the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request;

[0031] The construction unit is used for the large model to generate an SQL query statement corresponding to the query request according to the constructed prompt.

[0032] Furthermore, the device also includes:

[0033] A verification module, used for performing rule verification on the SQL query statement;

[0034] The optimization module is used to optimize the performance of the SQL query statement.

[0035] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the storage medium stores a computer program, wherein the computer program is configured to execute any one of the methods in the first aspect when executed.

[0036] In a fourth aspect, an embodiment of the present invention provides an electronic device, comprising a memory and a processor, characterized in that a computer program is stored in the memory, and the processor is configured to run the computer program to execute any method described in the first aspect.

[0037] The technical solution provided by the present invention receives a query request from a user in natural language, performs semantic analysis on the query request, obtains a semantic analysis result, queries a metadata knowledge graph according to the semantic analysis result to obtain meta-information related to the semantic analysis result, and inputs the meta-information corresponding to the query request into a large model for analysis and processing to construct an SQL query statement corresponding to the query request. Thus, the automatic conversion from user intention to SQL query is realized, the difficulty of users writing complex SQL is reduced, the efficiency of data access is improved, and the association relationship between data can be considered and a query statement with high accuracy can be generated. At the same time, on the one hand, the multi-table SQL query statement generation solution based on the big model and metadata knowledge graph realizes seamless conversion between natural language and SQL query language, so that users can easily express query requirements through natural language without professional SQL knowledge, and can automatically build SQL query statements corresponding to query requests. This automated process not only improves the efficiency of query generation, but also reduces the risk of errors; on the other hand, the solution uses metadata knowledge graph to store the table structure information of the database. This storage method of structured information makes the query process more efficient and accurate; thirdly, the solution combines the powerful generation ability of the big model to handle complex query requests, including multi-table queries, nested queries, etc. The big model can generate SQL query statements that conform to grammatical specifications and are logically correct according to the query intent and the information in the metadata knowledge graph, and will also consider the optimization of the query to improve the execution speed of the query; fourthly, the solution also has the dual guarantee of result verification and optimization. It will not only perform rule verification to ensure that the generated SQL query statement has no grammatical errors, but also can correctly access the tables and fields in the target database, further improving the accuracy and reliability of the query. At the same time, it will also optimize the performance of the generated SQL query statement to further improve the execution efficiency of the query. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 This is a flowchart of a multi-table SQL generation method based on a large model and metadata knowledge graph provided in Example 1 of the present invention;

[0039] Figure 2 It is a schematic diagram of a structure diagram of a multi-table SQL generation device based on a large model and metadata knowledge graph provided in the second embodiment of the present invention;

[0040] Figure 3 It is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION

[0041] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0042] Embodiment 1

[0043] See also Figure 1 , Figure 1 This is a flowchart of a multi-table SQL generation method based on a large model and metadata knowledge graph provided in Example 1 of the present invention. The method includes the following steps:

[0044] Step 101: Receive a query request from a user in natural language, and perform semantic analysis on the query request to obtain a semantic analysis result.

[0045] In this step, the system first receives the query request made by the user in natural language, and then performs semantic analysis on the received natural language query request to parse out the user's query intention, required data, and possible filtering conditions, etc. The result of the analysis is a structured representation that contains the key information required for the query, which usually includes the key concepts and logic of the query.

[0046] Step 102: According to the semantic analysis result, query the metadata knowledge graph to obtain meta-information related to the semantic analysis result, wherein the meta-information includes tables, fields, semantic information, business tags, classification information and blood relationships.

[0047] In this step, the results of semantic analysis are used to search for relevant table and field information in the metadata knowledge graph, where the metadata knowledge graph is a graph containing database structure information, including table names, field names, field types, and relationships between tables, etc. By querying the metadata knowledge graph, the system can obtain table and field information related to the query request, including relationships between tables (such as foreign key associations), field data types, etc. This information will be used for subsequent SQL generation.

[0048] In this step, the metadata knowledge graph is used to store the table structure information of the database. This storage method of structured information makes the query process more efficient and accurate.

[0049] Step 103: Input the meta information corresponding to the query request into the big model for analysis and processing to construct an SQL query statement corresponding to the query request.

[0050] In this step, the obtained meta information is input into the big model for analysis and processing. The big model is a trained deep learning model that can understand complex query requests and build corresponding SQL queries based on meta information (such as table name, field name, data type, etc.). The SQL query statement can include Select clause, From clause, Where clause, etc. At the same time, the big model will also consider the optimization of the query, such as selecting appropriate indexes to avoid unnecessary full table scans, etc. Among them, the analysis and processing process of the big model can include understanding the context of the query, determining the logical structure of the query, selecting appropriate SQL functions and operators, etc. This SQL query statement can accurately reflect the user's query request and can be executed in the database to obtain the required data.

[0051] This step combines the powerful generation capabilities of the big model to process complex query requests, including multi-table queries, embedded queries, etc. The big model can generate grammatically correct and logically correct SQL query statements based on the query intent and the information in the metadata knowledge graph.

[0052] In the embodiment of the present invention, in step 102, according to the semantic analysis result, the metadata knowledge graph is queried to obtain table and field information related to the semantic analysis result. Obtaining the metadata information can be achieved by the following steps:

[0053] Step 1021: According to the semantic analysis results, search for relevant table and field information in the metadata knowledge graph, wherein the metadata knowledge graph includes table names, field names, field types, and relationships between tables.

[0054] Semantic analysis is a key step in natural language processing (NLP), which aims to understand the meaning and context of text or data. It may involve parsing a piece of text or query to understand the query request intent and the information required. Then, based on the results of the semantic analysis, the system searches for information in a specific data structure called the metadata knowledge graph. The goal of the search is to obtain table and field information related to the results of the semantic analysis. The metadata knowledge graph includes table names, field names, field types, and relationships between tables. The table name is the identifier of the table in the database, the field name refers to the identifier of each field in the table, the field type indicates the data type stored in the field (such as integers, strings, dates, etc.), and the relationship between tables describes how different tables are related to each other (such as foreign key relationships).

[0055] Step 1022: Obtain meta information related to the query request by querying the metadata knowledge graph, where the meta information includes tables, fields, semantic information, business tags, classification information, and blood relationships.

[0056] Since the metadata knowledge graph describes the structure of tables in the database, field types, relationships between tables, and other information, in the knowledge graph, tables, fields, and the relationships between them are represented as nodes and edges, forming a complex but orderly network structure. The system will search for relevant nodes and edges in the metadata knowledge graph based on the results of semantic analysis, which usually involves query operations on the graph database, such as searching for specific nodes (such as table names or field names) or traversing according to edges (such as relationships between tables), so as to obtain table and field information related to the query request. Finally, the system integrates these extracted table and field information to form a complete set of meta information. This meta information not only contains the information directly requested by the user, for example, the meta information includes tables, fields, semantic information, business tags, classification information, and blood relationships, but may also include some additional useful information, such as the default value of the field, whether it is allowed to be empty, etc.

[0057] This step allows the system to respond to user query requests in an automated manner and provide accurate and comprehensive meta-information, which not only improves query efficiency but also reduces the risk of errors, making database management and maintenance easier and more reliable.

[0058] Among them, step 103 of inputting the meta information corresponding to the query request into the big model for analysis and processing to construct an SQL query statement corresponding to the query request can be implemented by the following steps:

[0059] Step 1031: Write the metadata of the table in the database into the vector database in advance.

[0060] In this step, the metadata of the tables in the database need to be organized in advance. This involves writing the detailed information of each table, such as field name, field type, and the relationship between tables, into the vector database.

[0061] Step 1032: input the meta information corresponding to the query request into the large model, and the large model searches and matches the meta information corresponding to the query request in the vector database.

[0062] In this step, the big model searches and matches the relevant table metadata information in the vector database. Through vector retrieval or full-text search and other technologies, the big model can determine which tables the user's query intent is associated with and extract the relevant table metadata information.

[0063] Step 1033: The large model merges the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request.

[0064] After matching the relevant table metadata information, the big model will merge this information with the user's query request to generate a prompt containing all the required information. This prompt usually includes the role description, the user's initial question, the matched relevant table metadata information, and some constraints. In order to make the big model recognize each part of the prompt, XML tags can be used to separate these contents.

[0065] Step 1034: The large model generates an SQL query statement corresponding to the query request according to the constructed prompt.

[0066] Finally, the big model will generate the final SQL query statement based on the constructed prompt. This step requires the big model to have strong computing power and accurate understanding ability to ensure that the generated SQL statement can accurately reflect the user's query intention. At the same time, the big model also needs to consider the specific syntax and functions of the database type, as well as query optimization techniques, to generate efficient and accurate SQL query statements.

[0067] In some other embodiments of the present invention, the method may further include:

[0068] Step 104: perform rule verification on the SQL query statement.

[0069] The big model will verify the generated SQL statements to ensure that they can be executed correctly and return the expected execution results. Specifically, this can be achieved by running the query statements in a test environment and checking the accuracy of the results. Furthermore, the verification methods can include syntax verification, semantic verification, business rule verification, etc.

[0070] Among them, syntax verification refers to checking whether the generated SQL statement conforms to the syntax rules of the SQL language. If there is a syntax error in the SQL statement, the system will immediately report an error and prompt the user to correct it.

[0071] After the syntax verification is passed, the system will perform semantic verification to further check whether the table name, column name, function name, etc. in the SQL statement exist in the target database, and whether the relationship between them is correct. If an object (such as a table or column) in the SQL query statement does not exist, or the relationship between objects is incorrect (such as a foreign key constraint error), the system will immediately report an error and prompt the user to make corrections.

[0072] Furthermore, in addition to syntax verification and semantic verification, the system will also verify SQL statements according to business rules, which may include data value ranges, data integrity constraints, etc. If the SQL statement violates the business rules, the system will immediately report an error and prompt the user to make corrections.

[0073] Step 105: Optimize the performance of the SQL query statement.

[0074] After generating SQL statements, the large model can also optimize the generated SQL statements to improve query efficiency and accuracy, such as selecting appropriate indexes, avoiding unnecessary full table scans, adjusting query order, and other strategies.

[0075] The technical solution provided by the present invention receives a query request raised by a user in the form of natural language, performs semantic analysis on the query, obtains a semantic analysis result, queries a metadata knowledge graph according to the semantic analysis result to obtain table and field information related to the semantic analysis result, obtains meta information corresponding to the query request, and inputs the meta information corresponding to the query request into a large model for analysis and processing to construct an SQL query statement corresponding to the query request. Thus, the automatic conversion from user intention to SQL query is realized, the difficulty of users writing complex SQL is reduced, the efficiency of data access is improved, and at the same time, the association relationship between data can be considered and a query statement with high accuracy can be generated.

[0076] Embodiment 2

[0077] See also Figure 2 , Figure 2 : is a schematic diagram of a structure diagram of a multi-table SQL generation device based on a large model and metadata knowledge graph provided by Embodiment 2 of the present invention, the device comprising:

[0078] The receiving module 21 is used to receive a query request from a user in a natural language form, and perform semantic analysis on the query request to obtain a semantic analysis result;

[0079] An analysis module 22 is used to query the metadata knowledge graph to obtain meta information related to the semantic analysis result according to the semantic analysis result;

[0080] The construction module 23 is used to input the meta information corresponding to the query request into the large model for analysis and processing, so as to construct an SQL query statement corresponding to the query request.

[0081] Preferably, the analysis module 22 may include:

[0082] A search unit 221 is used to search for relevant table and field information in a metadata knowledge graph according to the semantic analysis result, wherein the metadata knowledge graph includes table names, field names, field types, and relationships between tables;

[0083] The acquisition module 222 is used to obtain meta information related to the query request by querying the metadata knowledge graph.

[0084] Preferably, the building block 23 may include:

[0085] A writing unit 231 is used to write the metadata of the table in the database into the vector database in advance;

[0086] A matching unit 232, configured to input the meta information corresponding to the query request into the large model, and the large model searches and matches the meta information corresponding to the query request in the vector database;

[0087] A merging unit 233, used for the large model to merge the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request;

[0088] The construction unit 234 is used for the large model to generate an SQL query statement corresponding to the query request according to the constructed prompt.

[0089] Preferably, the device may further include:

[0090] A verification module 24, used for performing rule verification on the SQL query statement;

[0091] The optimization module 25 is used to optimize the performance of the SQL query statement.

[0092] Therefore, the technical solution provided by the present invention receives a query request raised by a user in natural language, performs semantic analysis on the query, obtains a semantic analysis result, queries the metadata knowledge graph according to the semantic analysis result to obtain table and field information related to the semantic analysis result, obtains meta information corresponding to the query request, and inputs the meta information corresponding to the query request into the large model for analysis and processing to construct an SQL query statement corresponding to the query request. Thus, the automatic conversion from user intention to SQL query is realized, the difficulty of users writing complex SQL is reduced, the efficiency of data access is improved, and at the same time, the association relationship between data can be considered and a query statement with high accuracy can be generated.

[0093] It should be noted that the multi-table SQL generation device based on the big model and metadata knowledge graph in the embodiment of the present invention and the multi-table SQL generation method based on the big model and metadata knowledge graph in the above embodiment belong to the same inventive concept. The technical details not described in detail in this device can be found in the previous description of the method and will not be repeated here.

[0094] In addition, an embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the aforementioned method when running.

[0095] Figure 3A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.

[0096] like Figure 3 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0097] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0098] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as an idle detection method.

[0099] In some embodiments, the idle detection method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the idle detection method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the idle detection method in any other appropriate manner (e.g., by means of firmware).

[0100] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0101] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0102] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0103] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).

[0104] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.

[0105] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.

[0106] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.

[0107] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A multi-table SQL generation method based on a large model and metadata knowledge graph, characterized in that: The method comprises: Receive a query request from a user in natural language, and perform semantic analysis on the query request to obtain a semantic analysis result; According to the semantic analysis result, query the metadata knowledge graph to obtain meta information related to the semantic analysis result, wherein the meta information includes tables, fields, semantic information, business tags, classification information and blood relationship; The meta information corresponding to the query request is input into the large model for analysis and processing to construct an SQL query statement corresponding to the query request.

2. The method according to claim 1, characterized in that According to the semantic analysis result, querying the metadata knowledge graph to obtain meta-information related to the semantic analysis result includes: According to the semantic analysis results, relevant table and field information is searched in the metadata knowledge graph, wherein the metadata knowledge graph includes table names, field names, field types, and the relationship between tables; By querying the metadata knowledge graph, meta information related to the query request is obtained, and the meta information includes tables, fields, semantic information, business tags, classification information and blood relationships.

3. The method according to claim 1, characterized in that: Inputting the meta information corresponding to the query request into the large model for analysis and processing to construct an SQL query statement corresponding to the query request includes: Write the metadata of the table in the database into the vector database in advance; Inputting the meta information corresponding to the query request into the large model, and the large model searching and matching the meta information corresponding to the query request in the vector database; The large model merges the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request; The large model generates an SQL query statement corresponding to the query request according to the constructed prompt.

4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Performing rule verification on the SQL query statement; The performance of the SQL query statement is optimized.

5. A multi-table SQL generation device based on a large model and metadata knowledge graph, characterized in that: The device comprises: A receiving module is used to receive a query request from a user in a natural language form, and perform semantic analysis on the query request to obtain a semantic analysis result; An analysis module, used to query the metadata knowledge graph according to the semantic analysis result to obtain meta-information related to the semantic analysis result, wherein the meta-information includes tables, fields, semantic information, business tags, classification information and blood relationship; The construction module is used to input the meta information corresponding to the query request into the large model for analysis and processing, so as to construct an SQL query statement corresponding to the query request.

6. The device according to claim 5, characterized in that The analysis module comprises: A search unit, used to search for relevant table and field information in a metadata knowledge graph according to the semantic analysis result, wherein the metadata knowledge graph includes table names, field names, field types, and relationships between tables; The acquisition module is used to obtain meta information related to the query request by querying the metadata knowledge graph, and the meta information includes tables, fields, semantic information, business tags, classification information and blood relationships.

7. The device according to claim 5, characterized in that The building blocks include: A writing unit, used for writing the metadata of the table in the database into the vector database in advance; A matching unit, configured to input the meta information corresponding to the query request into the large model, and the large model searches and matches the meta information corresponding to the query request in the vector database; A merging unit, used for the large model to merge the meta information corresponding to the query request with the query request to generate a prompt containing all the information corresponding to the query request; The construction unit is used for the large model to generate an SQL query statement corresponding to the query request according to the constructed prompt.

8. The device according to any one of claims 5 to 7, characterized in that: The device also includes: A verification module, used for performing rule verification on the SQL query statement; The optimization module is used to optimize the performance of the SQL query statement.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 4 when executed.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 4.

Citation Information

Cited By

  • Construction method, data processing method and device, electronic equipment and storage medium

    CN120216705A

  • Data blood relationship construction method and system based on NL2SQL and data blood relationship analysis method and system based on NL2SQL

    CN120653761A

  • Multi-source heterogeneous database query method, system, equipment and medium

    CN120950542A

  • E-commerce order data quality detection method and device based on NL2SQL instruction, equipment and medium

    CN120950919A

  • Natural language database query method and system based on large-model two-channel context enhancement

    CN121350101A