Query statement generation method and device, equipment and storage medium
By extracting the query parameters entered by the user and the filtered context prompt information, combining the large language model to generate initial query statements, and generating target query statements through pattern links, the existing Text2SQL conversion technology is solved, and the accuracy of existing Text2SQL conversion technology is not high when processing complex queries, achieving more efficient and accurate query statement generation.
Patent Information
- Application Number
- CN202411767948.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-28
AI Technical Summary
When existing Text2SQL conversion technology deals with cumbersome database information or complex user intentions, it is difficult to accurately understand the natural language input by the user, resulting in low accuracy in generating query statements.
By receiving the query information input by the user, extracting the query parameters and filtering out the corresponding context prompt information from the preset database. Use pre-trained large language model to process query parameters and context prompt information, and generate initial query statements. Then, parse the initial query statement through pattern linking to generate the target query statement.
It improves the accuracy of generating query statements, reduces the redundancy of search resources and information, improves the efficiency of query statement generation, reduces the dependence of manually writing query statements, and reduces the error rate.
Smart Images

Figure CN119719321A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a method for generating a query statement. Background Art
[0002] With the rapid development of artificial intelligence technology, large language models (LLMs) have demonstrated powerful capabilities in the field of natural language processing. Among them, the natural language to structured query language (SQL) conversion technology (Text2SQL) has been widely used in fields such as database question answering and information retrieval, and has made remarkable progress.
[0003] At present, the Text2SQL conversion technology can convert the natural language input by the user into accurate SQL statements, and use the converted SQL statements to achieve efficient query of the database.
[0004] However, although Text2SQL conversion technology has made many achievements, it still faces many challenges in practical applications, especially when dealing with cumbersome database information or complex user intentions. The current Text2SQL conversion technology is difficult to accurately understand the natural language input by users, resulting in low accuracy of generated query statements. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method, device, equipment and storage medium for generating a query statement, the main purpose of which is to improve the accuracy of generating a query statement.
[0006] In order to solve the above technical problems, the embodiment of the present application provides a method for generating a query statement, which adopts the following technical solution:
[0007] Receiving query information input by a user, and extracting query parameters of the query information;
[0008] According to the query parameter, filtering out context prompt information corresponding to the query parameter from a preset database;
[0009] Processing the query parameters and the context prompt information using a pre-trained large language model to generate an initial query statement;
[0010] Parsing the initial query statement to obtain an initial table name and an initial column name corresponding to the initial query statement, linking the initial table name and the initial column name with a processing mode of the preset database, and generating prompt information after the mode linking;
[0011] According to the prompt information after the mode link, the pre-trained large language model is used to generate a target query sentence.
[0012] Furthermore, after receiving the query information input by the user, the method further includes:
[0013] Identify the data type of the query information;
[0014] If the data type is identified as a non-text form, obtaining a text conversion method for the non-text form;
[0015] According to the text conversion method, the query information is converted into a text form.
[0016] Further, the extracting the query parameters of the query information includes:
[0017] Extracting keywords of the query information using a preset keyword extraction method to obtain multiple keywords of the query information;
[0018] Performing a deduplication operation on the multiple keywords to obtain multiple merged keywords;
[0019] The multiple combined keywords are converted according to a predetermined format to obtain query parameters of the query information.
[0020] Furthermore, after filtering out the context prompt information corresponding to the query parameter from the preset database, the method further includes:
[0021] Performing sensitive data identification on the context prompt information;
[0022] If it is identified that the context prompt information contains the sensitive data, a preset desensitization method is used to desensitize the sensitive data in the context prompt information to obtain the desensitized context prompt information.
[0023] Furthermore, the use of a pre-trained large language model to process the query parameters and the context prompt information to generate an initial query statement includes:
[0024] According to the context prompt information, a fine-tuning data set is obtained;
[0025] Using the fine-tuning data set to fine-tune the pre-trained large language model to obtain a fine-tuned large language model;
[0026] According to the context prompt information, the query parameters are processed by the fine-tuned large language model to obtain the initial query statement.
[0027] Furthermore, after generating a target query sentence using the pre-trained large language model according to the prompt information after the mode link, the method further includes:
[0028] Execute the target query statement;
[0029] If the target query statement is executed successfully, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user;
[0030] If the target query fails to be executed, the error cause is detected by the pre-trained large language model, and correction is performed according to the error cause to obtain a corrected target query;
[0031] The modified target query statement is re-executed until the modified query statement is successfully executed, the target answer is obtained, and the target answer is fed back to the user.
[0032] Furthermore, if the target query statement is executed successfully, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user, the method further includes:
[0033] Regularly obtain data whose access times exceed a preset threshold within a preset time period to obtain a high-frequency data set;
[0034] Using a preset indexing technology to index key fields of the high-frequency data set to obtain index fields;
[0035] Storing the index field in a search engine, and storing the high-frequency data set in a preset cache;
[0036] When the target query statement is received, the target answer is queried from the preset cache according to the index field.
[0037] In order to solve the above technical problems, the embodiment of the present application further provides a query statement generation device, which adopts the following technical solution:
[0038] An extraction module, used to receive query information input by a user and extract query parameters of the query information;
[0039] A screening module, configured to screen out contextual prompt information corresponding to the query parameter from a preset database according to the query parameter;
[0040] A first generation module is used to process the query parameters and the context prompt information using a pre-trained large language model to generate an initial query statement;
[0041] A mode linking module is used to parse the initial query statement, obtain the initial table name and the initial column name corresponding to the initial query statement, link the initial table name and the initial column name with the mode of the preset database, and generate prompt information after the mode linking;
[0042] The second generation module is used to generate a target query sentence using the pre-trained large language model according to the prompt information after the pattern link.
[0043] In order to solve the above technical problems, an embodiment of the present application also provides a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the query statement generation method as described above.
[0044] In order to solve the above technical problems, an embodiment of the present application further provides a computer-readable storage medium storing a computer program, which implements the query statement generation method as described above when executed by a processor.
[0045] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0046] By receiving the query information input by the user and extracting the query parameters of the query information, the query intention of the query information can be clarified, which provides a basis for the query statements generated subsequently, thereby improving the accuracy of the subsequent query statement generation, and reducing the search resources and information, thereby improving the efficiency of the subsequent query statement generation;
[0047] According to the query parameters, context prompt information corresponding to the query parameters is screened out from a preset database, which can improve the generation efficiency and accuracy of subsequent query statements;
[0048] By parsing query parameters according to contextual prompt information to generate initial query statements, the model can generate more accurate initial query statements and improve the accuracy of initial query statement generation. In addition, by using a large language model to generate initial query statements, it not only supports processing requests with complex query parameters, but also reduces the reliance on manually written query statements, thereby improving work efficiency and reducing the risk of errors.
[0049] By inputting the prompt information after pattern linking into the pre-trained large language model, the prompt information can be automatically parsed and the corresponding query statement can be generated. This reduces the need for manual writing of query statements and improves work efficiency; by using the pre-trained large language model to generate query statements, the error rate caused by manually writing query statements can be significantly reduced, and the accuracy of target query statement generation can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. 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.
[0051] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0052] Figure 2 A flowchart of an embodiment of a method for generating a query statement according to the present application;
[0053] Figure 3 is a structural schematic diagram of an embodiment of a device for generating a query statement according to the present application;
[0054] Figure 4 It is a structural schematic diagram of an embodiment of a device according to the present application. DETAILED DESCRIPTION
[0055] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0056] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0057] 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 accompanying drawings.
[0058] like Figure 1As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables.
[0059] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0060] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to a laptop computer 1011, a tablet computer 1012 or a mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.
[0061] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .
[0062] It should be noted that the query statement generation method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the query statement generation device is generally set in the server / terminal device.
[0063] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to the implementation requirements.
[0064] Continue to refer Figure 2 , shows a flow chart of an embodiment of a method for generating a query statement according to the present application. According to different requirements, the order of the steps in the flow chart can be changed, and some steps can be omitted. The method for generating a query statement provided in the embodiment of the present application can be applied to any scenario where query statements need to be generated, and the method for generating a query statement can be applied to products in these scenarios. The method for generating a query statement comprises the following steps:
[0065] Step S201: receiving query information input by a user, and extracting query parameters of the query information.
[0066] In this embodiment, the query statement generation method is executed on the electronic device (eg Figure 1 The server / terminal device shown in the figure) can receive the query information input by the user through a wired connection or a wireless connection. It should be pointed out that the above-mentioned wireless connection method may include but is not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future. The executor of the present application may be a large language model, or simply referred to as a model. The above-mentioned query information usually has the same format as the query training data used in the training of the large language model, but the training data contains other noise, depending on the specific situation. Among them, in the business scenario of generating query statements, the query information can be input through the user's handheld terminal, etc.
[0067] In this embodiment, query information input by a user is received, the query information is preprocessed to obtain preprocessed query information, keywords are extracted from the preprocessed query information to obtain multiple keywords, the multiple keywords are converted according to a predetermined format to obtain query parameters of the query information.
[0068] In this embodiment, the above-mentioned preprocessing operations include but are not limited to text cleaning operations, word segmentation and part-of-speech tagging, etc.; in order to improve user experience and the diversity of query information, the above-mentioned query information can be in text form, voice form or image form; after receiving the query information input by the user, it is necessary to identify the data type of the query information, convert the query information into text form according to the data type, and then extract keywords from the query information in text form to obtain query parameters corresponding to the query information.
[0069] In one embodiment, after receiving the query information input by the user, the method further includes:
[0070] Identify the data type of the query information;
[0071] If the data type is identified as a non-text form, obtaining a text conversion method for the non-text form;
[0072] According to the text conversion method, the query information is converted into a text form.
[0073] In this embodiment, after receiving the query information input by the user, the specific query method can be directly judged. If the query information is a string type, it is judged that the query information is in text form and no conversion is performed; if the query information exists in the form of a file, the file extension is checked. When the file extension is .jpg, .png, etc., the query information is judged to be in image form; when the file extension is .wav, etc., the query information is judged to be an audio file; when the query information is in image form, OCR technology is used to extract the query information text to obtain the query information in text form; when the query information is in audio form, speech recognition technology (such as Speech-to-Text API, etc.) is used to convert the query information into text information.
[0074] In this embodiment, by supporting query information input in various forms, the user experience can be improved, the flexibility of the query is increased, and the query scope is expanded, so as to improve the accuracy of query statement generation in the subsequent process.
[0075] In one embodiment, extracting the query parameter of the query information includes:
[0076] Extracting keywords of the query information using a preset keyword extraction method to obtain multiple keywords of the query information;
[0077] Performing a deduplication operation on the multiple keywords to obtain multiple merged keywords;
[0078] The multiple combined keywords are converted according to a predetermined format to obtain query parameters of the query information.
[0079] In this embodiment, the above-mentioned preset keyword extraction methods include but are not limited to TF-IDF (term frequency and inverse document frequency) extraction methods, which calculate the term frequency (TF) and inverse document frequency (IDF) of each word in the text, and combine the values of the two to select keywords according to the values of the two; topic model extraction methods, such as Dirichlet (LDA, Latent Dirichlet Allocation) extraction methods, which identify the subject of the query information and extract words related to the subject as keywords; neural network extraction methods (such as CNN, etc.), which encode the query information and output the probability distribution of keywords through a trained neural network model; extract keywords from the query information through the above-mentioned trained model or algorithm to obtain multiple keywords, wherein the query information at this time exists in the form of text;
[0080] After extracting multiple keywords, since there may be repeated words in the multiple keywords, in order to improve the accuracy of query parameter extraction, the multiple keywords are de-duplicated, wherein the above-mentioned de-duplication of multiple keywords can be performed by traversing all keywords through a predefined synonym dictionary to find words with similar semantics, or by calculating the semantic similarity of any two keywords through a semantic similarity calculation method, and merging semantically similar keywords or any two keywords whose semantic similarity is greater than a preset semantic similarity threshold to obtain multiple merged keywords; the multiple merged keywords are converted according to a predetermined format to finally obtain the query parameters of the query information.
[0081] In this embodiment, by extracting keywords from the query information, the core content of the query information can be understood more quickly, thereby improving the efficiency of generating subsequent query statements; and by merging multiple keywords, the accuracy of generating subsequent query statements can be improved.
[0082] In an implementable example A, query information "Query all auto insurance claim records submitted with policy number: 123456" is received from a user via a mobile phone, and keywords such as "policy number: 123456", "auto insurance", and "claim record" are extracted from the query information to determine whether there are semantically similar keywords among the multiple keywords. If not, the keywords are converted according to a predefined format to obtain query parameters such as customer ID = 123456 AND insurance type = auto insurance AND query type = claim record.
[0083] In this embodiment, by receiving the query information input by the user and extracting the query parameters of the query information, the query intent of the query information can be clarified, providing a basis for the subsequently generated query statements, thereby improving the accuracy of the subsequent query statement generation, and reducing the search resources and information, thereby improving the efficiency of the subsequent query statement generation.
[0084] S202: Filter out context prompt information corresponding to the query parameter from a preset database according to the query parameter.
[0085] In this embodiment, the preset database refers to a database storing multiple different data tables, such as a claims record table, a customer ID table, etc., and sample data of each table; according to the query parameter, metadata information of the data table corresponding to the query parameter is obtained from the preset database. For example, if the query parameter includes a claims record, metadata information of the claims record table is obtained from the preset database. The metadata information includes a table name, a column name, etc. After the metadata information is obtained, a string concatenation method is used to construct a table structure description text. For example, the concatenated description text is "claims(id INT, customer_id INT, status VARCHAR(20), amount DECIMAL(10,2))", wherein the claims represents the table name, id INT represents the primary key in the form of an integer, customer_id INT represents the customer ID in the form of an integer (such as the policy number mentioned above), status VARCHAR(20) represents a field in the form of a variable string and is limited to 20 characters (such as the claim status is Approved, Pending, or Reject), and amount DECIMAL(10,2) indicates a field in the form of a fixed-point number, with a maximum of 10 digits, including two decimal places, which is used to record the claim amount. A preset number of rows of data are randomly selected from the claim record table as sample data, the cell values of the sample data are extracted, and the cell values are filled into the above table structure description text to obtain context prompt information. For example, the context prompt information finally generated is claims|id:1,customer_id:123456,status:'Approved',amount:1000.00.
[0086] In one embodiment, after filtering out the context prompt information corresponding to the query parameter from the preset database, the method further includes:
[0087] Performing sensitive data identification on the context prompt information;
[0088] If it is identified that the context prompt information contains the sensitive data, a preset desensitization method is used to desensitize the sensitive data in the context prompt information to obtain the desensitized context prompt information.
[0089] In this embodiment, the sensitive data is predefined, such as identity card number, bank card number, customer telephone number, specific address, etc. In order to ensure the security of sensitive data in the preset database and prevent leakage of sensitive data, after generating the context prompt information, it is also necessary to identify the sensitive data of the context prompt information. When the existence of sensitive data is identified, the sensitive data is desensitized. When the existence of sensitive data is not identified, the context prompt information is not processed.
[0090] Specifically, a sensitive data table is constructed, in which various sensitive data are defined. The context prompt information is scanned using regular expressions, string matching algorithms, or specific sensitive data detection tools to determine whether the context prompt information contains sensitive data. If the context prompt information contains sensitive data, a suitable desensitizing method is selected according to the type and characteristics of the sensitive data to desensitize the sensitive data. For example, for an ID card number, desensitization can be performed by partially hiding, replacing characters, or encrypting the number; for a bank card number, only part of the data can be displayed or the bank card number can be hashed to finally obtain the desensitized context prompt information.
[0091] In this embodiment, by identifying sensitive data in the context prompt information and performing desensitization processing, data security is enhanced and unnecessary losses caused by data leakage are prevented.
[0092] In this embodiment, according to the query parameters, context prompt information corresponding to the query parameters is screened out from a preset database, which can improve the generation efficiency and accuracy of subsequent query statements.
[0093] S203: Using a pre-trained large language model to process the query parameters and the context prompt information to generate an initial query statement.
[0094] In this embodiment, the above-mentioned large language model LLM (Large Language Models) includes but is not limited to the BERT model, etc., and a trained large language model is obtained by training the large language model. The trained large language model can generate an initial query statement according to query parameters and context prompt information, wherein the pre-trained large language model has the ability to understand natural language, parse complex query requirements, and generate structured query language (SQL, etc.) according to context prompt information and query parameters.
[0095] In this embodiment, the query parameters and contextual prompt information are input into a pre-trained large language model together. The large language model parses and converts the query parameters according to the contextual prompt information, wherein the parsing and conversion process includes but is not limited to semantic understanding of the keywords in the query parameters, logical processing of the screening conditions, and matching of the database structure, etc., and finally generates an initial query statement.
[0096] In one embodiment, the using of a pre-trained large language model to process the query parameters and the context prompt information to generate an initial query statement includes:
[0097] According to the context prompt information, a fine-tuning data set is obtained;
[0098] Using the fine-tuning data set to fine-tune the pre-trained large language model to obtain a fine-tuned large language model;
[0099] According to the context prompt information, the query parameters are processed by the fine-tuned large language model to obtain the initial query statement.
[0100] In this embodiment, the fine-tuning operation refers to further training and adjusting the model based on the pre-trained model using a small-scale dataset of a specific task to adapt to the new task; obtaining a fine-tuning dataset for the fine-tuning operation according to the context prompt information, the fine-tuning dataset including query parameters related to the context prompt information and corresponding query statement pairs (such as SQL statement pairs), and performing a fine-tuning operation on the pre-trained large language model through the fine-tuning dataset, the fine-tuning operation including adjusting the parameters of the pre-trained large language model so that the model can better process the query parameters according to the context prompt information to generate a more accurate initial query statement
[0101] The above method of obtaining a fine-tuning data set for fine-tuning operations based on contextual prompt information is as follows: specifically, if all training data are pre-assigned with a unique identifier when stored, when obtaining the fine-tuning data set, the unique identifier of each training data in the training data set can be matched according to the contextual prompt information to screen out the fine-tuning data set that can be used for the fine-tuning operation; if all training data are not pre-assigned with a unique identifier when stored, a string matching algorithm and a structure matching algorithm are used to retrieve data from the training data set according to the content and structure related to the contextual prompt information, and the retrieved data is used as the fine-tuning data set that can be used for the fine-tuning operation; it is also possible to perform a clustering operation on all training data in advance, and then match the contextual prompt information with each cluster after the clustering operation, select all data contained in the corresponding cluster as the fine-tuning data, and obtain a fine-tuning data set that can be used for the fine-tuning operation.
[0102] In this embodiment, by selecting a training set that is more suitable for the initial query statement according to the context prompt information and performing a fine-tuning operation, a more accurate initial query statement can be generated, and the generalization ability of the model can be enhanced through the fine-tuning operation.
[0103] In this embodiment, by parsing query parameters according to contextual prompt information to generate an initial query statement, the model can generate a more accurate initial query statement and improve the accuracy of the initial query statement generation; and generating the initial query statement through a large language model not only supports processing requests for complex query parameters, but also reduces the reliance on manually written query statements, thereby improving work efficiency and reducing the risk of errors.
[0104] S204, parsing the initial query statement to obtain an initial table name and an initial column name corresponding to the initial query statement, linking the initial table name and the initial column name with a processing mode of the preset database, and generating prompt information after the mode linking.
[0105] In this embodiment, the above-mentioned pattern linking refers to the process of matching and associating the initial table name and initial column name in the initial query statement with the actual table structure and column structure in the preset database; the above-mentioned prompt information refers to simple prompt information that helps to generate subsequent query statements, such as "the query statement has been successfully linked to the users table of the preset database, and the name and email columns are selected" or "query the name column and email column in the users table"; the initial query statement is parsed by a preset natural language processing method, the initial column name of the initial query statement and the initial table name to which the initial column name belongs are identified, and the pattern information in the preset database is obtained, the pattern information includes the table names to be matched of all tables in the preset database and each table package The table name contains all the column names to be matched, and the initial table name is matched with all the table names to be matched. If the match is successful, the initial column name is matched with the column name to be matched. If the match is successful, the initial table name and the initial column name are associated with the table structure of the table name to be matched and the column structure of the column name to be matched to obtain a target association relationship, and prompt information after the pattern link is generated according to the target association relationship, wherein the above matching method can be that when the initial table name is consistent with the table name to be matched, the match is successful; when the initial column name is consistent with the column name to be matched, the match is successful; wherein, in the above matching process, the column name to be matched belongs to the table name to be matched, that is, when the initial table name is successfully matched with the table name to be matched, in the column name matching step, it is only necessary to match the initial column name with at least one column name to be matched that belongs to the table name to be matched.
[0106] In this embodiment, a fault-tolerant mechanism is pre-constructed, and the fault-tolerant mechanism includes checking whether there are possible spelling errors (such as the possible spelling errors of users are user, uaers, etc.) and inconsistent capitalization; if the initial table name fails to match with all the table names to be matched, for example, the initial table name is the user table, and the table name to be matched is the users table, the error in the initial table name is automatically identified and corrected through the fault-tolerant mechanism, and then the corrected initial table name is matched with the table name to be matched again. If the match is successful, the above-mentioned column name matching steps are continued until the prompt information after the mode link is generated. If the second match still fails, an error message is generated, for example, the table name user of the query statement does not exist in the database, please check whether the initial table name is correct.
[0107] In this embodiment, the preset database needs to be updated regularly to improve the accuracy of subsequent target query statement generation.
[0108] In this embodiment, by performing a pattern link with a preset database to generate prompt information after the pattern link, the accuracy of subsequent query statement generation can be ensured to avoid query failures due to incorrect table names or column names; and the parsing and pattern linking process of the initial query statement can provide a basis for the subsequent automatic generation of target query statements, so that users can generate complex database query statements through simple natural language input, thereby lowering the query threshold.
[0109] S205, generating a target query statement using the pre-trained large language model according to the prompt information after the mode link;
[0110] The prompt information after pattern linking is input into a pre-trained large language model, the prompt information after pattern linking is parsed to obtain a parsing result, and at least one query statement template corresponding to the parsing result is obtained from a query language template library, wherein the query statement template includes replaceable placeholders, and the replaceable placeholders in the query statement template are replaced with the table name to be matched and the column name to be matched in the prompt information after pattern linking, ensuring that the insertion positions of the table name to be matched and the column name to be matched match the placeholder positions in the query statement template, and when the replacement is completed, a target query statement is generated.
[0111] For example, if the prompt is to query the emails whose name is A in the users table, the selected template is SELECT placeholder 1 FROM placeholder 2 WHERE placeholder 3, and the placeholders of the template are replaced by the above prompt. The target query statement finally generated is SELECT email FROM users WHERE name='A'.
[0112] In one embodiment, after generating a target query sentence using the pre-trained large language model according to the prompt information after the mode link, the method further includes:
[0113] Execute the target query statement;
[0114] If the target query statement is executed successfully, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user;
[0115] If the target query fails to be executed, the error cause is detected by the pre-trained large language model, and correction is performed according to the error cause to obtain a corrected target query;
[0116] The modified target query statement is re-executed until the modified query statement is successfully executed, the target answer is obtained, and the target answer is fed back to the user.
[0117] In this embodiment, the target query statement is executed in the preset database. If the execution is successful, the target answer corresponding to the target query statement returned by the preset database is received, and the target answer is fed back to the user; if the target query statement fails to be executed in the preset database, the error cause of the failure to execute the target query statement is detected by a pre-trained large language model in a self-questioning and self-answering manner, and the error cause includes an error type and an error location, and the error type includes a grammatical error or a logical error. According to the error type and the error location, a pre-trained large language model is used to generate corresponding correction suggestions, such as a correction suggestion report for the lack of necessary conditions, and the correction suggestion report is fed back to the pre-trained large language model. By fusing the correction suggestion report and the target query statement, a corrected target query statement is generated, and the corrected query statement is executed. If the corrected query statement is successfully executed, the target answer is fed back to the user. If the corrected query statement fails to be executed, a correction report is generated again, and it is corrected again according to the correction report. The above steps are repeated until the corrected query statement is successfully executed.
[0118] In this embodiment, when the target query statement fails to execute, the system can automatically detect the cause of the error and correct it, avoiding the tedious process of users manually troubleshooting and modifying query statements, thereby improving query efficiency; it realizes the automatic generation of query statements, intelligent and automated error detection and correction, and improves the efficiency and reliability of the entire query process; and through the cyclic correction steps, the system can continuously learn and optimize its own query generation and correction capabilities, further improving performance and accuracy.
[0119] In another embodiment, after the target query statement is successfully executed, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user, the method further includes:
[0120] Regularly obtain data whose access times exceed a preset threshold within a preset time period to obtain a high-frequency data set;
[0121] Using a preset indexing technology to index key fields of the high-frequency data set to obtain index fields;
[0122] Storing the index field in a search engine, and storing the high-frequency data set in a preset cache;
[0123] When the target query statement is received, the target answer is queried from the preset cache according to the index field.
[0124] In this embodiment, data with a number of accesses exceeding a preset number threshold within a preset time period is periodically obtained, for example, data with a number of accesses exceeding 5 times within 24 hours is obtained to obtain a high-frequency data set, and an indexing technology (such as hash index, B+ tree index, etc.) is used to create an index for each data in the high-frequency data set, and the index is stored in a search engine (such as Redis, Elasticsearch, etc.), and the high-frequency data set is stored in a memory or cache with a fast processing speed, and an expiration time and an update policy of the cache are set to periodically update the data in the memory or cache; when a target query statement is received, data is preferentially searched from the cache or memory according to the index field, and if the target answer corresponding to the target query statement cannot be hit in the cache or memory, the target answer is searched from a preset database, and the target answer is fed back to the user.
[0125] In this embodiment, by screening out high-frequency data sets and indexing the key fields of each high-frequency data in the high-frequency data sets, the target answer can be quickly located, the query speed is improved and the query fields are reduced; by storing the high-frequency data sets in a cache or memory, the characteristics of the memory are utilized to improve the query speed and reduce the burden on the database.
[0126] In this embodiment, by inputting the prompt information after pattern linking into the pre-trained large language model, the prompt information can be automatically parsed and the corresponding query statement can be generated. This reduces the need for manual writing of query statements and improves work efficiency; by using the pre-trained large language model to generate query statements, the error rate caused by manually writing query statements can be significantly reduced, and the accuracy of generating target query statements can be improved.
[0127] It should be emphasized that in order to further ensure the privacy and security of the generation results, target answers, etc. of the above query statements, the generation results, target answers, etc. of the above query statements can also be stored in a node of a blockchain.
[0128] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0129] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0130] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0131] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0132] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0133] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a device for generating a query statement, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the apparatus can be specifically applied to various computer devices.
[0134] like Figure 3 As shown, the query statement generation device 300 described in this embodiment includes: an extraction module 301, a screening module 302, a first generation module 303, a pattern linking module 304 and a second generation module 305. Among them:
[0135] Extraction module 301, used to receive query information input by a user and extract query parameters of the query information;
[0136] In one embodiment, the apparatus further comprises:
[0137] A first identification module, used to identify the data type of the query information;
[0138] A method acquisition module, for acquiring a text conversion method of the non-text form if the data type is identified as a non-text form;
[0139] The text conversion module is used to convert the query information into text form according to the text conversion method.
[0140] In one embodiment, the extraction module 301 includes:
[0141] A keyword extraction submodule, used to extract keywords of the query information by using a preset keyword extraction method to obtain multiple keywords of the query information;
[0142] A merging submodule, used for performing a deduplication operation on the multiple keywords to obtain multiple merged keywords;
[0143] The format conversion submodule is used to convert the multiple merged keywords into a predetermined format to obtain the query parameters of the query information.
[0144] A screening module 302, configured to screen out context prompt information corresponding to the query parameter from a preset database according to the query parameter;
[0145] In one embodiment, the apparatus further comprises:
[0146] A second identification module is used to identify sensitive data of the context prompt information;
[0147] The desensitizing module is used to, if it is identified that the context prompt information contains the sensitive data, perform desensitization processing on the sensitive data in the context prompt information by using a preset desensitization method to obtain the desensitized context prompt information.
[0148] A first generation module 303 is used to process the query parameters and the context prompt information using a pre-trained large language model to generate an initial query statement;
[0149] In one embodiment, the first generating module 303 includes:
[0150] A data acquisition submodule, used to acquire a fine-tuning data set according to the context prompt information;
[0151] A fine-tuning submodule, configured to use the fine-tuning data set to perform a fine-tuning operation on the pre-trained large language model to obtain a fine-tuned large language model;
[0152] The first generation submodule is used to process the query parameters through the fine-tuned large language model according to the context prompt information to obtain the initial query statement.
[0153] The mode linking module 304 is used to parse the initial query statement, obtain the initial table name and the initial column name corresponding to the initial query statement, link the initial table name and the initial column name with the mode of the preset database, and generate prompt information after the mode linking;
[0154] The second generation module 305 is used to generate a target query sentence using the pre-trained large language model according to the prompt information after the pattern link.
[0155] In one embodiment, the apparatus further comprises:
[0156] An execution module, used for executing the target query statement;
[0157] A first feedback module is used to obtain a target answer corresponding to the target query statement if the target query statement is executed successfully, and to feed back the target answer to the user;
[0158] A correction module, for detecting the cause of the error by using the pre-trained large language model if the target query fails to be executed, and performing corrections according to the cause of the error to obtain a corrected target query;
[0159] The second feedback module is used to re-execute the modified target query statement until the modified query statement is successfully executed, the target answer is obtained, and the target answer is fed back to the user.
[0160] In one embodiment, the apparatus further comprises:
[0161] A regular acquisition module is used to regularly acquire data whose access times exceed a preset threshold within a preset time period to obtain a high-frequency data set;
[0162] An indexing module, used to use a preset indexing technology to index the key fields of the high-frequency data set to obtain index fields;
[0163] A cache module, used to store the index field in a search engine, and store the high-frequency data set in a preset cache;
[0164] A query module is used to query the target answer from the preset cache according to the index field when receiving the target query statement.
[0165] In this embodiment, by receiving the query information input by the user and extracting the query parameters of the query information, the query intention of the query information can be clarified, which provides a basis for the query statements generated subsequently, thereby improving the accuracy of the subsequent query statement generation, and reducing the search resources and information, thereby improving the efficiency of the subsequent query statement generation;
[0166] According to the query parameters, context prompt information corresponding to the query parameters is screened out from a preset database, which can improve the generation efficiency and accuracy of subsequent query statements;
[0167] By parsing query parameters according to contextual prompt information to generate initial query statements, the model can generate more accurate initial query statements and improve the accuracy of initial query statement generation. In addition, by using a large language model to generate initial query statements, it not only supports processing requests with complex query parameters, but also reduces the reliance on manually written query statements, thereby improving work efficiency and reducing the risk of errors.
[0168] By inputting the prompt information after pattern linking into the pre-trained large language model, the prompt information can be automatically parsed and the corresponding query statement can be generated. This reduces the need for manual writing of query statements and improves work efficiency; by using the pre-trained large language model to generate query statements, the error rate caused by manually writing query statements can be significantly reduced, and the accuracy of target query statement generation can be improved.
[0169] In order to solve the above technical problems, the present application embodiment also provides a device (computer device). Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0170] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 4 with a memory 41, a processor 42, and a network interface 43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0171] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0172] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk equipped on the computer device 4, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the method for generating query statements, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0173] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run computer-readable instructions or process data stored in the memory 41, such as computer-readable instructions for running the method for generating the query statement.
[0174] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0175] During the implementation process, the electronic device of the present application receives the query information input by the user and extracts the query parameters of the query information, thereby clarifying the query intention of the query information, providing a basis for the query statements generated subsequently, thereby improving the accuracy of the subsequent query statement generation, and reducing the search resources and information, thereby improving the efficiency of the subsequent query statement generation;
[0176] According to the query parameters, context prompt information corresponding to the query parameters is screened out from a preset database, which can improve the generation efficiency and accuracy of subsequent query statements;
[0177] By parsing query parameters according to contextual prompt information to generate initial query statements, the model can generate more accurate initial query statements and improve the accuracy of initial query statement generation. In addition, by using a large language model to generate initial query statements, it not only supports processing requests with complex query parameters, but also reduces the reliance on manually written query statements, thereby improving work efficiency and reducing the risk of errors.
[0178] By inputting the prompt information after pattern linking into the pre-trained large language model, the prompt information can be automatically parsed and the corresponding query statement can be generated. This reduces the need for manual writing of query statements and improves work efficiency; by using the pre-trained large language model to generate query statements, the error rate caused by manually writing query statements can be significantly reduced, and the accuracy of target query statement generation can be improved.
[0179] The present application also provides another implementation, namely, providing a storage medium (computer-readable storage medium), wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the query statement generation method as described above.
[0180] During the implementation process, the computer-readable storage medium of the present application can receive query information input by the user, extract the query parameters of the query information, clarify the query intention of the query information, provide a basis for the query statement generated subsequently, thereby improving the accuracy of the subsequent query statement generation, and reducing the search resources and information, thereby improving the efficiency of the subsequent query statement generation;
[0181] According to the query parameters, context prompt information corresponding to the query parameters is screened out from a preset database, which can improve the generation efficiency and accuracy of subsequent query statements;
[0182] By parsing query parameters according to contextual prompt information to generate initial query statements, the model can generate more accurate initial query statements and improve the accuracy of initial query statement generation. In addition, by using a large language model to generate initial query statements, it not only supports processing requests with complex query parameters, but also reduces the reliance on manually written query statements, thereby improving work efficiency and reducing the risk of errors.
[0183] By inputting the prompt information after pattern linking into the pre-trained large language model, the prompt information can be automatically parsed and the corresponding query statement can be generated. This reduces the need for manual writing of query statements and improves work efficiency; by using the pre-trained large language model to generate query statements, the error rate caused by manually writing query statements can be significantly reduced, and the accuracy of target query statement generation can be improved.
[0184] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.
[0185] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0186] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A method for generating a query statement, characterized in that: The steps include: Receiving query information input by a user, and extracting query parameters of the query information; According to the query parameter, filtering out context prompt information corresponding to the query parameter from a preset database; Processing the query parameters and the context prompt information using a pre-trained large language model to generate an initial query statement; Parsing the initial query statement to obtain an initial table name and an initial column name corresponding to the initial query statement, linking the initial table name and the initial column name with a processing mode of the preset database, and generating prompt information after the mode linking; According to the prompt information after the mode link, the pre-trained large language model is used to generate a target query sentence.
2. The method for generating a query statement according to claim 1, wherein: After receiving the query information input by the user, the method further includes: Identify the data type of the query information; If the data type is identified as a non-text form, obtaining a text conversion method for the non-text form; According to the text conversion method, the query information is converted into a text form.
3. The method for generating a query statement according to claim 1, wherein: The step of extracting the query parameter of the query information includes: Extracting keywords of the query information using a preset keyword extraction method to obtain multiple keywords of the query information; Performing a deduplication operation on the multiple keywords to obtain multiple merged keywords; The multiple combined keywords are converted according to a predetermined format to obtain query parameters of the query information.
4. The method for generating a query statement according to claim 1, wherein: After filtering out the context prompt information corresponding to the query parameter from the preset database, the method further includes: Performing sensitive data identification on the context prompt information; If it is identified that the context prompt information contains the sensitive data, a preset desensitization method is used to desensitize the sensitive data in the context prompt information to obtain the desensitized context prompt information.
5. The method for generating a query statement according to claim 1, wherein: The using of a pre-trained large language model to process the query parameters and the context prompt information to generate an initial query statement includes: According to the context prompt information, a fine-tuning data set is obtained; Using the fine-tuning data set to fine-tune the pre-trained large language model to obtain a fine-tuned large language model; According to the context prompt information, the query parameters are processed by the fine-tuned large language model to obtain the initial query statement.
6. The method for generating a query statement according to claim 1, wherein: After generating a target query sentence according to the prompt information after the mode link using the pre-trained large language model, the method further includes: Execute the target query statement; If the target query statement is executed successfully, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user; If the target query fails to be executed, the error cause is detected by the pre-trained large language model, and correction is performed according to the error cause to obtain a corrected target query; The modified target query statement is re-executed until the modified query statement is successfully executed, the target answer is obtained, and the target answer is fed back to the user.
7. The method for generating a query statement according to claim 6, wherein: If the target query statement is executed successfully, a target answer corresponding to the target query statement is obtained, and the target answer is fed back to the user, the method further includes: Regularly obtain data whose access times exceed a preset threshold within a preset time period to obtain a high-frequency data set; Using a preset indexing technology to index key fields of the high-frequency data set to obtain index fields; Storing the index field in a search engine, and storing the high-frequency data set in a preset cache; When the target query statement is received, the target answer is queried from the preset cache according to the index field.
8. A query statement generating device, characterized in that: The device comprises: An extraction module, used to receive query information input by a user and extract query parameters of the query information; A screening module, configured to screen out contextual prompt information corresponding to the query parameter from a preset database according to the query parameter; A first generation module is used to process the query parameters and the context prompt information using a pre-trained large language model to generate an initial query statement; A mode linking module is used to parse the initial query statement, obtain the initial table name and the initial column name corresponding to the initial query statement, link the initial table name and the initial column name with the mode of the preset database, and generate prompt information after the mode linking; The second generation module is used to generate a target query sentence using the pre-trained large language model according to the prompt information after the pattern link.
9. A computer device, characterized in that: The computer device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for generating a query statement as described in any one of claims 1 to 7.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for generating a query statement according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Optical cable monitoring analysis method and system based on large language model
CN119917637A
Query statement generation method and system and storage medium
CN120162428A
Structured query statement generation method, system and device and electronic equipment
CN120353820A
Text conversion query statement generation method and system, medium and equipment
CN120371853A
Data processing method and device, equipment, storage medium and product
CN121326601A
