Data query method and device based on large model and electronic equipment

Through the big model-based data query method, accurate SQL statements are generated using the target data table and semantic similarity query statements, which solves the problem of insufficient accuracy of data query and achieves more efficient answer generation.

CN119829602APending Publication Date: 2025-04-15BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411885617.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-19
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

In the prior art, the accuracy of data queries is insufficient, resulting in the generated answers being inaccurate enough.

Method used

Using a big model-based data query method, by obtaining the target data table and fields related to the user query statement, finding a second query statement with similar semantics and its corresponding SQL statements, using the big model to generate the target SQL statement, and performing data queries to obtain the answer.

Benefits of technology

Improves the accuracy of data queries, thereby improving the accuracy of generated answers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829602A_ABST
    Figure CN119829602A_ABST
Patent Text Reader

Abstract

The invention provides a data query method and device based on a large model and electronic equipment, relates to the technical field of artificial intelligence such as large models, model training and deep learning, and can be applied to interactive scenes based on artificial intelligence, such as application scenes such as generative search, intelligent assistants and data query. According to the specific implementation scheme, a target data table related to a first query statement is obtained, and a target field in the target data table is obtained; obtaining a second query statement similar to the first query statement in semantics and a structured query language (SQL) statement corresponding to the second query statement; by taking the second query statement and the corresponding SQL statement as examples, generating a target SQL statement corresponding to the first query statement based on the target data table and the target field through a large model; and performing data query based on the target SQL statement to obtain an answer to the first query statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the fields of artificial intelligence technologies such as big models, model training, and deep learning, and can be applied to interactive scenarios based on artificial intelligence, such as generative search, intelligent assistants, data query, and other application scenarios, and in particular to data query methods, devices, and electronic devices based on big models. Background Art

[0002] With the rapid development of big data and computer technology, users' demand for data is growing. The data query system in the related technology can query data according to the user's query and return the answer required by the user. However, how to improve the accuracy of data query and thus improve the accuracy of the generated answer is a problem that needs to be solved. Summary of the invention

[0003] The present invention provides a data query method, device and electronic device based on a large model.

[0004] According to a first aspect of the present disclosure, a data query method based on a big model is provided, including: obtaining a target data table related to a first query statement, and obtaining a target field in the target data table; obtaining a second query statement with similar semantics to the first query statement and a structured query language SQL statement corresponding to the second query statement; taking the second query statement and the corresponding SQL statement as examples, generating a target SQL statement corresponding to the first query statement based on the target data table and the target field through a big model; performing data query based on the target SQL statement to obtain an answer to the first query statement.

[0005] According to a second aspect of the present disclosure, a model training method is provided, including: obtaining a training sample set; using the training sample set to train an initial large model to obtain a target large model; wherein the target large model is used to take a second query statement and a corresponding SQL statement as examples, and based on a target data table and a target field in the target data table, generate a target SQL statement corresponding to a first query statement; wherein the second query statement has similar semantics to the first query statement, and the target data table is related to the first query statement.

[0006] According to a third aspect of the present disclosure, a data query device based on a big model is provided, including: a first acquisition module, used to acquire a target data table related to a first query statement, and acquire a target field in the target data table; a second acquisition module, used to acquire a second query statement with similar semantics to the first query statement and a structured query language SQL statement corresponding to the second query statement; a first generation module, used to take the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field through a big model; a processing module, used to perform data query based on the target SQL statement to obtain an answer to the first query statement.

[0007] According to a fourth aspect of the present disclosure, a model training device is provided, comprising: a fourth acquisition module, used to acquire a training sample set; a training module, used to train an initial large model using the training sample set to obtain a target large model; wherein the target large model is used to take a second query statement and a corresponding SQL statement as an example, and based on a target data table and a target field in the target data table, generate a target SQL statement corresponding to the first query statement; wherein the second query statement has similar semantics to the first query statement, and the target data table is related to the first query statement.

[0008] According to a fifth aspect of the present disclosure, there is provided an electronic device, including:

[0009] at least one processor; and

[0010] a memory communicatively connected to the at least one processor; wherein,

[0011] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data query method based on the large model as described in the first aspect, or execute the model training method as described in the second aspect.

[0012] According to the sixth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the large model-based data query method as described in the first aspect, or to execute the model training method as described in the second aspect.

[0013] According to a seventh aspect of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by a processor, implement the large model-based data query method as described in the first aspect, or implement the model training method as described in the second aspect.

[0014] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0016] Figure 1 It is a flowchart of a data query method based on a large model provided according to an embodiment of the present disclosure;

[0017] Figure 2 is a flowchart of a data query method based on a large model provided according to another embodiment of the present disclosure;

[0018] Figure 3 is a flowchart of a data query method based on a large model provided according to another embodiment of the present disclosure;

[0019] Figure 4 is a flowchart of a model training method provided according to an embodiment of the present disclosure;

[0020] Figure 5 is a structural diagram of a data query device based on a large model provided according to an embodiment of the present disclosure;

[0021] Figure 6 is a structural schematic diagram of a model training device provided according to an embodiment of the present disclosure;

[0022] Figure 7 It is a block diagram of an electronic device used to implement the large model-based data query method or model training method of the embodiment of the present disclosure. DETAILED DESCRIPTION

[0023] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0024] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, comply with the relevant laws and regulations, and do not violate public order and good morals.

[0025] With the rapid development of big data and computer technology, users' demand for data is growing. The data query system in the related technology can query data according to the user's query and return the answer the user needs. However, how to improve the accuracy of data query and thus improve the accuracy of the generated answer is a problem that needs to be solved.

[0026] In order to improve the accuracy of data query and thus improve the accuracy of generated answers, the embodiments of the present disclosure propose a data query method, model training method, device and electronic device based on a large model.

[0027] In order to facilitate understanding of the embodiments of the present disclosure, some technical terms in the embodiments of the present disclosure are first briefly explained.

[0028] The prompt word, i.e., the query, is encapsulated as an instruction for interacting with the big model. After the prompt word is input into the big model, the response (reply or answer) output by the big model can be obtained. After further processing, the response can be presented to the user as the final result.

[0029] The prompt word template is a template used to generate prompt words. The content can be preset as needed. For example, it can be set to include indication information for the large model, as well as positions to be filled or information to be replaced. By using the specified information to fill in the positions to be filled or replace the information to be replaced, the corresponding prompt words can be obtained.

[0030] The following describes a large model-based data query method, model training method, device and electronic device according to an embodiment of the present disclosure with reference to the accompanying drawings.

[0031] It should be noted that the execution subject of the data query method based on the big model in this embodiment is a data query device based on the big model. In the following embodiments, the data query device based on the big model is referred to as a data query device. The data query device can be implemented by software and / or hardware, and can be configured in an electronic device, which can include but is not limited to a terminal, a server, etc.

[0032] For example, the data query device may be a data query system configured in a large screen or a server of the large screen. The data query system is any system having a data query function. For example, when a chat system has a data query function, the chat system can be regarded as a data query system. The chat system may be, for example, a digital human system or other systems.

[0033] Figure 1 It is a flowchart of a data query method based on a large model provided according to an embodiment of the present disclosure.

[0034] like Figure 1 As shown, the data query method based on the large model includes:

[0035] Step 101: obtain a target data table related to a first query statement, and obtain a target field in the target data table.

[0036] The first query statement may be input by the user in the form of voice or text.

[0037] The target data table is related to the first query statement and is used to generate an answer to the first query statement. The number of the target data table may be one or more, and the present disclosure does not limit this.

