Query statement generation methods, data query methods, and generative model training methods

CN116303558BActive Publication Date: 2026-03-10ALIBABA (CHINA) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-18
Publication Date
2026-03-10

Smart Images

  • Figure CN116303558B_ABST
    Figure CN116303558B_ABST
Patent Text Reader

Abstract

This specification provides a query statement generation method, a data query method, and a generative model training method. The query statement generation method includes: receiving a query request; determining the database schema of the target database based on the target database identifier; constructing a query structure graph based on the query information and the database schema; and inputting the query information and the query structure graph into the generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder performs fusion encoding on the query information and the query structure graph, and the decoder decodes the fusion encoded features to obtain the target query statement. By inputting the query structure graph into the generative model and performing fusion encoding on the query information and the query structure graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model and accurately generating the target query statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of computer technology, and in particular to a query statement generation method. One or more embodiments of this specification also relate to a data query method, a generative model training method, a query statement generation apparatus, a data query apparatus, a generative model training apparatus, a data query system, a computing device, a computer-readable storage medium, and a computer program. Background Technology

[0002] With the development of computer technology, more and more work and study tasks can be automated. Computer technology has been gradually applied to various daily education and learning activities, such as using computer technology to query data, thereby greatly saving human resources.

[0003] Currently, various tasks in Natural Language Processing (NLP) technology have been significantly improved with the support of pre-trained models. However, this structure, which is entirely based on deep learning models (transformers), cannot effectively consider the relationships between data, resulting in a lack of reasoning ability and an inability to generate accurate query statements (SQL). Therefore, there is an urgent need for a query statement generation scheme that considers the relationships between data and has high accuracy. Summary of the Invention

[0004] In view of the above, embodiments of this specification provide a query statement generation method. One or more embodiments of this specification also relate to a data query method, a generative model training method, a query statement generation apparatus, a data query apparatus, a generative model training apparatus, a data query system, a computing device, a computer-readable storage medium, and a computer program, to address the technical deficiencies existing in the prior art.

[0005] According to a first aspect of the embodiments of this specification, a query statement generation method is provided, comprising:

[0006] Receive a query request, which includes query information and a target database identifier;

[0007] Determine the database schema of the target database based on the target database identifier;

[0008] Based on the query information and database schema, a query structure relationship graph is constructed, which represents the association between the query information and the database schema.

[0009] The query information and query structure relationship graph are input into the generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0010] According to a second aspect of the embodiments of this specification, a data query method is provided, including:

[0011] Receive query requests from users via the front end, where the query request includes query information and the target database identifier;

[0012] Determine the database schema of the target database based on the target database identifier;

[0013] Based on the query information and database schema, a query structure relationship graph is constructed, which represents the association between the query information and the database schema.

[0014] The query information and query structure relationship graph are input into the generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0015] Use the target query statement to search the database and obtain the query results corresponding to the query information;

[0016] Send the query results to the front end so that the front end can display the query results.

[0017] According to a third aspect of the embodiments of this specification, a generative model training method is provided, applied to a cloud-side device, comprising:

[0018] Obtain a sample set, which includes multiple sample query information, each carrying a query tag;

[0019] Input multiple sample query information and the sample structure relationship graph corresponding to the multiple sample query information into the initial generation model to obtain the predicted statement corresponding to each sample query information. The initial generation model includes an encoder and a decoder. The encoder is used to fuse and encode the sample query information and the sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the predicted statement.

[0020] Based on the prediction statement and query tags, the initial generative model is trained to obtain the model parameters of the trained generative model;

[0021] Send the model parameters of the generated model obtained from training to the edge device.

[0022] According to a fourth aspect of the embodiments of this specification, a query statement generation apparatus is provided, comprising:

[0023] The first receiving module is configured to receive query requests, wherein the query request includes query information and a target database identifier;

[0024] The first determining module is configured to determine the database schema of the target database based on the target database identifier;

[0025] The first construction module is configured to construct a query structure relationship graph based on query information and database schema, wherein the query structure relationship graph represents the association between query information and database schema;

[0026] The first input module is configured to input query information and query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information. The generation model includes an encoder and a decoder. The encoder is used to perform fusion encoding on the query information and query structure relationship graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement.

[0027] According to a fifth aspect of the embodiments of this specification, a data query apparatus is provided, comprising:

[0028] The second receiving module is configured to receive query requests input by the user through the front end, wherein the query request includes query information and target database identifier;

[0029] The second determining module is configured to determine the database schema of the target database based on the target database identifier;

[0030] The second building module is configured to construct a query structure relationship graph based on the query information and the database schema, wherein the query structure relationship graph represents the association between the query information and the database schema;

[0031] The second input module is configured to input query information and query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information. The generation model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0032] The search module is configured to use the target query statement to search the query database and obtain the query results corresponding to the query information.

[0033] The first sending module is configured to send the query results to the front end so that the front end can display the query results.

[0034] According to a sixth aspect of the embodiments of this specification, a generative model training apparatus is provided, applied to a cloud-side device, comprising:

[0035] The acquisition module is configured to acquire a sample set, which includes multiple sample query information, and the sample query information carries query tags;

[0036] The third input module is configured to input multiple sample query information and the sample structure relationship graph corresponding to the multiple sample query information into the initial generation model to obtain the prediction statement corresponding to each sample query information. The initial generation model includes an encoder and a decoder. The encoder is used to fuse and encode the sample query information and the sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the prediction statement.

[0037] The training module is configured to train the initial generative model based on the predicted statement and query tags, and obtain the model parameters of the trained generative model.

[0038] The second sending module is configured to send the model parameters of the generated model obtained from training to the end-side device.

[0039] According to a seventh aspect of the embodiments of this specification, a data query system is provided, the data query system including a client and a server;

[0040] The client is configured to send a query request to the server, wherein the query request includes query information and the target database identifier;

[0041] The server is configured to determine the database schema of the target database based on the target database identifier; construct a query structure graph based on the query information and the database schema, where the query structure graph represents the association between the query information and the database schema; input the query information and the query structure graph into a generative model to obtain the target query statement corresponding to the query information, where the generative model includes an encoder and a decoder, the encoder is used to fuse and encode the query information and the query structure graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement; use the target query statement to search the query database to obtain the query results corresponding to the query information; and send the query results to the client.

[0042] The client is also configured to display query results.

[0043] According to an eighth aspect of the embodiments of this specification, a computing device is provided, comprising:

[0044] Memory and processor;

[0045] The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the method provided in the first, second, or third aspect described above.

[0046] According to a ninth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed by a processor, implement the steps of the methods provided in the first, second, or third aspects described above.

[0047] According to a tenth aspect of the embodiments of this specification, a computer program is provided, wherein when the computer program is executed in a computer, it causes the computer to perform the steps of the method provided in the first, second, or third aspect described above.

[0048] This specification provides a query statement generation method according to one embodiment. The method receives a query request, which includes query information and a target database identifier. Based on the target database identifier, it determines the database schema of the target database. Based on the query information and the database schema, it constructs a query structure graph, where the query structure graph represents the association between the query information and the database schema. The method inputs the query information and the query structure graph into a generation model to obtain the target query statement corresponding to the query information. The generation model includes an encoder and a decoder. The encoder performs fusion encoding on the query information and the query structure graph, and the decoder decodes the fusion encoded features to obtain the target query statement. By inputting the query structure graph into the generation model and performing fusion encoding on the query information and the query structure graph in the encoder of the generation model, structural information is effectively injected into the encoder, improving the reasoning ability of the generation model and accurately generating the target query statement. Attached Figure Description

[0049] Figure 1a This is a framework diagram of a query statement generation system provided in one embodiment of this specification;

[0050] Figure 1b This is a framework diagram of a data query system provided in one embodiment of this specification;

[0051] Figure 2 This is a framework diagram of another query statement generation system provided in one embodiment of this specification;

