Method and device for generating structured query statement, equipment and storage medium

By utilizing knowledge base and machine learning models, structured query statements are generated, and the problem of professional knowledge and time required to generate query statements in the existing technology is solved, achieving higher query accuracy and user satisfaction.

CN119807220APending Publication Date: 2025-04-11BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411845855.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-13
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

In the prior art, generating structured query statements requires a lot of expertise and time, and template-based query methods are difficult to flexibly process users' query intentions, resulting in low accuracy and user satisfaction of query results.

Method used

By responding to user query problems, determine the knowledge base associated with the target database, determine the query variables from it, and generate corresponding structured query statements using predetermined templates and machine learning models.

Benefits of technology

It improves the accuracy and efficiency of generating structured query statements, enhances the flexible processing of user query intentions, and improves the quality of query results and user satisfaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119807220A_ABST
    Figure CN119807220A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for generating a structured query statement, equipment and a storage medium. The method comprises the following steps: in response to a received query problem of a user for a target database, determining a knowledge base associated with data in the target database; determining a query variable aiming at the query problem from the determined knowledge base; determining a first cue word based on the query variable and the query problem by utilizing a preset first template; and generating a first structured query statement which corresponds to the query problem and aims at the target database based on the first cue word by utilizing a machine learning model. Therefore, by combining a retrieval enhancement generation technology, external knowledge is fully understood before the structured query statement is generated, so that the more accurate and context-related structured query statement is generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Example embodiments of the present disclosure generally relate to the field of artificial intelligence technology, and more particularly to a method, apparatus, device, and computer-readable storage medium for generating a structured query statement. Background Art

[0002] In modern data analysis and business decision-making, it is often necessary to query and analyze data from huge databases to support various business intelligence and data-driven decision-making processes.

[0003] In the related technologies, structured query statements of databases usually require a lot of professional knowledge and time costs. Users need to have a deep understanding of the database structure and related syntax to complete complex data query tasks. In addition, query methods based on templates or fixed formats often lack the flexibility to handle user query intentions, resulting in low accuracy of query results and low user satisfaction.

[0004] Therefore, a method for generating structured query statements with higher accuracy and applicability is needed. Summary of the invention

[0005] In a first aspect of the present disclosure, a method for generating a structured query statement is provided. The method includes: in response to receiving a query question from a user for a target database, determining a knowledge base associated with data in the target database; determining a query variable for the query question from the determined knowledge base; using a predetermined first template, based on the query variable and the query question, determining a first prompt word; and using a machine learning model, based on the first prompt word, generating a first structured query statement for the target database corresponding to the query question.

[0006] In a second aspect of the present disclosure, a device for generating a structured query statement is provided. The device includes: a knowledge base determination module, configured to determine a knowledge base associated with data in a target database in response to receiving a query question from a user for a target database; a query variable determination module, configured to determine a query variable for the query question from the determined knowledge base; a prompt word determination module, configured to determine a first prompt word based on the query variable and the query question using a predetermined first template; and a generation module, configured to generate a first structured query statement for the target database corresponding to the query question based on the first prompt word using a machine learning model.

[0007] In a third aspect of the present disclosure, an electronic device is provided. The device includes at least one processing unit; and at least one memory, the at least one memory is coupled to the at least one processing unit and stores instructions for execution by the at least one processing unit. When the instructions are executed by the at least one processing unit, the device executes the method of the first aspect.

[0008] In a fourth aspect of the present disclosure, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and the computer program can be executed by a processor to implement the method of the first aspect.

[0009] In a fifth aspect of the present disclosure, a computer program product is provided, which is tangibly stored in a computer storage medium and includes computer executable instructions, which when executed by a device cause the device to perform the method according to the first aspect of the present disclosure.

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

[0011] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0012] Figure 1 A schematic diagram showing an example environment in which embodiments of the present disclosure can be implemented;

[0013] Figure 2 A flowchart of a process for generating a structured query statement according to some embodiments of the present disclosure is shown;

[0014] Figure 3A A schematic diagram showing a process of determining first knowledge in some embodiments of the present disclosure;

[0015] Figure 3B A schematic diagram showing a process of determining business indicator variables in some embodiments of the present disclosure;

[0016] Figure 3C A schematic diagram showing a process of verifying and processing a first structured query statement according to some embodiments of the present disclosure is shown;

[0017] Figure 3D A schematic diagram showing a process of processing a second structured query statement according to some embodiments of the present disclosure;

[0018] Figure 4 A block diagram showing an apparatus for generating a structured query statement according to some embodiments of the present disclosure; and

[0019] Figure 5 A block diagram of an electronic device capable of implementing one or more embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0020] It is understandable that before using the technical solutions disclosed in the embodiments of the present disclosure, the types, scope of use, usage scenarios, etc. of the personal information involved in the present disclosure should be informed to the user and the user's authorization should be obtained in an appropriate manner in accordance with relevant laws and regulations.

[0021] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly prompt the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can autonomously choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0022] As an optional but non-limiting implementation, in response to receiving an active request from the user, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0023] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet the relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0024] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and relevant provisions.

[0025] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0026] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The term "some embodiments" should be understood as "at least some embodiments". Other explicit and implicit definitions may also be included below.

[0027] As briefly mentioned above, with the development of various storage technologies, the scale of user data is becoming increasingly large. Data analysis and business decision-making often rely on extracting and analyzing data from a large number of databases. In order to support intelligent and data-driven decision-making processes, users usually need to construct complex structured query languages ​​(SQL) statements to obtain the required data. However, constructing accurate and efficient SQL query statements requires a high level of professional knowledge from users, and usually requires familiarity with database structure, SQL syntax, and business logic.

[0028] In the related technologies, there are mainly the following data query methods, but they all have certain limitations:

[0029] Manually writing SQL queries: Users need to have a high level of knowledge of SQL syntax and database structure to construct complex query statements; manually writing and debugging SQL query statements requires a lot of time and effort; due to the complexity of SQL statements, manual writing is prone to syntax errors or logical errors, resulting in inaccurate query results.

[0030] Template-based query method: Template-based query methods are difficult to cope with users' diverse and complex query needs, and can often only handle preset query scenarios; template-based queries cannot fully consider users' personalized needs and changes in the current business environment, resulting in low applicability and accuracy of query results.