[0038] The target field is a field in the target data table, and the field may be related to the first query statement. The number of the target fields may be one or more, and the present disclosure does not limit this.

[0039] In some embodiments, the first query statement can be obtained in the following ways: obtaining a sound signal input by the user through a voice acquisition device such as a pickup or microphone; converting the sound signal into an electrical signal; converting the electrical signal into a computer signal through an analog-to-digital converter; converting the computer signal into a text signal through ASR (Automatic Speech Recognition) technology, and obtaining the first query statement through the text signal.

[0040] In some embodiments, a target data table related to the first query statement may be first obtained from multiple data tables in a database, and then a target field may be obtained from the target data table.

[0041] Step 102: Obtain a second query statement having semantics similar to the first query statement and a structured query language SQL statement corresponding to the second query statement.

[0042] The second query statement may be obtained from a pre-saved query statement. The number of the second query statement may be one or more, which is not limited in the present disclosure.

[0043] The SQL statement corresponding to the second query statement is a pre-saved SQL statement corresponding to the second query statement.

[0044] In some embodiments, a data analysis library may be pre-built, wherein the data analysis library includes multiple query statements and SQL statements corresponding to each query statement. For the sake of distinction, the query statement may be referred to as a candidate query statement. Thus, the data query device may obtain a second query statement having semantic similarity to the first query statement from the multiple candidate query statements in the data analysis library, and obtain the SQL statement corresponding to the second query statement based on the correspondence between the second query statement and the corresponding SQL statement.

[0045] Step 103, taking the second query statement and the corresponding SQL statement as examples, a target SQL statement corresponding to the first query statement is generated based on the target data table and the target field through the large model.

[0046] Among them, the big model is a large neural network model trained using deep learning algorithms, designed to understand and generate natural language text. The big model is trained with a large amount of text data, and is able to capture the complexity and nuances of language, so as to perform various natural language processing tasks, such as text generation, code generation, question-answering systems, semantic understanding and reasoning, etc. This model is designed to improve the model's expressiveness and predictive performance, and can handle more complex tasks and data, showing human-like intelligence.

[0047] The large model in the disclosed embodiments may be the following large models, such as LLM (Large Language Model), GPT3 (Generative Pre-trained Transformer), GPT4, T5 (Text-to-Text Transfer Transformer), LLaMA (LargeLanguage Model Meta AI), LLaMA2, etc.

[0048] It can be understood that, since the target SQL statement is generated by the large model using the second query statement and the corresponding SQL statement as examples, the structure of the target SQL statement and the structure of the SQL statement corresponding to the second query statement may be the same.

[0049] Step 104: perform data query based on the target SQL statement to obtain an answer to the first query statement.

[0050] In some embodiments, a data query may be performed in a database based on a target SQL statement to obtain target data, and then an answer to the first query statement may be generated based on the target data.

[0051] The data query method based on the big model provided by the embodiment of the present disclosure obtains the target data table related to the first query statement, and obtains the target field in the target data table; obtains the second query statement with similar semantics to the first query statement and the structured query language SQL statement corresponding to the second query statement; takes the second query statement and the corresponding SQL statement as an example, and generates the target SQL statement corresponding to the first query statement based on the target data table and the target field through the big model; performs data query based on the target SQL statement to obtain the answer to the first query statement. Thus, the first query statement can be converted into the target SQL statement through the big model, and when the big model generates the target SQL statement, it can refer to the second query statement and the corresponding SQL statement as well as the target data table and the target field in the target data table related to the first query statement, thereby improving the accuracy of the generated target SQL, and then performing data query based on the target SQL statement can improve the accuracy of the data query, and then improve the accuracy of the generated answer.

[0052] In order to clearly explain the process of obtaining the target data table and the target field and the process of obtaining the second query statement and the corresponding SQL statement, the embodiment of the present disclosure also provides a data query method based on a large model.

[0053] Figure 2 It is a flowchart of a data query method based on a large model provided according to another embodiment of the present disclosure.

[0054] like Figure 2 As shown, the data query method based on the large model includes:

[0055] Step 201, obtain a knowledge graph generated based on multiple data tables.

[0056] Among them, the knowledge graph includes multiple table nodes, multiple field nodes and multiple edges, wherein the table node represents a data table, the field node represents a field, and the edge includes a first edge and a second edge, wherein the first edge connects any table node and any field node in the knowledge graph, and the first edge represents the belonging relationship between the data table corresponding to the connected table node and the field corresponding to the connected field node, and the second edge connects any two table nodes in the knowledge graph, and the second edge represents the association relationship between the data tables corresponding to the two connected table nodes.

[0057] The multiple data tables may include all data tables or part of the data tables in the database, which is not limited in the present disclosure.

[0058] Knowledge graph is a graph structure constructed by entities and relationships, which can represent knowledge in the real world in a graph. Knowledge graph consists of nodes and edges, where each node represents an entity and the edge represents the relationship between different entities.

[0059] In some embodiments, a knowledge graph may be generated in advance based on multiple data tables, and the generated knowledge graph may be saved, so that a data query device may directly obtain the pre-generated knowledge graph.

[0060] In the knowledge graph generated based on multiple data tables, a table node represents a data table, and a field node represents a field. In addition, the attribute information of the data table, such as the name and description of the data table, can be used as the attribute information of the corresponding table node, and the attribute information of the field, such as the type information of integer or string, can be used as the attribute information of the corresponding field node to enhance the semantic information of the knowledge graph.

[0061] In a knowledge graph generated based on multiple data tables, edges may include edges between different table nodes and edges between table nodes and field nodes. For ease of distinction, in the disclosed embodiment, the edge between a table node and a field node is referred to as a first edge, and the edge between different table nodes is referred to as a second edge.

[0062] Among them, when a certain field is included in a certain data table, that is, when a certain field belongs to a certain data table, there is an ownership relationship between the data table and the field. Correspondingly, in the knowledge graph generated based on multiple data tables, there is a first edge between the field node representing the field and the table node representing the data table. Among them, the field node can also be called a child node of the table node. When there is an association relationship between a certain data table and another data table, in the knowledge graph generated based on multiple data tables, there is a second edge between the table nodes representing the two data tables.

[0063] The association relationship may include foreign key relationship, index relationship, etc. When a field in a data table is a foreign key of another data table, the two data tables are said to have a foreign key relationship. When a field in a data table and a field in another data table represent the same meaning, the two data tables are said to have an index relationship.

[0064] In some embodiments, a knowledge graph can be generated based on multiple data tables based on a certain large model. For example, some data tables and fields in multiple data tables can be obtained first, and the relationship between the obtained data tables and the relationship between the data tables and the fields can be manually annotated. Then, the annotated data tables and fields are used as examples, and merged with the pre-built prompt word template for generating knowledge graphs to obtain corresponding prompt words, wherein the prompt words are used to indicate that the large model refers to the above examples, based on the pre-set knowledge graph generation rules, to generate the knowledge graphs corresponding to the above multiple data tables, so as to input the prompt words into the large model, and the large model can refer to the examples according to the knowledge graph generation rules, identify the relationship between the data tables in multiple data tables and the relationship between the data tables and the fields, and then obtain the knowledge graph. Among them, the knowledge graph generation rules, for example, can include nodes in the knowledge graph to represent data tables or fields, edges to represent the belonging relationship between data tables and fields or the association relationship between different data tables, etc. Among them, the large model can be the same large model as the large model used in the embodiment of the present disclosure to generate the target SQL statement, or it can be a different large model, and the present disclosure does not limit this.