[0052] Figure 3 This is a flowchart illustrating a query statement generation method provided in one embodiment of this specification;

[0053] Figure 4 This is a schematic diagram of a query structure relationship diagram provided in one embodiment of this specification;

[0054] Figure 5 This is a flowchart illustrating a data query method provided in one embodiment of this specification;

[0055] Figure 6 This is a flowchart illustrating a generative model training method provided in one embodiment of this specification;

[0056] Figure 7 This is a schematic diagram illustrating the training process of a generative model provided in one embodiment of this specification;

[0057] Figure 8 This is a flowchart illustrating the processing steps of a query statement generation method provided in one embodiment of this specification.

[0058] Figure 9 This is a schematic diagram of a data query interface provided in one embodiment of this specification;

[0059] Figure 10 This is a schematic diagram of the structure of a query statement generation device provided in one embodiment of this specification;

[0060] Figure 11 This is a schematic diagram of the structure of a data query device provided in one embodiment of this specification;

[0061] Figure 12 This is a schematic diagram of the structure of a generative model training device provided in one embodiment of this specification;

[0062] Figure 13 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation

[0063] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.

[0064] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms “a,” “described,” and “the” as used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0065] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."

[0066] First, the terms and concepts used in one or more embodiments of this specification will be explained.

[0067] Tab leQA: A human-computer interaction system based on tabular knowledge

[0068] Text-to-SQL: The core technology of TableQA, a language understanding method that converts natural human speech (Text) into SQL statements (SQL).

[0069] Pattern linking: specifically refers to the correspondence between patterns in a table and words in a natural language problem.

[0070] T5 (Transfer Text-to-Text Transformer) model: A pre-trained model consisting of an encoder and a decoder, each composed of a 12-layer Transformer structure.

[0071] Relational databases, as a vital resource, have become increasingly prevalent in many fields, such as healthcare, sports, and entertainment, due to the advent of the big data era. For data users, accessing information in databases through Structured Query Language (SQL) is highly efficient. However, the complex nature of SQL results in a very high learning curve for non-technical users. Therefore, text-to-SQL, which translates natural language instructions or questions into SQL queries, has attracted significant attention from industry and businesses.

[0072] Currently, Tab-based knowledge-based human-computer dialogue interaction systems (Tab-leQA) have become a hot topic in academia and industry due to their ease of use and scalability. The core method of Tab-leQA systems is Text-to-SQL. In recent years, with the rapid development of pre-trained models, various tasks in Natural Language Processing (NLP) have been significantly improved with the support of pre-trained models. However, while this structure based entirely on transformers can effectively utilize the rich knowledge learned during pre-training, it neglects the structure between text and database schemas. This results in the trained model lacking the ability to reason about input information and thus failing to generate accurate query statements (SQL). Therefore, a highly accurate query statement generation solution is urgently needed.

[0073] Based on this, the embodiments of this specification provide a query statement generation scheme that injects structural information into a pre-trained model. The query information and database schema are treated as sequential inputs, for example, the input format is: (tok1, tok2, ..., tok_n, schema1, schema2...schema_n). However, both the query text and the database schema inherently possess structure. For example, text has syntactic structure, and database schema has schema structure (foreign key information). Furthermore, the interaction between them, i.e., schema links (specifically referring to the correspondence between schemas in tables and words in natural language problems), is also manifested in a structural way. Therefore, structure can be combined with the pre-trained model to improve the accuracy of generated query statements, achieving the goal of modeling structural information with only a small number of additional parameters.

[0074] Specifically, the process involves receiving a query request, which includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure graph based on the query information and the database schema, where the query structure graph represents the association between the query information and the database schema; and inputting the query information and the query structure graph into a generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder performs fusion encoding on the query information and the query structure graph, and the decoder decodes the fusion-encoded features to obtain the target query statement. By inputting the query structure graph into the generative model and performing fusion encoding on the query information and the query structure graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model and accurately generating the target query statement.

[0075] This specification provides a query statement generation method, and also relates to a data query method, a generative model training method, a query statement generation device, a data query device, a generative model training device, a data query system, a computing device, a computer-readable storage medium, and a computer program, which will be described in detail in the following embodiments.

[0076] See Figure 1a , Figure 1a This specification shows a framework diagram of a query statement generation system according to an embodiment of the present specification, wherein the query statement generation system includes a server 100 and a client 200;

[0077] Client 200: Sends a query request to server 100, wherein the query request includes query information and target database identifier;

[0078] Server 100: Determines the database schema of the target database based on the target database identifier; constructs a query structure relationship graph based on the query information and the database schema, where the query structure relationship graph represents the association between the query information and the database schema; inputs the query information and the query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information, where the generation model includes an encoder and a decoder, the encoder is used to perform fusion encoding on the query information and the query structure relationship graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement; sends the target query statement to client 200;

[0079] Client 200: Receives the target query statement sent by server 100.

[0080] The scheme implemented in this specification involves receiving a query request, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure graph based on the query information and the database schema, wherein the query structure graph represents the association between the query information and the database schema; and inputting the query information and the query structure graph into a generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder, wherein the encoder is used to perform fusion encoding on the query information and the query structure graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement. By inputting the query structure graph into the generative model and performing fusion encoding on the query information and the query structure graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model and accurately generating the target query statement.

[0081] See Figure 1b , Figure 1bA framework diagram of a data query system provided in one embodiment of this specification is shown, wherein the data query system includes a server 100 and a client 200;

[0082] Client 200: Sends a query request to server 100, wherein the query request includes query information and target database identifier;

[0083] Server 100: Determines the database schema of the target database based on the target database identifier; constructs a query structure graph based on the query information and the database schema, where the query structure graph represents the association between the query information and the database schema; inputs the query information and the query structure graph into the generation model to obtain the target query statement corresponding to the query information, where the generation model includes an encoder and a decoder, the encoder is used to fuse and encode the query information and the query structure graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement; uses the target query statement to search the query database to obtain the query results corresponding to the query information; and sends the query results to client 200.

[0084] Client 200: Receives query results sent by server 100.

[0085] The scheme implemented in this specification involves receiving a query request input by a user through a front-end, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure relationship graph based on the query information and the database schema, wherein the query structure relationship graph represents the association between the query information and the database schema; inputting the query information and the query structure relationship graph into a generative model to obtain the target query statement corresponding to the query information, wherein the generative model includes an encoder and a decoder, the encoder being used to perform fusion encoding on the query information and the query structure relationship graph, and the decoder being used to decode the fusion encoded features to obtain the target query statement; using the target query statement, searching in the query database to obtain the query result corresponding to the query information; and sending the query result to the front-end for display. By inputting the query structure relationship graph into the generative model and performing fusion encoding on the query information and the query structure relationship graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model, accurately generating the target query statement, and further obtaining accurate query results.

[0086] See Figure 2 , Figure 2This diagram illustrates a framework of another query statement generation system provided in one embodiment of this specification. The system may include a server 100 and multiple clients 200. The multiple clients 200 can establish communication connections through the server 100. In a query statement generation scenario, the server 100 provides query statement generation services between the multiple clients 200. Each client 200 can act as a sender or receiver, achieving real-time communication through the server 100.

[0087] Users can interact with server 100 through client 200 to receive data sent by other clients 200, or send data to other clients 200, etc. In the query statement generation scenario, users can publish data streams to server 100 through client 200, server 100 can generate query statements based on the data streams, and push the query statements to other clients that have established communication.

[0088] In this system, client 200 and server 100 establish a connection via a network. The network provides the medium for communication between the client and server. The network can include various connection types, such as wired or wireless communication links or fiber optic cables. Data transmitted by client 200 may need to undergo encoding, transcoding, compression, or other processing before being published to server 100.

