Structured query statement generation method and device, storage medium and electronic equipment
By matching the description information with database metadata and using natural language models to generate SQL statements, the problem of low SQL statement generation efficiency in the prior art is solved, and a more efficient data query process is achieved.
Patent Information
- Application Number
- CN202411906614.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
AI Technical Summary
In the prior art, SQL statements need to be written manually when processing data in data tables, resulting in low efficiency in generating SQL statements.
By obtaining the description information input by the target object, matching it with the metadata information of the data table in the database, generating the target prompt word, and generating a structured query statement based on the target prompt word through a natural language model.
It improves the efficiency of SQL statement generation, reduces manual intervention, optimizes the data query process, and provides strong support for business decision-making.
Smart Images

Figure CN119829607A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and device for generating a structured query statement, a storage medium, and an electronic device. Background Art
[0002] In the booming financial industry, data query and analysis play a vital role. With the rapid development of business and the rapid changes in the market environment, the business personnel of financial institutions have an increasing demand for data processing, and the diversity and immediacy of the demand are increasing. However, the traditional data query method requires manual writing of structured query statements (SQL statements), which not only has a certain technical threshold for business personnel, but also often needs to rely on professional data analysts or technical teams when facing complex and changing query requirements, resulting in slow response speed and low efficiency.
[0003] In view of the problem that in the related art, when processing data in a data table, it is necessary to manually write corresponding SQL statements, resulting in relatively low efficiency in generating SQL statements, no effective solution has been proposed yet. Summary of the invention
[0004] The main purpose of the present application is to provide a method and device for generating a structured query statement, a storage medium and an electronic device, so as to solve the problem in the related art that when processing data in a data table, it is necessary to manually write corresponding SQL statements, resulting in relatively low efficiency in generating SQL statements.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a method for generating a structured query statement is provided. The method comprises: obtaining description information input by a target object, wherein the description information is used to describe the processing requirements of the target object for data in a data table; matching the description information with metadata information of a data table in a database to obtain a matching result, wherein the matching result at least includes metadata information of a target data table; generating a target prompt word based on the description information and the matching result; obtaining a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirements of the target object for data in a data table.
[0006] Furthermore, the description information is matched with the metadata information of the data table in the database to obtain a matching result, including: vectorizing the description information to obtain a first vector; obtaining a second vector corresponding to the metadata information of the data table; and performing similarity calculation on the first vector and the second vector to match the description information with the metadata information of the data table in the database to obtain a matching result.
[0007] Furthermore, vectorizing the description information to obtain the first vector includes: splitting the description information to obtain split description information; cleaning the split description information to obtain cleaned description information; and vector mapping words in the cleaned description information to obtain the first vector.
[0008] Furthermore, obtaining a target structured query statement based on the target prompt word through a natural language model includes: generating a first structured query statement based on the target prompt word through the natural language model; interacting with the target object through the natural language model to obtain interaction information; adjusting the first structured query statement according to the interaction information to obtain a second structured query statement; and obtaining the target structured query statement according to the second structured query statement.
[0009] Further, adjusting the first structured query statement according to the interactive information to obtain the second structured query statement includes: performing intent recognition on the interactive information to obtain intent information; adjusting the first structured query statement according to the target prompt word and the intent information to obtain the second structured query statement.
[0010] Further, obtaining the target structured query statement based on the second structured query statement includes: testing the second structured query statement to obtain a test result; if the test result indicates that the test is passed, obtaining the target structured query statement based on the second structured query statement; if the test result indicates that the test is not passed, correcting the second structured query statement to obtain the target structured query statement.
[0011] Furthermore, the second structured query statement is tested to obtain a test result, including: performing error detection on the syntax of the second structured query statement to obtain a first test result; performing error detection on the field name and table name of the data table in the second structured query statement to obtain a second test result; and obtaining the test result based on the first test result and the second test result.
[0012] In order to achieve the above-mentioned purpose, according to another aspect of the present application, a device for generating a structured query statement is provided. The device includes: an acquisition unit, which is used to acquire the description information input by the target object, wherein the description information is used to describe the processing requirements of the target object on the data in the data table; a matching unit, which is used to match the description information with the metadata information of the data table in the database to obtain a matching result, wherein the matching result at least includes the metadata information of the target data table; a generation unit, which is used to generate a target prompt word based on the description information and the matching result; a processing unit, which is used to obtain a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirements of the target object on the data in the data table.
[0013] Furthermore, the matching unit includes: a processing subunit, used to vectorize the description information to obtain a first vector; an acquisition subunit, used to obtain a second vector corresponding to the metadata information of the data table; and a calculation subunit, used to perform similarity calculation on the first vector and the second vector to match the description information with the metadata information of the data table in the database to obtain a matching result.
[0014] Furthermore, the processing subunit includes: a splitting module, used to split the description information to obtain split description information; a cleaning module, used to clean the split description information to obtain cleaned description information; a mapping module, used to perform vector mapping on words in the cleaned description information to obtain the first vector.
[0015] Furthermore, the processing unit includes: a first generating subunit, used to generate a first structured query statement based on the target prompt word through the natural language model; an interacting subunit, used to interact with the target object through the natural language model to obtain interaction information; an adjusting subunit, used to adjust the first structured query statement according to the interaction information to obtain a second structured query statement; and a second generating subunit, used to obtain the target structured query statement based on the second structured query statement.
[0016] Furthermore, the adjustment subunit includes: an identification module, used to perform intent recognition on the interactive information to obtain intent information; an adjustment module, used to adjust the first structured query statement according to the target prompt word and the intent information to obtain the second structured query statement.
[0017] Furthermore, the second generating subunit includes: a testing module, used to test the second structured query statement to obtain a testing result; a generating module, used to obtain the target structured query statement based on the second structured query statement if the testing result indicates that the test has passed; and a correcting module, used to correct the second structured query statement to obtain the target structured query statement if the testing result indicates that the test has failed.
[0018] Furthermore, the verification module includes: a first detection submodule, used to perform error detection on the syntax of the second structured query statement to obtain a first detection result; a second detection submodule, used to perform error detection on the field name and table name of the data table in the second structured query statement to obtain a second detection result; and a generation submodule, used to obtain the verification result based on the first detection result and the second detection result.
[0019] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute any one of the above-mentioned methods for generating a structured query statement.
[0020] According to another aspect of an embodiment of the present invention, an electronic device is provided, including a memory storing an executable program; and a processor for running the program, wherein the program executes any one of the above-mentioned methods for generating a structured query statement when running.
[0021] According to another aspect of an embodiment of the present invention, a computer program product is further provided. The computer program product includes a stored computer program. When the computer program is executed by a processor, any one of the above-mentioned methods for generating a structured query statement is implemented.
[0022] In an embodiment of the present application, descriptive information input by a target object is obtained, wherein the descriptive information is used to describe the processing requirements of the target object for data in a data table; the descriptive information is matched with metadata information of a data table in a database to obtain a matching result, wherein the matching result at least includes metadata information of the target data table; a target prompt word is generated based on the descriptive information and the matching result; a target structured query statement is obtained based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirements of the target object for data in the data table, thereby solving the problem in the prior art that when processing data in a data table, it is necessary to manually write corresponding SQL statements, resulting in relatively low efficiency in generating SQL statements.
[0023] In this solution, the description information input by the target object is matched with the metadata information in the database to obtain the corresponding matching results, and then the target prompt words are generated according to the description information and the matching results. Finally, the natural language model is used to obtain the target structured query statement based on the target prompt words, avoiding the manual writing of the corresponding SQL statement in the prior art, improving the generation efficiency of the SQL statement, and thus achieving the effect of improving the processing efficiency of the data in the data table. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0025] Figure 1 A hardware structure block diagram of a computer terminal for implementing a method for generating a structured query statement is shown;
[0026] Figure 2 It is a flowchart of a method for generating a structured query statement according to an embodiment of the present application;
[0027] Figure 3 is a schematic diagram of a method for generating a structured query statement according to an embodiment of the present application;
[0028] Figure 4 is a schematic diagram of a device for generating a structured query statement according to an embodiment of the present application;
[0029] Figure 5 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0030] 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. 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 ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] It should be noted that the collected information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this application are information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of relevant data are in compliance with relevant laws, regulations and standards, necessary confidentiality measures are taken, and public order and good customs are not violated, and corresponding operation entrances are provided for users to choose to authorize or refuse. For example, an interface is set up between this system and relevant users or institutions to provide users with corresponding operation entrances for users to choose to agree or refuse the results of automated decision-making; if the user chooses to refuse, the expert decision-making process will be entered.
[0033] Example 1
[0034] According to an embodiment of the present application, an embodiment of a method for generating a structured query statement is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0035] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 The hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for generating a structured query statement is shown. Figure 1As shown, the computer terminal 10 (or mobile device) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0036] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0037] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method for generating structured query statements in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the method for generating structured query statements described above is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0038] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0039] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).
[0040] Under the above operating environment, this application provides Figure 2 The method for generating the structured query statement shown. Figure 2 It is a flowchart of a method for generating a structured query statement according to the first embodiment of the present application.
[0041] Step S201, obtaining description information input by the target object, wherein the description information is used to describe the processing requirements of the target object on the data in the data table.
[0042] Optionally, the user writes corresponding description information according to the processing requirements for the data in the data table. For example, the description information is "I now want to obtain a list of customers of XX branch who have assets of more than 50,000 but have not opened a pension account."
[0043] Step S202, matching the description information with the metadata information of the data table in the database to obtain a matching result, wherein the matching result at least includes the metadata information of the labeled data table.
[0044] Optionally, after obtaining the above-mentioned description information, the description information can be vectorized, and then the similarity between the vectorized description information and the metadata information of the data table in the database can be calculated, thereby achieving a match between the description information and the metadata information of the data table in the database to obtain the above-mentioned matching result.
[0045] It should be noted that the language input by the user can be vectorized through the embedding model, and each word or phrase will be mapped to a vector with a specific dimension.
[0046] It should be noted that in order to facilitate the matching of the description information with the metadata information of the data table in the database, the data tables in the database can be sorted out and the metadata of the tables in the database can be systematically organized. For example, the detailed information of each table, such as field name, data type, relationship between tables, etc. (i.e. metadata), can be written into the vector database for subsequent vector matching.
[0047] Step S203: Generate a target prompt word according to the description information and the matching result.
[0048] Optionally, after obtaining the matching result, the description information and the metadata information of the target data table in the matching result are integrated, and the above-mentioned target prompt is generated. It should be noted that the prompt is used to instruct the natural language model to understand the user's true intention and generate a standard structured query statement (SQL, Structured Query Language). For example, the prompt can be to generate SQL based on the description information and the metadata information of the target data table in the matching result, so as to obtain the data required in the description information through SQL.
[0049] Step S204, obtaining a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirement of the target object on the data in the data table.
[0050] Optionally, the target prompt word is input into a natural language model, and an accurate target structured query statement is generated through the natural language model. It should be noted that the target structured query statement is used to realize the user's processing requirements on the data in the data table.
[0051] In summary, the description information input by the target object is matched with the metadata information in the database to obtain the corresponding matching results, and then the target prompt words are generated according to the description information and the matching results. Finally, the target structured query statement is obtained based on the target prompt words using the natural language model, which avoids the manual writing of the corresponding SQL statement in the prior art, improves the generation efficiency of the SQL statement, and thus achieves the effect of improving the processing efficiency of the data in the data table.
[0052] Optionally, the description information is matched with the metadata information of the data table in the database to obtain a matching result, including: vectorizing the description information to obtain a first vector; obtaining a second vector corresponding to the metadata information of the data table; and performing similarity calculation on the first vector and the second vector to match the description information with the metadata information of the data table in the database to obtain a matching result.
[0053] In an optional embodiment, the following steps may be used to match the description information with the metadata information of the data table in the database: first, the description information is vectorized to obtain a first vector, for example, the description information is input into an embedding model, and the description information input by the user is vectorized through the embedding model, and each word or phrase is mapped to a vector with a specific dimension. Then, a second vector corresponding to the metadata information of the data table is obtained.
[0054] The similarity of the first vector and the second vector is calculated to obtain a similarity value, and the data table is screened according to the similarity value. A data table with a larger similarity value can be selected as the above target data table, thereby obtaining the above matching result.
[0055] Vectorization and similarity calculation can effectively improve the accuracy of matching description information with metadata information of data tables in the database.
[0056] Optionally, vectorizing the description information to obtain the first vector includes: splitting the description information to obtain split description information; cleaning the split description information to obtain cleaned description information; and vector mapping words in the cleaned description information to obtain the first vector.
[0057] In an optional embodiment, the description information may be vectorized by the following steps: the description information is split, that is, the description information is split into individual characters to obtain the split description information. Then, the split description information is cleaned to remove repeated or redundant characters, and finally, vector mapping is performed based on the words in the cleaned description information to obtain the first vector.
[0058] By splitting and cleaning the description information, the accuracy of the vectorization of the description information is improved, thereby achieving the effect of improving the processing efficiency of the data in the data table.
[0059] Optionally, obtaining a target structured query statement based on a target prompt word through a natural language model includes: generating a first structured query statement based on a target prompt word through a natural language model; interacting with a target object through a natural language model to obtain interaction information; adjusting the first structured query statement based on the interaction information to obtain a second structured query statement; and obtaining a target structured query statement based on the second structured query statement.
[0060] In an optional embodiment, the target structured query statement may be obtained by taking the following steps: inputting the target prompt word into a natural language model, and the natural language model generates an initial SQL (ie, the first structured query statement mentioned above) according to the target prompt word.
[0061] In order to avoid the problem that the natural language model cannot accurately generate SQL due to ambiguous description information, the natural language model will interact with the target object based on the ambiguous information to obtain interactive information. For example, the user asks "I want to get a list of customers in XX branch who have assets of more than 50,000 but have never opened a pension account", but the concept of "assets" may correspond to multiple fields such as "average daily asset balance" or "point-in-time asset balance". Therefore, the natural language model can be used to ask the user questions to determine whether the query is "average daily asset balance" or "point-in-time asset balance".
[0062] After the interaction information is obtained, the first structured query statement is adjusted according to the interaction information to obtain a second structured query statement, and finally a target structured query statement is obtained according to the second structured query statement.
[0063] The interactive information can prevent LLM from generating SQL statements that may contain errors, thereby improving the accuracy of the target structured query statements.
[0064] Optionally, adjusting the first structured query statement according to the interactive information to obtain the second structured query statement includes: performing intent recognition on the interactive information to obtain intent information; adjusting the first structured query statement according to the target prompt word and the intent information to obtain the second structured query statement.
[0065] In an optional embodiment, the first structured query statement can be adjusted to obtain a second structured query statement through the following steps: the intention of the interactive information can be identified through an intention recognition model to determine that the user is thinking of the information in the data table, and then the first structured query statement is adjusted according to the target prompt word and the intention information to obtain a corrected second structured query statement.
[0066] By deeply understanding the interactive information, we can accurately judge the user's query intention and modify the SQL query accordingly to ensure correct execution and return of expected results, thereby improving the accuracy of SQL statements.
[0067] Optionally, obtaining a target structured query statement based on the second structured query statement includes: testing the second structured query statement to obtain a test result; if the test result indicates that the test is passed, obtaining the target structured query statement based on the second structured query statement; if the test result indicates that the test is not passed, correcting the second structured query statement to obtain the target structured query statement.
[0068] In an optional embodiment, obtaining a target structured query statement according to the second structured query statement includes the following steps: verifying the second structured query statement to obtain a verification result, for example, performing grammatical analysis, semantic analysis and other processing on the second structured query statement, and then determining whether the second structured query statement needs to be corrected according to the processing result; if correction is not required, determining the second structured query statement as the target structured query statement; if correction is required, determining the corrected second structured query statement as the target structured query statement.
[0069] The accuracy of SQL statements is further improved by detecting structured query statements.
[0070] Optionally, the second structured query statement is tested to obtain a test result including: performing error detection on the syntax of the second structured query statement to obtain a first test result; performing error detection on the field name and table name of the data table in the second structured query statement to obtain a second test result; and obtaining a test result based on the first test result and the second test result.
[0071] In an optional embodiment, the following steps may be used to test the second structured query statement: combining grammatical analysis and semantic analysis to perform grammatical error detection on the second structured query statement to obtain a first detection result. For example, the SQL query statement may be deeply analyzed to accurately identify common error types such as grammatical errors, spelling errors, part-of-speech confusion, and keyword omissions; the deep meaning of the SQL query may be analyzed to effectively identify semantic defects such as logical errors and relationship confusion; and the vocabulary in the SQL query may be carefully tagged with part-of-speech to accurately identify part-of-speech errors such as misusing a numeric field as a string.
[0072] The field names and table names of the data table in the second structured query statement may also be subjected to error detection to obtain a second detection result. For example, the field names in the SQL query may be compared with the database schema one by one to accurately identify field name errors. For example, if a field that does not exist in the database is referenced in the query, the table name in the SQL query may be verified to ensure that the table name is consistent with the database schema to avoid using a non-existent table in the query, the relational expression in the SQL query may be matched with the database schema to ensure the accuracy of the relational expression to avoid using a relation that does not exist in the database as a query condition, etc.
[0073] Finally, a test result is obtained according to the first test result and the second test result.
[0074] By performing error detection on the syntax of the second structured query statement and performing error detection on the field name and table name of the data table in the second structured query statement, the accuracy of the SQL statement is improved.
[0075] In an optional embodiment, negative feedback adjustment can also be performed based on the execution results of the target SQL statement. For example, the execution results of the SQL query can be deeply analyzed to accurately determine whether there are logical errors or data inconsistencies, such as empty result sets or results that do not meet expectations, etc. According to the execution results, the source of errors in the SQL query can be accurately tracked, such as the specific fields or conditions that cause logical errors or data inconsistencies. By continuously collecting and analyzing user data, the mechanism gradually grasps user query habits and needs, optimizes error detection and correction strategies, and provides users with more accurate, efficient and intelligent query services.
[0076] In an optional embodiment, the following may be used: Figure 3 The schematic diagram shown realizes the generation of structured query statements, which specifically includes: a data sorting module, an input module, an LLM (Large Language Model) processing module and an error detection and correction module.
[0077] The data sorting module performs normalization processing on data assets (all tables in the database). The input module receives the user's natural language query, obtains prompt words, and receives interactive information with the user about fuzzy information; the LLM processing module converts natural language queries into SQL queries using a pre-trained large language model; the error detection and correction module analyzes the generated SQL queries, identifies potential syntax errors, logical errors, and database mismatches, and corrects the SQL queries with context awareness based on the error detection results.
[0078] The method for generating a structured query statement provided in an embodiment of the present application is to obtain a matching result including the metadata information of a target data table by having a user input descriptive information describing the processing requirements of the user on the data in the data table, generate a target prompt word, and obtain a target structured query statement based on the target prompt word through a natural language model, thereby solving the problem of low efficiency in generating SQL statements due to the need to manually write corresponding SQL statements when processing the data in the data table.
[0079] In this solution, the target object inputs description information, obtains the processing requirements of the target object for the data in the table, matches the description information with the metadata information in the database, obtains the matching result, and the matching result includes the metadata information of the target data table. According to the matching result, the target prompt word is generated, and then the target structured query statement is obtained based on the target prompt word through the natural language model, so as to realize the processing requirements of the target object for the data in the data table. It avoids processing the data in the data table by manually writing SQL statements, thereby achieving the effect of improving the efficiency of generating SQL statements.
[0080] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0081] Example 2
[0082] The embodiment of the present application also provides a structured query statement generation device. It should be noted that the structured query statement generation device of the embodiment of the present application can be used to execute the structured query statement generation method provided in the embodiment of the present application. The structured query statement generation device provided in the embodiment of the present application is introduced below.
[0083] According to an embodiment of the present application, a device for implementing the above structured query statement generation method is also provided, such as Figure 4 As shown, the device includes: an acquisition unit 401, a matching unit 402, a generation unit 403, and a processing unit 404.
[0084] An acquisition unit 401 is used to acquire description information input by a target object, wherein the description information is used to describe the processing requirements of the target object on the data in the data table;
[0085] A matching unit 402 is used to match the description information with the metadata information of the data table in the database to obtain a matching result, wherein the matching result at least includes the metadata information of the target data table;
[0086] A generating unit 403, used to generate a target prompt word according to the description information and the matching result;
[0087] The processing unit 404 is used to obtain a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirement of the target object on the data in the data table.
[0088] The structured query statement generation device provided in the embodiment of the present application obtains description information input by the target object through an acquisition unit, wherein the description information is used to describe the processing requirements of the target object for the data in the data table; the matching unit matches the description information with the metadata information of the data table in the database to obtain a matching result, wherein the matching result at least includes the metadata information of the target data table; the generation unit generates a target prompt word according to the description information and the matching result; the processing unit obtains a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirements of the target object for the data in the data table, solves the problem that the corresponding SQL statement needs to be manually written when processing the data in the data table, resulting in relatively low efficiency in generating SQL statements, reduces the frequency of manual intervention, optimizes the data query process, and provides strong support for business decisions.
[0089] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the matching unit includes: a processing subunit, used to vectorize the description information to obtain a first vector; an acquisition subunit, used to obtain a second vector corresponding to the metadata information of the data table; and a calculation subunit, used to perform similarity calculation on the first vector and the second vector to match the description information with the metadata information of the data table in the database to obtain a matching result.
[0090] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the processing subunit includes: a splitting module, used to split the description information to obtain the split description information; a cleaning module, used to clean the split description information to obtain the cleaned description information; a mapping module, used to perform vector mapping on the words in the cleaned description information to obtain a first vector.
[0091] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the processing unit includes: a first generation sub-unit, used to generate a first structured query statement based on a target prompt word through a natural language model; an interaction sub-unit, used to interact with the target object through a natural language model to obtain interaction information; an adjustment sub-unit, used to adjust the first structured query statement according to the interaction information to obtain a second structured query statement; and a second generation sub-unit, used to obtain a target structured query statement based on the second structured query statement.
[0092] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the adjustment subunit includes: an identification module, used to identify the intent of the interactive information and obtain the intent information; an adjustment module, used to adjust the first structured query statement based on the target prompt word and the intent information to obtain the second structured query statement.
[0093] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the second generation sub-unit includes: a verification module, which is used to verify the second structured query statement and obtain a verification result; a generation module, which is used to obtain a target structured query statement based on the second structured query statement if the verification result indicates that the verification has passed; and a correction module, which is used to correct the second structured query statement to obtain a target structured query statement if the verification result indicates that the verification has failed.
[0094] Optionally, in the configuration device of the electronic payment device provided in the embodiment of the present application, the verification module includes: a first detection submodule, used to perform error detection on the syntax of the second structured query statement to obtain a first detection result; a second detection submodule, used to perform error detection on the field name and table name of the data table in the second structured query statement to obtain a second detection result; and a generation submodule, used to obtain a verification result based on the first detection result and the second detection result.
[0095] It should be noted that the acquisition unit 401, matching unit 402, generation unit 403 and processing unit 404 correspond to steps S201 to S204 in Embodiment 1, and the four units and corresponding steps implement the same examples and application scenarios, but are not limited to the contents disclosed in Embodiment 1. It should be noted that the modules or units may be hardware components or software components stored in a memory (e.g., memory 104) and processed by one or more processors (e.g., processors 102a, 102b, ..., 102n), and the modules may also be part of a device and run in the computer terminal 10 provided in Embodiment 1.
[0096] Example 3
[0097] An embodiment of the present application may provide an electronic device, Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application. Figure 5 As shown, the electronic device may include: one or more ( Figure 5 (only one is shown) processor 502, memory 504, storage controller, and peripheral interface, wherein the peripheral interface is connected to the radio frequency module, audio module and display.
[0098] Among them, the memory can be used to store software programs and modules, such as program instructions / modules corresponding to the methods and devices in the embodiments of the present application, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, realizing the above-mentioned method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0099] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtain the description information input by the target object, wherein the description information is used to describe the processing requirements of the target object for the data in the data table; match the description information with the metadata information of the data table in the database to obtain a matching result, wherein the matching result at least includes the metadata information of the target data table; generate a target prompt word based on the description information and the matching result; obtain a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirements of the target object for the data in the data table.
[0100] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: match the description information with the metadata information of the data table in the database, and obtain the matching result including: vectorizing the description information to obtain a first vector; obtaining a second vector corresponding to the metadata information of the data table; performing similarity calculation on the first vector and the second vector to match the description information with the metadata information of the data table in the database to obtain a matching result.
[0101] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: vectorize the description information to obtain the first vector, including: splitting the description information to obtain split description information; cleaning the split description information to obtain cleaned description information; vector mapping the words in the cleaned description information to obtain the first vector.
[0102] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtaining a target structured query statement based on the target prompt word through the natural language model includes: generating a first structured query statement based on the target prompt word through the natural language model; interacting with the target object through the natural language model to obtain interaction information; adjusting the first structured query statement according to the interaction information to obtain a second structured query statement; and obtaining a target structured query statement based on the second structured query statement.
[0103] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: adjusting the first structured query statement based on the interactive information to obtain the second structured query statement including: performing intent recognition on the interactive information to obtain intent information; adjusting the first structured query statement based on the target prompt word and the intent information to obtain the second structured query statement.
[0104] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtaining a target structured query statement based on the second structured query statement includes: testing the second structured query statement to obtain a test result; if the test result indicates that the test is passed, obtaining the target structured query statement based on the second structured query statement; if the test result indicates that the test is not passed, correcting the second structured query statement to obtain the target structured query statement.
[0105] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: verify the second structured query statement, and obtain the verification result including: perform error detection on the syntax of the second structured query statement to obtain a first detection result; perform error detection on the field name and table name of the data table in the second structured query statement to obtain a second detection result; obtain the verification result based on the first detection result and the second detection result.
[0106] In an embodiment of the present application, a method for generating a structured query statement is provided. The target object is used to input description information describing its processing requirements for data in a data table, and the description information is matched with the metadata information of the data table in the database to obtain a matching result including the metadata information of the target data table, generate a target prompt word, and obtain a target structured query statement based on the target prompt word through a natural language model, thereby solving the problem that the corresponding SQL statement needs to be manually written when processing the data in the data table, resulting in a relatively low efficiency in generating the SQL statement.
[0107] It can be understood by those skilled in the art that Figure 5The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Figure 5 The structure of the electronic device is not limited. Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations shown.
[0108] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0109] Example 4
[0110] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to store the program code executed by the method for generating structured query statements provided in the first embodiment.
[0111] Optionally, in this embodiment, the above storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0112] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing the steps of the method for generating a structured query statement.
[0113] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0114] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0115] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0116] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0117] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0118] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0119] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for generating a structured query statement, characterized in that: include: Obtaining description information input by the target object, wherein the description information is used to describe the processing requirements of the target object on the data in the data table; Matching the description information with metadata information of a data table in a database to obtain a matching result, wherein the matching result at least includes metadata information of a target data table; Generate a target prompt word according to the description information and the matching result; A target structured query statement is obtained based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirement of the target object on the data in the data table.
2. The method according to claim 1, characterized in that The description information is matched with the metadata information of the data table in the database, and the matching results obtained include: Performing vectorization processing on the description information to obtain a first vector; Obtaining a second vector corresponding to the metadata information of the data table; A similarity calculation is performed on the first vector and the second vector to match the description information with metadata information of a data table in a database to obtain a matching result.
3. The method according to claim 2, characterized in that The description information is vectorized to obtain a first vector including: Splitting the description information to obtain split description information; Cleaning the split description information to obtain cleaned description information; Vector mapping is performed on the words in the cleaned description information to obtain the first vector.
4. The method according to claim 1, characterized in that: The target structured query sentence is obtained based on the target prompt word through the natural language model, including: Generate a first structured query statement based on the target prompt word through the natural language model; Interacting with the target object through the natural language model to obtain interaction information; adjusting the first structured query statement according to the interactive information to obtain a second structured query statement; The target structured query statement is obtained according to the second structured query statement.
5. The method according to claim 4, characterized in that The first structured query statement is adjusted according to the interactive information to obtain a second structured query statement including: Performing intent recognition on the interaction information to obtain intent information; The first structured query statement is adjusted according to the target prompt word and the intention information to obtain the second structured query statement.
6. The method according to claim 4, characterized in that Obtaining the target structured query statement according to the second structured query statement includes: Testing the second structured query statement to obtain a test result; If the inspection result indicates that the inspection is passed, obtaining the target structured query statement according to the second structured query statement; If the inspection result indicates that the inspection fails, the second structured query statement is modified to obtain the target structured query statement.
7. The method according to claim 6, characterized in that The second structured query statement is tested, and the test results obtained include: Performing error detection on the syntax of the second structured query statement to obtain a first detection result; Performing error detection on the field name and table name of the data table in the second structured query statement to obtain a second detection result; The inspection result is obtained according to the first detection result and the second detection result.
8. A device for generating a structured query statement, characterized in that: include: An acquisition unit, used for acquiring description information input by a target object, wherein the description information is used for describing the processing requirements of the target object on the data in the data table; A matching unit, configured to match the description information with metadata information of a data table in a database to obtain a matching result, wherein the matching result at least includes metadata information of a target data table; A generating unit, configured to generate a target prompt word according to the description information and the matching result; The processing unit is used to obtain a target structured query statement based on the target prompt word through a natural language model, wherein the target structured query statement is used to realize the processing requirement of the target object on the data in the data table.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is run, the device where the computer-readable storage medium is located is controlled to execute the method for generating a structured query statement according to any one of claims 1 to 7.
10. An electronic device, characterized in that: include: A memory storing an executable program; A processor is used to run the program, wherein the program executes the method for generating a structured query statement according to any one of claims 1 to 7 when running.
Citation Information
Cited By
Structured query statement generation method, system and device and electronic equipment
CN120353820A
Natural language query method and device in power field, terminal equipment and storage medium
CN120804145A
Industrial production data processing method and device and storage medium
CN121501951A
Method for processing industrial production data, processing device and storage medium
CN121501951B
Knowledge retrieval method and device based on question and answer agent, equipment and medium
CN122387997A