[0065] Step 202, based on the knowledge graph, obtain the target data table and target field.

[0066] After obtaining the knowledge graph generated based on multiple data tables, the target data table and the target field in the target data table related to the first query statement can be obtained by querying the knowledge graph.

[0067] In some embodiments, step 202 may be implemented by:

[0068] Identifying an entity in a first query statement and determining a first entity type of the entity;

[0069] Determine a first node from the knowledge graph according to the first entity type, wherein the second entity type corresponding to the first node matches the first entity type;

[0070] From the knowledge graph, determine a second node connected to the first node through the first edge or the second edge;

[0071] The data table represented by the table node in the first node and the second node is used as the target data table, and the field represented by the field node in the first node and the second node is used as the target field.

[0072] In some embodiments, a pre-trained information extraction model may be used to identify entities in the first query statement.

[0073] Entities are used to represent specific objects or abstract concepts in the real world, such as events, time, location, time dimension (such as day, month, week, etc.), city, query index, etc. The number of entities in the first query statement may be one or more.

[0074] Different entities may correspond to different entity types. The entity type is used to classify entities with similar characteristics into one category. For ease of distinction, in the embodiment of the present disclosure, the entity type of the entity in the first query statement is referred to as the first entity type.

[0075] Among them, the first entity type can be determined in the following way: pre-set entity characteristics corresponding to different entity types, for each entity in the first query statement, query the entity type whose corresponding entity characteristics match the characteristics of the entity from multiple pre-set entity types, and use the matching entity type as the first entity type of the entity.

[0076] In some embodiments, each node in the knowledge graph may have a corresponding entity type. For the sake of distinction, the entity type is referred to as the second entity type. Among them, the second entity type can be the type of object described by the data table or field corresponding to the node in the knowledge graph, which can be determined according to the semantics and / or business logic in the data table or field. For example, assuming that a table node in the knowledge graph represents a user table, which contains the attribute information of the user, that is, the object described by the data table is a user, and the type of the user is a "user" type, then the entity type corresponding to the table node can be a "user" type. Assuming that a table node in the knowledge graph represents an order table, which contains information about orders, that is, the object described by the data table is an order, and the type of the order is an "order" type, then the entity type corresponding to the table node can be an "order" type. Assuming that a field node in the knowledge graph represents the "traffic accident" field, where the object described by the field is a traffic accident, and the type of the traffic accident is a "traffic accident" type, then the entity type corresponding to the field node can be a "traffic accident" type.

[0077] For each entity in the first query statement, by matching the first entity type of the entity with the second entity type corresponding to each node in the knowledge graph, the first node where the entity is located can be determined from the knowledge graph, wherein the second entity type corresponding to the first node matches the first entity type. Furthermore, the second node can be determined from the knowledge graph through the first edge or the second edge connected to the first node, wherein the second node is connected to the first node through the first edge or the second edge. Furthermore, the data table represented by the table node in the first node and the second node can be used as the target data table, and the field represented by the field node in the first node and the second node can be used as the target field.

[0078] For each entity in the first query statement, the number of first nodes where the entity is located in the knowledge graph may be one or more. The first node where each entity is located in the knowledge graph may be a table node representing a data table or a field node representing a field. The number of second nodes connected to the same first node may be one or more.

[0079] In some embodiments, for any first node, when the first node is a table node, the field node connected to the first node through a first edge and the table node connected to the first node through a second edge in the knowledge graph can be determined as the second node connected to the first node; when the first node is a field node, the table node connected to the first node through the first edge in the knowledge graph can be determined as the second node.

[0080] For example, assuming that data table A includes the fields "traffic accidents" and "number of motor vehicles", and data table B also includes the field "traffic accidents", the knowledge graph may include table node 1 corresponding to data table A and table node 2 corresponding to data table B, wherein table node 1 and table node 2 may be connected via a second edge, table node 1 may be connected to field node 1 corresponding to the "traffic accidents" field via a first edge, and table node 1 may be connected to field node 2 corresponding to the "number of motor vehicles" field via a first edge, and table node 2 may be connected to field node 3 corresponding to the "traffic accidents" field via a first edge, wherein field node 1 and field node 3 may be different field nodes.

[0081] When the first query statement is "query the number of traffic accidents in the past year", for the entity "traffic accident", the first node where the entity is located can be determined in the knowledge graph to include field node 1 and field node 3, and table node 1 connected to field node 1 and table node 2 connected to field node 3 are determined as second nodes. Furthermore, data table A and data table B can be used as target data tables, and the field "traffic accident" can be determined as the target field in data table A and data table B.

[0082] Assuming that the first node where a certain entity in a first query statement is located in the knowledge graph is the above table node 1, the table node 2, field node 1, and field node 2 connected to the table node 1 can be determined as the second node. Furthermore, data table A and data table B can be used as target data tables, and the field "traffic accidents" and the field "number of motor vehicles" can be used as target fields in data table A.

[0083] Thus, only by querying the knowledge graph based on the entity in the first query statement, the target data table and the target field in the target data table related to the first query statement can be quickly obtained according to the data table represented by the table node in the knowledge graph, the field represented by the field node, the first edge between the table node and the field node, and the second edge between the two table nodes. And by determining the field node connected to the first node through the first edge and the table node connected to the first node through the second edge in the knowledge graph as the second node when the first node is a table node, and determining the table node connected to the first node through the first edge in the knowledge graph as the second node when the first node is a field node, it can be achieved that when the first node represents a data table or field, the second node associated with the first node can be accurately determined, and then based on the data table or field represented by the first node and the second node, respectively, the target data table and target field can be accurately determined.

[0084] Step 203: Obtain semantic similarities between the plurality of candidate query statements and the first query statement.

[0085] The candidate query statements are pre-saved query statements. In addition, the SQL statements corresponding to each candidate query statement may also be pre-saved.

[0086] In some embodiments, a data analysis library may be pre-built, wherein the data analysis library includes a plurality of candidate query statements and a SQL statement corresponding to each candidate query statement.

[0087] In some embodiments, step 203 may be implemented by:

[0088] For any candidate query statement among the multiple candidate query statements, obtaining a first feature vector of the candidate query statement, wherein the first feature vector represents a semantic feature of the corresponding candidate query statement;

[0089] Obtaining a second feature vector of the first query statement, wherein the second feature vector represents a semantic feature of the first query statement;

[0090] The similarity between the first feature vector and the second feature vector is determined, and the similarity is determined as the semantic similarity between the candidate query statement and the first query statement.

[0091] The similarity between the first feature vector and the second feature vector may be cosine similarity or other similarities, which is not limited in the present disclosure.

[0092] The first feature vector and the second feature vector can be obtained by a pre-trained text vectorization model. The text vectorization model can encode a text, such as a sentence or a paragraph, into a feature vector, which can represent the semantic features of the text.

[0093] For any candidate query statement among the multiple candidate query statements, by determining the semantic similarity between the candidate query statement and the first query statement based on the similarity between the first feature vector of the candidate query statement and the second feature vector of the first query statement, the accuracy of the determined semantic similarity can be improved.

[0094] Step 204 : Determine, as a target query statement, a candidate query statement among the plurality of candidate query statements whose semantic similarity with the first query statement is higher than a set threshold.

[0095] The threshold value may be set as required.

[0096] The number of target query statements may be one or more, which is not limited in the present disclosure.

[0097] In some embodiments, after determining the semantic similarity between each candidate query statement in the plurality of candidate query statements and the first query statement, the candidate query statements may be sorted in descending order of semantic similarity, and the top N candidate query statements are used as target query statements, where N is an integer greater than or equal to 1.