[0031] Natural Language to Structured Query Language (NL2SQL): NL2SQL is a technology that converts natural language into SQL queries. Its goal is to convert the query requests made by users in natural language into machine-readable SQL query statements so as to retrieve the corresponding data from the database.

[0032] However, the existing NL2SQL technology often cannot accurately map the query intent of users to the database structure and business logic, resulting in inaccurate SQL statements. In addition, it usually lacks the ability to dynamically adapt to real-time data and user attributes, and cannot fully utilize the latest business data and user information.

[0033] Therefore, in order to improve the accuracy and efficiency of generating SQL statements while enhancing flexibility and adaptability, a more accurate and efficient solution for generating structured query statements is needed, which can combine language models and information retrieval technology to guide the generation of SQL statements by retrieving relevant information from the knowledge base, thereby improving the quality and accuracy of queries.

[0034] In an embodiment of the present disclosure, a scheme for generating a structured query statement is provided. According to an embodiment of the present disclosure, in response to receiving a query question from a user for a target database, a knowledge base associated with data in the target database is determined; a query variable for the query question is determined from the determined knowledge base; a first prompt word is determined based on the query variable and the query question using a predetermined first template; and a first structured query statement for the target database corresponding to the query question is generated based on the first prompt word using a machine learning model.

[0035] Therefore, by utilizing the Retrieval-Augmented Generation (RAG) technology, combining machine learning models and information retrieval technology, the various variables in the prompt word generation template are determined by retrieving relevant information from the knowledge base associated with the data in the target database, thereby guiding the generation of SQL statements and improving the accuracy and efficiency of generating SQL statements.

[0036] Figure 1 A schematic diagram of an example environment 100 in which embodiments of the present disclosure can be implemented is shown. In the environment 100, the electronic device 110 determines a knowledge base 130 associated with data in the target database 140 in response to receiving a query question 120 from a user for a target database 140. The electronic device 110 determines information related to the user query by searching the knowledge base 130, thereby guiding the generation of a structured query language 150.

[0037] In the disclosed embodiment, the knowledge base 130 may include knowledge associated with the data in the target database 140, which covers all information resources used in the process of generating SQL statements. Knowledge refers to information or data that has been organized, integrated, refined and verified, generally has a clear structure and meaning, and can be directly used to support the implementation of functions, such as user query intent recognition, generating prompt words, guiding the generation of SQL statements, etc. In the knowledge base 130, knowledge is often organized and refined through specific methods and tools (such as offline processing, online acquisition), and has a structured or semi-structured form, such as database records, knowledge graph nodes, etc., which together form the basis for the system to understand user query problems, generate prompt words and final SQL statements.

[0038] In some embodiments, the electronic device 110 may also regularly update the knowledge base 130 based on real-time data in the target database 140 or new research results, industry trends, etc., to ensure the timeliness and accuracy of the knowledge.

[0039] In the environment 100, the electronic device 110 can be any type of device with computing capabilities, including a terminal device or a server device. The terminal device can be any type of mobile terminal, fixed terminal or portable terminal, including a mobile phone, a desktop computer, a laptop computer, a notebook computer, a netbook computer, a tablet computer, a media computer, a multimedia tablet, a personal communication system (PCS) device, a personal navigation device, a personal digital assistant (PDA), an audio / video player, a digital camera / camcorder, a positioning device, a television receiver, a radio broadcast receiver, an e-book device, a gaming device, or any combination of the foregoing, including accessories and peripherals of these devices or any combination thereof. The server device can include, for example, a computing system / server, such as a mainframe, an edge computing node, a computing device in a cloud environment, and the like.

[0040] It should be understood that the structure and functionality of environment 100 are described for exemplary purposes only and does not imply any limitation on the scope of the present disclosure.

[0041] Figure 2 1 is a flowchart of a process 200 for generating a structured query statement according to some embodiments of the present disclosure. The process 200 may be implemented in the environment 100, for example, the process 200 may be implemented at the electronic device 110. In the following, for ease of discussion, reference will be made to Figure 1 The process 200 is described below.

[0042] In block 210 , in response to receiving a query question 120 from a user directed to a target database 140 , the electronic device 110 determines a knowledge base 130 associated with data in the target database 140 .

[0043] In some embodiments, the user's query 120 refers to a question raised by the user in a natural language, which is intended to query data in the target database 140. The query 120 may be a query sent by the user in various forms such as text, voice, or image.

[0044] As an example, query question 120 may include querying data under specific conditions, such as "querying departments with sales exceeding 100,000 last month"; statistical summary data query, such as "calculating the average salary of each department"; complex screening condition query, such as "querying the name and email address of employees who joined the company in XX year and whose current position is 'A'"; and multi-table joint query involving at least two data tables, such as "querying the customer name, order amount and corresponding order date of each order."

[0045] In some embodiments, after receiving the user's query question 120, the electronic device 110 may first determine the knowledge base 130 associated with the data in the target database 140. The knowledge base 130 may help the electronic device 110 better understand the context of the user's query, including the structure of the database, the specific content of the data, and specific indicators related to the business, thereby guiding the electronic device 110 to generate more accurate SQL statements.

[0046] In some embodiments, the knowledge base 130 may include first knowledge that is predetermined and stored during a period of time when there is no direct interaction with the user, thereby providing static data-related information for generating SQL statements. The first knowledge is the basis for understanding and querying the database, which enhances the electronic device 110's ability to understand the database structure and business logic, and improves the accuracy and efficiency of SQL generation.

[0047] In some embodiments, the first knowledge includes data table knowledge and / or business indicator knowledge.

[0048] In some embodiments, the electronic device 110 acquires first knowledge about the target database 140 .

[0049] In some embodiments, the electronic device 110 determines the first knowledge in the following manner: determining data table knowledge based on table structure information of a data table stored in the target database and / or data in the data table. Determining business indicator knowledge based on the data table in the target database.

[0050] As an example, Figure 3A A schematic diagram of a process of determining the first knowledge 131 according to some embodiments of the present disclosure is shown. The process 300A may be implemented at the electronic device 110 .

[0051] In block 311 , the electronic device 110 determines a data table in the target database 140 .

