A method and data query device for generating a structured query language
By combining stored historical query information with a large language model, candidate examples are filtered to generate the SQL statement corresponding to the user's current input question. This solves the problem of accuracy in converting user input questions into SQL statements and improves the accuracy and efficiency of query results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
- Filing Date
- 2023-05-10
- Publication Date
- 2026-07-24
AI Technical Summary
In existing technologies, the accuracy of converting user-input questions into SQL statements is difficult to guarantee, which affects the accuracy of query results.
By storing historical query information, the mapping relationship between the user's historical input questions and the corresponding correct SQL statements is recorded. Using a large language model and similarity to filter candidate examples, the SQL statement corresponding to the user's current input question is generated.
It improves the accuracy of generated SQL statements, simplifies the work of data developers, and enhances the accuracy of query results.
Smart Images

Figure CN117112590B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and more specifically, to a method and data query device for generating structured query language. Background Technology
[0002] Structured Query Language (SQL) is a database query and programming language used to access, query, update, and manage relational database systems. SQL is the standardized query language for relational databases, enabling operations such as data definition, data querying, and data control within a target database. In basic SQL queries, users generally don't need to understand how the data in the database is defined or stored; they only need to understand the table structure to retrieve the required information.
[0003] Natural Language to Structured Query Language (NL2SQL) is a technique that converts natural language into SQL queries. Its purpose is to transform natural language queries into machine-readable SQL queries so that data can be retrieved from relational databases. For example, in practical applications, a user can directly input a question, the backend generates the corresponding SQL statement, and the user uses this SQL statement to send an operation request to the database. The database server processes the request and returns the query results to the user. However, the accuracy of the generated SQL statement corresponding to the user's question can affect the accuracy of the query results.
[0004] Therefore, how to improve the accuracy of generated SQL statements in response to user input has become a technical problem that needs to be solved. Summary of the Invention
[0005] This application provides a method for generating structured query language, which can improve the accuracy of generated SQL statements.
[0006] Firstly, a method for generating a structured query language is provided. This method can be executed by a data query device, or by components of the data query device (such as chips or circuits), or by various servers or virtual machines in a cloud service system, without limitation.
[0007] The method includes: storing historical query information, which includes a first mapping relationship between first information and a first structured query language (SQL) statement, wherein the first information includes a question input by the user in the past, and the first SQL statement is a previously generated correct SQL statement corresponding to the question input by the user in the past; filtering the historical query information according to second information to obtain candidate examples, wherein the second information includes the question input by the user in the present, and the candidate examples include the filtered first mapping relationship, wherein the similarity between the first information and the second information in the filtered first mapping relationship is greater than or equal to a first threshold; generating third information according to the second information and the candidate examples, wherein the third information includes the second information and the candidate examples; and generating a second SQL statement corresponding to the second information according to a large language model and the third information, wherein the input of the large language model is the third information, and the output of the large language model is the second SQL statement.
[0008] Specifically, the similarity between questions can be measured using methods such as: first, one-hot encoding or word embedding encoding can be used to vectorize the user's current input question and the stored user's historical input questions; then, similarity can be compared by comparing their inner product, or by distance measurement, or by using neural networks, etc.
[0009] In this application, historical query information can be stored. This information records the mapping relationship between the user's previous input questions and the corresponding correctly generated SQL statements. Then, the candidate example that best matches the user's current input question is found in the historical query records. The user's current input question and the candidate example are then used as input to a large language model, causing the large language model to output the corresponding SQL statement. The method provided in this application can conveniently and accurately obtain the candidate example corresponding to the user's current input question, thereby improving the accuracy of the SQL statement generated based on the user's current input question.
[0010] Optionally, the second information also includes the table schema corresponding to the question currently entered by the user. In this case, the second information specifically includes the question currently entered by the user and the table schema corresponding to that question. The first information also includes the table schema corresponding to the questions entered by the user in the past. In this case, the historical query information can specifically be the mapping relationship between the questions entered by the user in the past, the table schema corresponding to that question, and the first structured query language SQL statement.
[0011] Specifically, filtering based on table schemas can be done by setting rules. For example, users can edit various rules for filtering, such as: identical table names, identical column names, related tables, or tables with different names but identical primary / foreign key relationships. These rules can score the table schemas corresponding to the user's historical input questions. When the score is greater than or equal to a certain threshold (e.g., the first threshold), it can be identified as a candidate example. Alternatively, users can define custom rules to filter based on table schema attributes, such as table quality or table date, scoring the table schemas corresponding to the user's historical input questions. When the score is greater than or equal to a certain threshold (e.g., the first threshold), it can be identified as a candidate example.
[0012] In this application, when filtering historical query information, not only can the user's current input question be used for filtering, but the user's current input question can also be further filtered by the table schema corresponding to the user's current input question. This can further ensure the matching of the filtered candidate examples with the user's current input question, thereby ensuring the accuracy of the generated SQL statement.
[0013] In conjunction with the first aspect, in one possible implementation, after obtaining candidate examples, the method further includes: determining a target example from the candidate examples; generating third information based on the second information and the candidate examples, the third information including the question currently input by the user and the candidate examples, including: generating third information based on the second information and the target example, the third information including the question currently input by the user and the target example.
[0014] In this application, after obtaining candidate examples, the candidate examples can be further filtered to obtain target examples. This can remove redundant information in the candidate examples and ensure the richness of the target examples, which can save computing resources and improve the richness of the obtained target examples.
[0015] In conjunction with the first aspect, in one possible implementation, the obtained candidate examples include multiple candidate examples, wherein each candidate example includes a filtered first mapping relationship, which is a mapping relationship between filtered user historical input questions and filtered first SQL statements. Determining a target example from the candidate examples includes: filtering multiple first SQL statements based on the differences between multiple first SQL statements included in the multiple first mapping relationships corresponding to the multiple candidate examples to obtain multiple target SQL statements, wherein the difference between the multiple target SQL statements is greater than or equal to a second threshold; determining multiple target examples based on the multiple target SQL statements and the filtered user historical input questions corresponding to each of the multiple target SQL statements, wherein each target example includes a mapping relationship between filtered user historical input questions and target SQL statements.
[0016] In this application, when determining the differences between various SQL statements, the differences between SQL statements can be determined, for example, by comparing the contents of each field of the SQL statement.
[0017] In conjunction with the first aspect, in one possible implementation, the obtained candidate examples include multiple candidate examples, wherein each candidate example includes a filtered first mapping relationship, the filtered first mapping relationship being a mapping relationship between a filtered user historical input question, a table schema corresponding to the filtered user historical input question, and a filtered first SQL statement. Determining a target example from the candidate examples includes: filtering multiple table schemas based on the differences between multiple table schemas included in the multiple first mapping relationships corresponding to the multiple candidate examples to obtain multiple target table schemas, wherein the difference between the multiple target table schemas is greater than or equal to a third threshold; determining multiple target examples based on the multiple target table schemas and the filtered user historical input questions and filtered first SQL statements corresponding to each of the multiple target table schemas; wherein each target example includes: a mapping relationship between a filtered user historical input question, a filtered target table schema, and a filtered first SQL statement.
[0018] In conjunction with the first aspect, in one possible implementation, the obtained candidate examples include multiple candidate examples, wherein each candidate example includes a filtered first mapping relationship, which is a mapping relationship between filtered user historical input questions, the table schema corresponding to the filtered user historical input questions, and filtered first SQL statements. Determining target examples based on the candidate examples includes: filtering each first SQL statement based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to the multiple candidate examples to obtain multiple target SQL statements, wherein the difference between the multiple target SQL statements is greater than or equal to a second threshold; determining multiple target examples based on the multiple target SQL statements and the filtered user historical input questions and the table schema corresponding to the filtered user historical input questions corresponding to the multiple target SQL statements; wherein each target example includes: the filtered user historical input questions, the filtered table schema, and the mapping relationship between the target SQL statements.
[0019] It should be understood that when all candidate examples are similar, filtering by differences can be interpreted as ultimately retaining one or two candidate examples, which become the target examples. This process can be understood as removing redundant examples, thus reducing resource consumption.
[0020] In this application, after obtaining candidate examples, the candidate examples can be filtered according to the differences in SQL statements and / or table schemas to obtain target examples, so that the target examples are more closely matched with the user's current input question or the target examples are more closely matched with the user's current input question and the table schema corresponding to the question, thereby improving the accuracy of the generated SQL statements.
[0021] Secondly, this application proposes a data query device for performing the method described in the first aspect. Specifically, the device may include units and / or modules for performing the method described in the first aspect, such as a transceiver unit and / or a processing unit.
[0022] Thirdly, a data query device is provided, comprising: at least one processor for executing a computer program or instructions stored in a memory to perform the method described in the first aspect. Optionally, the device further comprises a memory for storing the computer program or instructions. Optionally, the device further comprises a communication interface through which the processor reads the computer program or instructions stored in the memory.
[0023] In one implementation, the device is a functional data query device for implementing methods to generate SQL statements within a chip.
[0024] In another implementation, the device is a chip, chip system, or circuit that implements a method for generating SQL statements within a chip.
[0025] Fourthly, this application provides a processor, including: an input circuit, an output circuit, and a processing circuit. The processing circuit is used to receive signals through the input circuit and to transmit signals through the output circuit, causing the processor to execute the method described in the first aspect.
[0026] In specific implementation, the processor can be one or more chips, the input circuit can be input pins, the output circuit can be output pins, and the processing circuit can be transistors, gate circuits, flip-flops, and various logic circuits. The input signal received by the input circuit can be received and input by, for example, but not limited to, a transceiver, and the signal output by the output circuit can be, for example, but not limited to, output to and transmitted by a transmitter. Furthermore, the input circuit and the output circuit can be the same circuit, which is used as both the input circuit and the output circuit at different times. This application does not limit the specific implementation of the processor and various circuits.
[0027] Unless otherwise specified, or if it does not contradict its actual function or internal logic in the relevant description, the transmission and acquisition / reception operations involved in the processor can be understood as processor output and reception, input and other operations, or as transmission and reception operations performed by radio frequency circuits and antennas. This application does not limit them in this regard.
[0028] Fifthly, a processing apparatus is provided, including a processor and a memory. The processor is used to read instructions stored in the memory and to receive signals via a transceiver and transmit signals via a transmitter to execute the method described in the first aspect.
[0029] Optionally, the processor may be one or more, and the memory may be one or more.
[0030] Optionally, the memory may be integrated with the processor, or the memory may be separated from the processor.
[0031] In the specific implementation process, the memory can be a non-transitory memory, such as read-only memory (ROM), which can be integrated with the processor on the same chip or set on different chips. The embodiments of this application do not limit the type of memory or the way the memory and processor are set.
[0032] It should be understood that the relevant data interaction process, such as sending indication information, can be the process of the processor outputting indication information, and receiving capability information can be the process of the processor receiving input capability information. Specifically, the data output by the processor can be sent to the transmitter, and the input data received by the processor can come from the transceiver. Here, the transmitter and the transceiver can be collectively referred to as transceivers.
[0033] The processing device mentioned in the fifth aspect above can be one or more chips. The processor in the processing device can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, integrated circuit, etc.; when implemented in software, the processor can be a general-purpose processor that reads software code stored in memory. This memory can be integrated into the processor or located outside the processor and exist independently.
[0034] In a sixth aspect, a computing device cluster is provided, comprising at least one computing device, each computing device including a processor and a memory; the processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the computing device cluster to perform the method described in the first aspect or any possible implementation thereof.
[0035] Optionally, the processor can be a general-purpose processor, which can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, integrated circuit, etc.; when implemented in software, the processor can be a general-purpose processor that reads software code stored in memory. This memory can be integrated into the processor or located outside the processor and exist independently.
[0036] In a seventh aspect, a computer-readable storage medium is provided that stores program code for execution by a device, the program code including the method described in the first aspect.
[0037] Eighthly, a computer program product containing instructions is provided, which, when run on a computer, causes the computer to perform the method described in the first aspect.
[0038] A ninth aspect provides a chip system including a processor for calling and running a computer program from a memory, causing a device equipped with the chip system to perform the method of the first aspect described above. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of a data query device architecture to which this application applies.
[0040] Figure 2This is a schematic flowchart of a method 200 for generating SQL statements provided in this application.
[0041] Figure 3 This is another illustrative flowchart for generating SQL statements provided in this application.
[0042] Figure 4 This is a schematic block diagram of the data query device 100 provided in this application.
[0043] Figure 5 This is a schematic block diagram of the data query device 200 provided in this application.
[0044] Figure 6 This is a schematic diagram of the architecture of a computing device cluster provided in an embodiment of this application.
[0045] Figure 7 This is a schematic diagram showing the connection between computing devices 600A and 600B via a network provided in an embodiment of this application. Detailed Implementation
[0046] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0047] To facilitate understanding of the technical solution of this application, a brief explanation of some of the technical terms involved in this application is provided below.
[0048] 1. Large Language Model (LLM)
[0049] Large language models refer to natural language processing models built using deep learning techniques. They can take text as input and predict missing parts of the text. Large language models are typically trained on large amounts of text data, such as news articles, blogs, and Wikipedia entries from the internet. These models can generate natural language text, answer natural language questions, perform machine translation, speech recognition, and other tasks, and are widely used in the field of language processing. Currently, some large technology companies such as Google and Microsoft have built very powerful large language models. These models possess very strong language understanding and generation capabilities, can be used for various language processing tasks, and have demonstrated excellent performance in many fields. The "large language models" mentioned in this application also include other machine learning models that may emerge in the future.
[0050] 2. Chat-generating pre-trained transformation model
[0051] Chat-based generative pre-trained transform models are among the most advanced natural language processing (NLP) models available. As a language model-based machine learning model, it can generate natural language text with a high level of language understanding. By learning from different datasets, it can achieve very high text comprehension and generation capabilities. LLM, represented by chat-based generative pre-trained transform models, can assist humans in completing various tasks, thereby reducing workload and improving productivity. The efficiency and accuracy of chat-based generative pre-trained transform models are widely recognized in various fields of NLP. For example, it can be used in machine translation, automatic summarization, text correction, and speech generation.
[0052] 3. Structured Query Language (SQL)
[0053] SQL is a database language with multiple functions, including data manipulation and data definition. This interactive language provides great convenience to users, and database management systems should fully utilize SQL to improve the quality and efficiency of computer application systems. SQL can be used to manipulate databases, such as creating items, querying content, updating content, and deleting entries. Typically, the general format of an SQL statement includes the following fields: "select", "from", "where", "group by", and "order by".
[0054] 4. Natural Language to Structured Query Language (NL2SQL)
[0055] NL2SQL is a technology that converts users' natural language statements into executable SQL statements, which is of great significance for improving the interaction between users and databases. The essence of NL2SQL is to convert users' natural language statements into a canonical semantic representation that computers can understand and execute, which is a subtask in the field of semantic analysis. The main application areas of NL2SQL include: (1) Intelligent search engines: Using NL2SQL technology, users can query data in relational databases using natural language, thereby improving the intelligence level of search engines. (2) Chatbots: Using NL2SQL technology, chatbots can be made intelligent, enabling them to automatically recognize users' natural language queries and retrieve relevant information from the database. (3) Database queries: NL2SQL technology can support database management systems, allowing users to query data in the database using natural language, thus improving query efficiency.
[0056] Based on the current development of large language models, and considering their potential application in the NL2SQL domain, the most common use case for large language models is to provide query results based on user input. To make the output of large language models more comprehensive and meet user expectations, chat-generating pre-trained transformation models, for example, employ in-context learning models. By guiding the model, they generate reasonable content from appropriate contextual associations. For instance, when users input their questions, they can provide additional examples to the large language model, thus guiding its development. For example, a user could input the following: "Please translate 'I like to eat chocolate,' for example: apple-apple, banana-banana." The language model will then learn from the user's input examples ("e.g., apple-apple, banana-banana") that this is a Chinese-to-English translation task, thus performing a fast and efficient Chinese-to-English translation. Similarly, for an NL2SQL task, providing examples can lead to more comprehensive or accurate SQL statements. Alternatively, it can be understood that writing a more appropriate example will affect the accuracy of the generated SQL statement, which in turn will directly affect the accuracy of the query results obtained from the user's input.
[0057] However, a data development engineer might be dealing with an entire data lake. Data in a data lake originates from different storage systems, such as object storage, data warehouses, and databases. It also comes from different business systems, such as customer relationship management (CRM), enterprise resource planning (ERP), and operations and maintenance systems. In this complex system, having engineers determine the appropriate example for the current input problem through deliberation would be extremely time-consuming, and the input example might not even be the best match for the current problem, leading to potentially inaccurate SQL statements. In other words, how to make the SQL statements generated by a large language model more accurate becomes a technical problem that needs to be solved.
[0058] In view of this, this application proposes storing historical query information, which records the mapping relationship between the user's previously input questions and the corresponding correctly generated SQL statements. Then, it finds the candidate example that best matches the user's current input question from the historical query records. The user's current input question and the candidate example are then used as input to a large language model, enabling the large language model to output the corresponding SQL statement. The method provided in this application can conveniently and accurately obtain the candidate example corresponding to the user's current input question, thereby improving the accuracy of the SQL statement generated based on the user's current input question.
[0059] Figure 1 This is a schematic architecture diagram of a data query device applicable to this application, such as... Figure 1 As shown, the text content input by the user or the text content converted from speech is input into the NL2SQL model through the interaction layer. The NL2SQL model searches for the corresponding SQL statement in the database and feeds back the SQL execution result to the interaction layer.
[0060] Figure 2 This is a schematic flowchart illustrating a method 200 for obtaining SQL statements proposed in this application. The technical solution provided in this application can be implemented by various servers (e.g., virtual machines) in a cloud service architecture, or by ordinary data query devices (e.g., data query engines). Figure 2 As shown, the method includes:
[0061] Step 201: Store historical query information, which includes a first mapping relationship between first information and a first structured query language (SQL) statement.
[0062] In this application, the first information includes the questions input by the user historically. The first SQL statement can be understood as the correct SQL statement generated historically corresponding to the questions input by the user historically. At this time, the historical query information can be specifically understood as: the mapping relationship between the questions input by the user historically and the correct SQL statement generated historically corresponding to the questions input by the user historically. For example, the format of the historical query information stored in this way is <key_1: the questions input by the user historically, value: the correct SQL statement generated historically>. Exemplarily, the first mapping relationship can be understood as the corresponding relationship shown in Table 1 below.
[0063] Table 1
[0064] First mapping relationship First Information First SQL statement Mapping Relationship #1 Issue #1: User input history Correct SQL statement generated in history #1 Mapping Relationship #2 User input history issue #2 Correct SQL statement generated in history #2 Mapping Relationship #3 User input history issue #3 The correct SQL statement generated in history #3 Mapping Relationship #4 User input history issue #4 Correct SQL statement generated in history #4
[0065] Optionally, in some implementation manners, the first information further includes the table schema corresponding to the questions input by the user historically. At this time, the historical query information can be understood as: the mapping relationship among the questions input by the user historically, the questions input by the user historically, the table schema (table schema) corresponding to the questions input by the user historically, and the correct SQL statement generated historically. For example, the format of the historical query information stored in this way is <key_1: the questions input by the user historically, key_2: the table schema corresponding to the questions input by the user historically, value: the correct SQL statement generated historically>. Exemplarily, at this time, the first mapping relationship can be understood as the corresponding relationship shown in Table 2 below.
[0066] Table 2
[0067] First mapping relationship First Information First SQL statement Mapping Relationship #5 User history input question #1—Table schema #1 The correct SQL statement generated in history #A Mapping Relationship #6 User history input question #2—Table schema #2 for question #2 The correct SQL statement generated in history #B Mapping Relationship #7 User history input question #3 — Table pattern #3 for question #3 The correct SQL statement generated in history #C Mapping Relationship #8 User history input question #4 — Table pattern #4 for question #4 The correct SQL statement generated in history #D
[0068] In this application, the "table schema" can be understood as the attributes of the table, the name of the table, the names of the columns in the table, and so on.
[0069] In this application, the first SQL statement includes the SQL statement generated by the large language model before and directly executed, and also includes the SQL statement finally executed after being manually modified after the large language model generates the SQL statement.
[0070] Alternatively, the "mapping relationship" and "corresponding relationship" herein can also be expressed as "association relationship". It should be understood that the "mapping relationship" mentioned in the embodiments of this application can be saved or recorded in the form of a function relationship, a table, or the like.
[0071] Step 202, screen the historical query information according to the second information to obtain candidate examples.
[0072] In this application, the second information includes the question currently entered by the user, and the candidate examples include a filtered first mapping relationship. The similarity between the first information and the second information in the filtered first mapping relationship is greater than or equal to a first threshold.
[0073] In one implementation, when the second information only includes the question currently entered by the user, and the first information includes questions entered by the user in the past, the similarity between the first and second information can be specifically understood as the similarity between the question currently entered by the user and the stored questions entered by the user in the past. This implementation can also be understood as filtering based on the similarity of the questions in the first mapping relationship to obtain a filtered first mapping relationship.
[0074] Specifically, the similarity between questions can be measured using methods such as: first, one-hot encoding or word embedding encoding can be used to vectorize the user's current input question and the stored user's historical input questions; then, similarity can be compared by comparing their inner product, or by distance measurement, or by using neural networks, etc.
[0075] For example, the candidate examples finally determined by the screening based on question similarity are mapping relationships #1, #2, #3, and #4 in Table 1.
[0076] In another implementation, when the second information includes the user's currently input question and the corresponding table schema, the first information includes the user's historically input questions and the corresponding table schemas. In this case, the similarity between the first and second information can be specifically understood as: the similarity between the user's currently input question and the stored historically input questions, and the similarity between the table schema corresponding to the user's currently input question and the table schema corresponding to the user's historically input questions. This implementation can be understood as allowing filtering not only based on question similarity but also based on the corresponding table schema, thereby obtaining the filtered first mapping relationship. It should be understood that filtering can also be performed first based on table schema similarity and then based on question similarity; the order of the two is not limited.
[0077] Specifically, filtering based on table schemas can be done by setting rules. For example, users can edit various rules for filtering, such as: identical table names, identical column names, related tables, or tables with different names but identical primary / foreign key relationships. These rules can score the table schemas corresponding to the user's historical input questions. When the score is greater than or equal to a certain threshold (e.g., the first threshold), it can be identified as a candidate example. Alternatively, users can define custom rules to filter based on table schema attributes, such as table quality or table date, scoring the table schemas corresponding to the user's historical input questions. When the score is greater than or equal to a certain threshold (e.g., the first threshold), it can be identified as a candidate example.
[0078] The phrase "different table names but the same table linked by the primary and foreign keys" can be understood as follows: although the table names are different, each table contains certain information, and information related to that information can be found by looking up information that is linked to the same table.
[0079] For example, the candidate examples determined by filtering based on question similarity are mapping relationships #5, #6, #7, and #8 in Table 2. The candidate examples are then filtered again based on the similarity of the table patterns, and the final candidate examples determined are mapping relationships #5, #6, and #7 in Table 2.
[0080] Step 203: Generate third information based on the second information and the candidate examples. The third information includes the second information and the candidate examples.
[0081] As an example, suppose the user's current input question is: "How many blue sportswear items are left in the warehouse?", and the candidate examples filtered from historical storage records are: "Find how many red cars are left?"—"A table called cars with columns id and color"—"Select..." "from cars where color = 'red'". Therefore, the third piece of information can be understood as: querying how many blue sportswear items are left in the warehouse, for example, "finding how many red cars are left"—"Atable called carts with columns id and color" "Select from cars where color ='red'".
[0082] To ensure that the final examples cover all dimensions or aspects and to remove redundant examples (meaning that only one similar example is retained among the candidate examples), the candidate examples can be further filtered to obtain the target example. Therefore, in one possible implementation, after obtaining the candidate examples, the method further includes: determining the target example from the candidate examples. This can also be understood as the application proposing further filtering of the candidate examples to obtain the target example. At this point, third information is generated based on the second information and the candidate examples, including: generating third information based on the second information and the target example, where the third information includes the user's current input question and the target example. The following describes the various implementation methods for filtering candidate examples to obtain the target example in this application:
[0083] Method 1:
[0084] Suppose that the candidate examples include multiple candidate examples, each of which includes a filtered first mapping relationship, where the filtered first mapping relationship is the mapping relationship between the filtered user historical input questions and the filtered first SQL statement. For example, suppose the candidate examples are mapping relationships #1 to #4 in Table 1 above.
[0085] At this point, multiple first SQL statements can be filtered based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to multiple candidate examples, to obtain multiple target SQL statements. The difference between these multiple target SQL statements is greater than or equal to a second threshold. For example, mapping relationships #1 to #4 in the candidate examples correspond to historically generated correct SQL statements #1 to #4, respectively. The differences between each historically generated correct SQL statement can be compared, ensuring that the final selection of each historically generated correct SQL statement has a difference greater than or equal to a certain threshold (e.g., the second threshold). For instance, after filtering, it is found that the differences between historically generated correct SQL statements #1 and #2 are significant; therefore, the target examples can be determined as mapping relationships #1 and #2.
[0086] In this application, when determining the differences between various SQL statements, the differences between SQL statements can be determined, for example, by comparing the contents of each field of the SQL statement.
[0087] Method 2:
[0088] Suppose that the candidate examples include multiple candidate examples, and each candidate example includes a filtered first mapping relationship, wherein the filtered first mapping relationship is the mapping relationship between the filtered user historical input question, the table schema corresponding to the filtered user historical input question, and the filtered first SQL statement. For example, suppose the candidate examples are mapping relationships #1 to #3 in Table 2 above.
[0089] At this point, multiple first SQL statements can be filtered based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to multiple candidate examples, to obtain multiple target SQL statements. The difference between these multiple target SQL statements is greater than or equal to a second threshold. For example, mapping relationships #5 to #7 in the candidate examples correspond to historically generated correct SQL statements #A to #C, respectively. The differences between these historically generated correct SQL statements can be compared to ensure that the final selection of these statements is based on a difference greater than or equal to a certain threshold (e.g., the second threshold). For instance, after filtering, it is found that historically generated correct SQL statements #A and #B have a large difference, therefore, the target examples can be determined as mapping relationships #5 and #6.
[0090] Method 3:
[0091] Suppose that the candidate examples include multiple candidate examples, and each candidate example includes a filtered first mapping relationship, wherein the filtered first mapping relationship is the mapping relationship between the filtered user historical input question, the table schema corresponding to the filtered user historical input question, and the filtered first SQL statement. For example, suppose the candidate examples are mapping relationships #1 to #3 in Table 2 above.
[0092] At this point, multiple table schemas can be filtered based on the differences between the multiple table schemas included in the multiple first mapping relationships corresponding to multiple candidate examples, to obtain multiple target table schemas. The difference between these multiple target schemas is greater than or equal to a third threshold. For example, mapping relationships #5 to #7 in the candidate examples correspond to historically generated correct SQL statements #A to #C, respectively. In this case, the differences between each table schema can be compared, so that the final selection of each table schema has a difference greater than or equal to a certain threshold (e.g., the third threshold). For example, after filtering, it is found that table schemas #1 and #3 have a large difference, so the target examples can be determined as mapping relationships #5 and #7.
[0093] In this application, when determining the differences between the table schemas in each candidate example, the target table schema can be determined by comparing the table name, column name, etc. of each table separately.
[0094] Of course, methods 2 and 3 can be executed simultaneously. That is, the differences between the first SQL statement and the differences between the table schemas can be filtered to determine the target example by combining the results of both aspects. For example, combining methods 2 and 3, the target examples are mapping relationship #6 and mapping relationship #7.
[0095] In this application, after obtaining candidate examples, the candidate examples can be further filtered to obtain target examples. This can remove redundant information in the candidate examples and ensure the richness of the target examples, which can save computing resources and improve the richness of the obtained target examples.
[0096] It should be understood that when all candidate examples are similar, filtering by differences can be interpreted as ultimately retaining one or two candidate examples, which become the target examples. This process can be understood as removing redundant examples, thus reducing resource consumption.
[0097] As described above, this application can determine candidate examples based on the similarity between questions or between the similarity between questions and table schemas. The target example is determined by the differences between the first SQL statements in the candidate examples and / or the differences between table schemas. Multiple filtering processes ensure that the final selected examples best match the user's current input question, thereby guaranteeing the accuracy of the generated SQL statements.
[0098] Step 204: Generate the second SQL statement corresponding to the second information based on the large language model and the third information.
[0099] In this application, the input to the large language model is the question currently input by the user and the target example, and the output of the large language model is the SQL statement corresponding to the question currently input by the user. For example, the input information of the large language model is "Query how many blue sportswear items are left in the warehouse, example: find how many red cars are left—"A table called cartswith columns id and color" "Select The output of the large language model is "A table called tracksuit with columns id and color". "Select" fromtracksuit where color ='blue'".
[0100] It should be noted that the large language model in this application can be deployed on a third-party server or integrated on the same server, without limitation.
[0101] Figure 3 This application provides another illustrative flowchart for generating SQL statements, such as... Figure 3 As shown, step 301 involves storing the historical query information. The format of the stored historical query information can be:<key_1,value> Alternatively, the format for storing historical query information can be:<key_1,key_2,value> Step 302: Filter historical query information based on table schema rules. For example, filtering can be performed on historical queries where the table name of the user's previously entered question is the same as the table name of the user's current entered question. Another example is filtering for historical queries where the table name of the user's previously entered question is different, but the column attributes are the same as those of the user's current entered question. Yet another example is filtering for historical queries where the table name of the user's previously entered question is different, but the primary and foreign keys of the tables associated with it are the same as those of the user's current entered question. Step 303: Filter historical query information based on question similarity. Step 304: Filter based on differences in SQL statements and / or table schemas. Step 305: Concatenate the user's current entered question with the filtered examples (e.g., using the prompt technique). Step 306: Invoke the large language model to output the SQL statement corresponding to the user's current entered question.
[0102] Based on the above scheme, this application progressively filters examples from stored historical query information to obtain examples that closely match the user's current input question. The user's current input question and the filtered examples are then used as input to a large language model, enabling the model to output the SQL statement corresponding to the user's current input question. This method ensures a high degree of matching between the obtained examples and the user's current input question. Developers do not need to manually input examples, thus guaranteeing the accuracy of the obtained examples, simplifying the work of data developers, and improving the efficiency of generating SQL statements.
[0103] It is understood that the term "and / or" in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0104] Those skilled in the art will recognize that, based on the units and algorithm steps described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is implemented in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0105] This application embodiment can divide the computing device into functional modules according to the above method example. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing module. The integrated modules can be implemented in hardware or as software functional modules. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division. In actual implementation, there may be other division methods. The following description uses the division of functional modules according to each function as an example.
[0106] Figure 4 This is a schematic block diagram of a data query device 100 provided in an embodiment of this application. As shown in the figure, the device 100 may include: a storage module 110, a filtering module 120, and a processing module 130.
[0107] The modules described above are used to execute the various steps of the aforementioned model acquisition method, which will not be elaborated here.
[0108] It should also be understood that the data query device 100 here is embodied in the form of a functional unit. The term "unit" here may refer to application-specific integrated circuits (ASICs), electronic circuits, processors (e.g., shared processors, proprietary processors, or group processors) and memory for executing one or more software or firmware programs, combined logic circuits, and / or other suitable components that support the described functions.
[0109] The data query device 100 of each of the above schemes has the function of implementing the corresponding steps of the above method 200. The function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions; for example, the filtering unit can be replaced by a processor to execute the send / receive operations and related processing operations in each method embodiment. Furthermore, the processing unit can be a processing circuit.
[0110] It should be pointed out that, Figure 4 The device mentioned can be the data query device in the aforementioned method embodiments, or it can be a chip or chip system of a computing device, such as a system on a chip (SoC). The processing unit is a processor, microprocessor, or integrated circuit integrated on the chip. No limitation is made here.
[0111] Figure 5 This is a schematic block diagram of another data query device 200 provided in an embodiment of this application. As shown, the device 200 includes at least one processor 220. The processor 220 is coupled to a memory and is used to execute instructions stored in the memory to send and / or receive signals. Optionally, the device 200 also includes a memory 230 for storing instructions. Optionally, the device 200 also includes a transceiver 210, and the processor 220 controls the transceiver 210 to send and / or receive signals.
[0112] It should be understood that the processor 220 and memory 230 described above can be combined into a single processing device, with the processor 220 executing the program code stored in the memory 230 to achieve the aforementioned functions. In specific implementations, the memory 230 can be integrated into the processor 220 or independent of the processor 220.
[0113] It should also be understood that transceiver 210 may include a transceiver (or receiver) and a transmitter (or transmitter). The transceiver may further include an antenna, and the number of antennas may be one or more. Transceiver 210 may have a communication interface or interface circuitry.
[0114] Specifically, the processor 220 in the device 200 can correspond to the filtering module 120 and the processing module 130 in the data query device 100.
[0115] As one approach, the data query device 200 is used to implement the steps in the above-described method 200 embodiment.
[0116] For example, processor 220 is used to execute computer programs or instructions stored in memory 230 to implement the various steps in method 200 above.
[0117] Figure 6This is a schematic diagram of the architecture of a computing device cluster provided in an embodiment of this application. The computing device cluster includes at least one computing device. This computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone. Figure 6 As shown, the computing device cluster includes at least one computing device 600. The memory 630 in one or more computing devices 600 in the computing device cluster may store the same instructions for executing the method of generating SQL statements described in the above embodiments.
[0118] In some possible implementations, the memory 630 of one or more computing devices 600 in the computing device cluster may also store partial instructions for executing the method of generating SQL statements described in the above embodiments. In other words, a combination of one or more computing devices 600 can jointly execute the instructions for executing the method of generating SQL statements described in the above embodiments.
[0119] It should be noted that the memory 630 in different computing devices 600 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the computing device 600. That is, the instructions stored in the memory 630 of different computing devices 600 can implement the functions of one or more modules among the storage module 110, the filtering module 120, and the processing module 130.
[0120] Alternatively, the memory 630 in different computing devices 600 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the aforementioned data query devices 100-200. That is, the instructions stored in the memory 630 of different computing devices 600 can implement the functions of one or more modules among the storage module 110, filtering module 120, and processing module 130.
[0121] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 7 One possible implementation method is shown. Figure 7 This is a schematic diagram illustrating the connection between computing devices 600A and 600B via a network, as provided in an embodiment of this application. The two computing devices 600A and 600B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this possible implementation, the memory 630 in computing device 600A stores instructions for executing the functions of the filtering module 120 and the processing module 130. Simultaneously, the memory 630 in computing device 600B stores instructions for executing the functions of the storage module 110.
[0122] Figure 7 The connection method between the computing device clusters shown can be based on the fact that the SQL generation method provided in this application needs to store a large amount of historical query information, so the function implemented by the storage module 110 is to be executed by the computing device 600B.
[0123] It should be understood that Figure 7 The functions of computing device 600A shown can also be performed by multiple computing devices 600. Similarly, the functions of computing device 600B can also be performed by multiple computing devices 600.
[0124] According to the method provided in the embodiments of this application, this application also provides a computer program product, which stores computer program code, and when the computer program code is run on a computer, the computer performs the steps in the embodiments of method 200.
[0125] According to the method provided in the embodiments of this application, this application also provides a computer-readable medium storing program code, which, when run on a computer, causes the computer to perform the steps in the embodiments of the above-described method 200.
[0126] The explanations and beneficial effects of the relevant contents in any of the devices provided above can be found in the corresponding method embodiments provided above, and will not be repeated here.
[0127] It should be understood that the specific process by which each transceiver and processor performs the above-mentioned corresponding steps has been described in detail in the above method embodiments, and will not be repeated here for the sake of brevity.
[0128] In implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, detailed descriptions are omitted here.
[0129] It should be noted that the processor in the embodiments of this application can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method embodiments can be completed by the integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied as execution by a hardware decoding processor, or as a combination of hardware and software modules in the decoding processor. The software modules can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.
[0130] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., high-density digital video discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).
[0131] In the above device embodiments, corresponding modules or units perform corresponding steps. For example, the transceiver unit (transceiver) performs the receiving or sending steps in the method embodiments, while other steps besides sending and receiving can be performed by the processing unit (processor). The function of specific units can be found in the corresponding method embodiments. There can be one or more processors.
[0132] As used in this specification, the terms "component," "module," "system," etc., are used to refer to computer-related entities, hardware, firmware, combinations of hardware and software, software, or software in execution. For example, a component can be, but is not limited to, a process running on a processor, a processor, an object, an executable file, an execution thread, a program, and / or a computer. As illustrated, applications running on computing devices and computing devices can both be components. One or more components may reside in a process and / or an execution thread, and components may be located on a single computer and / or distributed among two or more computers. Furthermore, these components can be executed from various computer-readable media on which various data structures are stored. Components can communicate, for example, via local and / or remote processes based on signals having one or more data packets (e.g., data from two components interacting with another component between a local system, a distributed system, and / or a network, such as the Internet interacting with other systems via signals).
[0133] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0134] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0135] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0136] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0137] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0138] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0139] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for generating a structured query language, characterized in that, include: The system stores historical query information, which includes a first mapping relationship between first information and a first structured query language (SQL) statement. The first information includes questions entered by the user in the past, and the first SQL statement is the correct SQL statement generated in the past corresponding to the questions entered by the user in the past. The historical query information is filtered based on the second information to obtain candidate examples, wherein the second information includes the question currently entered by the user, and the candidate examples include the filtered first mapping relationship, wherein the similarity between the first information and the second information in the filtered first mapping relationship is greater than or equal to a first threshold. Third information is generated based on the second information and the candidate examples, wherein the third information includes the second information and the candidate examples; The second SQL statement corresponding to the second information is generated based on the large language model and the third information, wherein the input of the large language model is the third information and the output of the large language model is the second SQL statement; After obtaining candidate examples, the method further includes: In the candidate examples, a target example is determined, wherein the target example is obtained by filtering the candidate examples based on the differences in SQL statements, and the difference between the SQL statements in the selected target examples is greater than or equal to a second threshold, and / or, if the first information also includes the table schema corresponding to the user's historical input question, and the second information also includes the table schema corresponding to the user's current input question, the target example is obtained by filtering the candidate examples based on the differences in table schemas, and the difference between the table schemas in the selected target examples is greater than or equal to a third threshold; The step of generating third information based on the second information and the candidate examples, wherein the third information includes the question currently entered by the user and the candidate examples, includes: Third information is generated based on the second information and the target example, the third information including the question currently entered by the user and the target example.
2. The method according to claim 1, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, and the filtered first mapping relationship is the mapping relationship between the filtered user historical input questions and the filtered first SQL statement. The step of determining the target example from the candidate examples includes: Based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to the multiple candidate examples, the multiple first SQL statements are filtered to obtain multiple target SQL statements, wherein the difference between the multiple target SQL statements is greater than or equal to a second threshold. Based on the plurality of target SQL statements and the filtered questions of the user's historical input corresponding to each of the plurality of target SQL statements, the plurality of target examples are determined; Each of the plurality of target examples includes a mapping relationship between the filtered user history input questions and the target SQL statement.
3. The method according to claim 1, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, the filtered first mapping relationship being the mapping relationship between the filtered user historical input questions, the table schema corresponding to the filtered user historical input questions, and the filtered first SQL statement. The step of determining the target example from the candidate examples includes: Based on the differences between the multiple table patterns included in the multiple first mapping relationships corresponding to the multiple candidate examples, the multiple table patterns are filtered to obtain multiple target table patterns, and the difference between the multiple target table patterns is greater than or equal to a third threshold. The multiple target examples are determined based on the multiple target table schemas, the filtered user historical input questions corresponding to each of the multiple target table schemas, and the filtered first SQL statement; Each of the plurality of target examples includes: the mapping relationship between the filtered user historical input questions, the filtered target table schema, and the filtered first SQL statement.
4. The method according to claim 1, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, the filtered first mapping relationship being the mapping relationship between the filtered user historical input questions, the table schema corresponding to the filtered user historical input questions, and the filtered first SQL statement. The step of determining the target example based on the candidate examples includes: Based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to the multiple candidate examples, the multiple first SQL statements are filtered to obtain multiple target SQL statements, and the difference between the multiple target SQL statements is greater than or equal to a second threshold. Based on the plurality of target SQL statements, the filtered user historical input questions corresponding to each of the plurality of target SQL statements, and the table schema corresponding to the filtered user historical input questions, the plurality of target examples are determined; Each of the plurality of target examples includes: the filtered questions from the user's historical input, the filtered table schema, and the mapping relationship between the target SQL statements.
5. A data query device, characterized in that, include: Storage module, filtering module, processing module, among which, The storage module is used to store historical query information, which includes a first mapping relationship between first information and a first structured query language (SQL) statement. The first information includes questions entered by the user in the past, and the first SQL statement is the correct SQL statement generated in the past corresponding to the questions entered by the user in the past. The filtering module is used to filter the historical query information according to the second information to obtain candidate examples, wherein the second information includes the question currently entered by the user, and the candidate examples include the first mapping relationship after filtering, wherein the similarity between the first information and the second information in the first mapping relationship after filtering is greater than or equal to a first threshold. The processing module generates third information based on the second information and the candidate examples, wherein the third information includes the second information and the candidate examples; The processing module is used to generate a second SQL statement corresponding to the second information based on the large language model and the third information, wherein the input of the large language model is the third information and the output of the large language model is the second SQL statement; The processing module is used to determine a target example from the candidate examples, wherein the target example is obtained by filtering the candidate examples based on the differences in SQL statements, and the difference between the SQL statements in the selected target examples is greater than or equal to a second threshold, and / or, when the first information also includes the table pattern corresponding to the question input by the user in the past, and the second information also includes the table pattern corresponding to the question input by the user in the present, the target example is obtained by filtering the candidate examples based on the differences in table patterns, and the difference between the table patterns in the selected target examples is greater than or equal to a third threshold; The processing module is used to generate third information based on the second information and the candidate examples, the third information including the question currently input by the user and the candidate examples, including: The processing module is used to generate third information based on the second information and the target example, the third information including the question currently entered by the user and the target example.
6. The data query device according to claim 5, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, and the filtered first mapping relationship is the mapping relationship between the filtered user historical input questions and the filtered first SQL statement. The processing module is used to determine the target example from the candidate examples, including: The processing module is used to filter multiple first SQL statements based on the differences between multiple first SQL statements included in multiple first mapping relationships corresponding to multiple candidate examples, and obtain multiple target SQL statements, wherein the difference between the multiple target SQL statements is greater than or equal to a second threshold. The processing module is used to determine the multiple target examples based on the multiple target SQL statements and the filtered questions of the user's historical input corresponding to each of the multiple target SQL statements; Each of the plurality of target examples includes a mapping relationship between the filtered user history input questions and the target SQL statement.
7. The data query device according to claim 5, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, the filtered first mapping relationship being the mapping relationship between the filtered user historical input questions, the table schema corresponding to the filtered user historical input questions, and the filtered first SQL statement. The processing module is used to determine the target example from the candidate examples, including: The processing module is used to filter the multiple table patterns based on the differences between the multiple table patterns included in the multiple first mapping relationships corresponding to the multiple candidate examples, and obtain multiple target table patterns, wherein the difference between the multiple target table patterns is greater than or equal to a third threshold. The processing module is used to determine the multiple target examples based on the multiple target table patterns, the filtered user historical input questions corresponding to each of the multiple target table patterns, and the filtered first SQL statement; Each of the plurality of target examples includes: the mapping relationship between the filtered user historical input questions, the filtered target table schema, and the filtered first SQL statement.
8. The data query device according to claim 5, characterized in that, The obtained candidate examples include multiple candidate examples, wherein each candidate example includes the filtered first mapping relationship, the filtered first mapping relationship being the mapping relationship between the filtered user historical input questions, the table schema corresponding to the filtered user historical input questions, and the filtered first SQL statement. The processing module is used to determine the target example based on the candidate examples, including: The processing module is used to filter the multiple first SQL statements based on the differences between the multiple first SQL statements included in the multiple first mapping relationships corresponding to the multiple candidate examples, and obtain multiple target SQL statements, wherein the difference between the multiple target SQL statements is greater than or equal to a second threshold. The processing module is used to determine the multiple target examples based on the multiple target SQL statements, the filtered user historical input questions corresponding to each of the multiple target SQL statements, and the table schema corresponding to the filtered user historical input questions; Each of the plurality of target examples includes: the filtered questions from the user's historical input, the filtered table schema, and the mapping relationship between the target SQL statements.
9. The data query device according to claim 5, characterized in that, The data query device is deployed on a cloud server for artificial intelligence (AI) applications.
10. A computing device, characterized in that, It includes a processor and a memory, wherein the processor executes instructions in the memory such that the processor performs the method as described in any one of claims 1 to 4.
11. A computing device cluster, characterized in that, It includes at least one computing device, each computing device including a processor and memory; The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the cluster of computing devices to perform the method as described in any one of claims 1 to 4.
12. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing device cluster, the computing device cluster performs the method as described in any one of claims 1 to 4.
13. A computer-readable storage medium, characterized in that, Includes computer program instructions, which, when executed by a cluster of computing devices, perform the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Question and answer method and system based on table
CN114579600A
Man-machine interaction method, device and equipment based on table data
CN114637765A
Data content searching method and device, computer equipment and readable storage medium
CN115203206A
Complex knowledge base question and answer oriented query graph generation method and system
CN115858723A