[0098] Step 205: Use the target query statement as the second query statement, and use the SQL statement corresponding to the target query statement as the SQL statement corresponding to the second query statement.

[0099] In this way, a second query statement having semantics similar to the first query statement and an SQL statement corresponding to the second query statement may be obtained.

[0100] Step 206, taking the second query statement and the corresponding SQL statement as examples, a target SQL statement corresponding to the first query statement is generated based on the target data table and the target field through the large model.

[0101] In some embodiments, step 206 may be implemented by:

[0102] Generate a prompt word based on the target data table, the target field, the second query statement and the corresponding SQL statement; wherein the prompt word is used to instruct the large model to use the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field;

[0103] Input the prompt word into the big model to get the target SQL statement.

[0104] Among them, the target data table, the target field, the second query statement and the corresponding SQL statement, and the first query statement can be filled into a preset prompt word template for generating SQL statements to obtain prompt words; or, the target data table, the target field, the second query statement and the corresponding SQL statement, and the first query statement can be used to replace the corresponding information to be replaced in the preset prompt word template for generating SQL statements to obtain prompt words; or, the prompt words can be obtained in other ways, which are not limited in the present disclosure.

[0105] For example, the preset prompt word template for generating SQL statements can be as follows:

[0106] Assuming you are a SQL master, I will enter a natural language query. Please fully read and understand the Schema of the following PostgreSQL (relational database management system) table and write an SQL statement that meets the query intent.

[0107] [Target data table and target fields]

[0108] Notice:

[0109] 1. Pay attention to the compatibility of generating PostgreSQL statements. The current time is 2024-12-10

[0110] 2. Use double quotes " or backticks ` for field names, and use single quotes to limit the query value. The output must conform to the syntax of the Gaussian database. If there are uppercase letters in the field name, then the field name needs to be enclosed in backticks, and the alias also needs to be enclosed in backticks.

[0111] 3.ObstructionReason (blocking reason), RouteName (route name or path name), etc. may be empty. You need to first determine whether they are empty

[0112] 4. EventOccurTime (event occurrence time) is a string and should be converted to a timestamp before use. CongestionDistance (congestion distance) is a string and should be converted to a floating point number before use. The congestion distance is enclosed in brackets with the unit of "kilometers"

[0113] 5. Output only SQL statements

[0114] [The second query statement and the corresponding SQL statement]

[0115] Please answer the following question, `[input query]`

[0116] Then, the acquired target data table and target field can be used to replace the content in the first square bracket of the prompt word template, the second query statement and the corresponding SQL statement can be used to replace the content in the second square bracket of the prompt word template, and the first query statement can be used to replace the content in the third square bracket of the prompt word template to obtain the prompt word.

[0117] Therefore, prompt words are generated based on the target data table, the target field, the second query statement and the corresponding SQL statement, wherein the prompt words are used to instruct the big model to take the second query statement and the corresponding SQL statement as examples, and generate the target SQL statement corresponding to the first query statement based on the target data table and the target field. The prompt words are input into the big model to obtain the target SQL statement. This can guide the big model to understand the task requirements more accurately through the prompt words, thereby taking the second query statement and the corresponding SQL statement as examples, and accurately generating the target SQL statement corresponding to the first query statement based on the target data table and the target field.

[0118] In addition, it is understandable that the number of data tables in the database is very large, and when a large model is used to process a task, the information required by the large model to process the task needs to be input into the large model. Since the information input into the large model is limited in character length, it may not be possible to input all the data tables in the database into the large model, and only some of the data tables are input into the large model, which will affect the accuracy of the target SQL statement output by the large model. In the disclosed embodiment, by first obtaining the target data table related to the first query statement, and obtaining the target field in the target data table, and then generating a prompt word based on the target data table, the target field, the second query statement and the corresponding SQL statement, and inputting the prompt word into the large model, not only can the character length of the prompt word be reduced, but also the large model can be directly based on the target data table related to the first query statement and the target field in the target data table, accurately generate the target SQL statement of the first query statement.

[0119] Step 207: perform data query based on the target SQL statement to obtain an answer to the first query statement.

[0120] In some embodiments, step 207 may be implemented by:

[0121] By executing the target SQL statement, the target data is queried; a chart is generated based on the target data, and an initial answer to the first query statement is generated based on the target data through the big model; and an answer to the first query statement is obtained based on the chart and the initial answer. The big model and the big model used in step 206 can be the same big model.

[0122] It is understandable that by executing the target SQL statement, the target data matching the first query statement can be queried from the database. Then, a chart can be generated based on the target data, and the target data can be analyzed through the large model to generate an initial answer to the first query statement. By integrating the chart and the initial answer, the final answer to the first query statement can be obtained.

[0123] In some embodiments, the process of generating a chart based on target data may include: determining the chart type of the chart to be generated according to the data structure of the target data and the user requirements reflected by the first query statement, and generating a chart of the chart type based on the target data. The chart type may include a line chart, a pie chart, a column chart, etc.

[0124] For example, when the first query statement is "query the order volume change trend in the past three months" and the target data includes the order volume of each month in the past three months, it can be determined that the chart type of the chart to be generated is a line chart, and then a line chart type chart can be generated based on the order volume data of each month in the past three months.

[0125] In some embodiments, the process of generating an initial answer to the first query statement based on the target data by using the big model may include:

[0126] Generate corresponding prompt words based on the target data, wherein the prompt words are used to instruct the large model to generate an initial answer to the first query statement based on the target data; input the prompt words into the large model to obtain the initial answer to the first query statement.

[0127] Among them, the target data and the first query statement can be filled into a preset prompt word template for generating an answer to obtain a prompt word; or, the target data and the first query statement can be used to replace the corresponding information to be replaced in the preset prompt word template for generating an answer to obtain a prompt word; or, the prompt word can be obtained in other ways, which is not limited in the present disclosure.

[0128] Therefore, by executing the target SQL statement, the target data is queried, a chart is generated based on the target data, and through the large model, the initial answer to the first query statement is generated based on the target data. Based on the chart and the initial answer, the answer to the first query statement is obtained. The answer required by the user can be generated, and the answer is in various forms. The chart can intuitively display the target data and help users quickly understand the target data.

[0129] The data query method based on a large model provided by the embodiment of the present disclosure obtains a knowledge graph generated based on multiple data tables, and obtains a target data table and a target field based on the knowledge graph. It can be realized that only by querying the knowledge graph, the target data table and the target field in the target data table related to the first query statement can be quickly and accurately obtained according to the data table represented by the table node in the knowledge graph, the field represented by the field node, the first edge between the table node and the field node, and the second edge between the two table nodes. In addition, when it is necessary to add new data tables and fields, it is only necessary to add corresponding nodes and edges in the knowledge graph, which is simple and convenient. By obtaining the semantic similarity between multiple candidate query statements and the first query statement, the candidate query statements with a semantic similarity higher than a set threshold between the multiple candidate query statements and the first query statement are determined as target query statements, the target query statement is used as the second query statement, and the SQL statement corresponding to the target query statement is used as the SQL statement corresponding to the second query statement, so that the second query statement and the corresponding SQL statement with semantic similarity to the first query statement can be accurately determined. By taking the second query statement and the corresponding SQL statement as examples, and generating a target SQL statement corresponding to the first query statement based on the target data table and the target field through the big model, the accuracy of the generated target SQL can be provided, and then data query can be performed based on the target SQL statement, which can improve the accuracy of the data query and thus improve the accuracy of the generated answer.