[0052] In some embodiments, the data tables in the target database 140 may include two types: online tables and offline tables. Among them, online tables generally refer to those data tables that are directly connected to the database system and can be accessed and updated in real time. Offline tables are data tables that users upload to the system but are not directly connected to the database system. These tables may be imported from other data sources (such as Excel files, CSV files, etc.), or data snapshots exported from online tables at a specific point in time.

[0053] In some embodiments, for offline tables uploaded by users, the electronic device 110 can automatically create corresponding virtual online tables. The table name can be automatically generated based on user information and timestamps, the column name can be automatically generated by machine learning models such as large language models, and information such as data types and field descriptions can also be automatically determined and generated by large language models. In this way, the electronic device 110 can uniformly process data query requirements for online and offline tables.

[0054] In block 312 , the electronic device 110 may read the data in the data table based on a predetermined time interval and determine the data table knowledge based on the table structure information of the data table and / or the data in the data table.

[0055] In some embodiments, the data table knowledge includes column knowledge 131-1 (such as column name, data type, Chinese description, etc.) and enumeration value knowledge 131-2 (such as the value of the enumerable column). This information can be automatically generated when the electronic device 110 accesses the data table in the target database 140 and stored in a predetermined database.

[0056] As an example, Table 1 shows the fields that the column knowledge 131 - 1 may include and the corresponding descriptions.

[0057] Table 1 lists the knowledge related fields and descriptions

[0058]

[0059]

[0060] As shown in Table 1, column knowledge 131-1 may include metadata (Metadata) of a data table of the target database 140 for describing the database table structure and characteristics, such as database identification (Identity document, ID), table name, column name, data type, description, special entity type, etc. This information helps the electronic device 110 to accurately reference and process data columns in the database when generating SQL statements.

[0061] In some embodiments, a partition key is a key concept used to divide the data in a data table into multiple parts (i.e., partitions). For example, by partitioning based on the order date, the order data can be divided into multiple partitions stored in time units such as years, months, or days. Partitioning can improve the performance of database queries, especially when processing large amounts of data. Each partition can be managed and queried independently, thereby reducing the impact on the overall database performance. Adding whether a partition key is added to the column knowledge 131-1 helps generate more efficient query statements. For example, by specifying the value of a partition field to limit the scope of the query, unnecessary full table scans can be reduced, thereby increasing query speed.

[0062] In some embodiments, a foreign key is a field in a database table that is used to associate the primary key of other tables. By adding a foreign key field to the column knowledge 131-1, the foreign key relationship between data tables can be understood to help the electronic device 110 understand the user's query intention more accurately, especially when the user's query involves multiple tables, the electronic device 110 can use the foreign key information to construct appropriate connection conditions to ensure the accuracy of the query results.

[0063] In some embodiments, adding value samples (also referred to as example values ​​or value examples) to the column knowledge 131-1 helps to better understand the actual distribution and characteristics of the column data. By viewing the example values, the electronic device 110 can use machine learning models such as large language models to more accurately infer the possible data types, formats, and possible query scenarios of the columns, thereby improving the accuracy and generalization ability when generating SQL statements.

[0064] As an example, Table 2 shows the fields that the enumeration value knowledge 131 - 2 may include and the corresponding descriptions.

[0065] Table 2 Enumeration knowledge related fields and descriptions

[0066] Field Chinese name Field Description Database ID Unique ID of the database Database Type Database type, for example: MySQL / ClickHouse / Oracle Table name The name of the online table to which the current column belongs Enumeration value name Enumeration Values Related column names The names of all columns that contain the current enumeration value

[0067] As shown in Table 2, enumeration values ​​refer to a set of predefined possible values, which are usually used to represent limited, discrete options. For example, the enumeration values ​​of department data may include "Department A", "Department B", "Department C". These values ​​are fixed and limited.

[0068] In some embodiments, the query question 120 of the user received by the electronic device 110 may directly use these specific enumeration values ​​as query conditions. For example, the user's query question 120 is "query the data of Department A" to obtain relevant information of a specific department. In order to improve the accuracy of the query, the electronic device 110 can use the enumeration value knowledge 131-2 in the knowledge base 130 to verify and match the enumeration value input by the user. For example, the electronic device 110 retrieves and confirms that "Department A" is a legal enumeration value in the enumeration value knowledge 131-2, and then constructs the corresponding SQL statement.

[0069] Continue to refer Figure 3A , in box 313 , the electronic device 110 determines the business indicator knowledge 131 - 3 .

[0070] In some embodiments, the first knowledge 131 further includes business indicator knowledge 131 - 3 . The business indicator knowledge 131 - 3 at least indicates a business indicator calculated based on data in the target database and / or a calculation method of the business indicator.

[0071] As an example, Table 3 shows the fields that the business indicator knowledge 131 - 3 may include and the corresponding descriptions.

[0072] Table 3 Business indicator knowledge related fields and descriptions

[0073]

[0074] As shown in Table 3, business indicator knowledge 131-3 is used to process indicator data that are complex in logic and difficult to obtain directly through simple queries. These indicator data may involve data from multiple data tables and require complex calculation logic to obtain. For example, if a user needs to query the indicator data of total sales, the electronic device 110 can obtain the business indicator knowledge 131-3 pre-entered by the user: indicator name: total sales; indicator alias: total sales, turnover; indicator calculation caliber: sales equals the sum of the sales amount of goods for each order in the order table. Business indicator knowledge can help the electronic device 110 understand the data that needs to be queried in the target database 140 and the complex calculation logic corresponding to the indicator data.

[0075] In the disclosed embodiment, the electronic device 110 provides the necessary data structure and business logic basis for subsequent queries through the pre-stored offline first knowledge, thereby enhancing the electronic device 110's ability to understand the database structure and business logic and improving the accuracy and efficiency of SQL generation.

[0076] In some embodiments, the knowledge base 130 may also include online knowledge determined according to the specific needs of the user during the period of interaction with the user in response to receiving the user's query. The online knowledge provides the electronic device 110 with dynamic, real-time data table information and external information, so that it can more accurately understand the user's query intention and generate SQL statements that meet the actual business scenario.

[0077] In some embodiments, online knowledge may include associations between data tables to be queried in the target database 140 and / or real-time external knowledge (such as real-time time information, user information, etc.) obtained through third-party tools.