[0089] Client 200 can be a browser, an app (APP), a web application such as an H5 (HyperText Markup Language 5) application, a lightweight application (also known as a mini-program), or a cloud application. Client 200 can be developed based on the software development kit (SDK) provided by the server, such as a Real-Time Communication (RTC) SDK. Client 200 can be deployed on electronic devices, requiring the device to run or certain apps on the device to function. Electronic devices can have displays and support information browsing, such as personal mobile terminals like smartphones, tablets, and personal computers. Various other types of applications can also be configured on electronic devices, such as human-computer interaction applications, model training applications, text processing applications, web browser applications, shopping applications, search applications, instant messaging tools, email clients, and social media platforms.

[0090] Server 100 may include servers providing various services, such as servers providing communication services to multiple clients, servers supporting backend training of models used on clients, and servers processing data sent by clients. It should be noted that server 100 can be implemented as a distributed server cluster composed of multiple servers, or as a single server. The server can also be a server in a distributed system, or a server integrated with blockchain. The server can also be a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with artificial intelligence technology.

[0091] It is worth noting that the query statement generation method provided in the embodiments of this specification is generally executed by the server. However, in other embodiments of this specification, the client may also have similar functionality to the server, thereby executing the query statement generation method provided in the embodiments of this specification. In other embodiments, the query statement generation method provided in the embodiments of this specification may also be executed jointly by the client and the server.

[0092] See Figure 3 , Figure 3 This specification shows a flowchart of a query statement generation method according to an embodiment, which specifically includes the following steps:

[0093] Step 302: Receive a query request, wherein the query request includes query information and target database identifier.

[0094] In one or more embodiments of this specification, a query request can be received, and the query content corresponding to the query request and the database where the query content is located can be determined based on the query information and target database identifier carried in the query request, so as to further accurately generate the query statement corresponding to the query request.

[0095] Specifically, query information refers to information used to query the target database. Query information can take various forms, such as query text, query audio, etc., and the choice depends on the specific circumstances. This specification and its embodiments do not impose any limitations on this. The target database identifier is used to uniquely identify the target database. The target database identifier can be the database identity document number (ID), such as 0001, or it can be the database address of the target database, and the choice depends on the specific circumstances. This specification and its embodiments do not impose any limitations on this.

[0096] In practical applications, there are various ways to receive query requests, and the specific method should be selected according to the actual situation. This specification does not impose any limitations on these methods in the embodiments. In one possible implementation, this specification can receive query requests actively sent by the user through the front-end. In another possible implementation, a query statement can be sent to the front-end to generate a prompt, which is then displayed on the front-end. After seeing the prompt, the user can send a query request through the front-end.

[0097] Step 304: Determine the database schema of the target database based on the target database identifier.

[0098] In one or more embodiments of this specification, after receiving a query request, the database schema of the target database can be further determined based on the target database identifier.

[0099] Specifically, a database schema, also known as a logical schema, is a description of the logical structure and characteristics of all data in a database. It specifically refers to information such as table names, column names, and values ​​in database tables. A database has only one schema.

[0100] In practical applications, there are multiple ways to determine the database schema of a target database based on the target database identifier. The specific method to be selected depends on the actual situation, and the embodiments in this specification do not impose any limitations on this.

[0101] In one possible implementation of this specification, the database schema corresponding to the target database identifier can be directly searched.

[0102] In another possible implementation of this specification, since the database schema contains a large amount of information, directly storing the correspondence between the database identifier and the database schema would consume a lot of resources. Therefore, the target database can be determined first based on the target database identifier, and then the database schema of the target database can be extracted. That is, the above-mentioned determination of the database schema of the target database based on the target database identifier may include the following steps:

[0103] Find the target database corresponding to the target database identifier;

[0104] The database structure of the target database is analyzed to determine the database schema, which includes database objects and the relationships between them.

[0105] Specifically, databases naturally possess a schema structure, which can also be understood as foreign key information. A foreign key is a field in one table that references the primary key in another table. The referenced table is called the child table, and the referenced table is called the parent table. A foreign key is a constraint that describes the relationship between tables.

[0106] It should be noted that there are multiple ways to find the target database corresponding to the target database identifier, and the specific method should be selected according to the actual situation. This specification does not impose any limitations on this method in the embodiments. In one possible implementation, all database identifiers can be checked sequentially, and each database identifier can be compared with the target database identifier. The database whose identifier matches the target database identifier is identified as the target database. In another possible implementation, the database whose identifier matches the target database identifier can be directly searched based on the target database identifier, and that database is identified as the target database.

[0107] Furthermore, after identifying the target database, the pre-stored database schema of the target database can be directly obtained. Alternatively, the database structure of the target database can be analyzed to determine its database schema. Specifically, this involves analyzing the composition of each record in the database, their relationships, the characteristics of data items, data security, integrity constraints, and other information to determine the database schema of the target database.

[0108] By applying the scheme of the embodiments in this specification, the target database corresponding to the target database identifier is located; the database structure of the target database is analyzed to determine the database schema of the target database, wherein the database schema includes database objects and the relationships between database objects, thereby achieving accurate determination of the database schema and preparing for the subsequent construction of an accurate query structure relationship diagram.

[0109] Step 306: Based on the query information and database schema, construct a query structure relationship graph, whereby the query structure relationship graph represents the association between the query information and the database schema.

[0110] In one or more embodiments of this specification, after receiving a query request and determining the database schema of the target database based on the target database identifier, a query structure relationship diagram can be further constructed based on the query information and the database schema.

[0111] In practical applications, after determining the database schema, the database objects in the database can be determined based on the database schema. Furthermore, a query structure diagram can be constructed based on the structural relationships of the query information, the associations between database objects, and the key relationships between the query information and database objects. That is, constructing a query structure diagram based on the query information and the database schema can include the following steps:

[0112] Extract at least one keyword from the query information;

[0113] Construct a query structure graph with at least one keyword and a database object in the database schema as nodes, and at least one relationship between keywords, between database objects, and between at least one keyword and a database object as edges.

[0114] In the embodiments of this specification, if the query information is in audio format, the query audio can be converted into query text to facilitate the determination of the structural relationship of the query information. There are various ways to convert query audio into query text; audio-to-text conversion tools can be used, or the conversion can be performed manually. The specific method of audio-to-text conversion is selected according to the actual situation, and this embodiment of the specification does not impose any limitations on it.

[0115] It should be noted that there are multiple ways to extract at least one keyword from query information, and the specific method should be selected according to the actual situation. This specification does not impose any limitations on this method in its embodiments. In one possible implementation, the query text can be matched with a pre-built keyword database to determine at least one keyword in the query text. In another possible implementation, a pre-trained keyword extraction model can be used to extract at least one keyword from the query information. This keyword extraction model is trained based on multiple sample information and the keyword labels corresponding to each sample information.

[0116] By applying the scheme of the embodiments of this specification, at least one keyword is extracted from the query information; a query structure relationship graph is constructed using at least one keyword and database objects in the database schema as nodes, and the association relationships between at least one keyword, between database objects, and between at least one keyword and database objects as edges. This improves the accuracy of the query structure relationship graph, further realizes the effective injection of structural information into the encoder, improves the reasoning ability of the generative model, and accurately generates the target query statement.

[0117] In one optional embodiment of this specification, the query structure graph constructed using at least one keyword and a database object in a database schema as nodes, and the relationships between at least one keyword, the relationships between database objects, and the relationships between at least one keyword and a database object as edges, may not necessarily cover all structural relationships. Traditionally, non-matching edges can be directly added, but this results in a very large number of edges, leading to a space complexity of (N x M). Furthermore, a large number of edges increases computational complexity and can cause overfitting, where N is the length of the query information and M is the length of the database schema. To address these issues and improve the robustness of the query structure graph, bridging nodes, or virtual nodes, can be introduced. When two nodes are not connected, they are connected to a bridging node, reducing the complexity to N+M. That is, after constructing the query structure graph using at least one keyword and a database object in a database schema as nodes, and the relationships between at least one keyword, the relationships between database objects, and the relationships between at least one keyword and a database object as edges, the following steps may also be included:

[0118] Add a bridging node to the query structure graph;

[0119] By connecting the first and second nodes in the query structure graph through a bridging node, an updated query structure graph is obtained, where the first and second nodes are two nodes in the query structure graph that do not have an edge.

[0120] See Figure 4 , Figure 4 The diagram illustrates a query structure graph provided in one embodiment of this specification. (a) is the query structure graph obtained by adding No-Match in the traditional scheme, and (b) is the query structure graph obtained by adding bridging nodes (black solid circles). It can be seen that (b) is more concise than (a), which can effectively reduce the computational load of the generative model and improve the efficiency of query statement generation.

[0121] By applying the scheme of the embodiments of this specification, a bridging node is added to the query structure graph; the first node and the second node in the query structure graph are connected by the bridging node to obtain an updated query structure graph, wherein the first node and the second node are two nodes in the query structure graph that do not have edges, which reduces the complexity of the query structure graph, effectively reduces the computational load of the generation model, and improves the efficiency of query statement generation.

[0122] Step 308: Input the query information and query structure relationship graph into the generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0123] In one or more embodiments of this specification, after receiving a query request, determining the database schema of the target database based on the target database identifier, and constructing a query structure relationship diagram based on the query information and the database schema, the query information and the query structure relationship diagram can be further input into the generation module to obtain the target query statement corresponding to the query information.

[0124] Specifically, a generative model can be a model that includes an encoder and a decoder, such as the T5 (Transfer Text-to-Text Transformer) model. A target query is a computer language used to store, retrieve, and modify data stored in a relational database.

[0125] The scheme implemented in this specification involves receiving a query request, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure graph based on the query information and the database schema, wherein the query structure graph represents the association between the query information and the database schema; and inputting the query information and the query structure graph into a generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder, wherein the encoder is used to perform fusion encoding on the query information and the query structure graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement. By inputting the query structure graph into the generative model and performing fusion encoding on the query information and the query structure graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model and accurately generating the target query statement.

[0126] In one optional embodiment of this specification, in order to accurately inject the query structure graph into the generative model, a graph processing layer can be added to the generative model. This layer retains the encoding layer parameters of the generative model while adding new structural information; that is, the encoder includes a graph processing layer and multiple encoding layers. Inputting the query information and the query structure graph into the generative model to obtain the target query statement corresponding to the query information can include the following steps:

[0127] Input the query structure graph into the graph processing layer to obtain the structural features corresponding to the query structure graph.

[0128] For any given coding layer, the output of this layer is determined based on the structural features and the query features output by the previous coding layer. The input of the first layer is the query information, and the output of the last layer is the fused coding features.

[0129] The fused encoded features are input into the decoder to obtain the target query statement corresponding to the query information.

[0130] It should be noted that the generative model consists of an encoder-decoder structure, with each encoder and decoder consisting of a 12-layer transformer structure.

[0131] The scheme of the embodiments in this specification is applied by inputting the query structure relationship graph into the graph processing layer to obtain the structural features corresponding to the query structure relationship graph; for any encoding layer, the output of the current layer is determined based on the structural features and the query features output by the previous encoding layer, wherein the input of the first layer is the query information and the output of the last layer is the fused encoding features; the fused encoding features are input into the decoder to obtain the target query statement corresponding to the query information, thereby realizing the injection of graph structure information into the encoder and improving the accuracy of the target query statement.

[0132] In one optional embodiment of this specification, the above-mentioned inputting the query structure relationship graph into the graph processing layer to obtain the structural features corresponding to the query structure relationship graph may include the following steps:

[0133] The query structure graph is input into the graph processing layer, and after mapping processing by the graph processing layer, the initial structural features, key vectors and value vectors are obtained.

[0134] Based on the initial structural features, key vector, and value vector, determine the structural features corresponding to the query structure relationship graph.

[0135] It should be noted that when determining the structural features corresponding to the query structure graph, the initial structural features are obtained by incorporating structural information mapping during the calculation of the key vector and value vector, thereby injecting structural information into the generative model. The calculation logic for the structural features corresponding to the query structure graph is as follows:

[0136]

[0137] Among them, e i e j Let W be the token, and r be the learnable parameter. ij This is structural information: Q is the query vector, K is the key vector, V is the value vector, and Φ represents r. ij Mapped to a specific vector, N is the normalization factor. irepresents the neighboring nodes of node i (connected by edges), Softmax and LayerNorm are functions, and FFN is a linear mapping layer.

[0138] By applying the scheme of the embodiments of this specification, the query structure relationship graph is input into the graph processing layer, and after the mapping processing of the graph processing layer, the initial structural features, key vectors and value vectors are obtained; based on the initial structural features, key vectors and value vectors, the structural features corresponding to the query structure relationship graph are determined, thereby improving the accuracy of the structural features.

[0139] In one optional embodiment of this specification, determining the output of the current layer based on structural features and query features output by the previous coding layer may include the following steps:

[0140] Input the query information into the first layer of multiple coding layers to obtain the query features corresponding to the query information;

[0141] The query features and structural features are merged to obtain the updated query features. The updated query features are then input into the next coding layer to obtain the output query features of the next coding layer. The process of merging query features and structural features to obtain the updated query features is repeated until the last coding layer outputs the fused coding features.

[0142] It should be noted that query features and structural features can be combined using the following formula:

[0143]

[0144] in, The output vector of each encoding layer, which is also the query feature. This is the output vector of structure learning, i.e., the structural features.

[0145] The scheme of the embodiments of this specification is applied by inputting query information into the first layer of multiple coding layers to obtain query features corresponding to the query information; merging query features and structural features to obtain updated query features, and inputting the updated query features into the next coding layer to obtain the query features output by the next coding layer; returning to the step of merging query features and structural features to obtain updated query features, until the last coding layer outputs fused coding features, thereby improving the accuracy of fused coding features.

[0146] In one optional embodiment of this specification, the training method for the generative model may include the following steps:

[0147] Obtain a sample set, which includes multiple sample query information, each carrying a query tag;

[0148] Extract the first sample query information from the sample set, where the first sample query information is any one item in the sample set;

[0149] The first sample query information and the first sample structure relationship graph corresponding to the first sample query information are input into the initial generation model to obtain the first predicted statement corresponding to the first sample query information. The initial generation model includes an encoder and a decoder. The encoder is used to fuse and encode the first sample query information and the first sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the first predicted statement.

[0150] Calculate the first loss value based on the first prediction statement and the first query label carried by the first sample query information;

[0151] Based on the first loss value, adjust the model parameters of the initial generated model, and return to the step of extracting the first sample query information from the sample set until the preset stopping condition is met to obtain the generated model.

[0152] In practical applications, there are multiple ways to obtain a sample set. It can be formed by manually inputting a large amount of sample query information, or it can be formed by reading a large amount of sample query information from other data acquisition devices or databases. The specific method of obtaining the sample set is selected according to the actual situation, and the embodiments in this specification do not limit it in any way.

[0153] Furthermore, when training the initial generation model based on the first prediction statement and the first query label carried by the first sample query information, a first loss value can be calculated based on the first prediction statement and the first query label. Based on the first loss value, the model parameters of the initial generation model are adjusted, and the step of extracting the first sample query information from the sample set is returned. If the preset stopping condition is met, the model parameters of the trained generation model are obtained.

[0154] In one possible implementation of this specification, the preset stopping condition includes a first loss value being less than or equal to a first preset threshold. The first preset threshold is specifically selected based on actual circumstances, and this specification does not impose any limitations on it. The first sample query information and the corresponding first sample structure relationship diagram are input into the initial generation model to obtain the first prediction statement corresponding to the first sample query information. After obtaining the first prediction statement, a first loss value is calculated based on the first prediction statement and the first query label, and the first loss value is compared with the first preset threshold.