[0130] Combine the following Figure 3 , further illustrating the big model-based data query method provided in the embodiment of the present disclosure.

[0131] Figure 3 It is a flowchart of a data query method based on a large model provided according to another embodiment of the present disclosure.

[0132] like Figure 3 As shown, the data query method based on the large model includes:

[0133] Step 301: Obtain a target SQL generation template that matches a first query statement from multiple SQL generation templates.

[0134] The SQL generation template is a pre-built template for generating SQL statements.

[0135] In some embodiments, a SQL generation template library may be pre-built, including a plurality of SQL generation templates.

[0136] In some embodiments, step 301 may be implemented in the following manner:

[0137] Extracting information from the first query statement to obtain a first key element in the first query statement;

[0138] Matching the first key element with second key elements corresponding to the plurality of SQL generation templates;

[0139] The SQL generation template corresponding to the second key element matching the first key element is used as the target SQL generation template.

[0140] In some embodiments, a pre-trained information extraction model may be used to extract information from the first query statement to obtain key elements in the first query statement. For ease of distinction, the key elements in the first query statement may be referred to as first key elements. The first key element may be time, time dimension, event, location, city, query index, etc. The number of first key elements may be one or more, and the present disclosure does not limit this.

[0141] In some embodiments, the correspondence between multiple SQL generation templates and the second key element can be saved in advance. The number of second key elements corresponding to each SQL generation template can be one or more, and the present disclosure does not limit this. Then, the first key element can be matched with the second key element corresponding to each SQL generation template to obtain the second key element matching the first key element, and the SQL generation template corresponding to the second key element matching the first key element is used as the target SQL generation template.

[0142] Therefore, by extracting information from the first query statement, the first key element in the first query statement is obtained, the first key element is matched with the second key elements corresponding to multiple SQL generation templates, and the SQL generation template corresponding to the second key element that matches the first key element is used as the target SQL generation template, so that the target SQL generation template that matches the first query statement can be accurately obtained.

[0143] Step 302: When a target SQL generation template is obtained, a target SQL statement corresponding to the first query statement is generated based on the target SQL generation template.

[0144] In some embodiments, when the target SQL generation template is obtained, the first key element in the first query statement can be obtained, and the first key element can be merged with the target SQL generation template to obtain the target SQL statement.

[0145] Step 303: if the target SQL generation template is not obtained, obtain the target data table related to the first query statement, and obtain the target field in the target data table.

[0146] Step 304: Obtain a second query statement having semantics similar to the first query statement and a structured query language SQL statement corresponding to the second query statement.

[0147] Step 305: Taking the second query statement and the corresponding SQL statement as examples, a target SQL statement corresponding to the first query statement is generated based on the target data table and the target field through the large model.

[0148] The specific implementation process and principle of steps 303-305 may refer to the description of other embodiments and will not be repeated here.

[0149] Step 306: perform data query based on the target SQL statement to obtain an answer to the first query statement.

[0150] The data query method based on a big model provided by the embodiment of the present disclosure can improve the efficiency of generating the target SQL statement by acquiring a target SQL generation template matching the first query statement from multiple SQL generation templates, and generating the target SQL statement corresponding to the first query statement based on the target SQL generation template when the target SQL generation template is acquired, and by acquiring the target data table related to the first query statement and the target field in the target data table when the target SQL generation template is not acquired, and acquiring the second query statement with similar semantics to the first query statement and the structured query language SQL statement corresponding to the second query statement, and taking the second query statement and the corresponding SQL statement as examples, and generating the target SQL statement corresponding to the first query statement based on the target data table and the target field through the big model, so that the big model can refer to the second query statement and the corresponding SQL statement and the target data table and the target field in the target data table related to the first query statement when generating the target SQL statement, thereby improving the accuracy of the generated target SQL. Therefore, the efficiency and accuracy of generating the target SQL statement can be improved as a whole, and then data query can be performed based on the target SQL statement, which can improve the efficiency and accuracy of data query, and then improve the efficiency of answer generation and the accuracy of the generated answer.

[0151] With respect to the large model adopted in the above-mentioned embodiments, the present disclosure also provides a model training method.

[0152] It should be noted that the executor of the model training method of this embodiment is a model training device. The model training device can be implemented by software and / or hardware and can be configured in an electronic device. The electronic device may include but is not limited to a terminal, a server, etc.

[0153] Figure 4 It is a flowchart of a model training method provided according to an embodiment of the present disclosure.

[0154] like Figure 4 As shown, the model training method includes:

[0155] Step 401: Obtain a training sample set.

[0156] Step 402, use the training sample set to train the initial large model to obtain the target large model, wherein the target large model is used to take the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field in the target data table; wherein the second query statement is similar in semantics to the first query statement, and the target data table is related to the first query statement.

[0157] In some embodiments, the training sample set may include a first training sample, wherein the first training sample includes:

[0158] The first sample prompt word is used to instruct the initial large model to use the first sample query statement and the corresponding SQL statement as examples, and to generate a predicted SQL statement corresponding to the second sample query statement based on the sample data table and the sample fields in the sample data table; wherein the first sample query statement and the second sample query statement have similar semantics, and the sample data table is related to the second sample query statement;

[0159] The expected SQL statement corresponding to the second sample query statement.

[0160] The initial large model is a large model to be trained. The initial large model can be the following large models, such as LLM, GPT3, GPT4, T5, LLaMA, LLaMA2, etc.

[0161] The target big model is a big model obtained by training the initial big model, and can be applied to the big model-based data query method in the above embodiments of the present disclosure.

[0162] The second sample query statement is a query statement to be converted into a prediction SQL statement.

[0163] The sample data table is related to the second sample query statement and is used to generate an answer to the second sample query statement. The number of the sample data table may be one or more, and the present disclosure does not limit this.

[0164] The sample field is a field in the sample data table, and the field may be related to the second sample query statement. The number of the sample field may be one or more, and the present disclosure does not limit this.

[0165] The method for obtaining the sample data table and the sample fields in the sample data table may refer to the method for obtaining the target data table and the target fields in the target data table in the above embodiment, and will not be described in detail here.

[0166] The first sample query statement has similar semantics to the second sample query statement. The number of the first sample query statements may be one or more, and the present disclosure does not limit this.

[0167] Among them, the method for obtaining the first sample query statement and the corresponding SQL statement can refer to the method for obtaining the second query statement and the corresponding SQL statement in the above embodiment, which will not be repeated here.

[0168] The expected SQL statement corresponding to the second sample query statement is the SQL statement corresponding to the second sample query statement generated by the expected large model.

[0169] Therefore, by using the first training sample to train the initial large model to obtain the target large model, the target large model can be used to use the second query statement and the corresponding SQL statement as examples to generate a target SQL statement corresponding to the first query statement based on the target data table and the target field in the target data table.

[0170] In some embodiments, the training sample set further includes a second training sample, and the target large model is further used to generate an initial answer to the first query statement based on target data, and the target data is obtained by executing a target SQL statement; wherein the second training sample includes:

[0171] The second sample prompt word is used to instruct the initial large model to generate a predicted answer corresponding to the second sample query statement based on the sample data, and the sample data is obtained by executing the expected SQL statement;

[0172] The expected answer corresponding to the second sample query statement.

[0173] The expected answer corresponding to the second sample query statement is the answer to the second sample query statement generated by the expected large model.