[0078] In some embodiments, determining the knowledge base 130 associated with the data in the target database 140 includes: determining the association relationship between the data tables to be queried in the target database 140 based on the first knowledge.

[0079] As an example, before performing a database query, the user can confirm that he has the authority to query a specific data table. The user can then select the data table to be queried in the target database 140 within his authority and send the selection result to the electronic device 110. After the electronic device 110 determines the data table to be queried in the target database 140, it can extract the first knowledge corresponding to the data table to be queried from the database that stores the offline first knowledge, and obtain the association relationship between these data tables through the large language model (LLM). By understanding the association relationship between tables, the electronic device 110 can further improve the executability and accuracy of the generated SQL statement when the user's query question 120 involves complex queries between data in multiple tables.

[0080] In some embodiments, determining the knowledge base 130 associated with the data in the target database 140 further includes: determining the time when the query question is received and / or user information of the user based on a predetermined application programming interface.

[0081] In some embodiments, the user's query question 120 may involve time and user attribute information, for example, "query XX last week" requires time information; "query XX in this department" requires the user's department information. Therefore, the electronic device 110 also needs to use corresponding knowledge to improve the executability and accuracy of the generated SQL statement. For example, the electronic device 110 obtains real-time external knowledge, such as the current date and time, the user's department, the city, etc., through the corresponding application programming interface (API) of the third-party tool.

[0082] In the disclosed embodiment, by determining the online knowledge in the knowledge base 130 in real time during the user interaction stage, the electronic device 110 can adapt to the user's query needs in real time and optimize the query performance and accuracy of the generated SQL statements.

[0083] Return to reference Figure 2 In block 220 , the electronic device 110 determines query variables for the query question 120 from the determined knowledge base 130 .

[0084] In some embodiments, after determining the knowledge base 130 that provides basic data structure and business logic support and helps understand the user's query needs, the electronic device 110 can use RAG technology to search based on offline knowledge and / or online knowledge in the knowledge base 130 to obtain key information for constructing structured query statements.

[0085] In some embodiments, the electronic device 110 can use a template with reserved variable slots to use key information determined from the knowledge base 130 for constructing a structured query statement as a corresponding query variable, thereby obtaining prompt words that can dynamically change according to the knowledge in the knowledge base and the user's query question.

[0086] In some embodiments, query variables may include business indicator variables and / or data table variables. Business indicator variables refer to specific indicator data involved in the query process, which may correspond to aggregate calculations, specific logic calculations, etc. of one or more fields in the database. Data table variables refer to the data table and its field information involved in the user query, which are used to specify the data source and query object of the SQL query.

[0087] Figure 3B A schematic diagram of a process 300B for determining a business indicator variable according to some embodiments of the present disclosure is shown. The process 300B may be implemented at the electronic device 110 .

[0088] In box 321, the electronic device 110 performs intent recognition on the query question 120.

[0089] In some embodiments, the electronic device 110 first performs intent recognition on the query question, that is, determines the target query data that the user wants to query. For example, the electronic device 110 performs a preliminary analysis on the user's query question 120 through text analysis technology (such as keyword matching, semantic similarity calculation, etc.) to identify the data name or related terms that the user wants to query.

[0090] In box 322, the electronic device 110 determines whether the user's target query data includes indicator data that needs to be calculated based on the data in the target database based on the intention recognition result for the query question.

[0091] In some embodiments, the electronic device 110 determines, based on the intent recognition result for the query question, whether the content that the user wants to query involves indicator data that is logically complex and difficult to obtain directly through a simple query.

[0092] For example, a user needs to query the total sales of a product, but the data table of the target database 140 only stores the sales of each order, and the query result cannot be obtained directly. The electronic device 110 can search the business indicator knowledge included in the knowledge base 130 to see whether there is indicator data of the total sales, so as to determine whether the user's query intention can be converted into an executable query step based on the business indicator knowledge.

[0093] In box 323, if the electronic device 110 determines that the target query data includes indicator data, a calculation method for the indicator data is determined from the business indicator knowledge included in the knowledge base.

[0094] In some embodiments, the business indicator knowledge included in the knowledge base 130 stores information such as the name, alias, and calculation caliber of each indicator. If the electronic device 110 retrieves the record of the corresponding indicator name or alias in the business indicator knowledge through the identification result of the query question 120, the electronic device 110 can parse the calculation caliber field in the record to extract the calculation method of the indicator data. For example, the electronic device 110 determines that the calculation method of the indicator data of total sales is to calculate the sum of the sales amount of each order in the order data table.

[0095] In block 324 , the electronic device 110 determines a business indicator variable for the query question based on the indicator data and a calculation method of the indicator data.

[0096] In some embodiments, the electronic device 110 constructs a business indicator variable including indicator name, calculation logic, etc. according to the context information, indicator data, and calculation method of the indicator data of the query question 120. The business indicator variable is used to be embedded in the corresponding slot of the prompt word template to form a complete prompt word.

[0097] As an example, the calculation method of the indicator data can be the calculation logic described in natural language, such as: calculating the sum of the sales amount of each order in the order data table (orders). The calculation method of the indicator data can also be an SQL statement, such as: SELECT SUM(sales)FROM orders WHERE date BETWEEN'YY-MM-DD'AND'YY-MM-DD'.

[0098] In the disclosed embodiment, the electronic device 110 can accurately identify the user's query intent and determine whether the query contains indicator data that needs to be calculated. For queries containing indicator data, the electronic device 110 can further determine the calculation method of the indicator and construct the corresponding business indicator variable, which is helpful for subsequent generation of more accurate SQL statements.

[0099] In some embodiments, the electronic device 110 determines, based on the query question, the data table corresponding to the user's target query data and / or the data column corresponding to the target query data from the data table knowledge included in the determined knowledge base.

[0100] As an example, the electronic device 110 traverses the data table knowledge included in the knowledge base 130, and matches the Chinese description of each column with the keywords of the identified user's target query data. At the same time, for the enumeration value column, the electronic device 110 also checks whether the enumeration value matches the specific value of the target query data. Based on the matching results, the electronic device 110 filters out data columns that are not related to the query question 120 and retains those data columns that may be related to the target query data. Based on natural language processing technology and semantic analysis, the electronic device 110 can accurately identify the data table and / or data column corresponding to the query question 120 through precise matching and correlation analysis.