[0155] Specifically, if the first loss value is greater than the first preset threshold, it indicates that the difference between the first predicted statement and the first query label is large, and the initial generation model has poor prediction ability for the query statement. At this time, the model parameters of the initial generation model can be adjusted, and the step of extracting the first sample query information from the sample set can be returned to continue training the initial generation model until the first loss value is less than or equal to the first preset threshold, indicating that the difference between the first predicted statement and the first query label is small, the preset stopping condition is reached, and the model parameters of the generation model that has been trained are obtained.

[0156] In another possible implementation of this specification, in addition to comparing the magnitude of the first loss value and the first preset threshold, the number of iterations can also be used to determine whether the current initial generation model has been trained.

[0157] Specifically, if the first loss value is greater than the first preset threshold, the parameters of the initial generation model are adjusted, and the step of extracting the first sample query information from the sample set is returned to continue training the initial generation model. When the first preset number of iterations is reached, the iteration is stopped, and the fully trained generation model is obtained. The first preset number of iterations is selected according to the actual situation, and the embodiments in this specification do not limit it in any way.

[0158] In practical applications, there are many functions for calculating the first loss value, such as the cross-entropy loss function, L1 norm loss function, maximum loss function, mean squared error loss function, logarithmic loss function, etc. The specific function to be selected depends on the actual situation, and the embodiments in this specification do not impose any limitations on this. Preferably, the cross-entropy loss function can be used to calculate the first loss value. By using the cross-entropy loss function to calculate the cross-entropy between the first predicted statement and the first query label as the first loss value, the efficiency of calculating the first loss value is improved, thereby improving the training efficiency of the initial generative model.

[0159] The scheme described in this specification involves obtaining a sample set, which includes multiple sample query information entries, each carrying a query label. First sample query information is extracted from the sample set, where the first sample query information is any one entry in the sample set. The first sample query information and its corresponding first sample structure graph are input into an initial generation model to obtain a first predicted statement. The initial generation model includes an encoder and a decoder. The encoder performs fusion encoding on the first sample query information and the first sample structure graph, and the decoder decodes the fusion features to obtain the first predicted statement. A first loss value is calculated based on the first predicted statement and the first query label carried by the first sample query information. The model parameters of the initial generation model are adjusted based on the first loss value, and the process of extracting the first sample query information from the sample set is repeated until a preset stopping condition is met, thus obtaining the generation model. By continuously adjusting the model parameters of the initial generation model, the final generation model becomes more accurate. Furthermore, by introducing parameters from graph learning, the generation model's capabilities are not significantly impaired, which can alleviate catastrophic forgetting.

[0160] The following is in conjunction with the appendix Figure 5 Taking the application of the query statement generation method provided in this specification in the field of data querying as an example, the query statement generation method will be further explained. Among them, Figure 5 This specification shows a flowchart of a data query method according to an embodiment, which specifically includes the following steps:

[0161] Step 502: Receive the query request input by the user through the front end, wherein the query request includes query information and target database identifier.

[0162] Step 504: Determine the database schema of the target database based on the target database identifier.

[0163] Step 506: Based on the query information and database schema, construct a query structure relationship graph, whereby the query structure relationship graph represents the association between the query information and the database schema.

[0164] Step 508: Input the query information and query structure relationship graph into the generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0165] Step 510: Use the target query statement to search the database for the query results corresponding to the query information.

[0166] Step 512: Send the query results to the front end so that the front end can display the query results.

[0167] It should be noted that the specific implementation methods of steps 502, 504, 506, and 508 are the same as those of steps 502, 504, 506, and 508 above, and will not be described again in the embodiments of this specification.

[0168] Furthermore, after obtaining the target query statement corresponding to the query information, the query cache can be checked. If the cache is hit, the query result stored in the cache is returned and sent to the front end so that the front end can display the query result.

[0169] The scheme implemented in this specification involves receiving a query request input by a user through a front-end, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure relationship graph based on the query information and the database schema, wherein the query structure relationship graph represents the association between the query information and the database schema; inputting the query information and the query structure relationship graph into a generative model to obtain the target query statement corresponding to the query information, wherein the generative model includes an encoder and a decoder, the encoder being used to perform fusion encoding on the query information and the query structure relationship graph, and the decoder being used to decode the fusion encoded features to obtain the target query statement; using the target query statement, searching in the query database to obtain the query result corresponding to the query information; and sending the query result to the front-end for display. By inputting the query structure relationship graph into the generative model and performing fusion encoding on the query information and the query structure relationship graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model, accurately generating the target query statement, and further obtaining accurate query results.

[0170] See Figure 6 , Figure 6 This specification illustrates a flowchart of a generative model training method according to an embodiment. The generative model training method is applied to a cloud-side device and specifically includes the following steps:

[0171] Step 602: Obtain the sample set, which includes multiple sample query information, and the sample query information carries query tags.

[0172] Step 604: Input multiple sample query information and the sample structure relationship graph corresponding to the multiple sample query information into the initial generation model to obtain the prediction statement corresponding to each sample query information.

[0173] The initial generation model includes an encoder and a decoder. The encoder is used to fuse and encode the sample query information and the sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the predicted statement.

[0174] Step 606: Train the initial generative model based on the prediction statement and query tags to obtain the model parameters of the trained generative model.

[0175] Step 608: Send the model parameters of the generated model obtained from training to the edge device.

[0176] It should be noted that the specific implementation methods of steps 602, 604, and 606 are the same as those described above. Figure 3 The training method for the generative model provided is the same as that in the previous example, so the embodiments in this specification will not be described again.

[0177] Furthermore, after the cloud-side device obtains the model parameters of the generated model, it can send the model parameters of the generated model to the end-side device. After receiving the model parameters of the generated model, the end-side device can reconstruct the generated model based on the model parameters and further generate the query statement locally.

[0178] The scheme described in this specification involves obtaining a sample set, which includes multiple sample query information entries, each carrying a query tag. The multiple sample query information entries and their corresponding sample structure relationship graphs are input into an initial generation model to obtain predicted statements for each sample query information entry. The initial generation model includes an encoder and a decoder. The encoder performs fusion encoding on the sample query information and the sample structure relationship graph, while the decoder decodes the fusion features to obtain the predicted statements. Based on the predicted statements and query tags, the initial generation model is trained to obtain model parameters. These model parameters are then sent to the edge device. By inputting the sample structure relationship graph into the initial generation model and performing fusion encoding on the sample query information and the sample query structure relationship graph in the encoder of the initial generation model, structural information is effectively injected into the encoder, improving the inference ability of the initial generation model and thus obtaining a more accurate generation model.

[0179] In one optional embodiment of this specification, before inputting multiple sample query information and the sample structure relationship graph corresponding to the multiple sample query information into the initial generation model to obtain the prediction statement corresponding to each sample query information, the following steps may be included:

[0180] For any given sample query information, extract at least one sample keyword from the sample query information;

[0181] Determine the sample database schema of the sample database corresponding to the sample query information;

[0182] Using at least one sample keyword and a sample database object in the sample database pattern as nodes, and the relationships between at least one sample keyword, between sample database objects, and between at least one sample keyword and a sample database object as edges, construct a sample structure relationship graph corresponding to the sample query information.

[0183] It should be noted that the specific implementation method of "extracting at least one sample keyword from the sample query information" is the same as the implementation method of "extracting at least one keyword from the query information". Similarly, the specific implementation method of "constructing a sample structure relationship graph corresponding to the sample query information using at least one sample keyword and sample database objects in the sample database pattern as nodes, and the relationships between at least one sample keyword, between sample database objects, and between at least one sample keyword and sample database objects as edges" is the same as the implementation method of "constructing a query structure relationship graph using at least one keyword and database objects in the database pattern as nodes, and the relationships between at least one keyword, between database objects, and between at least one keyword and database objects as edges". Therefore, the embodiments in this specification will not be described in detail again.