[0174] Therefore, by using a training sample set including a first training sample and a second training sample, the first training sample and the second training sample are used to train the initial large model, so that the target large model can be used to use the second query statement and the corresponding SQL statement as examples to generate a target SQL statement corresponding to the first query statement based on a target data table and a target field in the target data table, and can also be used to generate an initial answer to the first query statement based on the target data, and the target data is obtained by executing the target SQL statement.

[0175] In some embodiments, the number of the first training samples may be multiple, and the number of the second training samples may be multiple.

[0176] It should be noted that the above method of using the first training sample and the second training sample in the training sample set to train the initial large model and finally obtain the target large model can be set as needed. For example, the Lora (Low-Rank Adaptation) and DPO (Direct Preference Optimization) methods in related technologies can be used to train the initial large model.

[0177] In some embodiments, the initial large model can be iteratively trained based on the first training sample and the second training sample, that is, each iteration uses one training sample to optimize the large model to be trained, so that the optimized large model can perform the task corresponding to this type of training sample, and in the next iteration, another training sample is used to continue to improve the model performance. After multiple iterations, the model is gradually optimized so that the final large model can perform multiple tasks.

[0178] In some embodiments, the first training sample and the second training sample can also be mixed to train the initial large model together, and the optimized target large model can be obtained by fine-tuning the model parameters, wherein the target large model can be used to process tasks corresponding to various training samples. After the training is completed, the performance of the target large model can be evaluated. If it does not meet expectations, the target model can continue to be trained, and the model capabilities can be continuously improved after multiple rounds of training. The target large model finally obtained can be applied to the large model-based data query method in the above embodiment.

[0179] It should be noted that the steps or implementation processes in the embodiment of the present disclosure that are similar to those in other embodiments will not be repeated here.

[0180] The model training method provided by the embodiment of the present disclosure uses a training sample set to train an initial large model to obtain a target large model, so that the target large model can be used to use the second query statement and the corresponding SQL statement as examples, and based on the target data table and the target field in the target data table, accurately generate a target SQL statement corresponding to the first query statement.

[0181] In order to implement the above embodiments, the present disclosure also provides a data query device based on a large model.

[0182] Figure 5 It is a structural diagram of a data query device based on a large model provided according to an embodiment of the present disclosure.

[0183] like Figure 5 As shown, the data query device 500 based on the large model includes:

[0184] A first acquisition module 501 is used to acquire a target data table related to a first query statement, and acquire a target field in the target data table;

[0185] A second acquisition module 502 is used to acquire a second query statement having similar semantics to the first query statement and a structured query language SQL statement corresponding to the second query statement;

[0186] The first generating module 503 is used to use the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field through the big model;

[0187] The processing module 504 is used to perform data query based on the target SQL statement to obtain an answer to the first query statement.

[0188] As a possible implementation of the embodiment of the present disclosure, the first acquisition module 501 includes:

[0189] A first acquisition unit is used to acquire a knowledge graph generated based on multiple data tables; wherein the knowledge graph includes multiple table nodes, multiple field nodes and multiple edges, wherein the table node represents a data table, the field node represents a field, and the edge includes a first edge and a second edge, wherein the first edge connects any table node and any field node in the knowledge graph, and the first edge represents the belonging relationship between the data table corresponding to the connected table node and the field corresponding to the connected field node, and the second edge connects any two table nodes in the knowledge graph, and the second edge represents the association relationship between the data tables corresponding to the two connected table nodes;

[0190] The second acquisition unit is used to acquire the target data table and target field based on the knowledge graph.

[0191] As a possible implementation of the embodiment of the present disclosure, the second acquisition unit includes:

[0192] an identification subunit, configured to identify an entity in the first query statement and determine a first entity type of the entity;

[0193] A first determination subunit is used to determine a first node from the knowledge graph according to the first entity type, wherein the second entity type corresponding to the first node matches the first entity type;

[0194] A second determination subunit, used to determine, from the knowledge graph, a second node connected to the first node through the first edge or the second edge;

[0195] The third determination subunit is used to use the data table represented by the table node in the first node and the second node as the target data table, and use the field represented by the field node in the first node and the second node as the target field.

[0196] As a possible implementation manner of the embodiment of the present disclosure, the second determining subunit is configured to:

[0197] In the case where the first node is a table node, a field node connected to the first node through a first edge and a table node connected to the first node through a second edge in the knowledge graph are determined as second nodes;

[0198] When the first node is a field node, a table node connected to the first node through a first edge in the knowledge graph is determined as a second node.

[0199] As a possible implementation of the embodiment of the present disclosure, the second acquisition module 502 includes:

[0200] A third acquisition unit, used to acquire semantic similarities between the plurality of candidate query statements and the first query statement;

[0201] A first determining unit is used to determine, among the plurality of candidate query statements, a candidate query statement whose semantic similarity with the first query statement is higher than a set threshold, as a target query statement;

[0202] The second determining unit is configured to use the target query statement as the second query statement, and use the SQL statement corresponding to the target query statement as the SQL statement corresponding to the second query statement.

[0203] As a possible implementation of the embodiment of the present disclosure, the third acquisition unit includes:

[0204] A first acquisition subunit is used to acquire a first feature vector of any candidate query statement among the multiple candidate query statements, wherein the first feature vector represents a semantic feature of the corresponding candidate query statement;

[0205] A second acquisition subunit is used to acquire a second feature vector of the first query statement, wherein the second feature vector represents a semantic feature of the first query statement;

[0206] The fourth determining subunit is configured to determine the similarity between the first feature vector and the second feature vector, and determine the similarity as the semantic similarity between the candidate query statement and the first query statement.

[0207] As a possible implementation of the embodiment of the present disclosure, the first generating module 503 includes:

[0208] A first generating unit is used to generate a prompt word based on the target data table, the target field, the second query statement and the corresponding SQL statement; wherein the prompt word is used to instruct the large model to use the second query statement and the corresponding SQL statement as examples and generate a target SQL statement based on the target data table and the target field;

[0209] The processing unit is used to input the prompt words into the large model to obtain the target SQL statement.

[0210] As a possible implementation of the embodiment of the present disclosure, the data query device 500 based on the big model further includes a third acquisition module, which is used to acquire a target SQL generation template matching the first query statement from multiple SQL generation templates;

[0211] Correspondingly, the first acquisition module is used to acquire the target data table related to the first query statement and acquire the target field in the target data table when the target SQL generation template is not acquired.

[0212] As a possible implementation of the embodiment of the present disclosure, the third acquisition module includes:

[0213] An information extraction unit, configured to extract information from the first query statement to obtain a first key element in the first query statement;

[0214] A matching unit, used to match the first key element with second key elements corresponding to the plurality of SQL generation templates;

[0215] The third determining unit is configured to use the SQL generation template corresponding to the second key element matching the first key element as the target SQL generation template.

[0216] As a possible implementation of the embodiment of the present disclosure, the data query device 500 based on the large model further includes:

[0217] The second generation module is used to generate a target SQL statement based on the target SQL generation template when the target SQL generation template is acquired.

[0218] As a possible implementation of the embodiment of the present disclosure, the processing module 504 includes:

[0219] A query unit, used to query and obtain target data by executing a target SQL statement;

[0220] A second generating unit is used to generate a chart based on the target data, and generate an initial answer to the first query statement based on the target data through the large model;

[0221] The third generating unit is used to obtain an answer to the first query statement based on the graph and the initial answer.

[0222] It should be noted that the aforementioned explanation of the data query method based on the big model is also applicable to the data query device based on the big model of this embodiment, and will not be repeated here.

[0223] In order to implement the above embodiments, the present disclosure also provides a model training device.

[0224] Figure 6 It is a structural diagram of a model training device provided according to an embodiment of the present disclosure.