[0101] In some embodiments, the electronic device 110 determines data table variables for the query question based on a data table corresponding to the target query data and / or a data column corresponding to the target query data.

[0102] In some embodiments, based on the determined data tables and data columns, the electronic device 110 organizes the information of these data tables and data columns in a certain format to form a data table variable for the query question as a key part in the prompt word template.

[0103] In the disclosed embodiment, data columns irrelevant to the query are filtered out through data table knowledge, and only columns relevant to the query are retained. This ensures that accurate and efficient SQL statements can be generated and the generated SQL statements only retrieve relevant data, thereby improving the accuracy of the query.

[0104] In some embodiments, the user's query question 120 often involves multi-table queries or contains time information and user attribute information. In order to generate accurate and executable SQL statements, the electronic device 110 needs to determine the corresponding query variables through the online knowledge in the knowledge base 120 to improve the accuracy and execution efficiency of the SQL statements.

[0105] In some embodiments, if the electronic device 110 determines that the user's target query data is stored in at least two data tables of the target database, the association variable is determined based on the association relationship between the data tables to be queried included in the determined knowledge base.

[0106] As an example, the user's query question 120 is "Query the names and department names of employees who joined Department A last month." The electronic device 110 recognizes that the user's question involves obtaining employee names and department names. This information is stored in the employee table (employee_data) and the department table (department_data), respectively, so a joined table query is required. The electronic device 110 can use the association relationship knowledge included in the knowledge base 130 to determine that the association key of the two tables is the employee ID (dept_id), and then generate an associated variable: JOIN department_data d ON e.dept_id=d.dept_id. Through the above process, the electronic device 110 dynamically generates an associated variable using the association relationship of the tables to ensure that the query results can accurately reflect the user's needs. This method can be widely used in query scenarios that need to obtain related data from multiple tables.

[0107] In some embodiments, if the electronic device 110 determines that the user's target query data includes time information and / or user information, it determines the time variable and / or user attribute variable based on the time when the query question was received and / or the user information of the user included in the determined knowledge base.

[0108] As another example, the user's query question 120 is "Query the number of employees who joined Department A in Location B last month." The electronic device 110 recognizes that the user's question involves time information, user department information, and user location information. The electronic device 110 can determine the time variable as "YY-DD-MM" and the user attribute variables as "Department A" and "Location B" based on external knowledge obtained by calling a third-party tool or interface. In this way, the electronic device 110 can dynamically integrate the latest external data and accurately reflect the user's real-time needs in the process of generating prompt words, thereby ensuring the accuracy and real-time performance of the generated SQL statements.

[0109] Continue to refer Figure 2 In block 230 , the electronic device 110 uses a predetermined first template to determine a first prompt word based on the query variables and the query question.

[0110] In some embodiments, the first prompt word refers to a template statement that includes a series of query variables and can dynamically change according to the specific query context and the user's query statement. The first template is a specially designed statement template, which includes multiple variable slots for filling in specific query variables when generating the first prompt word. These variable slots include but are not limited to user-entered questions, database types, table structure information, current time, partition field reminders, user information, and business indicator knowledge.

[0111] In some embodiments, the first template defines at least fields corresponding to the query question, fields corresponding to the query variables, and guidance information for the machine learning model.

[0112] As an example, Table 4 shows various fields that may be included in the first template and corresponding descriptions.

[0113] Table 4 Fields and descriptions of the first template

[0114]

[0115] As an example, based on the user's query question "Query the total sales of department A last month", the electronic device 110 may generate the following prompt words:

[0116] Generate an SQL query statement to query the total sales of department A in the previous month; database type: MySQL; data table variables: - table name: `sales`; - column names: `department`(VARCHAR), `sale_amount`(DECIMAL), `sale_date`(DATE); - value examples: the value of `department` is "A", "B"; the value of `sale_amount` is 1000, 2000, 3000; the value of `sale_date` is 'Y1-M1-D1',,'Y2-M2-D2'; current time: YY-MM-DD; user department: A; business indicator: sales.

[0117] In the disclosed embodiment, the first template flexibly combines the user's query question 120 and dynamically generates semantically accurate query variables suitable for specific situations based on the knowledge base 130, thereby providing clear guidance and support for the subsequent generation of corresponding structured query statements.

[0118] Continue to refer Figure 2 In box 240, the electronic device 110 uses the machine learning model to generate a first structured query statement for the target database corresponding to the query question based on the first prompt word.

[0119] In some embodiments, the electronic device 110 generates an SQL statement by inputting a prompt word composed of a template and actual query variable values ​​into a machine learning model (such as a large language model LLM). Machine learning models such as large language models have powerful natural language understanding capabilities. By inputting prompt words determined by RAG (retrieval enhanced generation) technology, they can better understand complex query requirements and generate SQL statements that conform to natural language descriptions.

[0120] In some embodiments, for actual production environments, SQL statements generated directly by machine learning models may have various problems due to the limitations of the large language model (LLM), differences in system and software versions, etc. Therefore, it is very necessary to verify and adapt the generated structured query statements.

[0121] Figure 3C A schematic diagram of a process 300C of checking and processing a first structured query statement according to some embodiments of the present disclosure is shown. The process 300C may be implemented at the electronic device 110 .

[0122] In block 331, the electronic device 110 determines whether a first structured query statement for the target database corresponding to the query question 120 is successfully generated. If it is determined that the first structured query statement is successfully generated, block 332 is executed. In block 332, the electronic device 110 performs a post-processing operation on the first structured query statement.

[0123] In some embodiments, the post-processing operation includes performing data processing on the first structured query statement to ensure that it is in an executable format.

[0124] As an example, when generating SQL statements, the values ​​of some fields may be empty or contain invalid formats. If these values ​​are used directly in database queries, they may cause the query to fail or return incorrect results. By performing post-processing operations to detect and correct these empty or invalid values, the correct execution of SQL statements is ensured.

[0125] As another example, date and time fields are often used in SQL queries, but different systems and databases may have different requirements for date and time formats. The date and time format in the SQL statement generated by the machine learning model may not meet the format requirements of the target database. Through post-processing operations, the date and time format can be uniformly converted to a format acceptable to the database to avoid query errors.