[0184] In practical applications, when determining the sample database mode of the sample database corresponding to the sample query information, it can be determined based on the sample database identifier carried by the sample query information. Furthermore, the specific implementation method of "determining the sample database mode of the sample database corresponding to the sample query information" is the same as the implementation method of "determining the database mode of the target database based on the target database identifier" mentioned above, and will not be described again in the embodiments of this specification.

[0185] Applying the scheme of the embodiments in this specification, for any sample query information, at least one sample keyword is extracted from the sample query information; the sample database pattern of the sample database corresponding to the sample query information is determined; and a sample structure relationship graph corresponding to the sample query information is constructed, using at least one sample keyword and sample database objects in the sample database pattern as nodes, and the association relationships between at least one sample keyword, between sample database objects, and between at least one sample keyword and sample database objects as edges. This improves the accuracy of the sample structure relationship graph, further realizes the effective injection of structural information into the encoder, and improves the accuracy of the generative model training process.

[0186] See Figure 7 , Figure 7This diagram illustrates a training process for a generative model according to an embodiment of this specification. The process involves: acquiring a sample set, which includes multiple sample query information entries carrying query tags; extracting at least one sample keyword from any given sample query information; determining the sample database pattern of the sample database corresponding to the sample query information; constructing a sample structure graph corresponding to the sample query information, using at least one sample keyword and sample database objects in the sample database pattern as nodes, and the relationships between at least one sample keyword, between sample database objects, and between at least one sample keyword and a sample database object as edges; inputting the sample structure graphs corresponding to multiple sample query information entries into the graph processing layer of the initial generative model to obtain sample structure features corresponding to each graph; inputting multiple sample query information entries into the first layer of multiple encoding layers of the initial generative model to obtain sample query features corresponding to the sample query information; merging the sample query features and sample structure features to obtain updated sample query features, and inputting the updated sample query features into the next encoding layer to obtain the output sample query features of the next encoding layer; returning to the step of merging the sample query features and sample structure features to obtain updated sample query features, until the last encoding layer outputs sample fusion encoding features. The sample fusion encoding features are input into multiple decoding layers in the decoder to obtain the predicted statement corresponding to the query information of each sample; based on the predicted statement and query label corresponding to the query information of each sample, the initial generation model is trained to obtain the model parameters of the trained generation model.

[0187] See Figure 8 , Figure 8 This document illustrates a flowchart of a query statement generation method according to an embodiment of this specification. The method involves receiving a query request, which includes the query information "Find the number of dog pets that are registered by female students" and a target database identifier "00001". Based on the target database identifier, the database schema of target database 00001 is determined. This database schema includes a Pets table, a Has_Pet table, and a Student table. The Student table includes columns for student ID, Sex, and Age. The Pets table includes columns for Pet ID, PetType, and Pet_age. The Has_Pet table includes columns for student ID and Pet ID. Figure 8As shown, directly establishing the relationship between "female" and "sex" is difficult. However, in the query structure graph, "female" and "student" are connected by MOD syntax, "student" and "student" can be directly connected by rule links, and "Student" and "sex" are connected by schema (belonging to the same table). Through this transfer, the required connection between "female" and "sex" can be established, further generating the correct SQL. That is, based on the query information and database schema, a query structure graph is constructed, where the query structure graph represents the association between the query information and the database schema. The query information and the query structure graph are input into the generation model to obtain the target query statement corresponding to the query information: "SELECT count(*) FROM student AS TI JOIN has pet AS T2 ON T1.stu id=T2.stu id JOI N pets AST3 ON T2.pet id=T3.pet id WHERE T1.sex='F'AND T3.pettype='dog'". The generative model includes an encoder and a decoder. The encoder is used to fuse and encode the query information and the query structure relationship graph, and the decoder is used to decode the fused and encoded features to obtain the target query statement.

[0188] See Figure 9 , Figure 9 This diagram illustrates a data query interface according to an embodiment of this specification. The data query interface includes a query request upload interface and a query result display interface. The query request upload interface includes a query request upload box, an "OK" control, and a "Cancel" control. The query result display interface includes a query result display box. The user uploads a query request in the query request upload box and clicks the "OK" control. The front-end sends the query request to the server. The server determines the database schema of the target database based on the target database identifier. Based on the query information and the database schema, it constructs a query structure relationship diagram. The query information and the query structure relationship diagram are input into the generation model to obtain the target query statement corresponding to the query information. Using the target query statement, the server searches the query database to obtain the query result corresponding to the query information and sends the query result to the front-end so that the front-end displays the query result in the query result display box.

[0189] It should be noted that users can interact with the control in any of the following ways: clicking, double-clicking, touching, hovering the mouse, swiping, long-pressing, voice control, or shaking. The specific method to be selected depends on the actual situation, and this specification does not limit the specific method used in this embodiment.

[0190] It should be noted that the query information, target database identifier, sample query information, initial generation model and other information and data involved in the above method embodiments are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0191] Corresponding to the above-described query statement generation method embodiments, this specification also provides query statement generation apparatus embodiments. Figure 10 A schematic diagram of a query statement generation apparatus according to one embodiment of this specification is shown. Figure 10 As shown, the device includes:

[0192] The first receiving module 1002 is configured to receive a query request, wherein the query request includes query information and a target database identifier;

[0193] The first determining module 1004 is configured to determine the database schema of the target database based on the target database identifier;

[0194] The first construction module 1006 is configured to construct a query structure relationship graph based on query information and database schema, wherein the query structure relationship graph represents the association between query information and database schema;

[0195] The first input module 1008 is configured to input query information and query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information. The generation model includes an encoder and a decoder. The encoder is used to perform fusion encoding on the query information and query structure relationship graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement.

[0196] Optionally, the first determining module 1004 is further configured to find the target database corresponding to the target database identifier; analyze the database structure of the target database; and determine the database schema of the target database, wherein the database schema includes database objects and the relationships between database objects.

[0197] Optionally, the first construction module 1006 is further configured to extract at least one keyword from the query information; and construct a query structure relationship graph with at least one keyword and database objects in the database schema as nodes, and the association between at least one keyword, the association between database objects, and the association between at least one keyword and database objects as edges.

[0198] Optionally, the first building module 1006 is further configured to add a bridging node to the query structure graph; and to connect the first node and the second node in the query structure graph through the bridging node to obtain an updated query structure graph, wherein the first node and the second node are two nodes in the query structure graph that do not have an edge.

[0199] Optionally, the encoder includes a graph processing layer and multiple encoding layers; the first input module 1008 is further configured to input the query structure relationship graph into the graph processing layer to obtain the structural features corresponding to the query structure relationship graph; for any encoding layer, based on the structural features and the query features output by the previous encoding layer, the output of this layer is determined, wherein the input of the first layer is the query information and the output of the last layer is the fused encoding features; the fused encoding features are input into the decoder to obtain the target query statement corresponding to the query information.

[0200] Optionally, the first input module 1008 is further configured to input the query structure relationship graph into the graph processing layer, and obtain the initial structural features, key vectors and value vectors through the mapping processing of the graph processing layer; and determine the structural features corresponding to the query structure relationship graph based on the initial structural features, key vectors and value vectors.

[0201] Optionally, the first input module 1008 is further configured to input query information into the first layer of multiple coding layers to obtain query features corresponding to the query information; merge query features and structural features to obtain updated query features, and input the updated query features into the next coding layer to obtain the query features output by the next coding layer; return to the step of merging query features and structural features to obtain updated query features, until the last coding layer outputs fused coding features.