[0225] like Figure 6 As shown, the model training device 600 includes:

[0226] The fourth acquisition module 601 is used to acquire a training sample set;

[0227] A training module 602 is used to train an initial large model using a training sample set to obtain a target large model;

[0228] Among them, the target big model is used to take the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field in the target data table; wherein the second query statement has similar semantics to the first query statement, and the target data table is related to the first query statement.

[0229] As a possible implementation manner of the embodiment of the present disclosure, the training sample set includes a first training sample, wherein the first training sample includes:

[0230] The first sample prompt word is used to instruct the initial large model to use the first sample query statement and the corresponding SQL statement as examples, and to generate a predicted SQL statement corresponding to the second sample query statement based on the sample data table and the sample fields in the sample data table; wherein the first sample query statement and the second sample query statement have similar semantics, and the sample data table is related to the second sample query statement;

[0231] The expected SQL statement corresponding to the second sample query statement.

[0232] As a possible implementation of the embodiment of the present disclosure, the training sample set also includes a second training sample, and the target large model is also used to generate an initial answer to the first query statement based on target data, and the target data is obtained by executing the target SQL statement; wherein the second training sample includes:

[0233] The second sample prompt word is used to instruct the initial large model to generate a predicted answer corresponding to the second sample query statement based on the sample data, and the sample data is obtained by executing the expected SQL statement;

[0234] The expected answer corresponding to the second sample query statement.

[0235] It should be noted that the above explanation of the model training method is also applicable to the model training device of this embodiment and will not be repeated here.

[0236] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

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

[0238] like Figure 7 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a ROM (Read-Only Memory) 702 or a computer program loaded from a storage unit 705 to a RAM (Random Access Memory) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An I / O (Input / Output) interface 705 is also connected to the bus 704.

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

[0240] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a CPU (Central Processing Unit), a GPU (Graphic Processing Units), various dedicated AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSP (Digital Signal Processor), and any appropriate processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as a data query method or a model training method based on a large model. For example, in some embodiments, a data query method or a model training method based on a large model may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 705. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into RAM 703 and executed by the computing unit 701, one or more steps of the data query method or model training method based on the large model described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the data query method or model training method based on the large model in any other appropriate manner (e.g., by means of firmware).

[0241] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application Specific Standard Products), SOCs (System On Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that may be executed and / or interpreted on a programmable system including at least one programmable processor that may be a dedicated or general-purpose programmable processor that may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

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

[0243] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only-Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0244] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

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

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

[0247] It should be noted that artificial intelligence is a discipline that studies how computers can simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.), and includes both hardware-level and software-level technologies. Artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, and big data processing; artificial intelligence software technologies mainly include computer vision technology, speech recognition technology, natural language processing technology, as well as machine learning / deep learning, big data processing technology, knowledge graph technology, and other major directions.

[0248] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in the present disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved, and this document is not limited here. The above specific implementation methods do not constitute limitations on the scope of protection of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure should be included in the scope of protection of the present disclosure.

Claims

1. A data query method based on a large model, comprising: Acquire a target data table related to the first query statement, and acquire a target field in the target data table; Acquire a second query statement having semantics similar to the first query statement and a structured query language SQL statement corresponding to the second query statement; Taking the second query statement and the corresponding SQL statement as an example, a target SQL statement corresponding to the first query statement is generated based on the target data table and the target field through a large model; Perform data query based on the target SQL statement to obtain an answer to the first query statement.

2. According to the method of claim 1, the step of obtaining a target data table related to the first query statement and obtaining a target field in the target data table comprises: Obtain a knowledge graph generated based on multiple data tables; wherein the knowledge graph includes multiple table nodes, multiple field nodes and multiple edges, wherein the table node represents a data table, the field node represents a field, and the edge includes a first edge and a second edge, wherein the first edge connects any table node and any field node in the knowledge graph, and the first edge represents the belonging relationship between the data table corresponding to the connected table node and the field corresponding to the connected field node, and the second edge connects any two table nodes in the knowledge graph, and the second edge represents the association relationship between the data tables corresponding to the two connected table nodes; Based on the knowledge graph, the target data table and the target field are obtained.

3. The method according to claim 2, wherein: The acquiring the target data table and the target field based on the knowledge graph includes: Identifying an entity in the first query statement and determining a first entity type of the entity; Determining a first node from the knowledge graph according to the first entity type, wherein a second entity type corresponding to the first node matches the first entity type; Determine, from the knowledge graph, a second node connected to the first node through the first edge or the second edge; The data table represented by the table nodes in the first node and the second node is used as the target data table, and the field represented by the field nodes in the first node and the second node is used as the target field.

4. The method according to claim 3, wherein: The step of determining, from the knowledge graph, a second node connected to the first node through the first edge or the second edge includes: In the case where the first node is a table node, determining, in the knowledge graph, a field node connected to the first node through the first edge and a table node connected to the first node through the second edge as the second node; In the case where the first node is a field node, a table node in the knowledge graph that is connected to the first node through the first edge is determined as the second node.

5. The method according to claim 1, wherein: The obtaining of a second query statement having semantics similar to the first query statement and a structured query language SQL statement corresponding to the second query statement includes: Obtaining semantic similarities between a plurality of candidate query statements and the first query statement; Determine, as a target query statement, a candidate query statement whose semantic similarity with the first query statement is higher than a set threshold among the plurality of candidate query statements; The target query statement is used as the second query statement, and the SQL statement corresponding to the target query statement is used as the SQL statement corresponding to the second query statement.

6. The method according to claim 5, wherein: The obtaining of semantic similarities between the plurality of candidate query statements and the first query statement includes: For any candidate query statement among the multiple candidate query statements, obtaining a first feature vector of the candidate query statement, wherein the first feature vector represents a semantic feature of the corresponding candidate query statement; Acquire a second feature vector of the first query statement, wherein the second feature vector represents a semantic feature of the first query statement; A similarity between the first feature vector and the second feature vector is determined, and the similarity is determined as a semantic similarity between the candidate query statement and the first query statement.

7. The method according to claim 1, wherein: The method of taking the second query statement and the corresponding SQL statement as an example and generating a target SQL statement corresponding to the first query statement based on the target data table and the target field through a large model includes: Generate a prompt word based on the target data table, the target field, the second query statement and the corresponding SQL statement; wherein the prompt word is used to instruct the large model to use the second query statement and the corresponding SQL statement as examples and generate the target SQL statement based on the target data table and the target field; The prompt word is input into the large model to obtain the target SQL statement.

8. The method according to any one of claims 1 to 7, wherein: The step of acquiring a target data table related to the first query statement and acquiring a target field in the target data table includes: Acquire a target SQL generation template matching the first query statement from multiple SQL generation templates; In the case where the target SQL generation template is not obtained, a target data table related to the first query statement is obtained, and a target field in the target data table is obtained.

9. The method according to claim 8, wherein: The acquiring, from a plurality of SQL generation templates, a target SQL generation template matching the first query statement comprises: Extracting information from the first query statement to obtain a first key element in the first query statement; Matching the first key element with second key elements corresponding to a plurality of SQL generation templates; The SQL generation template corresponding to the second key element matching the first key element is used as the target SQL generation template.

10. The method according to claim 8, wherein: The method further comprises: When the target SQL generation template is acquired, the target SQL statement is generated based on the target SQL generation template.