[0126] In some embodiments, the post-processing operation may also include operations such as identifying and modifying the conflicting field names, unifying the function names into names supported by the target database to ensure the compatibility of SQL statements, and the like.

[0127] Continue to refer Figure 3C , in box 333, the electronic device 110 performs a verification operation on the generated SQL statement.

[0128] In some embodiments, the verification operation includes executing a query operation in a target database based on the generated first structured query statement to obtain a query result of the first structured query statement.

[0129] In block 334 , the electronic device 110 determines whether the generated SQL statement passes verification.

[0130] In some embodiments, if it is determined that the query result of the first structured query statement indicates the user's target query data, the electronic device 110 determines that the generated SQL statement passes the verification and executes box 335. In box 335, the electronic device 110 outputs the generated SQL statement and sends the first structured query statement to the user.

[0131] In some embodiments, if it is determined that the query result of the first structured query statement does not indicate the user's target query data, the electronic device 110 determines that the generated SQL has not passed the verification and / or the electronic device determines that the first structured query statement has not been successfully generated, the electronic device 110 executes box 336 to generate a first error message.

[0132] In some embodiments, the first error message indicates that the first structured query statement is not successfully generated or the query result of the first structured query statement does not indicate the user's target query data.

[0133] In the disclosed embodiment, by performing post-processing operations on the generated structured query statements, the accuracy and compatibility of the structured query statements can be improved, query errors can be reduced, and the robustness and stability of the system can be improved.

[0134] In some embodiments, when the SQL statement generated for the first time fails to meet the requirements (ie, generation fails or verification execution fails), the electronic device 110 may adopt an automatic correction mechanism to regenerate the SQL statement.

[0135] Figure 3D A schematic diagram of a process 300D for processing a second structured query statement according to some embodiments of the present disclosure is shown. The process 300D may be implemented at the electronic device 110 .

[0136] In block 341 , in response to the first error message for the structured query statement, the electronic device 110 determines a second template.

[0137] As an example, Table 5 shows various fields that may be included in the second template and corresponding descriptions.

[0138] Table 5 Second template fields and descriptions

[0139]

[0140] In some embodiments, the second template may also include a SQL skeleton template. The SQL skeleton template may be a structured natural language description for guiding the machine learning model to generate SQL statements. Through this template, complex queries can be decomposed into standardized fragments, making the generated SQL statements more accurate and standardized.

[0141] As an example, the structure of the SQL skeleton (sketch) template can be in the following form: query: <column name>, <column name>, <column name>, ...; the screening conditions are: <column name><operator><value>, <column name><operator><value>, ...; take the first <number of rows> results.

[0142] As another example, the structure of the SQL skeleton template can also be in the following form: query: <column name>, <column name>, <column name>,...; the filtering conditions are: <column name><operator><value>, <column name><operator><value>,...; group by <column name> column name,...; sort the results in ascending / descending order by <column name>; take the first <number of rows> of results.

[0143] Continue to refer Figure 3D In block 342 , the electronic device 110 uses a predetermined second template to determine a second prompt word based on the query variable and the user's query question.

[0144] In some embodiments, the electronic device 110 can convert the user's natural language query into a structured SQL statement framework, i.e., the "skeleton" of the SQL statement, based on a SQL skeleton template. The SQL skeleton template is used to provide a more stable and easier to correct starting point when SQL generation fails, so as to regenerate a possibly correct SQL statement.

[0145] As an example, the user's query question is "Query the number of people who joined Department A last month". The electronic device 110 can convert the natural language query question into an SQL skeleton based on the SQL skeleton template: "Query: department, hire_date, employee_id; Filter condition: department = 'Department A', hire_date BETWEEN 'Y1-M1-D1' AND 'Y1-M2-D1'; Take the first 10 results". Then, the electronic device 110 can use the generated SQL skeleton as the user's query question, thereby providing a more stable and easier to modify starting point, and use the second template and query variables to determine the second prompt word.

[0146] In box 343, the electronic device 110 generates a second structured query statement based on the second prompt word using the machine learning model.

[0147] In some embodiments, the electronic device 110 generates a new second structured query statement based on the new prompt word using a machine learning model (such as a large language model LLM).

[0148] In box 344, the electronic device 110 determines whether the second structured query statement for the target database corresponding to the query question 120 is successfully generated. If it is determined that the second structured query statement is not successfully generated, box 349 is executed. In box 349, the electronic device 110 generates a second error message. The second error message indicates that the structured query statement corresponding to the query question is not successfully generated.

[0149] In some embodiments, the electronic device 110 may perform the above-mentioned Figure 3C The operations in blocks 322 to 342 are similar post-processing operations and verification operations.

[0150] If it is determined that the second structured query statement is successfully generated, then block 345 is executed. In block 345, the electronic device 110 performs a post-processing operation on the second structured query statement to ensure that it is in an executable format.

[0151] In block 346 , the electronic device 110 performs a verification operation on the second structured query statement.

[0152] In some embodiments, the verification operation includes executing a query operation in the target database based on the generated second structured query statement to obtain a query result of the second structured query statement.

[0153] In block 347 , the electronic device 110 determines whether the second structured query statement passes verification.

[0154] If the electronic device 110 determines that the query result of the second structured query statement indicates the user's target query data, it is determined that the second structured query statement passes the verification and executes box 348. In box 348, the electronic device 110 outputs the SQL statement and sends the second structured query statement to the user.

[0155] If the electronic device 110 determines that the query result of the second structured query statement does not indicate the user's target query data, block 349 is executed. In block 349, the electronic device 110 generates a second error message. The second error message indicates that the structured query statement corresponding to the query question is not successfully generated.

[0156] In the disclosed embodiment, when the first structured query statement generated for the first time fails to execute successfully, the SQL automatic correction mechanism can use the error message as external knowledge to reconstruct the dynamic prompt words and generate an SQL skeleton (sketch). This process increases the chance of generating a valid SQL statement by introducing additional structure and logic guidance.

[0157] Figure 4 A block diagram of an apparatus 400 for generating a structured query statement according to some embodiments of the present disclosure is shown. The apparatus 400 may be implemented as or include the electronic device 110.

