Data processing method, computing device, storage medium and program product
By recalling sample pairs from the sample collection and using database description information, combined with large models to generate query statements, the problem of high computational cost of text conversion query statements is solved, efficient and accurate query statement generation is achieved, and the technical threshold and computational cost are reduced. , improving data access efficiency.
Patent Information
- Application Number
- CN202411274009.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-09-11
AI Technical Summary
In the existing technology, the computational cost of converting text into query statements is high, which limits the efficiency of data access. Especially for non-technical personnel, the threshold for self-service data exploration in the database is high.
By obtaining the target query text, recalling sample pairs from the sample set, and combining the database description information, the large model is used to generate the target query statement, which avoids expensive fine-tuning of the large model and reduces the computational cost and technical threshold.
It achieves efficient and accurate text-to-query statement conversion, lowers the technical threshold, enables non-technical personnel to easily conduct self-service data exploration in the database, and improves query efficiency and data utilization.
Smart Images

Figure CN118796982A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of data processing technology, and in particular, to a data processing method, a computing device, a storage medium, and a program product. Background Art
[0002] With the development of big data and cloud computing, text conversion to query statements has gradually become an important research direction in the field of database management and data query. In the era of big data, enterprises have accumulated a large amount of data, and how to effectively use this data to drive decision-making has become crucial. The traditional way of manually writing query statements has a high threshold for non-technical personnel, which limits the efficiency of data use. Therefore, developing the ability to automatically convert text into query statements has become the key to improving data access efficiency.
[0003] The emergence of big model technology makes it possible to use big models to convert text into query statements. However, the conventional implementation method is usually to use training corpus to fine-tune the pre-trained large language model, which makes the current text-to-query statement solution have the problem of high computational cost. Summary of the invention
[0004] The embodiments of the present application provide a data processing method, a computing device, a storage medium, and a program product to solve the technical problem of high computational cost of text conversion query statements in the prior art.
[0005] In a first aspect, an embodiment of the present application provides a data processing method, including: Get the target query text; Recalling at least one sample pair from the sample set, the sample pair comprising a sample query text and a sample query statement corresponding to the sample query text; Determining database description information that matches the target query text; A target query statement corresponding to the target query text is generated using a large model according to the database description information, the at least one sample pair, and the target query text.
[0006] Optionally, recalling at least one sample pair from the sample set includes: At least one sample pair that meets the relevance requirement with the target query text is recalled from the sample set.
[0007] Optionally, recalling at least one sample pair from the sample set includes: From the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs are recalled to obtain a plurality of sample pairs.
[0008] Optionally, recalling, from the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs to obtain a plurality of sample pairs comprises: From the sample set, unrecalled sample pairs whose similarity with the target query text satisfies a similarity condition and whose difference with the recalled sample pairs satisfies a difference condition are recalled to obtain a plurality of sample pairs.
[0009] Optionally, recalling, from the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs to obtain a plurality of sample pairs comprises: For any unrecalled sample pair in the sample set, calculate a first similarity between the target query text and the sample query text in the unrecalled sample pair, and a maximum second similarity with the sample query text in the recalled sample pair, and subtract the maximum second similarity from the first similarity to obtain a similarity difference; The unrecalled sample pairs with the largest similarity difference are recalled.
[0010] Optionally, recalling, from the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs to obtain a plurality of sample pairs comprises: For any unrecalled sample pair in the sample set, calculate the first similarity between the target query text and the sample query text in the unrecalled sample pair, and the maximum second similarity with the sample query text in the recalled sample pair, and find the sample pair that maximizes the first similarity and minimizes the maximum second similarity for recall.
[0011] Optionally, the determining of the database description information matching the target query text includes: Identify entities and attributes involved in the target query text; According to the entity and the attribute, the hit database description information is queried.
[0012] Optionally, the generating a target query statement corresponding to the target query text by using a large model according to the database description information, the at least one sample pair, and the target query text comprises: Generate prompt information according to a prompt template by using the database description information, the target query text and the at least one sample pair; The prompt information is input into a large model, so as to utilize the large model to perform context learning from the at least one sample pair, and to generate a query statement corresponding to the target query text based on the database description information.
[0013] Optionally, it also includes: The target query text and the target query sentence are taken as a sample pair and added to the sample set.
[0014] Optionally, recalling at least one sample pair from the sample set includes: Performing clustering processing on the sample set to obtain multiple sample combinations; At least one sample pair whose similarity with the target query text meets a similarity condition is recalled from the multiple sample combinations respectively.
[0015] Optionally, obtaining the target query text includes: Obtain the target query text submitted by the user; After generating the target query statement, the method further includes: Execute the target query statement to obtain a query result, and notify the user of the query result; or notify the user of the target query statement.
[0016] Optionally, obtaining the target query text includes: Obtain the target query voice submitted by the user; The target query speech is recognized to obtain a corresponding target query text.
[0017] In a second aspect, an embodiment of the present application provides a computing device, comprising a processing component and a storage component; the storage component stores one or more computer instructions; the one or more computer instructions are used to be called and executed by the processing component to implement the data processing method described in the first aspect above.
[0018] In a third aspect, an embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processing component, the data processing method described in the first aspect above is implemented.
[0019] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program / instructions, which, when executed by a processing component, implements the data processing method described in the first aspect above.
[0020] In the embodiment of the present application, a target query text is obtained; at least one sample pair is recalled from a sample set, the sample pair including a sample query text and a sample query statement corresponding to the sample query text; database description information matching the target query text is determined; and a target query statement corresponding to the target query text is directly generated using an existing large model based on the database description information, at least one sample pair, and the target query text. In this process, by obtaining the target query text, the query requirements can be accurately captured, providing a basis for the subsequent construction of the query statement. By recalling at least one sample pair from the sample set, the existing sample pairs can be used as context information to guide the generation of target query statements, thereby increasing diversity and coverage on the basis of ensuring relevance, making the recall results more comprehensive, ensuring the quality of the recalled sample pairs while taking into account the recall efficiency; by determining the database description information that matches the target query text, it is ensured that the large model can understand the database structure to improve the accuracy of the generated target query statement; based on the database description information, at least one sample pair, and the target query text, the existing large model is directly used to generate the target query statement corresponding to the target query text. By combining the sample pairs, the target query text and the database description information, the large model is used to generate accurate and effective query statements, which not only fully utilizes the powerful generation ability of the large model and ensures that the generated query statement is both accurate and efficient, but more importantly, this method avoids the expensive fine-tuning process of the large model and greatly reduces the computing cost and technical threshold.
[0021] These and other aspects of the present application will become more clearly understood in the description of the following embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0023] Figure 1 A flow chart showing an embodiment of a data processing method provided by the present application is shown; Figure 2 A schematic diagram showing the interaction between the user end and the server end in a data processing scenario provided by the present application is shown; Figure 3 The following is a schematic diagram showing the interaction of the server provided by the present application in a data processing scenario; Figure 4 A schematic diagram showing the structure of an embodiment of a data processing device provided by the present application is shown; Figure 5A schematic diagram of the structure of a computing device provided by the present application is shown. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0025] In some of the processes described in the specification and claims of this application and the above-mentioned figures, multiple operations that appear in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this article or executed in parallel. The serial numbers of the operations, such as 101, 102, etc., are only used to distinguish between different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this article are used to distinguish different messages, devices, modules, etc., do not represent the order of precedence, and do not limit the "first" and "second" to be different types.
[0026] The technical solutions of the embodiments of the present application can be applied to the fields of database management and data query, such as query construction of data analysis systems and self-service data exploration by non-technical users, and other application scenarios.
[0027] As described in the background technology, traditional data query methods usually rely on technicians to manually write query statements or use fixed query templates to access data, but this method has the problem of low access efficiency. For non-technical personnel, due to their lack of necessary technical knowledge, they still have a high threshold to realize self-service data exploration of the database, which will cause the problem of low database utilization efficiency. Therefore, in order to connect human language with the query language of the database, facilitate users to query the database without manually writing query statements, the technology of converting text (Text) into query statements has emerged, such as Text-to-SQL (abbreviated as: Text2SQL) technology that converts text into SQL (Structured Query Language) statements. Although technologies that use large language models to convert text to query statements have emerged in recent years, these technologies often require a large amount of training data and high computing resources to fine-tune the model, making their implementation and maintenance costs very high.
[0028] In order to overcome the limitations of the above scheme, the inventor proposed a new solution, which can achieve efficient conversion of text to query statements without additional fine-tuning of the existing large model, and enable non-technical personnel to easily realize self-service data exploration of the database, thereby not only reducing the computational cost of converting text to query statements, but also lowering the technical threshold, and improving data utilization and query efficiency.
[0029] The technical solution of the embodiment of the present application includes: obtaining a target query text; recalling at least one sample pair from a sample set, the sample pair including a sample query text and a sample query statement corresponding to the sample query text; determining database description information that matches the target query text; and directly using an existing large model to generate a target query statement corresponding to the target query text based on the database description information, at least one sample pair, and the target query text. In this process, by obtaining the target query text, the query requirements can be accurately captured, providing a basis for the subsequent construction of the query statement. By recalling at least one sample pair from the sample set, the existing sample pairs can be used as context information to guide the generation of target query statements, thereby increasing diversity and coverage on the basis of ensuring relevance, making the recall results more comprehensive, ensuring the quality of the recalled sample pairs while taking into account the recall efficiency; by determining the database description information that matches the target query text, it is ensured that the large model can understand the database structure to improve the accuracy of the generated target query statement; based on the database description information, at least one sample pair, and the target query text, the existing large model is directly used to generate the target query statement corresponding to the target query text. By combining the sample pairs, the target query text and the database description information, the large model is used to generate accurate and effective query statements, which not only fully utilizes the powerful generation ability of the large model and ensures that the generated query statement is both accurate and efficient, but more importantly, this method avoids the expensive fine-tuning process of the large model and greatly reduces the computing cost and technical threshold.
[0030] The technical solution of the embodiment of the present application not only simplifies the process of converting text to query statements and lowers the technical threshold, so that users without database expertise can easily obtain complex and accurate query statements, so as to subsequently obtain corresponding query results based on the query statements, but also significantly improves the flexibility and accuracy of the query process and enhances the user experience.
[0031] It should be noted that the embodiments of the present application may involve the use of user data. In actual applications, user-specific personal data can be used in the scheme described in this article within the scope permitted by applicable laws and regulations, subject to the requirements of applicable laws and regulations of the country where the user is located (for example, with the user's explicit consent, effective notification to the user, etc.).
[0032] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0033] It should be noted that the technical solution of the embodiment of the present application is applicable to a network virtual environment. The users described generally refer to "virtual users". Real users can register a user account in the server through registration to obtain a user identity in the network environment.
[0034] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0035] Figure 1 This is a flowchart of an embodiment of a data processing method provided in an embodiment of the present application. In a practical application, the technical solution of the embodiment of the present application can be applied to a system architecture composed of a user end and a server end. The user end can interact with the server end through a network to receive or send messages, etc. The technical solution of this embodiment can be executed by the server end.
[0036] The user end may be a browser, an APP (Application), or a web application such as an H5 (HyperText Markup Language 5) application, a light application (also known as a mini-program, a lightweight application), or a cloud application, etc. The user end may be deployed in electronic devices that support functions such as information browsing, such as personal mobile terminals (such as mobile phones, tablet computers), personal computers, desktop computers, smart speakers, smart watches, etc.
[0037] The server may include servers that provide various services, such as a server that generates query statements and a server that executes query statements. For example, after receiving the target query text sent by the client, the server may call the big model to generate the corresponding query statement, and then call the database to execute the query statement to obtain the query result. Furthermore, the server may also notify the client of the query result; or directly notify the client of the query statement for further operation or confirmation by the user of the client.
[0038] The server side can be implemented as a distributed server cluster consisting of multiple servers or as a single server. The server can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, or an intelligent cloud computing server or intelligent cloud host with integrated artificial intelligence technology.
[0039] Figure 1 The method of the illustrated embodiment may include the following steps: 101: Get the target query text.
[0040] The target query text obtained may be a target query text submitted by a user. Obtaining the target query text submitted by a user is the starting point of the entire data processing flow. Optionally, the server may obtain a query request provided by a user sent by a user, and the query request may include the target query text, wherein the target query text is the query intention that the user wishes to express through natural language, for example: "Search for products with sales performance exceeding 1 million in the first quarter of this year".
[0041] In combination with the above description, it can be seen that the user end can be implemented as a browser, an application, or a web application such as an H5 application, or a light application or a cloud application, etc. Therefore, optionally, the method of submitting the target query text by the user may include but is not limited to: the query text entered by the user through a web application, an application, a light application, a cloud application, or any application that can receive user input and send a request to the server.
[0042] The user may directly provide the target query text. Furthermore, in order to further improve the user experience, obtaining the target query text may include: obtaining the target query voice submitted by the user, recognizing the target query voice to obtain the corresponding target query text.
[0043] In addition, in order to facilitate users to provide target query texts, multiple predefined query templates can also be provided to the user end. The user can select a template that is closest to his or her needs from the predefined multiple query templates, and then modify it to meet his or her own query requirements to generate the target query text. Alternatively, the server end can analyze the query texts submitted by the user in the past, identify the multiple query texts generated by the user's intention, and send the multiple query texts to the user end, so that the user can select the target query text from the multiple query texts according to the needs.
[0044] Of course, in addition to obtaining the target query text provided by the user, the target query text may also be obtained by other means, which is not limited in the embodiments of the present application.
[0045] It should be noted that after obtaining the target query text submitted by the user, the server can perform preliminary verification on the input target query text to ensure that its format is correct and does not contain illegal characters. In addition to the verification function, the server can also provide an intelligent prompt function, that is, the server can predict the user's intention based on the partial text entered by the user and provide possible content options to encourage the user to determine the target query text more quickly. In addition, the intelligent prompt function can also provide clear error messages to guide the user to correct the input when the target query text entered by the user does not conform to the expected format.
[0046] Through the above description, obtaining the target query text can be a comprehensive process covering multiple aspects such as user interaction, data processing, etc. Such a design is intended to ensure that users can submit query requests conveniently and prepare for the subsequent acquisition of query statements corresponding to the target query text.
[0047] 102: Recall at least one sample pair from the sample set.
[0048] The sample set includes multiple sample pairs, each of which includes a sample query text and a sample query statement corresponding to the sample query text. The sample pairs can be used as examples of input and output of the large model so that the large model can learn the conversion rules between the sample query texts in the recalled sample pairs and the sample query statements corresponding to the sample query texts, so as to more accurately generate the target query statement corresponding to the target query text in the subsequent step, wherein the query statement is implemented in a database query language, such as an SQL statement, etc., which can refer to a specific instruction or code snippet constructed using a query statement in order to obtain specific information from a database.
[0049] Optionally, the sample set may be constructed by professional technicians pre-writing representative sample query texts and their corresponding sample query statements, etc., which is not limited in this application.
[0050] For example, a database containing book information can be constructed by professional technicians by pre-writing representative sample pairs to form a sample set, which includes query texts that users may ask for the database and query statements corresponding to these query texts. The following provides an example of multiple sample pairs that the sample set may contain: Sample pair 1: Sample query text: "Find all books published in 2023"; Sample query: SELECT * FROM books WHERE publication_year = 2023; Sample pair 2: Sample query text: "List all works whose author is Jane Smith"; Sample query: SELECT * FROM books WHERE author = 'Jane Smith'; Sample pair 3: Sample query text: "Show novels published within the last year"; Sample query: SELECT * FROM books WHERE publication_year >= YEAR(CURRENT_DATE) - 1 AND genre = 'Novel'.
[0051] After the target query text is obtained, at least one sample pair may be recalled from the sample set, wherein the recall may be implemented in a variety of ways, which will be described in detail in the following embodiments.
[0052] 103: Determine database description information that matches the target query text.
[0053] In this step, the database description information that matches the target query text can be determined so that an accurate target query statement can be generated later.
[0054] Among them, the database description information may include table description information of the data tables in the database and field description information of the fields in the data tables, etc. The table description information may include, for example, the table name, included fields, foreign keys, primary keys, table comment information, table relationship information, etc., and may also include index information, views and / or constraints and other information.
[0055] Among them, table relationship information can refer to the relationship between a data table and other data tables stored in the database; table relationship information can include, for example, table association, table lineage, field lineage, lineage path information, etc. Table association refers to the connection between different data tables, such as a record in a data table is associated with a record in another data table. The association relationship is usually established by associating a foreign key in one data table with a primary key in another data table. For example, there is a customer ID (identification) field in the order table, which references the primary key ID in the customer table; table lineage refers to the lineage at the table granularity, indicating the source data table and target data table involved in the data flow process; field lineage refers to the lineage at the field granularity, indicating the fields in the source data table and the fields in the target data table involved in the data flow process; lineage path information can refer to the data tables involved in the data flow process, the flow order, the path depth, etc. In addition, table relationship information may also include inclusion relationships, transformation relationships, dependency relationships, aggregation relationships and / or derivation relationships of tables or fields. An inclusion relationship may refer to a field or record in a data table being part of a field or record in another data table. For example, an order table contains information in an order detail table, and each record in the order detail table corresponds to a specific order. A transformation relationship may refer to the change that occurs in the process of data from one data table or field to another. A dependency relationship describes the situation in which a field or data table depends on another field or data table. This dependency may be logical or formed during the data processing process. An aggregation relationship describes how to aggregate data from multiple data tables into one data table. For example, a sales overview table may aggregate data from multiple sales detail tables. A derivation relationship refers to the fact that data in a field or data table is calculated based on data in other fields or data tables.
[0056] In an optional manner, the database description information may adopt the Scheme (data model information) of the database, or of course, may also be some specified type of description data collected or generated based on data tables and field data in the database.
[0057] Database description information can help the large model understand the data structure, clarify the data table where the field is located and its data type, reduce ambiguity, and process complex queries and construct correct query statements based on the association and blood relationship between tables.
[0058] Among them, all database description information can be used as database description information matching the target query text; of course, the database description information matching the target query text can also be determined based on intent recognition in the target query text, which will be introduced in detail in the following embodiments.
[0059] 104: Generate a target query statement corresponding to the target query text using the large model according to the database description information, at least one sample pair, and the target query text.
[0060] Among them, a large model refers to a machine learning model with a large number of parameters and complex structure, which can process massive data and complete various complex tasks, such as natural language processing, computer vision, speech recognition, etc. It is an AI (Artificial Intelligence) model. Among them, the large model can be implemented by a large language model (Large Language Model, LLM) or a multimodal large model (Multimodal Large Model, MLM), etc. For example, GPT-3 (Generative Pre-Trained Transformer -3, the third generation of generative pre-training model), GPT-4 (Generative Pre-Trained Transforme-4, the fourth generation of generative pre-training model), BERT (Bidirectional Encoder Representation from Transformers, a bidirectional encoder model based on Transformers), Turing NLG (Turing Natural language Generation, Turing Natural Language Generation), etc. This application does not limit this. This type of large model can perform well in various natural language processing tasks, such as text generation, text translation, question-answering systems, etc. Of course, in addition to large language models, there are many other types of large models.
[0061] Optionally, based on database description information, at least one sample pair, and target query text, using a big model to generate a target query statement corresponding to the target query text may include: generating prompt information according to a prompt template based on the database description information, the target query text, and at least one sample pair; inputting the prompt information into the big model to use the big model to perform context learning from at least one sample pair, and generate a query statement corresponding to the target query text based on the database description information.
[0062] Prompt is a form of input used to prompt or guide the big model to give expected output. Prompt is a natural language input, similar to a command or instruction, to let the big model know what it needs to do.
[0063] In the embodiment of the present application, in order to facilitate the generation of prompt information, a prompt template can be pre-configured, and the database description information, at least one sample pair and the target query text can be added to the prompt template to generate the corresponding prompt information.
[0064] Among them, the prompt template usually contains the following parts: Database description information: presented in an easily understandable format, for example, it may be the example of “database description information” provided in the above embodiment.
[0065] Sample pair: An example showing how to convert natural language text into a query statement. For example, a sample pair is: sample query text: "Find all books published in 2023", sample query statement: SELECT * FROM books WHEREpublication_year = 2023.
[0066] Target query text: the query question raised by the user. For example, the query question is: "What is the sales volume of A in 2023?" Furthermore, after the prompt information is input into the big model, the big model learns how to convert natural language text into query statements based on the provided sample pairs, and then generates a target query statement based on the provided prompt information, and the query statement can extract the specific information required by the user from the database.
[0067] For example, the large model generates the following target query statement: SELECT product, year, quantity FROMsales WHERE product = 'A' AND year = 2023; In this embodiment, by learning sample pairs, the large model can accurately capture the user's intention to generate a correct query statement. By learning database description information, the large model can generate suitable query statements according to different database structures to ensure that the generated query statements can correctly access the database.
[0068] In the technical solution provided in the embodiment of the present application, by determining the database description information that matches the target query text, it is ensured that the big model can understand the database structure to improve the accuracy of the generated target query statement; according to the database description information, at least one sample pair, and the target query text, the existing big model is directly used to generate the target query statement corresponding to the target query text, and by combining the sample pairs, the target query text and the database description information, the big model is used to generate accurate and effective query statements, which not only fully utilizes the powerful generation capability of the big model, ensuring that the generated query statements are both accurate and efficient, but more importantly, this method avoids the expensive fine-tuning process of the big model, greatly reducing the computing cost and technical threshold.
[0069] In some possible implementations, the method of recalling at least one sample pair from the sample set may be to randomly select at least one sample pair from the sample set. In addition, in order to improve accuracy, some other possible implementations are provided below to facilitate understanding of how to recall at least one sample pair from the sample set.
[0070] In some embodiments, recalling at least one sample pair from the sample set may include: recalling at least one sample pair from the sample set that meets a relevance requirement with the target query text.
[0071] The following possible implementation methods may be included for “recalling at least one sample pair that meets the relevance requirement with the target query text”: As a possible implementation method, at least one sample pair whose similarity with the target query text satisfies a similarity condition may be recalled from the sample collection.
[0072] The similarity condition may be, for example, selecting a certain number of sample pairs in descending order of similarity; or the similarity condition may be that the similarity is greater than a similarity threshold, etc.
[0073] In practical applications, for example, the K-Nearest Neighbors (KNN) algorithm can be used to recall K sample pairs that meet the similarity requirements with the target query text from the sample set.
[0074] Among them, KNN is a distance-based similarity measurement method used to find a certain number of sample pairs that are most similar to a given target query text.
[0075] In this implementation, first, the sample query text and its corresponding sample query statement can be converted into a vector form, usually using word embedding (such as word vector (Word2Vec), BERT, etc.) or other text representation technology. Secondly, the target query text can also be converted into a vector form, and the similarity between the vector corresponding to the target query text and the vector corresponding to each sample query text in the sample set is calculated (for example, cosine similarity, Euclidean distance, etc.), so as to select a sample pair corresponding to at least one sample query text that meets the similarity condition with the target query text as the recall result.
[0076] As another possible implementation method, the sample set may be clustered to obtain multiple sample combinations; and at least one sample pair whose similarity with the target query text meets a similarity condition is recalled from each of the multiple sample combinations.
[0077] The sample set can be clustered by a clustering algorithm. For example, the clustering algorithm can use K-means clustering (K-means), density-based spatial clustering algorithm (Density-Based Spatial Clustering of Applications with Noise, DBSCAN), hierarchical clustering (Hierarchical Clustering, HC), etc., to divide the sample set into multiple clusters, so that multiple sample pairs in the same cluster have a higher similarity, while sample pairs in different clusters have a lower similarity.
[0078] The embodiment of the present application is explained by taking the clustering algorithm including the K-means clustering algorithm as an example. First, the number of clusters k needs to be determined in advance. That is, in this implementation, first, the sample set is divided into k clusters through the clustering algorithm so that the sample pairs in each cluster have a high similarity. Secondly, for each cluster, the similarity between the sample query text and the target query text in all sample pairs in the cluster is calculated in turn. If the similarity between a sample pair in the cluster and the target query text is higher than the similarity threshold, the sample pair is recalled or a predetermined number of sample pairs are selected for recall in descending order of similarity. The final recall result includes sample pairs in all clusters whose similarity to the target query text meets the similarity condition.
[0079] The clustering algorithm can be used to divide the sample set into multiple sample sets, and sample pairs can be recalled from each sample set to ensure the diversity of sample pairs. In addition, sample pairs can be recalled from each sample set according to similarity to ensure the relevance of sample pairs.
[0080] As another possible implementation method, in order to further ensure that at least one sample pair takes into account both relevance and diversity, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs may be recalled from the sample set to obtain multiple sample pairs.
[0081] Among them, relevance can be measured by similarity, and irrelevance can be measured by difference. Therefore, as an optional method, multiple sample pairs can be obtained in the following manner: from the sample set, unrecalled sample pairs that are related to the target query text and irrelevant to the recalled sample pairs are recalled to obtain multiple sample pairs, which may include: from the sample set, unrecalled sample pairs whose similarity to the target query text meets the similarity condition and whose difference with the recalled sample pairs meets the difference condition, to obtain multiple sample pairs.
[0082] This process aims to ensure that the recalled sample pairs are both relevant to the target query text and different from the recalled sample pairs, so as to improve the diversity and relevance of the recalled sample pairs.
[0083] In this implementation, similarity conditions are used to ensure that the recalled sample pairs are sufficiently similar to the target query text, and difference conditions are used to ensure that the newly recalled sample pairs are sufficiently different from the recalled sample pairs.
[0084] Similarity can be achieved, for example, by calculating cosine similarity or Euclidean distance, and the similarity condition can be, for example, the maximum similarity, and the difference can be obtained, for example, from the similarity calculation result, for example, the similarity is cosine similarity s, and the difference can be 1-s, etc. For example, the difference can also be achieved through Euclidean distance, the larger the Euclidean distance, the greater the difference, and the difference condition can be, for example, the maximum difference.
[0085] As another alternative, multiple sample pairs can be obtained as follows: For each unrecalled sample pair in the sample set, calculate the first similarity between the target query text and the sample query text of the sample pair, and the maximum second similarity with the sample query text in the recalled sample pairs, and find the sample pair that maximizes the first similarity and minimizes the maximum second similarity for recall. The above steps can be repeated until a certain number of sample pairs are obtained.
[0086] As another alternative, multiple sample pairs may be obtained as follows: For each unrecalled sample pair in the sample set, calculate the first similarity between the target query text and the sample query text of the sample pair, and the maximum second similarity with the sample query text in the recalled sample pair; calculate the similarity difference between the first similarity and the maximum second similarity, and select the sample pair with the largest similarity difference for recall. The above steps can be repeated until a certain number of sample pairs are obtained or the similarity difference is lower than a certain threshold.
[0087] The following is an example to illustrate the options mentioned above: Assume that the data is obtained as follows: Target query text Q: "Query the salary of all employees"; The sample set R contains the following sample pairs: D1: "Query the names and positions of all employees" and the corresponding query statement; D2: "Query the salary and bonus of all employees" and the corresponding query statement; D3: "Query the department numbers of all employees" and the corresponding query statement; Assume that the sample pair D1 has been recalled, and the first similarity between the target query text Q and the sample query text in the recalled sample pair D1, the first similarity between the target query text Q and the sample query text in the unrecalled sample pair (D2, D3), and the second similarity between the sample query text in the unrecalled sample pair (D2, D3) and the sample query text in the recalled sample pair D1 are calculated as follows: (D1,Q)=0.5, indicating that the first similarity between the recalled sample pair D1 and the target query Q is 0.5; (D2,Q)=0.8, indicating that the first similarity between the unrecalled sample pair D2 and the target query Q is 0.8; (D3,Q)=0.2, indicating that the first similarity between the unrecalled sample pair D3 and the target query Q is 0.2; (D2, D1) = 0.4, indicating that the second similarity between the unrecalled sample pair D2 and the recalled sample pair D1 is 0.4; (D3, D1) = 0.3, indicating that the second similarity between the unrecalled sample pair D3 and the recalled sample pair D1 is 0.3; In the above optional scheme of "finding a sample pair with the maximum first similarity and the minimum maximum second similarity for recall", it is necessary to find a sample pair with the maximum first similarity and the minimum maximum second similarity among the unrecalled sample pairs (D2, D3). From the above data, it can be determined that the first similarity between the unrecalled sample pair D2 and the target query Q is 0.8, and the second similarity between the unrecalled sample pair D2 and the recalled sample pair D1 is 0.4 (it should be noted that if the recalled sample pair is not limited to D1, it is also necessary to calculate the second similarities between other recalled sample pairs and the unrecalled sample pair D2, so as to determine the maximum second similarity between the unrecalled sample pair D2 and the recalled sample pair); the first similarity between the unrecalled sample pair D3 and the target query Q is 0.2, and the second similarity between the unrecalled sample pair D3 and the recalled sample pair D1 is 0.3.
[0088] By comparing the first similarity data between the unrecalled sample pair D2 and the target query Q with the first similarity data between the unrecalled sample pair D3 and the target query Q, it can be determined that the first similarity of the unrecalled sample pair D2 is much greater than the first similarity of the unrecalled sample pair D3, while its maximum second similarity is only slightly smaller than the maximum second similarity of the unrecalled sample pair D3. Therefore, it can be determined that the next recalled sample pair is D2.
[0089] In the above optional scheme of "calculating the similarity difference of the first similarity minus the maximum second similarity, and selecting the sample pair with the largest similarity difference for recall", it can be determined from the above data that for the unrecalled sample pair D2, its first similarity with the target query Q is 0.8, and its second similarity with the recalled sample pair D1 is 0.4; for the unrecalled sample pair D3, its first similarity with the target query Q is 0.2, and its second similarity with the recalled sample pair D1 is 0.3. Therefore, for each unrecalled sample pair (D2, D3), calculate its corresponding similarity difference as follows: Similarity difference (D2) = 0.8 − 0.4 = 0.4; Similarity difference (D3) = 0.2 − 0.3 = − 0.1; Therefore, the next recalled sample pair can be determined to be D2.
[0090] Optionally, an embodiment of the present application can be used according to the following recall formula to implement, for any unrecalled sample pair in the sample set, calculating the first similarity between the target query text and the sample query text in the unrecalled sample pair, and the maximum second similarity with the sample query text in the recalled sample pair, and subtracting the maximum second similarity from the first similarity to obtain the similarity difference and recalling the unrecalled sample pair with the largest similarity difference.
[0091] The recall formula can be specifically as follows: ; Where Di represents the i-th sample pair that has not been recalled, Q represents the target query text, R represents the sample set of the unrecalled sample pairs, which can be a sample set whose similarity with the target query text meets the similarity condition, and S represents the sample set of the recalled sample pairs. It is represented as the similarity score between Di and Q, that is, the first similarity, and Dj is represented as the jth sample pair recalled in S. It is expressed as the similarity score between Di and the jth sample pair in S, that is, the second similarity, Represented as a weight parameter to balance similarity and differences The contribution between.
[0092] The purpose of this formula is to select a sample pair Di from the sample set R of unrecalled sample pairs so that the similarity between the sample pair Di and the target query text Q is as high as possible, and the similarity with the sample set S of recalled sample pairs is as low as possible.
[0093] In the above formula, It is expressed as the first similarity between Di and the target query text Q, multiplied by the weight factor ; It is expressed as the maximum second similarity between Di and all sample pairs in the sample set S of the recalled sample pairs, multiplied by the weight factor (1- ). It is expressed as the similarity difference between the first similarity between Di and the target query text Q and the maximum second similarity between Di and all sample pairs in the sample set S of the recalled sample pairs.
[0094] This formula can be used to select the next sample pair from the unrecalled sample set to increase the diversity and relevance of the recall results. Specifically: This formula is used to find the sample pair with the largest similarity difference, that is, by maximizing the first similarity , to ensure that the similarity between the newly recalled sample pairs and the target query text Q is as high as possible, while minimizing the maximum second similarity , to ensure that the similarity between the newly recalled sample pairs and the recalled sample pairs S is as low as possible, so as to ensure that the similarity between the recalled sample pairs and the target query text meets the similarity condition while ensuring the diversity and uniqueness of the recalled sample pairs.
[0095] Here is a specific example: Assume there is a target query text Q and a sample set S of recalled sample pairs. It is hoped to select a sample pair Di from the sample set R of unrecalled sample pairs. The most appropriate Di is selected by using the above recall formula: First, for each Di∈R: calculate ; For each Dj∈S, calculate And select the maximum value; Second, use the weight factor To balance the similarity and differences , to select the expression The biggest land.
[0096] In this way, it can be ensured that the selected sample pairs are highly relevant to the target query text and are different from the recalled sample pairs.
[0097] It should be noted that, through one or a combination of the above-mentioned possible implementation methods, sample pairs that are relevant to the target query text and have diversity can be selected from the sample set to ensure that the recalled sample pairs are not only relevant to the target query text, but also have sufficient differences from each other, thereby increasing the diversity of the sample pairs. And through the above detailed description, it can be seen that recalling sample pairs from the sample set is a complex process, involving the selection of multiple technologies (such as K-means, etc.), the selection of these technologies depends on the characteristics of the specific application scenario, and can be determined according to actual needs.
[0098] In some embodiments, determining the database description information that matches the target query text includes: identifying entities and attributes involved in the target query text; and querying the matched database description information according to the entities and attributes.
[0099] Among them, the method of identifying the entities and attributes involved in the target query text can use natural language processing (NLP) technology, such as named entity recognition (NER), dependency syntax analysis, etc., to identify the entities and attributes in the target query text. In an embodiment of the present application, an entity may refer to a key object mentioned in the target query text. For example, in the target query text "What is the sales volume of A in 23 years", "A" is an entity, where A may refer to a certain brand of goods. An entity can generally correspond to a record in a database table or the data table itself. For example, in a book database, "book", "author" and "publisher" can all be regarded as entities.
[0100] Attributes can refer to characteristics related to an entity. For example, in the target query text "What is the sales volume of A in 23 years", "time (23 years)" and "sales volume" are attributes related to entity "A". Attributes can usually correspond to columns in a data table, that is, fields.
[0101] Furthermore, after identifying the entities and attributes involved in the target query text, the hit database description information can be queried according to the entities and attributes.
[0102] It can be to associate entities with table names in the database and to associate attributes with field names in the database. For example, suppose there is a database table named "A", which contains the sales data of "A", the column names of inventory quantity, time, etc., that is, it includes fields such as "year" and "quantity". According to the entity "A", it can be associated with the "A_clothing_sales" table, and according to the attributes "time" and "sales volume", it can be associated with the "year" and "quantity" fields in the "A" table. Therefore, the matched table description information can be determined according to the table name and the matched field description information can be determined according to the field name. The matched table description information and field description information can be used as the hit database description information.
[0103] Here is a specific example: Assume that the input target query text is: "What is the sales volume of A in 23 years?". After identifying the table name "A_clothing_sales" and the attributes "year" and "quantity" involved in the target query text, the matching table description information is determined according to the table name and the matching field description information is determined according to the field name, and the following database description information is obtained: <Table name: "A_clothing_sales"[Product sales details] Fields: 'year' [year] [int], 'product_name' [product name] [varchar(50)], 'quantity' [sales] int, 'price' [price] float, 'color' [color] [varchar(50)], 'size' [size] [varchar(10)] Primary Key: 'year' and 'product_name' Foreign key: 'quantity' references the product inventory table Note: 'year' indicates the year, 'product_name' indicates the product name, 'quantity' indicates the sales volume of the year, 'price' indicates the price of each product, 'color' indicates the color of the product, and 'size' indicates the size of the product. Relationship: 'year' and 'product_name' form a composite primary key, 'quantity' is a foreign key that references the product inventory table in another table Field description information: 'year': year [int], indicating the year 'product_name': Product name [varchar(50)], indicating the product name 'quantity': sales volume [int], indicating the sales volume for that year 'price': price [float], indicating the price of each item 'color': Color [varchar(50)], indicating the color of the product 'size': size [varchar(10)], indicating the size of the product Table description information: A_clothing_sales: A product sales details table, including year, product name, sales volume, price, color and size, etc. Primary key: composed of year and product name Foreign key: Sales volume references the product inventory table Blood relationship: Year and product name together constitute the primary key, and sales volume is used as a foreign key to reference the product inventory table. By obtaining the above database description information and generating query statements through the database description information, sample pairs and target query objects, it is ensured that the generated query statements can comply with the requirements of the database while also meeting the needs of accurately executing the target query text.
[0104] It should be noted that in addition to identifying entities and attributes in the target query text, operations (such as sorting, filtering, etc.) in the target query text can also be further identified. Operations refer to actions performed on entities and attributes, usually to obtain specific information or results. Operations can correspond to database operations such as select (SELECT), filter (WHERE), sort (ORDER BY), group (GROUP BY) and other SQL commands. The large model can generate the corresponding target query statement based on the operations in the target query text.
[0105] The following is a specific example of the complete data processing process: When the target query text "What is the sales volume of A in 23 years?" is input, at least one sample pair is recalled from the sample set, and after the database description information matching the target query text is determined, the following prompt information is generated according to the database description information, the at least one sample pair, and the target query text: {Given the following sample pairs and database description information, please combine the sample pairs to generate the SQL statement corresponding to the query text.
[0106] Sample query text: "What is the sales volume of product A in each quarter in 2023?" Sample query: SELECT EXTRACT(QUARTER FROM sale_date) AS quarter, SUM(quantity) AS total_sales FROM sales WHERE YEAR(sale_date) = 2023 AND product_code = 'A' GROUP BY quarter; Sample query text: "What is the average sales volume of product A in each month in 2023?" Sample query: SELECT EXTRACT(MONTH FROM sale_date) AS month, AVG(quantity) AS avg_sales FROM sales WHERE YEAR(sale_date) = 2023 AND product_code = 'A' GROUP BY month; Sample query text: "By what percentage did the sales volume of product A increase in 2023 compared to 2022?" Sample query statement: SELECT ((SUM(sales_2023.quantity) - SUM(sales_2022.quantity)) / SUM(sales_2022.quantity)) * 100 AS growth_percentage FROM ( SELECT SUM(quantity) AS quantity FROM sales WHERE YEAR(sale_date) = 2023 AND product_code = 'A' ) AS sales_2023, ( SELECT SUM(quantity) AS quantity FROM sales WHERE YEAR(sale_date) = 2022 AND product_code = 'A' ) AS sales_2022; Database description information: <Table name: "A_clothing_sales"[Product sales details] Fields: 'year' [year] [int], 'product_name' [product name] [varchar(50)], 'quantity' [sales] int, 'price' [price] float, 'color' [color] [varchar(50)], 'size' [size] [varchar(10)] Primary Key: 'year' and 'product_name' Foreign key: 'quantity' references the product inventory table Note: 'year' indicates the year, 'product_name' indicates the product name, 'quantity' indicates the sales volume of the year, 'price' indicates the price of each product, 'color' indicates the color of the product, and 'size' indicates the size of the product. Relationship: 'year' and 'product_name' form a composite primary key, 'quantity' is a foreign key that references the product inventory table in another table Field description information: 'year': year [int], indicating the year 'product_name': Product name [varchar(50)], indicating the product name 'quantity': sales volume [int], indicating the sales volume for that year 'price': price [float], indicating the price of each item 'color': Color [varchar(50)], indicating the color of the product 'size': size [varchar(10)], indicating the size of the product Table description information: A_clothing_sales: A product sales details table, including year, product name, sales volume, price, color and size, etc. Primary key: composed of year and product name Foreign key: Sales volume references the product inventory table Blood relationship: Year and product name together constitute the primary key, and sales volume is used as a foreign key to reference the product inventory table. Target query text: What is the sales volume of A in 2023? } After the above prompt information is input into the large model, the large model will output the following content: "Target query statement: SELECT product, year, quantity FROM sales WHERE product= 'A' AND year = 2023;" In some embodiments, the method may further include: adding the target query text and the target query sentence as a sample pair to the sample set.
[0107] In this embodiment, after the target query statement for the target query text is generated by the large model, the server can also add the pair of query text and query statement as a new sample pair to the sample collection. Adding new sample pairs can help the model better understand and handle different query scenarios, especially when facing new database structures or query requirements.
[0108] In some embodiments, after generating the target query statement, the method further includes: executing the target query statement to obtain a query result, and notifying the user of the query result.
[0109] In this embodiment, the server not only generates target query statements for the target query text by calling the large model, but also further calls the database to execute these query statements to obtain query results and send the query results to the user of the client.
[0110] Here is a specific example: Suppose you are building an application that helps users query sales data.
[0111] An example may include the following specific steps: Get target query text: The user submitted a target query text "What is the sales volume of Apple in the second quarter of 2023?" Generate a target query statement: The server generates a target query statement corresponding to the target query text based on the filtered sample pairs (for example, "sales volume of pears in the first quarter" corresponds to "SELECT * FROM sales WHERE product='pears' AND quarter=1 AND year=2023"), database description information, and target query text: SELECT *FROM sales WHERE product='apples' AND quarter=2 AND year=2023; Execute the target query statement: The server chooses to execute this query statement. Specifically, the server connects to the database containing sales data and executes the above query statement. After the query is completed, the server obtains the specific sales data of Apple in the second quarter of 2023 from the database and sends the specific sales data to the user as the query result (for example, "Apple sales in the second quarter of 2023 were 10,000").
[0112] In some embodiments, after generating the target query statement, the method further includes: notifying the user of the target query statement.
[0113] In this embodiment, if the query instruction is not executed, the server may also directly send the generated query statement to the client, so that the user can decide whether to execute it.
[0114] Here is a specific example: If the user only needs to view the query statement and does not want to execute the query immediately, the specific steps include the following: Get target query text: The user submitted a target query text "What is the sales volume of Apple in the second quarter of 2023?" Generate a target query statement: The server generates a target query statement corresponding to the target query text based on the filtered sample pairs (for example, "sales volume of pears in the first quarter" corresponds to "SELECT * FROM sales WHERE product='pears' AND quarter=1 AND year=2023"), database description information, and target query text: SELECT *FROM sales WHERE product='apples' AND quarter=2 AND year=2023; Feedback target query statement: The server sends the generated query statement to the user for confirmation or the user can choose to execute the query statement in a suitable environment.
[0115] These two implementations provide flexibility, allowing users to choose whether to execute the query immediately based on their needs. The first method is suitable for scenarios where results need to be obtained quickly, while the second method is more suitable for situations where users need to control the query execution themselves. In this way, the server can better meet the needs of different users.
[0116] Figure 2 This is an interactive schematic diagram of a data processing scenario provided in an actual application of an embodiment of the present application, such as Figure 2 As shown, the client 1 and the server 2 implement accurate database query for the "target query text" through a series of interactions. The following is a detailed description of the specific interaction process: Step 21: The user enters the target query text through the user terminal, for example: "Query the sales of all products in the second quarter of 2023." Step 22: The server 2 obtains the target query text sent by the client 1. The client 1 sends the target query text to the server 2.
[0117] Step 23: The server 2 recalls at least one sample pair from the sample set.
[0118] The server 2 recalls the unrecalled sample pairs that are related to the target query text and unrelated to the recalled sample pairs from the sample set through the Maximum Marginal Relevance (MMR) algorithm to obtain multiple sample pairs, wherein each sample pair includes a sample object sample query text and its corresponding database query statement sample query statement.
[0119] Step 24: Server 2 determines the database description information that matches the target query text.
[0120] Server 2 analyzes the content of the target query text and determines the database description information that matches it. This information includes table names, field names, etc., so that the correct database query statement can be generated later.
[0121] Step 25: The server 2 calls the large model to generate a target query statement corresponding to the target query text according to the database description information, at least one sample pair, and the target query text.
[0122] The server 2 uses the above information to call the pre-trained large model, which can generate corresponding database query statements based on the input target query text, sample pairs and database description information.
[0123] The generated target query statement should be able to accurately express the user's query intention and be executable in the actual database.
[0124] Step 26: Server 2 calls the database to execute the target query statement to obtain the query result.
[0125] Step 27: The server 2 notifies the query result to the client 1. Optionally, the target query statement may also be notified to the client 1, which is not limited in the present application.
[0126] In this step, the server can choose to directly execute the generated target query statement and obtain the query results from the database. Alternatively, the server can choose not to execute the query, but send the generated target query statement to the user, allowing the user to decide whether to execute the query. If the query is executed, the server sends the query results back to the user, and the user displays the query results to the user. If the query is not executed, the server sends the generated target query statement to the user, and the user can display it to the user, and the user decides whether to execute the query as needed.
[0127] in, Figure 3 The following is a schematic diagram of the interaction of the server 2 executing steps 22 to 26, as shown in FIG. Figure 3 As shown, the server obtains the target query text "Question" sent by the user 1 (i.e., step 22), and obtains the sample pair "Reference" that meets similar requirements from the sample set "SQL Examples" according to the target query text "Question" as a reference template for the subsequent construction of the target query statement (i.e., step 23). The server determines the database description information that matches the target query text from the database architecture "Schema" (i.e., step 24), and generates the prompt information "Prompt" according to the database description information, at least one sample pair, and the target query text (i.e., step 25). Finally, the server inputs the prompt information "Prompt" into the large model "LLMGenerate SQL" to generate the target query statement "SQL" corresponding to the target query text through the large model (i.e., step 26).
[0128] In the embodiment of the present application, by determining the database description information that matches the target query text, it is ensured that the big model can understand the database structure to improve the accuracy of the generated target query statement; based on the database description information, at least one sample pair, and the target query text, the existing big model is directly used to generate the target query statement corresponding to the target query text. By combining the sample pairs, the target query text and the database description information, the big model is used to generate accurate and effective query statements. This not only makes full use of the powerful generation capabilities of the big model, ensuring that the generated query statements are both accurate and efficient, but more importantly, this method avoids the expensive fine-tuning process of the big model, greatly reducing the computing cost and technical threshold.
[0129] Figure 4 A schematic diagram of a data processing device according to an embodiment of the present invention is shown in FIG. Figure 4 As shown, the device comprises: An acquisition module 41 is used to acquire a target query text; A recall module 42, configured to recall at least one sample pair from a sample set, wherein the sample pair includes a sample query text and a sample query statement corresponding to the sample query text; A determination module 43, used to determine database description information matching the target query text; The generating module 44 is used to generate a target query statement corresponding to the target query text by using a large model according to the database description information, the at least one sample pair, and the target query text.
[0130] Optionally, in the embodiment of the present application, the recall module 42 is specifically configured to recall at least one sample pair from the sample set that meets a relevance requirement with the target query text.
[0131] Optionally, in the embodiment of the present application, the recall module 42 is specifically used to recall, from the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs, so as to obtain multiple sample pairs.
[0132] Optionally, in an embodiment of the present application, the recall module 42 is specifically used to recall from the sample set the unrecalled sample pairs whose similarity with the target query text satisfies a similarity condition and whose difference with the recalled sample pairs satisfies a difference condition, so as to obtain multiple sample pairs.
[0133] Optionally, in the embodiment of the present application, the recall module 42 is specifically configured to calculate, for any unrecalled sample pair in the sample set, a first similarity between the target query text and the sample query text in the unrecalled sample pair, and a maximum second similarity with the sample query text in the recalled sample pair, and subtract the maximum second similarity from the first similarity to obtain a similarity difference; The unrecalled sample pairs with the largest similarity difference are recalled.
[0134] Optionally, in an embodiment of the present application, the recall module 42 is specifically used to calculate, for any unrecalled sample pair in the sample set, a first similarity between the target query text and the sample query text in the unrecalled sample pair, and a maximum second similarity with the sample query text in the recalled sample pair, and to find a sample pair for recall that maximizes the first similarity and minimizes the maximum second similarity.
[0135] Optionally, in an embodiment of the present application, the determination module 43 is specifically used to identify entities and attributes involved in the target query text; and query the hit database description information according to the entities and the attributes.
[0136] Optionally, in an embodiment of the present application, the generation module 44 is specifically used to generate prompt information according to a prompt template based on the database description information, the target query text and the at least one sample pair; input the prompt information into a large model to use the large model to perform context learning from the at least one sample pair, and generate a query statement corresponding to the target query text based on the database description information.
[0137] Optionally, in the embodiment of the present application, the device further includes: a processing module 45; The processing module 45 is used to add the target query text and the target query sentence as a sample pair to the sample set.
[0138] Optionally, in an embodiment of the present application, the recall module 42 is specifically used to cluster the sample set to obtain multiple sample combinations; and recall at least one sample pair whose similarity with the target query text meets a similarity condition from the multiple sample combinations.
[0139] Optionally, in the embodiment of the present application, the acquisition module 41 is specifically used to acquire the target query text submitted by the user; Optionally, in the embodiment of the present application, the device further includes: a sending module 46; The sending module 46 is used to execute the target query statement to obtain a query result and notify the user of the query result; or notify the user of the target query statement.
[0140] Optionally, in the embodiment of the present application, the acquisition module 41 is specifically used to acquire the target query voice submitted by the user; and recognize the target query voice to acquire the corresponding target query text.
[0141] Figure 4 The label processing device can perform Figure 1 The implementation principle and technical effect of the label processing method described in the illustrated embodiment will not be described in detail. The specific manner in which each module and unit performs operations in the label processing device in the above embodiment has been described in detail in the embodiment of the method, and will not be described in detail here.
[0142] The present application also provides a computing device, such as Figure 5 As shown, the computing device may include a storage component 51 and a processing component 52; The storage component 51 stores one or more computer instructions, wherein the one or more computer instructions are called and executed by the processing component to obtain a target query text; recall at least one sample pair from a sample set, wherein the sample pair includes a sample query text and a sample query statement corresponding to the sample query text; determine database description information that matches the target query text; and generate a target query statement corresponding to the target query text using a large model based on the database description information, the at least one sample pair, and the target query text.
[0143] Of course, the computing device may also include other components, such as input / output interfaces, display components, communication components, etc.
[0144] The input / output interface provides an interface between the processing component 52 and a peripheral interface module, which may be an output device, an input device, etc. The communication component is configured to facilitate wired or wireless communication between the computing device and other devices.
[0145] The processing component 52 may include one or more processors to execute computer instructions to complete all or part of the steps in the above method. Of course, the processing component may also be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.
[0146] The storage component is configured to store various types of data to support operations at the terminal. The storage component can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0147] The display component may be an electroluminescent (EL) element, a liquid crystal display or a micro display having a similar structure, or a retinal direct display or a similar laser scanning display.
[0148] It should be noted that the above computing device implements Figure 1 In the case of the data processing method shown, it can be a physical device or an elastic computing host provided by a cloud computing platform, etc. It can be implemented as a distributed cluster consisting of multiple servers or terminal devices, or as a single server or a single terminal device.
[0149] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program can achieve the above-mentioned Figure 1 The computer readable medium may be included in the computing device described in the above embodiment; or it may exist independently without being assembled into the computing device.
[0150] The present application also provides a computer program product, which includes a computer program carried on a computer-readable storage medium. When the computer program is executed by a computer, the computer program can achieve the above-mentioned Figure 1 The data processing method shown. In such an embodiment, the computer program can be downloaded and installed from a network, and / or installed from a removable medium. When the computer program is executed by a processor, various functions defined in the system of the present application are executed.
[0151] It should be noted that the embodiments of the present application may involve the use of user data. In actual applications, user-specific personal data can be used in the scheme described in this article within the scope permitted by applicable laws and regulations, subject to the requirements of applicable laws and regulations of the country where the user is located (for example, with the user's explicit consent, effective notification to the user, etc.).
[0152] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0153] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0154] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0155] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data processing method, characterized in that: include: Get the target query text; Recalling at least one sample pair from the sample set, the sample pair comprising a sample query text and a sample query statement corresponding to the sample query text; Determining database description information that matches the target query text; A target query statement corresponding to the target query text is generated using a large model according to the database description information, the at least one sample pair, and the target query text.
2. The method according to claim 1, characterized in that The recalling of at least one sample pair from the sample set comprises: At least one sample pair that meets the relevance requirement with the target query text is recalled from the sample collection.
3. The method according to claim 1, characterized in that The recalling of at least one sample pair from the sample set comprises: From the sample set, unrecalled sample pairs that are relevant to the target query text and irrelevant to the recalled sample pairs are recalled to obtain a plurality of sample pairs.
4. The method according to claim 3, characterized in that The step of recalling unrecalled sample pairs from the sample set that are related to the target query text and unrelated to the recalled sample pairs to obtain a plurality of sample pairs includes: From the sample set, unrecalled sample pairs whose similarity to the target query text satisfies a similarity condition and whose difference from the recalled sample pairs satisfies a difference condition are recalled to obtain a plurality of sample pairs.
5. The method according to claim 3, characterized in that The step of recalling unrecalled sample pairs from the sample set that are related to the target query text and unrelated to the recalled sample pairs to obtain a plurality of sample pairs includes: For any unrecalled sample pair in the sample set, calculating a first similarity between the target query text and the sample query text in the unrecalled sample pair, and a maximum second similarity between the target query text and the sample query text in the recalled sample pair, and subtracting the maximum second similarity from the first similarity to obtain a similarity difference; The unrecalled sample pairs with the largest similarity difference are recalled.
6. The method according to claim 3, characterized in that The step of recalling unrecalled sample pairs from the sample set that are related to the target query text and unrelated to the recalled sample pairs to obtain a plurality of sample pairs includes: For any unrecalled sample pair in the sample set, calculate the first similarity between the target query text and the sample query text in the unrecalled sample pair, as well as the maximum second similarity with the sample query text in the recalled sample pair, and find the sample pair that maximizes the first similarity and minimizes the maximum second similarity for recall.
7. The method according to claim 1, characterized in that The database description information for determining the target query text match includes: Identify entities and attributes involved in the target query text; According to the entity and the attribute, the hit database description information is queried.
8. The method according to claim 1, characterized in that Generating a target query statement corresponding to the target query text using a large model according to the database description information, the at least one sample pair, and the target query text includes: Generate prompt information based on the database description information, the target query text and the at least one sample pair according to a prompt template; The prompt information is input into a large model, so as to utilize the large model to perform context learning from the at least one sample pair, and to generate a query statement corresponding to the target query text based on the database description information.
9. The method according to claim 1, characterized in that Also includes: The target query text and the target query sentence are taken as a sample pair and added to the sample set.
10. The method according to claim 1, characterized in that The recalling of at least one sample pair from the sample set comprises: Performing clustering processing on the sample set to obtain multiple sample combinations; At least one sample pair whose similarity to the target query text meets a similarity condition is recalled from the multiple sample combinations.
11. The method according to claim 1, wherein The acquiring of the target query text includes: Obtain the target query text submitted by the user; After generating the target query statement, the method further includes: Execute the target query statement to obtain a query result, and notify the user of the query result; or notify the user of the target query statement.
12. The method according to any one of claims 1 to 11, characterized in that The acquiring of the target query text includes: Obtain the target query voice submitted by the user; The target query speech is recognized to obtain a corresponding target query text.
13. A computing device, characterized in that It comprises a processing component and a storage component; the storage component stores one or more computer instructions; the one or more computer instructions are used to be called and executed by the processing component to implement the data processing method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is executed by the processing component, the data processing method according to any one of claims 1 to 12 is implemented.
15. A computer program product, characterized in that The method comprises a computer program / instruction, wherein when the computer program / instruction is executed by a processing component, the data processing method according to any one of claims 1 to 12 is implemented.
Citation Information
Patent Citations
Text data processing method and device, equipment and medium
CN113761105A
Target search text determination method and device, equipment and storage medium
CN116955583A
Model training method, text recall method, equipment, medium and program product
CN117217278A
SQL (Structured Query Language) statement generation method and device based on large language model, equipment and medium
CN117743371A
Training method of statement generation model, statement generation method, system and equipment
CN117992791A
Cited By
Data sharing open platform data resource searching method and system based on large language model
CN119357316A
Intelligent online form template arrangement method for simply fusing form model and Text2SQL (Structured Query Language)
CN119808745A
A Simple Method for Intelligent Template Orchestration of Integrating Table Model and Text2SQL Online Forms
CN119808745B
Generative AI-based algorithm for improved cache hit performance in text-to-SQL systems
US12748755B1