11. The method according to any one of claims 1 to 7, wherein the step of performing a data query based on the target SQL statement to obtain an answer to the first query statement comprises: By executing the target SQL statement, querying and obtaining the target data; generating a graph based on the target data, and generating an initial answer to the first query statement based on the target data through the large model; Based on the graph and the initial answer, the answer to the first query statement is obtained.

12. A model training method, comprising: Obtain a training sample set; Using the training sample set to train the initial large model to obtain the target large model; Among them, the target big model is used to take the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field in the target data table; wherein the second query statement has similar semantics to the first query statement, and the target data table is related to the first query statement.

13. The method according to claim 12, wherein: The training sample set includes a first training sample, wherein the first training sample includes: The first sample prompt word is used to instruct the initial large model to use the first sample query statement and the corresponding SQL statement as examples, and to generate a predicted SQL statement corresponding to the second sample query statement based on a sample data table and a sample field in the sample data table; wherein the first sample query statement is semantically similar to the second sample query statement, and the sample data table is related to the second sample query statement; The expected SQL statement corresponding to the second sample query statement.

14. The method according to claim 13, wherein: The training sample set also includes a second training sample, and the target large model is further used to generate an initial answer to the first query statement based on target data, and the target data is obtained by executing the target SQL statement; wherein the second training sample includes: A second sample prompt word, used to instruct the initial large model to generate a predicted answer corresponding to the second sample query statement based on sample data, wherein the sample data is obtained by executing the expected SQL statement; The expected answer corresponding to the second sample query statement.

15. A data query device based on a large model, comprising: A first acquisition module, used to acquire a target data table related to the first query statement, and acquire a target field in the target data table; A second acquisition module, configured to acquire a second query statement having semantics similar to the first query statement and a structured query language SQL statement corresponding to the second query statement; A first generating module, configured to use the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field through a large model; A processing module is used to perform data query based on the target SQL statement to obtain an answer to the first query statement.

16. The device according to claim 15, wherein the first acquisition module comprises: A first acquisition unit is used to acquire a knowledge graph generated based on multiple data tables; wherein the knowledge graph includes multiple table nodes, multiple field nodes and multiple edges, wherein the table node represents a data table, the field node represents a field, and the edge includes a first edge and a second edge, wherein the first edge connects any table node and any field node in the knowledge graph, and the first edge represents the belonging relationship between the data table corresponding to the connected table node and the field corresponding to the connected field node, and the second edge connects any two table nodes in the knowledge graph, and the second edge represents the association relationship between the data tables corresponding to the two connected table nodes; The second acquisition unit is used to acquire the target data table and the target field based on the knowledge graph.

17. The device according to claim 16, wherein: The second acquisition unit includes: an identification subunit, configured to identify an entity in the first query statement and determine a first entity type of the entity; A first determining subunit, configured to determine a first node from the knowledge graph according to the first entity type, wherein a second entity type corresponding to the first node matches the first entity type; A second determining subunit, configured to determine, from the knowledge graph, a second node connected to the first node through the first edge or the second edge; The third determination subunit is used to use the data table represented by the table nodes in the first node and the second node as the target data table, and use the field represented by the field nodes in the first node and the second node as the target field.

18. The device according to claim 17, wherein: The second determining subunit is used to: In the case where the first node is a table node, determining, in the knowledge graph, a field node connected to the first node through the first edge and a table node connected to the first node through the second edge as the second node; In the case where the first node is a field node, a table node in the knowledge graph that is connected to the first node through the first edge is determined as the second node.

19. The device according to claim 15, wherein: The second acquisition module includes: A third acquisition unit, configured to acquire semantic similarities between a plurality of candidate query statements and the first query statement; A first determining unit, configured to determine, as a target query statement, a candidate query statement having a semantic similarity with the first query statement higher than a set threshold among the plurality of candidate query statements; The second determining unit is configured to use the target query statement as the second query statement, and use the SQL statement corresponding to the target query statement as the SQL statement corresponding to the second query statement.

20. The device according to claim 19, wherein The third acquisition unit includes: A first acquisition subunit is configured to acquire, for any candidate query statement among the multiple candidate query statements, a first feature vector of the candidate query statement, wherein the first feature vector represents a semantic feature of the corresponding candidate query statement; A second acquisition subunit is configured to acquire a second feature vector of the first query statement, wherein the second feature vector represents a semantic feature of the first query statement; The fourth determining subunit is configured to determine a similarity between the first feature vector and the second feature vector, and determine the similarity as a semantic similarity between the candidate query statement and the first query statement.

21. The device according to claim 15, wherein: The first generating module comprises: A first generating unit is configured to generate a prompt word based on the target data table, the target field, the second query statement and the corresponding SQL statement; wherein the prompt word is used to instruct the large model to use the second query statement and the corresponding SQL statement as examples and generate the target SQL statement based on the target data table and the target field; The processing unit is used to input the prompt word into the large model to obtain the target SQL statement.

22. The device according to any one of claims 15 to 21, wherein: The device further includes a third acquisition module, configured to acquire a target SQL generation template matching the first query statement from a plurality of SQL generation templates; The first acquisition module is used to acquire a target data table related to the first query statement and acquire a target field in the target data table when the target SQL generation template is not acquired.

23. The device according to claim 22, wherein: The third acquisition module includes: an information extraction unit, configured to extract information from the first query statement to obtain a first key element in the first query statement; A matching unit, configured to match the first key element with second key elements corresponding to a plurality of SQL generation templates; The third determining unit is configured to use the SQL generation template corresponding to the second key element matching the first key element as the target SQL generation template.

24. The device according to claim 22, wherein: The device also includes: The second generating module is used to generate the target SQL statement based on the target SQL generating template when the target SQL generating template is acquired.

25. The device according to any one of claims 15 to 21, wherein the processing module comprises: A query unit, used to query and obtain target data by executing the target SQL statement; A second generating unit, configured to generate a chart based on the target data, and generate an initial answer to the first query statement based on the target data by using the large model; A third generating unit is configured to obtain the answer to the first query statement based on the graph and the initial answer.

26. A model training device, comprising: The fourth acquisition module is used to acquire a training sample set; A training module, used for training an initial large model using the training sample set to obtain a target large model; Among them, the target big model is used to take the second query statement and the corresponding SQL statement as examples, and generate a target SQL statement corresponding to the first query statement based on the target data table and the target field in the target data table; wherein the second query statement has similar semantics to the first query statement, and the target data table is related to the first query statement.

27. The device according to claim 26, wherein: The training sample set includes a first training sample, wherein the first training sample includes: The first sample prompt word is used to instruct the initial large model to use the first sample query statement and the corresponding SQL statement as examples, and to generate a predicted SQL statement corresponding to the second sample query statement based on a sample data table and a sample field in the sample data table; wherein the first sample query statement is semantically similar to the second sample query statement, and the sample data table is related to the second sample query statement; The expected SQL statement corresponding to the second sample query statement.

28. The device according to claim 27, wherein The training sample set also includes a second training sample, and the target large model is further used to generate an initial answer to the first query statement based on target data, and the target data is obtained by executing the target SQL statement; wherein the second training sample includes: A second sample prompt word, used to instruct the initial large model to generate a predicted answer corresponding to the second sample query statement based on sample data, wherein the sample data is obtained by executing the expected SQL statement; The expected answer corresponding to the second sample query statement.

29. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any one of claims 1-11, or execute the method of any one of claims 12-14.

30. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the method of any one of claims 1-11, or to execute the method of any one of claims 12-14.

31. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 11, or implements the method according to any one of claims 12 to 14.

Citation Information

Cited By

  • Answer prediction method, device and equipment based on distributed learning

    CN120196729A