[0158] The device 400 includes a knowledge base determination module 410, which is configured to determine a knowledge base associated with data in a target database in response to receiving a query question from a user for the target database; a query variable determination module 420, which is configured to determine a query variable for the query question from the determined knowledge base; a prompt word determination module 430, which is configured to use a predetermined first template to determine a first prompt word based on the query variable and the query question; and a generation module 440, which is configured to use a machine learning model to generate a first structured query statement for the target database corresponding to the query question based on the first prompt word.

[0159] In some embodiments, the knowledge base determination module 410 is further configured to obtain first knowledge for the target database, the first knowledge including data table knowledge and / or business indicator knowledge, wherein the first knowledge is determined in the following manner: based on the table structure information of the data table stored in the target database and / or the data in the data table, the data table knowledge is determined; and / or based on the data table in the target database, the business indicator knowledge is determined, the business indicator knowledge at least indicating the business indicators calculated based on the data in the target database and / or the calculation method of the business indicators.

[0160] In some embodiments, the knowledge base determination module 410 is further configured to determine the association relationship between the data tables to be queried in the target database based on the first knowledge.

[0161] In some embodiments, the knowledge base determination module 410 is further configured to determine the time when the query question is received and / or the user information of the user based on a predetermined application programming interface.

[0162] In some embodiments, the query variable determination module 420 is further configured to perform intent recognition on the query question; based on the intent recognition result for the query question, determine whether the user's target query data includes indicator data that needs to be calculated based on the data in the target database; if it is determined that the target query data includes indicator data, determine the calculation method of the indicator data from the business indicator knowledge included in the knowledge base; based on the indicator data and the calculation method of the indicator data, determine the business indicator variable for the query question.

[0163] In some embodiments, the query variable determination module 420 is further configured to determine, based on the query question, the data table corresponding to the user's target query data and / or the data column corresponding to the target query data from the data table knowledge included in the determined knowledge base; and determine the data table variables for the query question based on the data table corresponding to the target query data and / or the data column corresponding to the target query data.

[0164] In some embodiments, the query variable determination module 420 is further configured to determine the associated variables based on the association relationship between the data tables to be queried included in the determined knowledge base if it is determined that the user's target query data is stored in at least two data tables of the target database; and to determine the time variable and / or user attribute variable based on the time of receiving the query question and / or the user information of the user included in the determined knowledge base if it is determined that the user's target query data includes time information and / or user information.

[0165] In some embodiments, the first template defines at least fields corresponding to the query question, fields corresponding to the query variables, and guidance information for the machine learning model.

[0166] In some embodiments, the device 400 includes a statement processing module 450, which is configured to perform a query operation in the target database based on the generated first structured query statement to obtain a query result of the first structured query statement; if it is determined that the query result of the first structured query statement does not indicate the user's target query data, a first error message is generated; and if it is determined that the query result of the first structured query statement indicates the user's target query data, the first structured query statement is sent to the user.

[0167] In some embodiments, the generation module 440 is also configured to determine a second prompt word in response to a first error message for a structured query statement, using a predetermined second template, based on query variables and the user's query question, wherein the first error message indicates that the first structured query statement was not successfully generated or the query result of the first structured query statement does not indicate the user's target query data; and generate a second structured query statement based on the second prompt word using a machine learning model.

[0168] In some embodiments, the statement processing module 450 is also configured to send the second structured query statement to the user if it is determined that the query result of the second structured query statement indicates the user's target query data; and to generate a second error message if it is determined that the query result of the second structured query statement does not indicate the user's target query data, and the second error message indicates that the structured query statement corresponding to the query question was not successfully generated.

[0169] The modules included in the device 400 can be implemented in various ways, including software, hardware, firmware, or any combination thereof. In some embodiments, one or more units can be implemented using software and / or firmware, such as machine executable instructions stored on a storage medium. In addition to or as an alternative to machine executable instructions, some or all of the units in the device 400 can be implemented at least in part by one or more hardware logic components. As an example and not limitation, exemplary types of hardware logic components that can be used include field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0170] Figure 5 1 shows a block diagram of an electronic device 500 in which one or more embodiments of the present disclosure may be implemented. It should be understood that Figure 5 The electronic device 500 shown is merely exemplary and should not constitute any limitation on the functionality and scope of the embodiments described herein.

[0171] like Figure 5 As shown, the electronic device 500 is in the form of a general electronic device. The components of the electronic device 500 may include, but are not limited to, one or more processors or processing units 510, a memory 520, a storage device 530, one or more communication units 540, one or more input devices 550, and one or more output devices 560. The processing unit 510 may be an actual or virtual processor and is capable of performing various processes according to a program stored in the memory 520. In a multi-processor system, multiple processing units execute computer executable instructions in parallel to improve the parallel processing capability of the electronic device 500.

[0172] The electronic device 500 typically includes a plurality of computer storage media. Such media may be any available media accessible to the electronic device 500, including but not limited to volatile and non-volatile media, removable and non-removable media. The memory 520 may be a volatile memory (e.g., registers, caches, random access memory (RAM)), a non-volatile memory (e.g., a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), flash memory), or some combination thereof. The storage device 530 may be a removable or non-removable medium, and may include a machine-readable medium, such as a flash drive, a disk, or any other medium, which may be capable of being used to store information and / or data and may be accessed within the electronic device 500.

[0173] The electronic device 500 may further include additional removable / non-removable, volatile / non-volatile storage media. Figure 5 As shown in , a disk drive for reading or writing from a removable, non-volatile disk (e.g., a "floppy disk") and an optical drive for reading or writing from a removable, non-volatile optical disk may be provided. In these cases, each drive may be connected to the bus (not shown) by one or more data media interfaces. The memory 520 may include a computer program product 525 having one or more program modules that are configured to perform various methods or actions of various embodiments of the present disclosure.

[0174] The communication unit 540 implements communication with other electronic devices through a communication medium. Additionally, the functions of the components of the electronic device 500 can be implemented in a single computing cluster or multiple computing machines that can communicate through a communication connection. Therefore, the electronic device 500 can operate in a networked environment using a logical connection with one or more other servers, a network personal computer (PC), or another network node.

[0175] The input device 550 may be one or more input devices, such as a mouse, a keyboard, a tracking ball, etc. The output device 560 may be one or more output devices, such as a display, a speaker, a printer, etc. The electronic device 500 may also communicate with one or more external devices (not shown) through the communication unit 540 as needed, such as a storage device, a display device, etc., communicate with one or more devices that allow a user to interact with the electronic device 500, or communicate with any device that allows the electronic device 500 to communicate with one or more other electronic devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface (not shown).