[0202] Optionally, the device further includes: a generative model training module configured to acquire a sample set, wherein the sample set includes multiple sample query information, and the sample query information carries query labels; extract first sample query information from the sample set, wherein the first sample query information is any one in the sample set; input the first sample query information and the first sample structure relationship graph corresponding to the first sample query information into an initial generative model to obtain a first predicted statement corresponding to the first sample query information, wherein the initial generative model includes an encoder and a decoder, the encoder is used to perform fusion encoding on the first sample query information and the first sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the first predicted statement; calculate a first loss value based on the first predicted statement and the first query label carried by the first sample query information; adjust the model parameters of the initial generative model based on the first loss value, and return to execute the step of extracting the first sample query information from the sample set until a preset stopping condition is reached to obtain the generative model.

[0203] The scheme implemented in this specification involves receiving a query request, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure graph based on the query information and the database schema, wherein the query structure graph represents the association between the query information and the database schema; and inputting the query information and the query structure graph into a generative model to obtain the target query statement corresponding to the query information. The generative model includes an encoder and a decoder, wherein the encoder is used to perform fusion encoding on the query information and the query structure graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement. By inputting the query structure graph into the generative model and performing fusion encoding on the query information and the query structure graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model and accurately generating the target query statement.

[0204] The above is a schematic scheme of a query statement generation device according to this embodiment. It should be noted that the technical solution of this query statement generation device and the technical solution of the query statement generation method described above belong to the same concept. For details not described in detail in the technical solution of the query statement generation device, please refer to the description of the technical solution of the query statement generation method described above.

[0205] Corresponding to the above-described data query method embodiments, this specification also provides data query device embodiments. Figure 11 A schematic diagram of a data query device according to one embodiment of this specification is shown. Figure 11 As shown, the device includes:

[0206] The second receiving module 1102 is configured to receive a query request input by a user through the front end, wherein the query request includes query information and a target database identifier;

[0207] The second determining module 1104 is configured to determine the database schema of the target database based on the target database identifier;

[0208] The second construction module 1106 is configured to construct a query structure relationship graph based on query information and database schema, wherein the query structure relationship graph represents the association between query information and database schema;

[0209] The second input module 1108 is configured to input query information and query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information. The generation model includes an encoder and a decoder. The encoder is used to perform fusion encoding on the query information and query structure relationship graph, and the decoder is used to decode the fusion encoded features to obtain the target query statement.

[0210] The lookup module 1110 is configured to use the target query statement to search the query database to obtain the query results corresponding to the query information.

[0211] The first sending module 1112 is configured to send the query results to the front end so that the front end can display the query results.

[0212] The scheme implemented in this specification involves receiving a query request input by a user through a front-end, wherein the query request includes query information and a target database identifier; determining the database schema of the target database based on the target database identifier; constructing a query structure relationship graph based on the query information and the database schema, wherein the query structure relationship graph represents the association between the query information and the database schema; inputting the query information and the query structure relationship graph into a generative model to obtain the target query statement corresponding to the query information, wherein the generative model includes an encoder and a decoder, the encoder being used to perform fusion encoding on the query information and the query structure relationship graph, and the decoder being used to decode the fusion encoded features to obtain the target query statement; using the target query statement, searching in the query database to obtain the query result corresponding to the query information; and sending the query result to the front-end for display. By inputting the query structure relationship graph into the generative model and performing fusion encoding on the query information and the query structure relationship graph in the encoder of the generative model, structural information is effectively injected into the encoder, improving the reasoning ability of the generative model, accurately generating the target query statement, and further obtaining accurate query results.

[0213] The above is an illustrative scheme of a data query device according to this embodiment. It should be noted that the technical solution of this data query device and the technical solution of the data query method described above belong to the same concept. For details not described in detail in the technical solution of the data query device, please refer to the description of the technical solution of the data query method described above.

[0214] Corresponding to the above embodiments of the generative model training method, this specification also provides embodiments of the generative model training apparatus. Figure 12 A schematic diagram of a generative model training apparatus according to one embodiment of this specification is shown. Figure 12 As shown, the device includes:

[0215] The acquisition module 1202 is configured to acquire a sample set, wherein the sample set includes multiple sample query information, and the sample query information carries query tags;

[0216] The third input module 1204 is configured to input multiple sample query information and the sample structure relationship graph corresponding to the multiple sample query information into the initial generation model to obtain the prediction statement corresponding to each sample query information. The initial generation model includes an encoder and a decoder. The encoder is used to fuse and encode the sample query information and the sample structure relationship graph, and the decoder is used to decode the sample fusion features to obtain the prediction statement.

[0217] Training module 1206 is configured to train the initial generative model based on the prediction statement and query label, and obtain the model parameters of the trained generative model.

[0218] The second sending module 1208 is configured to send the model parameters of the generated model obtained from training to the end-side device.

[0219] Optionally, the device further includes: a third construction module configured to extract at least one sample keyword from any sample query information; determine the sample database pattern of the sample database corresponding to the sample query information; and construct a sample structure relationship graph corresponding to the sample query information, using at least one sample keyword and sample database objects in the sample database pattern as nodes, and the association relationships between at least one sample keyword, between sample database objects, and between at least one sample keyword and sample database objects as edges.

[0220] The scheme described in this specification involves obtaining a sample set, which includes multiple sample query information entries, each carrying a query tag. The multiple sample query information entries and their corresponding sample structure relationship graphs are input into an initial generation model to obtain predicted statements for each sample query information entry. The initial generation model includes an encoder and a decoder. The encoder performs fusion encoding on the sample query information and the sample structure relationship graph, while the decoder decodes the fusion features to obtain the predicted statements. Based on the predicted statements and query tags, the initial generation model is trained to obtain model parameters. These model parameters are then sent to the edge device. By inputting the sample structure relationship graph into the initial generation model and performing fusion encoding on the sample query information and the sample query structure relationship graph in the encoder of the initial generation model, structural information is effectively injected into the encoder, improving the inference ability of the initial generation model and thus obtaining a more accurate generation model.

[0221] The above is an illustrative scheme of a generative model training device according to this embodiment. It should be noted that the technical solution of this generative model training device and the technical solution of the generative model training method described above belong to the same concept. For details not described in detail in the technical solution of the generative model training device, please refer to the description of the technical solution of the generative model training method described above.

[0222] Figure 13 A structural block diagram of a computing device according to one embodiment of this specification is shown. The components of the computing device 1300 include, but are not limited to, a memory 1310 and a processor 1320. The processor 1320 is connected to the memory 1310 via a bus 1330, and a database 1350 is used to store data.

[0223] The computing device 1300 also includes an access device 1340, which enables the computing device 1300 to communicate via one or more networks 1360. Examples of such networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. Access device 1340 may include one or more of any type of wired or wireless network interface (e.g., a network interface card (NIC)), such as an IEEE 802.11 wireless local area network (WLAN) interface, a Wi-MAX (World Interoperability for Microwave Access) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.

[0224] In one embodiment of this specification, the above-described components of the computing device 1300 and Figure 13 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 13 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0225] The computing device 1300 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 1300 can also be a mobile or stationary server.

[0226] The processor 1320 is configured to execute the following computer-executable instructions, which, when executed by the processor, implement the steps of the above-mentioned query statement generation method, data query method, or generative model training method.

[0227] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device belongs to the same concept as the technical solutions of the query statement generation method, data query method, and generative model training method described above. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solutions of the query statement generation method, data query method, or generative model training method described above.

[0228] An embodiment of this specification also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the query statement generation method, data query method, or generative model training method described above.

[0229] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solutions of the query statement generation method, data query method, and generative model training method described above. For details not described in detail in the technical solution of the storage medium, please refer to the description of the technical solutions of the query statement generation method, data query method, or generative model training method described above.

[0230] An embodiment of this specification also provides a computer program, wherein when the computer program is executed in a computer, it causes the computer to perform the steps of the above-described query statement generation method, data query method, or generative model training method.

[0231] The above is an illustrative scheme of a computer program according to this embodiment. It should be noted that the technical solution of this computer program belongs to the same concept as the technical solutions of the query statement generation method, data query method, and generative model training method described above. For details not described in detail in the technical solution of the computer program, please refer to the description of the technical solutions of the query statement generation method, data query method, or generative model training method described above.

[0232] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0233] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0234] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.

[0235] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0236] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.

Claims

1. A query statement generation method, comprising: receiving a query request, wherein the query request comprises query information and a target database identifier; determining a database schema of a target database according to the target database identifier, wherein the database schema comprises database objects and association relationships between the database objects; constructing a query structure relationship graph according to the query information and the database schema, wherein the query structure relationship graph represents association relationships between the query information and the database schema; inputting the query information and the query structure relationship graph into a generation model to obtain a target query statement corresponding to the query information, wherein the generation model comprises an encoder and a decoder, the encoder is configured to perform fusion encoding on the query information and the query structure relationship graph, and the decoder is configured to decode the fusion encoding features to obtain the target query statement.

2. The method of claim 1, wherein determining the database schema of the target database according to the target database identifier comprises: finding a target database corresponding to the target database identifier; and analyzing a database structure of the target database to determine the database schema of the target database.

3. The method of claim 1, wherein constructing the query structure relationship graph according to the query information and the database schema comprises: extracting at least one keyword in the query information; and constructing the query structure relationship graph by taking the at least one keyword and the database objects in the database schema as nodes, and taking association relationships between the at least one keyword, association relationships between the database objects, and association relationships between the at least one keyword and the database objects as edges.

4. The method of claim 3, further comprising, after constructing the query structure relationship graph by taking the at least one keyword and the database objects in the database schema as nodes, and taking association relationships between the at least one keyword, association relationships between the database objects, and association relationships between the at least one keyword and the database objects as edges: adding a bridge node to the query structure relationship graph; and connecting a first node and a second node in the query structure relationship graph through the bridge node to obtain an updated query structure relationship graph, wherein the first node and the second node are two nodes in the query structure relationship graph that do not have edges.

5. The method of claim 1, the encoder comprising a graph processing layer and a plurality of encoding layers; The method of inputting the query information and the query structure relationship graph into the generation model to obtain the target query statement corresponding to the query information comprises: inputting the query structure relationship graph into a graph processing layer to obtain structure features corresponding to the query structure relationship graph; for any encoding layer, determining an output of the layer based on the structure features and query features output by a previous encoding layer, wherein an input of a first layer is the query information, and an output of a last layer is fusion encoding features; and inputting the fusion encoding features into the decoder to obtain the target query statement corresponding to the query information.

6. The method of claim 5, wherein the inputting the query structure graph into the graph processing layer to obtain the structure feature corresponding to the query structure graph comprises: inputting the query structure graph into the graph processing layer, and obtaining an initial structure feature, a key vector and a value vector through mapping processing of the graph processing layer; determining the structure feature corresponding to the query structure graph according to the initial structure feature, the key vector and the value vector.

7. The method of claim 5, wherein the determining the output of the current layer based on the structure feature and the query feature output by the previous encoding layer comprises: inputting the query information into a first layer of the plurality of encoding layers to obtain a query feature corresponding to the query information; merging the query feature and the structure feature to obtain an updated query feature, and inputting the updated query feature into a next encoding layer to obtain a query feature output by the next encoding layer, and returning to perform the merging the query feature and the structure feature to obtain the updated query feature until a fusion encoding feature is output by a last encoding layer.

8. The method of claim 1, wherein the training manner of the generation model comprises: obtaining a sample set, wherein the sample set comprises a plurality of sample query information, and the sample query information carries a query label; extracting a first sample query information from the sample set, wherein the first sample query information is any one in the sample set; inputting the first sample query information and a first sample structure graph corresponding to the first sample query information into an initial generation model to obtain a first predicted sentence corresponding to the first sample query information, wherein the initial generation model comprises an encoder and a decoder, the encoder is configured to perform fusion encoding on the first sample query information and the first sample structure graph, and the decoder is configured to decode a sample fusion feature to obtain the first predicted sentence; calculating a first loss value according to the first predicted sentence and a first query label carried by the first sample query information; adjusting model parameters of the initial generation model according to the first loss value, and returning to perform the extracting the first sample query information from the sample set until a preset stop condition is reached to obtain a generation model.

9. A data query method, comprising: receiving a query request input by a user through a front end, wherein the query request comprises query information and a target database identifier; determining a database schema of a target database according to the target database identifier, wherein the database schema comprises database objects and association relationships between the database objects; constructing a query structure graph according to the query information and the database schema, wherein the query structure graph represents association relationships between the query information and the database schema; input the query information and the query structure relationship diagram into a generation model to obtain a target query statement corresponding to the query information, wherein the generation model comprises an encoder and a decoder, the encoder is configured to perform fusion coding on the query information and the query structure relationship diagram, and the decoder is configured to decode the fusion coding features to obtain the target query statement; use the target query statement to search for a query result corresponding to the query information in a query database; send the query result to the front end to enable the front end to display the query result.

10. A generation model training method applied to a cloud-side device, the method comprising: obtaining a sample set, wherein the sample set comprises a plurality of sample query information, and the sample query information carries a query label; inputting the plurality of sample query information and sample structure relationship diagrams corresponding to the plurality of sample query information into an initial generation model to obtain a predicted statement corresponding to each sample query information, wherein the initial generation model comprises an encoder and a decoder, the encoder is configured to perform fusion coding on the sample query information and the sample structure relationship diagram, and the decoder is configured to decode sample fusion features to obtain the predicted statement; training the initial generation model according to the predicted statement and the query label to obtain model parameters of a trained generation model; sending the model parameters of the trained generation model to an end-side device.

11. The method of claim 10, before the inputting the plurality of sample query information and sample structure relationship diagrams corresponding to the plurality of sample query information into an initial generation model to obtain a predicted statement corresponding to each sample query information, further comprising: extracting at least one sample keyword in the sample query information for any sample query information; determining a sample database mode of a sample database corresponding to the sample query information; constructing a sample structure relationship diagram corresponding to the sample query information by taking the at least one sample keyword and a sample database object in the sample database mode as nodes, and taking an association relationship between the at least one sample keyword, an association relationship between the sample database objects, and an association relationship between the at least one sample keyword and the sample database object as edges.

12. A data query system, comprising a client and a server; the client is configured to send a query request to the server, wherein the query request comprises query information and a target database identifier; The server is configured to determine a database schema of the target database according to the target database identifier, wherein the database schema comprises database objects and association relationships between the database objects; construct a query structure relationship graph according to the query information and the database schema, wherein the query structure relationship graph represents an association relationship between the query information and the database schema; input the query information and the query structure relationship graph into a generation model to obtain a target query statement corresponding to the query information, wherein the generation model comprises an encoder and a decoder, the encoder is configured to perform fusion coding on the query information and the query structure relationship graph, and the decoder is configured to decode the fusion coding features to obtain the target query statement; and find a query result corresponding to the query information in a query database by using the target query statement, and send the query result to the client. The client is further configured to display the query result. 13.A computing device, comprising: a memory and a processor; the memory is configured to store computer executable instructions, and the processor is configured to execute the computer executable instructions, and the computer executable instructions, when executed by the processor, implement steps of the method in any one of claims 1 to 8 or claim 9 or any one of claims 10 to 11. 14.A computer readable storage medium storing computer executable instructions, and the computer executable instructions, when executed by a processor, implement steps of the method in any one of claims 1 to 8 or claim 9 or any one of claims 10 to 11.

Citation Information

Patent Citations

  • Table question and answer data processing and model training method, electronic equipment and storage medium

    CN115221299A

  • Voice interaction method, voice interaction device, electronic equipment and storage medium

    CN115497477A