[0176] According to an exemplary implementation of the present disclosure, a computer-readable storage medium is provided, on which one or more computer instructions are stored, wherein the one or more computer instructions are executed by a processor to implement the method described above. According to an exemplary implementation of the present disclosure, a computer program product is also provided, which is tangibly stored on a non-transitory computer-readable medium and includes computer-executable instructions, and the computer-executable instructions are executed by a processor to implement the method described above.

[0177] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products implemented according to the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0178] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0179] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0180] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple implementations of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of a module, program segment or instruction includes one or more executable instructions for realizing the logical function of the specification. In some implementations as replacements, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a special hardware-based system that performs the function or action of the specification, or can be realized by a combination of special hardware and computer instructions.

[0181] The above descriptions of various implementations of the present disclosure are exemplary, non-exhaustive, and not limited to the disclosed implementations. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described implementations. The selection of terms used herein is intended to best explain the principles of the implementations, practical applications, or improvements to the technology in the marketplace, or to enable other persons of ordinary skill in the art to understand the implementations disclosed herein.

Claims

1. A method for generating a structured query statement, comprising: In response to receiving a query question from a user for a target database, determining a knowledge base associated with the data in the target database; Determining query variables for the query question from the determined knowledge base; Determine a first prompt word based on the query variable and the query question using a predetermined first template; as well as A first structured query statement for the target database corresponding to the query question is generated by using a machine learning model based on the first prompt word.

2. The method of claim 1, wherein determining a knowledge base associated with the data in the target database comprises: Acquire first knowledge for the target database, the first knowledge including data table knowledge and / or business indicator knowledge, wherein the first knowledge is determined in the following manner: Determining the data table knowledge based on table structure information of the data table stored in the target database and / or the data in the data table; and / or Based on the data table in the target database, the business indicator knowledge is determined, and the business indicator knowledge at least indicates the business indicator calculated based on the data in the target database and / or the calculation method of the business indicator.

3. The method of claim 2, wherein determining a knowledge base associated with the data in the target database comprises: Based on the first knowledge, the association relationship between the data tables to be queried in the target database is determined.

4. The method according to claim 1, wherein determining a knowledge base associated with the data in the target database further comprises: Based on a predetermined application programming interface, the time when the query question is received and / or the user information of the user are determined.

5. The method according to claim 1, wherein determining a query variable for the query question from the determined knowledge base comprises: performing intent recognition on the query question; Based on the intention recognition result for the query question, determining whether the user's target query data includes indicator data that needs to be calculated based on the data in the target database; If it is determined that the target query data includes the indicator data, determining a calculation method for the indicator data from the business indicator knowledge included in the knowledge base; Based on the indicator data and a calculation method of the indicator data, a business indicator variable for the query question is determined.

6. The method according to claim 1, wherein determining a query variable for the query question from the determined knowledge base further comprises: Based on the query question, determine the data table corresponding to the user's target query data and / or the data column corresponding to the target query data from the data table knowledge included in the determined knowledge base; Based on the data table corresponding to the target query data and / or the data column corresponding to the target query data, a data table variable for the query question is determined.

7. The method according to claim 1, wherein determining a query variable for the query question from the determined knowledge base further comprises: If it is determined that the target query data of the user is stored in at least two data tables of the target database, determining the association variable based on the association relationship between the data tables to be queried included in the determined knowledge base; as well as If it is determined that the user's target query data includes time information and / or user information, then the time variable and / or user attribute variable is determined based on the time when the query question is received and / or the user information of the user included in the determined knowledge base.

8. The method according to claim 1, wherein the first template defines at least fields corresponding to the query question, fields corresponding to the query variables, and guidance information for the machine learning model.

9. The method according to claim 1, further comprising: Based on the generated first structured query statement, a query operation is performed in the target database to obtain a query result of the first structured query statement; If it is determined that the query result of the first structured query statement does not indicate the target query data of the user, generating first error information; as well as If it is determined that the query result of the first structured query statement indicates the target query data of the user, the first structured query statement is sent to the user.

10. The method according to claim 1, further comprising: In response to a first error message for the structured query statement, a second prompt word is determined based on the query variable and the query question of the user using a predetermined second template, wherein the first error message indicates that the first structured query statement is not successfully generated or the query result of the first structured query statement does not indicate the target query data of the user; as well as A second structured query statement is generated based on the second prompt word by using a machine learning model.

11. The method according to claim 10, further comprising: If it is determined that the query result of the second structured query statement indicates the target query data of the user, sending the second structured query statement to the user; as well as If it is determined that the query result of the second structured query statement does not indicate the user's target query data, a second error message is generated, where the second error message indicates that the structured query statement corresponding to the query question is not successfully generated.

12. A device for generating a structured query statement, comprising: A knowledge base determination module, configured to determine a knowledge base associated with the data in the target database in response to receiving a query question from a user for the target database; A query variable determination module, configured to determine a query variable for the query question from the determined knowledge base; A prompt word determination module is configured to determine a first prompt word based on the query variable and the query question by using a predetermined first template; as well as The generation module is configured to use a machine learning model to generate a first structured query statement for the target database corresponding to the query question based on the first prompt word.

13. An electronic device comprising: at least one processing unit; as well as At least one memory, the at least one memory being coupled to the at least one processing unit and storing instructions for execution by the at least one processing unit, the instructions causing the electronic device to perform the method according to any one of claims 1 to 11 when executed by the at least one processing unit.

14. A computer-readable storage medium having a computer program stored thereon, wherein the computer program can be executed by a processor to implement the method according to any one of claims 1 to 11.

15. A computer program product tangibly stored in a computer storage medium and comprising computer executable instructions which, when executed by a device, cause the device to perform the method according to any one of claims 1 to 11.

Citation Information

Cited By

  • Mine enterprise knowledge training method based on large model

    CN120561227A

  • Intelligent algorithm development auxiliary tool for Lingpivot plasma control system

    CN120848868A

  • Construction method of business meta-knowledge base and local data analysis method based on business meta-knowledge base

    CN121301583A