Structured query statement generation method, system, device and electronic device

By extracting target structure information from the user database and constructing prompt information, and combining it with a pre-trained language model to generate and verify structured query statements, the problem of insufficient understanding of the database structure by large language models is solved, and more accurate query statement generation is achieved.

CN120353820BActive Publication Date: 2025-09-19INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510828621.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-19
Publication Date
2025-09-19
Estimated Expiration
2045-06-19

AI Technical Summary

Technical Problem

Existing large language models lack understanding of database structure when generating structured query statements, resulting in inaccurate generated statements.

Method used

By matching the target structure information with the structure information of the user database, constructing prompt information and inputting it into the pre-trained language model, a structured query statement is generated, and the generated result is verified using the structure information of the user database.

Benefits of technology

The accuracy of the generated structured query statements is improved to make them conform to the actual database architecture, solving the problem of inaccurate generation of large language models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353820B_ABST
    Figure CN120353820B_ABST
Patent Text Reader

Abstract

The present application discloses a method, system, device, and electronic device for generating structured query statements, relating to the field of data query technology. The method includes matching target structure information related to a user's target question from user database structure information, providing an accurate database structure foundation for a pre-trained language model, enabling the generated structured query statement to conform to the architecture of the actual database, verifying the structured query statement using the user database structure information, and outputting a structured query statement that passes the verification. Therefore, the method can solve the technical problem that the generation process of the pre-trained language model lacks an understanding of the database structure, which may lead to inaccurate structured query statements, thereby achieving the technical effect of improving the accuracy of structured query statement generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data query technology, and in particular to a method, system, device and electronic device for generating structured query statements. Background Art

[0002] Traditional database query methods require users to have certain knowledge of SQL (Structured Query Language), which is a high barrier to entry for non-technical personnel.

[0003] Related technologies typically input user queries into a Large Language Model (LLM). Leveraging the LLM's powerful language generation capabilities and deep understanding of context, the LLM generates corresponding structured query statements. However, the LLM generation process lacks understanding of the database structure, which can lead to inaccurate structured query statements. Summary of the Invention

[0004] The present application provides a method, system, device and electronic device for generating structured query statements, so as to at least solve the problem of inaccurate structured query statements generated in the related art.

[0005] This application provides a method for generating a structured query statement, including:

[0006] Matching target structure information related to the target question from the structure information in the user database according to the target question of the user;

[0007] Constructing prompt information based on the target question and the target structure information;

[0008] Inputting the prompt information into a pre-trained language model to obtain an output result of the pre-trained language model;

[0009] When a structured query statement exists in the output result, the structured query statement is verified according to the structural information, and when the verification passes, the structured query statement is output.

[0010] The present application also provides a structured query statement generation system, comprising: a dialogue client and a dialogue module;

[0011] The dialogue client is configured to receive a target question input by a user and send the target question to the dialogue module;

[0012] The dialogue module is used to implement the steps of any of the above-mentioned structured query statement generation methods.

[0013] The present application also provides a structured query statement generating device, comprising:

[0014] A matching module, configured to match target structure information related to the target question from the structure information in the user database according to the target question of the user;

[0015] A construction module, configured to construct prompt information based on the target question and the target structure information;

[0016] An input module, configured to input the prompt information into a pre-trained language model to obtain an output result of the pre-trained language model;

[0017] The output module is configured to verify the structured query statement according to the structure information when the structured query statement exists in the output result, and output the structured query statement when the verification passes.

[0018] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned structured query statement generation methods when executing the computer program.

[0019] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned structured query statement generation methods are implemented.

[0020] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned structured query statement generation methods when executed by a processor.

[0021] This application provides an accurate database structure foundation for the pre-trained language model by matching target structure information related to the user's target question from the user's database structure information. This allows the generated structured query to conform to the actual database architecture. The structured query is then verified using the user's database structure information, and a verified structured query is output. This resolves the technical issue of the pre-trained language model's lack of understanding of the database structure during generation, which can lead to inaccurate structured query statements. This improves the accuracy of structured query generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0023] Figure 1 This is a flow chart of a method for generating a structured query statement provided in an embodiment of the present application;

[0024] Figure 2 This is a schematic diagram of the data storage process provided by the embodiment of the present application;

[0025] Figure 3 This is a flowchart of the supplementary information storage provided by the embodiment of the present application;

[0026] Figure 4 This is a schematic diagram of the verification process of the structured query statement provided in the embodiment of the present application;

[0027] Figure 5 This is a schematic diagram of the architecture of the structured query statement generation system provided in an embodiment of the present application;

[0028] Figure 6 This is a flow chart of generating a structured query statement in a scenario example provided in an embodiment of the present application;

[0029] Figure 7 Schematic diagram of the structure of the structured query statement generation device provided in the embodiment of the present application;

[0030] Figure 8 It is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0031] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0032] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.

[0033] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0034] In conjunction with the specific application environment architecture or specific hardware architecture on which the execution of the structured query statement generation method depends, the specific application environment architecture or specific hardware architecture is described herein.

[0035] The embodiments of the present application provide a method for generating a structured query statement, and the method is described in detail in conjunction with the execution flow of the method for generating a structured query statement.

[0036] Specifically, Figure 1 The present invention provides a flowchart of a method for generating a structured query statement according to an embodiment of the present application.

[0037] like Figure 1 As shown, the structured query statement generating method includes: step 110, step 120, step 130 and step 140.

[0038] Step 110: Match target structural information related to the target question from the structural information in the user database according to the target question of the user.

[0039] In this step, the user database can be a database system created and maintained by the user based on their business needs or data management requirements. It stores a variety of data closely related to the user's business, including user transaction records, customer information, product details, and other aspects. A database typically includes multiple tables, each containing a specific type of data record. For example, an e-commerce database may include a user information table, an order table, and a product table. These tables are interconnected through fields (such as user ID and order number), forming a complex but orderly data storage structure.

[0040] The structural information of a user database can be a detailed description of the internal organization and architecture of the user database, including detailed information about each table and its fields. For example, this structural information includes the table structure in the user database, such as each table's name, column names, field type (integer, string, date, etc.), field constraints (whether it is a primary key, whether it allows nulls, etc.), and relationships between tables (foreign key constraints).

[0041] A user's target question can be the specific information they wish to obtain by querying the user database. This can be a query requirement expressed in natural language, such as "Query the names and sales of products with sales exceeding 1 million yuan in 2024" or "Find information on all users who have purchased a specific product." While the user's target question reflects their query intent for the user database data, they may not be familiar with structured query language (SQL). Therefore, a method is needed to convert natural language questions into structured query statements that the database can understand.

[0042] In some embodiments, the user's target question may also be a query requirement output in voice form. If the query requirement is output in voice form, the query requirement output in voice form can be converted into a query requirement described in natural language, thereby improving the flexibility and convenience of generating structured query statements.

[0043] In some embodiments, the user's target question can be obtained in a variety of ways. A target question can be obtained by directly entering a natural language description of the user in an interactive interface provided by the client. For example, in a query interface, a user can enter "I want to know the top 10 products with the highest sales volume last month." Of course, the target question can also be obtained through voice input or other interactive methods, such as selecting a graphical interface, which is not limited in this embodiment of the present application.

[0044] In this step, target structural information related to the target question can be matched from the structural information in the user database. Specifically, semantic analysis can be performed on the user's target question to extract key information, such as the query subject (e.g., product, user), query conditions (e.g., sales exceeding 1 million yuan, purchase of a certain product), and query results (e.g., product name, user information). Then, based on this key information, relevant tables and fields are searched from the structural information in the user database. For example, if the user's target question is to query the name and sales amount of products with sales exceeding 1 million yuan, tables containing product name and sales amount fields (e.g., product tables and sales record tables) can be found from the database structural information, and the data types and relationships between these fields can be determined. In this way, target structural information closely related to the target question can be gradually matched.

[0045] Step 120: Construct prompt information based on the target question and the target structure information.

[0046] Prompts serve as auxiliary input for the pre-trained language model, guiding it to generate structured queries that align with user needs and the structure of the user's database. Prompts can be structured text descriptions that include the user's target question, target structure information, and possibly query conditions and result requirements. Prompts help the pre-trained language model better understand the user's query intent and, based on the actual structure of the user's database, generate accurate structured queries.

[0047] Pre-training is a strategy for training deep learning models. Its core is to initially train the model using large-scale datasets, enabling it to learn common feature representations. This process is similar to the basic learning stage humans go through before acquiring new knowledge, accumulating experience through extensive reading and observation.

[0048] A pre-trained language model (PLM) is a model designed based on a large-scale corpus (including language training materials such as sentences and paragraphs). The model training task is then trained on a large-scale neural network algorithm structure to achieve learning. The resulting large-scale neural network algorithm structure and parameters are the pre-trained language model. Subsequent tasks can use this model to extract features or fine-tune the model to achieve specific task objectives. The idea behind pre-training is to first train a task to obtain a set of model parameters. This set of model parameters is then used to initialize the network model parameters. The initialized network model is then used to train other tasks to obtain a model adapted for these tasks. By pre-training on a large-scale corpus, neural language representation models can acquire powerful language representation capabilities and extract rich syntactic and semantic information from text. Pre-trained language models can provide token- and sentence-level features containing rich semantic information for use in downstream tasks. Fine-tuning can also be performed directly on the pre-trained model for downstream tasks, quickly and easily obtaining a dedicated downstream model.

[0049] The neural network algorithm structure used to train pre-trained language models can be CNN (Convolutional Neural Network), RNN (Recurrent Neural Network), LSTM (Long Short-Term Memory), etc., or models built on attention networks, such as Transformer, BERT (Bidirectional Encoder Representations from Transformer), GPT (Generative Pre-trained Transformer), Clip (Contrastive Language–Image Pretraining), etc., which are not limited in this application. Attention networks refer to network models trained using the attention mechanism. By assigning different weights to each part of the input sequence, the model extracts more important feature information from the input sequence, ultimately achieving more accurate output.

[0050] Fine-tuning refers to performing small-scale training on a pre-trained model for a specific task objective (downstream task) and task data (downstream data), making minor adjustments to the pre-trained model parameters, ultimately resulting in a model that is adapted to the specific task and data. In some embodiments, the pre-trained language model can be fine-tuned for the task objective of "generating structured queries" and the task data of "questions," making it more suitable for the task of generating structured queries.

[0051] The target question directly reflects the user's query intent and can be expressed in clear, accurate natural language in the prompt. For example, if the user's target question is "Query the names of products with sales greater than 500 in the fourth quarter of 2024," the original target question can be presented in the prompt, allowing the pre-trained language model to clearly understand the data direction the user is seeking.

[0052] Target structure information can include the user database's table structure, field information, and inter-table relationships. This information helps the pre-trained language model understand the specifics of the data storage. In the above example, if the user database has a "Product Table" storing product names and a "Sales Record Table" recording sales volume and sales date, and the two tables are linked by product ID, then when constructing the prompt, clearly describe the names, purposes, and relationships between these tables and fields. For example, the constructed prompt could read: "The user database has a 'Product Table' containing 'Product ID' and 'Product Name' fields; a 'Sales Record Table' containing 'Product ID', 'Sales Quantity', and 'Sales Date' fields, and the two tables are linked by 'Product ID'. Based on this information, please generate a structured query statement for the question 'Query the names of products with sales greater than 500 in the fourth quarter of 2024.'"

[0053] Step 130: Input the prompt information into the pre-trained language model to obtain an output result of the pre-trained language model.

[0054] In this step, after the prompt information is input into the pre-trained language model, the pre-trained language model can pre-process the prompt information, including word segmentation of the text, dividing continuous sentences into independent words or sub-units to better understand the text structure; and can also perform word vector conversion, mapping each word into a vector in a high-dimensional space, and capturing the semantic information of the word through the distance and relationship between the vectors, thereby achieving an understanding of the semantics of the prompt information.

[0055] After understanding the semantics of the prompt, the pre-trained language model searches and matches within its learned knowledge base, analyzing the target question, database structure, and other requirements contained in the prompt. Using its own generation mechanism, it generates output according to specific logic and rules. Specifically, the pre-trained language model can reference the tables and fields to be queried based on the user's database structure, construct a WHERE clause based on the conditions in the target question, and refine clauses like ORDER BY and GROUP BY according to other requirements, ultimately forming a complete, structured query.

[0056] Step 140: If the structured query statement exists in the output result, the structured query statement is verified according to the structure information. If the verification passes, the structured query statement is output.

[0057] The output results of a pre-trained language model may have different situations. One possibility is that the output contains a structured query statement, indicating that the pre-trained language model has generated code that initially meets the requirements according to the prompt information. Another possibility is that the output does not contain a structured query statement. This may be because the pre-trained language model failed to understand the prompt information, or there was a deviation in the generation process, resulting in content unrelated to the structured query statement, such as incorrect explanations or irrelevant text, or the user's target question may not be a database query.

[0058] In this step, natural language processing techniques can be used to identify and screen keywords in the output results. If keywords such as SELECT, FROM, WHERE, and JOIN are identified, the output results can be considered to contain structured query statements. Alternatively, regular expressions or a structured query parser can be used to check whether the output results contain parts that conform to the basic grammatical structure of structured query statements. If so, the output results can be considered to contain structured query statements. The identified structured query statements are extracted for subsequent verification.

[0059] Specifically, the verification process is carried out from multiple dimensions.

[0060] In some embodiments, it is possible to check whether the table and field names mentioned in the structured query statement exist in the structured information of the user database. For example, if the structured query statement mentions a non-existent table or field, then the structured query statement is incorrect. By comparing the structured information of the user database, it is possible to verify whether the tables and fields used in the structured query statement are legal.

[0061] In some embodiments, the fields in the structured query statement may be checked to see if their data types are consistent with those in the user database structure information. For example, if a field in the user database is of integer type, and the query condition for that field in the structured query statement is a string, then the structured query statement may result in a query error.

[0062] In some embodiments, the correctness of the associations between tables in a structured query statement can be verified. For example, if a structured query statement uses incorrect association fields or ignores necessary association conditions when performing a multi-table query, the query results may be inaccurate. By comparing the user database structure information, the correctness of the associations between tables in the structured query statement can be verified.

[0063] Of course, verification can also be performed in other ways, which is not limited in the embodiments of the present application.

[0064] After verification, the structured query statement can be output.

[0065] This application provides an accurate database structure foundation for the pre-trained language model by matching target structure information related to the user's target question from the user's database structure information. This allows the generated structured query to conform to the actual database architecture. The structured query is then verified using the user's database structure information, and a verified structured query is output. This resolves the technical issue of the pre-trained language model's lack of understanding of the database structure during generation, which can lead to inaccurate structured query statements. This improves the accuracy of structured query generation.

[0066] In some embodiments, matching target structure information related to the target question from the structure information in the user database according to the target question of the user includes:

[0067] Match target structure information related to the target problem from the vector database; the vector database stores the structure information of the user database;

[0068] And / or, matching target structure information related to the target problem from a relational database; the relational database stores structure information of the user database.

[0069] A vector database (VDB) is a database used to store and retrieve vector data. It converts text content into high-dimensional vectors and uses vector similarity calculations to find related data.

[0070] In this embodiment, natural language processing techniques can be used to convert the structural information of the user database, such as database table names, field names, field types, and inter-table relationships, into vector form and store it in the vector database. For example, pre-trained language models such as BERT (Bidirectional Encoder Representations from Transformer) and GPT (Generative Pre-trained Transformer) can be used to convert the structural information of the user database into semantic vectors, so that semantically similar content is closer in the vector space.

[0071] After receiving the user's target question, the target question can be converted into a vector representation through a pre-trained language model, and the target question can be mapped to the same vector space as the structural information of the user database, so that the target question and the structural information of the user database are in the same semantic space. The similarity between the target question vector and the various structural information vectors stored in the vector database is calculated through cosine similarity, Euclidean distance or other similarity methods, and the structural information vectors with high similarity to the target question vector are screened out. The structural information corresponding to these structural information vectors is the target structural information.

[0072] A relational database (DB) stores data in tables and organizes data relationships through a relational model. A relational database has a strictly defined structure, with each table having distinct fields and data types, and tables connected through primary and foreign key relationships.

[0073] In this embodiment, the structural information of the user database can be stored in a relational database in the form of relational data. Specifically, the metadata table of the user database can be extracted to record the structural information of the database. For example, a "table information table" is created to record the names and descriptions of all tables, a "field information table" is created to record the table to which each field belongs, the field name, data type, constraints, etc., and a "table relationship table" can be created to record the associations between tables.

[0074] After receiving the user's target question, we can perform natural language processing on the target question to extract key information of the target question, such as entities (such as "customer", "order", etc.) and attributes (such as "age", "amount", etc.) in the target question. Based on the key information, we can search from the relational database to find tables and fields containing relevant key information, thereby locating possibly related tables and fields. Furthermore, we can also determine the data types and constraints of the relevant tables and fields. The retrieved information is the target structure information related to the target question.

[0075] In this embodiment, the vector database utilizes semantic vector technology to convert the user database's structural information into high-dimensional vector storage. By calculating vector similarity, semantically relevant structural information is selected, reducing semantic ambiguity and unclear intent, and providing semantic information about the user database's structure. The relational database, leveraging its advantages in structured data storage and query, manages the user database's structural information in a tabular format, providing structured information about the user database's structure. The user database's structural information can be provided by either a vector database or a relational database, or the two databases can complement each other to provide more comprehensive structural information and improve the accuracy of structured query statements.

[0076] In some embodiments, the method further comprises:

[0077] Reading first structural information of a user database; the first structural information includes a table name, a column name, and a table creation statement;

[0078] The first structural information is converted into a vector and stored in a vector database.

[0079] In this embodiment, a connection request may be sent to the user database, and parameters such as the user database address and credentials may be provided in the connection request. After successfully connecting to the user database, the first structure information of the user database may be read.

[0080] The first structural information can include table names, column names, and table creation statements. Table names and column names are the basic identifiers of the database structure, such as table names like "User Table" and "Order Table," and column names like "User ID," "Name," and "Order Amount." Table creation statements can be DDL (Data Definition Language) statements, such as the CREATE TABLE statement, which describes the table structure, including field data types, lengths, whether nulls are allowed, and relationships between tables, such as primary and foreign key constraints.

[0081] In this embodiment, the read information such as table name, column name, and table creation statement can be converted into vector representation through BERT or GPT and stored in a vector database.

[0082] In this embodiment, by converting structural information into vectors and storing them, the deep semantic associations behind table names, column names and constraints can be captured through high-dimensional vectors, and the target structural information semantically related to the user's target problem can be accurately matched through semantic similarity, thereby improving the accuracy of target structural information matching.

[0083] In some embodiments, the method further comprises:

[0084] Obtaining supplementary information associated with a user database input by a user; the supplementary information includes at least one of a plurality of question-answer pairs, a plurality of description texts, and a plurality of table creation statements; the question-answer pair includes a question and a structured query statement matching the question; the description text includes a business description of the user database;

[0085] The supplementary information is stored in a vector database.

[0086] To further optimize the accuracy of structured query generation, this embodiment can also obtain supplementary information associated with the user database entered by the user. This supplementary information includes multi-dimensional content such as question-answer pairs, description text, and table creation statements. Combined with the vector database, it can enhance the subsequent pre-trained language model's understanding of the user database's business logic.

[0087] A question-answer pair consists of a question and a matching structured query. This provides query examples for generating structured queries, helping the pre-trained language model better understand the user's query intent and the corresponding structured query structure. For example, a question-answer example might be "How do I find the total sales?" and the corresponding structured query is "SELECT SUM (amount) FROM sales."

[0088] The description text includes a business description of the user database and may include semantic explanations of database tables and columns, helping the pre-trained language model better understand the meaning and purpose of each field in the user database. For example, a description text example might be: "The sales table records daily transaction flows, including fields such as amount, time, and customer ID."

[0089] A table creation statement defines the structure and field information of a database table. This statement can include a DDL statement. Although the first structure information already contains the table creation statement, user-provided DDL statements can be used as supplementary information. For example, an example DDL statement is: CREATE TABLE sales (id INT, amount DECIMAL(10,2),...).

[0090] In this embodiment, supplementary information such as multiple question-answer pairs, multiple description texts, and creation statements of multiple tables can be converted into vector representations through BERT or GPT and stored in a vector database.

[0091] In this embodiment, query examples are generated for structured query statements through questions and answers, and the description text can help the pre-trained language model better understand the semantics of the field, while the DDL statement makes the generated structured query statement more consistent with the actual structure of the user database. By storing this supplementary information in the vector database, the structure and business logic of the user database can be supplemented in the vector database, thereby generating more accurate structured query statements.

[0092] In some embodiments, the method further comprises:

[0093] Read the second structure information of the user database; the second structure information includes table name, column name and data type;

[0094] Store table names, column names, and data types in a relational database in a structured format.

[0095] In this embodiment, the second structural information of the user database can also be read. The second structural information includes table names, column names, and data types. The data type includes the storage format of each field, such as integer, string, date, etc. By reading the second structural information, the architecture of the user database can be understood.

[0096] A relational database stores data in a table format and organizes the associations between data using a relational model. In this embodiment, a specialized metadata table may be created to form a standard structured format to store information such as table names, column names, and data types.

[0097] Metadata tables can implement structured storage of basic information such as table names, column names, and data types through a hierarchical association model. For example, with the table information table at the core, each table can be uniquely identified by a primary key. The column information table can be linked to the table information table through foreign keys, forming a table-to-column tree structure. Bidirectional foreign keys between table-link tables can then be used to establish a network of relationships between tables. This storage method not only enables standardized metadata storage (such as the mapping of table names, column names, and data types), but also enhances data integrity through foreign key constraints.

[0098] In this embodiment, one or more metadata tables may be created, the read table names, column names, and data types may be filled into the corresponding metadata tables, and associations between tables and columns, and between tables may be established through foreign key constraints.

[0099] In this embodiment, by reading structural information such as table names, column names and data types and storing such structural information in a relational database, structured storage of the structural information of the user database is achieved, thereby enabling efficient management and query of the structural information of the user database.

[0100] In some embodiments, the vector database includes a plurality of storage modules, and the method further includes:

[0101] Storing the vector corresponding to the table name in the first storage module of the vector database;

[0102] The vectors corresponding to the column names of each table are grouped according to the table name and stored in the second storage module of the vector database;

[0103] Storing the vector corresponding to the creation statement of the table of the user database in the third storage module of the vector database;

[0104] Storing the vectors corresponding to the question-answer pairs in a fourth storage module in the vector database;

[0105] Storing the vector corresponding to the description text in a fifth storage vector in the vector database;

[0106] The vector corresponding to the creation statement of the table of supplementary information is stored in the third storage module.

[0107] In this embodiment, if Figure 2 As shown in the figure, after a user initiates a user database connection request, the database address, credentials, and other information in the connection request can be verified. After verification, the user database is successfully connected. Then, the table names in the user database, such as orders and customers, can be read. The structural information (column names, data types, constraints, etc.) of the corresponding tables can be read one by one according to the table name.

[0108] In this embodiment, the read information can be vectorized by using an encoding model (ENC), such as BERT, GPT, etc. First, the table name can be converted into a vector representation. For example, the order table name can be converted into a high-dimensional vector, such as [0.23, -0.56, ...], and stored in the first storage module of the vector database, i.e. Figure 2 The VDB-TBL module in is used for subsequent semantic retrieval.

[0109] Furthermore, the column names of each table can be vectorized. For example, the column names of the "orders" table, such as "order_id", "order_date", and "customer_id", can be converted into vectors, grouped by table name, and stored in the second storage module of the vector database, i.e. Figure 2 The VDB-COL module in

[15] is used. For example, vectors corresponding to all column names in the "orders" table are grouped together. This grouped storage facilitates quick locating of column information for a specific table in subsequent queries.

[0110] In this embodiment, the creation statement of each table, such as CREATE TABLE orders(...), can also be extracted, and these DDL statements are converted into vectors using the encoding model and stored in the third storage module of the vector database, namely Figure 2 The VDB-DDL module in is used to enhance the pre-trained language model's understanding of the table structure, making the generated structured query statements more accurate.

[0111] In this embodiment, if Figure 2 As shown, the original structural information, such as table names, column names, data types, primary and foreign keys, can be recorded in a standard format in a relational database. This can be used to verify whether the structured query syntax conforms to the actual table structure, complementing the vector database and taking into account both precise matching and semantic retrieval requirements.

[0112] By traversing the table name of the user data and reading the corresponding table structure, the storage of the structural information of the user data is completed.

[0113] In this embodiment, for the storage of supplementary information, such as Figure 3 As shown, the question-answer pair, description text, and table creation statement can be encoded into high-dimensional vectors through the encoding model, and the question-answer pair vectors are stored in the fourth storage module, i.e. Figure 3 The VDB-QA module in ; the description text vector is stored in the fifth storage module, i.e. Figure 3 The VDB-DOC module in the table stores the creation statement vector in the third storage vector, i.e. Figure 3 The VDB-DDL module in .

[0114] In this embodiment, by vectorizing table names, column names, table creation statements, supplementary information, etc., and storing them in a vector database in a modular manner, not only is the subsequent retrieval efficiency improved, but independent expansion and maintenance are also supported.

[0115] In some embodiments, constructing prompt information based on the target question and the target structure information includes:

[0116] Retrieve target description text and target question-answer pairs related to the target question from the vector database;

[0117] Construct prompt information based on the target question, target structure information, target description text and target question-answer pair.

[0118] In this embodiment, the target question can be converted into a vector, and then the vector database is searched for the vector most similar to the target question vector to obtain the target description text and the target question-answer pair. For example, the target description text can be retrieved from the VDB-DOC module, and the target question-answer pair can be retrieved from the VDB-QA module.

[0119] For example, the target question "Display sales in the Beijing area" may match the description text "The scsales table contains region and amount fields"; it may also match the question-answer pair "How to query sales in a certain region?" and "SELECT region, SUM(amount) FROM sales".

[0120] In this embodiment, a template for prompt information can be set in advance, for example, the first line is used to fill in the target question, the second line is used to fill in the target structure information, the third line is used to fill in the target description text, and the fourth line is used to fill in the target question and answer pair. The corresponding information is filled in the corresponding position to obtain the prompt information.

[0121] In this embodiment, through multi-dimensional retrieval of target structure information, target description text and target question-answer pairs, and constructing prompt information based on these multi-dimensional information, not only can the pre-trained language model's understanding of the user database business logic be enhanced, but question-answer examples are also provided as a reference, and further combined with the structural information of the user database, the generated structured query statements are made more accurate.

[0122] In some embodiments, verifying the structured query statement based on the structure information includes:

[0123] Extract object name information of structured query statements; object name information includes table name and column name;

[0124] In the case where the object name information exists in the relational database, the verification is passed; the relational database stores the structural information of the user database; and the structural information includes the object name information of the user database.

[0125] In this embodiment, the object name information may include a table name and a column name. By verifying the table name and the column name, it can be determined whether the execution target and data source of the structured query statement are accurate.

[0126] Structured query statements can be parsed to extract table and column names from them. Since relational databases store the structure of the user database, including table names, column names, and their data types, the object names in structured query statements can be compared with the structured information in the relational database to verify their legitimacy.

[0127] Specifically, you can first check whether the table name in the structured query statement exists in the relational database. For example, if the table name Products mentioned in the structured query statement exists in the metadata table of the relational database, then proceed to the next step of verification.

[0128] The next step in the validation process might be to check for the existence of column names. For each column name mentioned in the structured query, you can further check whether it belongs to the corresponding table. For example, for the ProductName column in the Products table, you can verify whether ProductName is a valid column name in the Products table. If all column names exist in the corresponding table, the validation passes.

[0129] In this embodiment, by extracting the object name information of the structured query statement and verifying it in a relational database, the structured storage and query capabilities of the relational database are utilized to verify the core components of the structured query statement, so that the structured query statement is logically consistent with the actual structure of the database, reducing the problem of query failure caused by incorrect table names or column names, thereby improving the accuracy of structured query statement generation.

[0130] In some embodiments, the method further comprises:

[0131] When the object name information does not exist in the relational database, target object name information matching the object name information is retrieved from the vector database; the vector database stores the structural information of the user database; the structural information includes the object name information of the user database.

[0132] Modify the prompt information according to the target object name information.

[0133] In this embodiment, if the object name information does not exist in the relational database, a vector database can be further used for supplementary search to find target object name information that matches the object name based on semantic similarity, and the prompt information can be modified based on the target object name information.

[0134] For example, if the table name Orders mentioned in a structured query doesn't exist in the relational database, you can convert Orders into a vector and search the vector database for the most similar table name vector. If the table name most similar to Orders found in the vector database is Sales, you can replace Orders in the prompt with Sales to modify the prompt.

[0135] In this embodiment, when the object name information does not exist in the relational database, similar object names are found through semantic similarity, and the prompt information is corrected, which can more accurately guide the pre-trained language model to generate structured query statements that conform to the actual structure of the user database, forming a "generate-verify-correct" closed loop.

[0136] The following example illustrates the verification process of a structured query statement in an embodiment of the present application.

[0137] like Figure 4 As shown, after the structured query statement is identified from the output result, the structured query statement can be parsed to extract the table name information involved in the structured query statement.

[0138] Check whether the table name is accurate: If the table name does not exist in the relational database, you can use the VDB-TBL module in the vector database to retrieve similar table names, correct the prompt information based on the retrieved similar table names, and resubmit the corrected prompt information to the pre-trained language model.

[0139] If the table name is correct, proceed to the column name check. Extract the column name information involved in the structured query statement and traverse to check whether the column name is correct. If the column name does not exist in the relational database, use the VDB-COL module in the vector database to search for similar column names. Based on the retrieved similar column names, correct the prompt information and resubmit the corrected prompt information to the pre-trained language model.

[0140] In some embodiments, the method further comprises:

[0141] When there is no structured query statement in the output result, the similarity between the target question and the questions in the corpus is calculated; the corpus stores multiple questions classified as database query types;

[0142] When the similarity is greater than the target threshold, the prompt information is adjusted.

[0143] In some cases, the pre-trained language model may not be able to generate structured query statements because the target question is more complex or has a low match with known structural information, or the target question is not a database query question.

[0144] To deal with this situation, when there is no structured query statement in the output result, the similarity between the target question and the questions in the corpus can be calculated.

[0145] Database query problems are those in which users want to obtain specific data from the data stored in the user database, such as "querying employee salaries" and "counting product sales".

[0146] The corpus contains a large number of database query questions, which can be stored in a vector database as vectors. Specifically, natural language processing techniques can be used to convert questions into high-dimensional semantic vectors. The entire corpus data set is then stored in the vector database, enabling fast retrieval and semantic matching based on vector similarity. By converting the target question into a vector and calculating similarity with the question vectors in the corpus, the similarity between the target question and the questions in the corpus is determined.

[0147] A high similarity indicates that the target question is close to a typical database query requirement; a low similarity indicates that the problem may be a non-database query problem, such as system operation or business consultation. You can pre-set a target threshold, such as 0.6, 0.7, 0.8, or other values, to classify questions into two categories: when the similarity is greater than the target threshold, it is determined to be a database query problem, requiring further adjustment of the prompt message; when the similarity is lower than the target threshold, it is determined to be a non-database query problem, and the user can be guided to rephrase or redirect to other processing steps, or an error message can be directly returned.

[0148] In this embodiment, by calculating the similarity, it is possible to determine whether the target question belongs to a database query type question, thereby reducing the processing of non-database query type questions. When the similarity is high, the prompt information is adjusted, which not only improves the success rate of generating structured query statements, but also enhances the fault tolerance capability, thereby better adapting to different user query needs.

[0149] In some embodiments, adjusting the prompt information includes:

[0150] Increase the number of target structural information related to the target problem matched from the structural information in the user database;

[0151] Add the newly added target structure information to the prompt information.

[0152] In this embodiment, the output result does not contain a structured query statement, which may be because the reference information in the prompt information is too little. Therefore, the amount of target structure information can be further increased to supplement the prompt information.

[0153] For example, in the initial setting, the number of target structural information related to the target question matched from the structural information in the user database is three, then the number can be increased to five, and the newly added target structural information is supplemented to the prompt information, and the supplemented prompt information is re-input into the pre-trained language model.

[0154] In this embodiment, by increasing the amount of target structural information, more tables and fields related to the target question can be mined, providing richer context and constraints for the pre-trained language model, thereby improving the success rate and accuracy of generating structured query statements.

[0155] In some embodiments, the method further comprises:

[0156] Execute structured query statements to obtain statistical results corresponding to the target question from the user database;

[0157] Output statistical results and visualize them.

[0158] In this embodiment, the generated structured query statement can be applied to the user database to actually query and extract data. Specifically, the generated structured query statement can be sent to the query interface of the user database to retrieve corresponding statistical results from the user database.

[0159] To present data more intuitively, you can visualize the statistical results. For example, the statistical results can be a table containing corresponding data, such as product name and corresponding sales total. The data in the table can be displayed using bar charts, line charts, pie charts, etc.

[0160] In this embodiment, by executing structured query statements and obtaining statistical results, the statistical results are visualized, allowing users to understand and analyze data more intuitively, realizing an end-to-end closed loop from target question input to executable structured queries to visual display of data, thereby improving the efficiency of data retrieval.

[0161] The embodiment of the present application also provides a structured query statement generation system, comprising: a dialogue client and a dialogue module;

[0162] The dialogue client is used to receive the target question input by the user and send the target question to the dialogue module;

[0163] The dialogue module is used to implement the steps of the above structured query statement generation method.

[0164] In an embodiment of the present application, the dialogue client belongs to the user interaction layer. The user can enter natural language questions (such as "check the total sales this month") through the dialogue client. The dialogue client sends the questions to the dialogue module to trigger subsequent processing procedures.

[0165] The dialogue module is a central coordination component responsible for receiving user input and coordinating the invocation of subsequent modules to complete parsing and querying. Key functions include connecting to the user database: reading the database's real-time table structure information (such as table names, column names, and data types); question classification: combining the built-in corpus in the vector database (VDB) to determine whether the user input is a database query or a statistical question; and context integration: passing the user question, database structure information, and prompt information to the encoding model (ENC) and pre-trained language model (PLM).

[0166] A pre-trained language model (PLM) is used to generate structured query statements that conform to the target database syntax based on the encoded input (user question + retrieved context hints + database structure).

[0167] Encoding Model (ENC): This converts text (such as user questions, question-answer pairs, and descriptions) into vectors, achieving semantic alignment. This facilitates rapid retrieval of relevant context in the vector database and provides structured input for PLM. It serves as the foundation for building and querying the vector database.

[0168] Vector Database (VDB): Used to store vectorized results of various text information, including table name and column name vectors, question-answer pair vectors, description text vectors, and DDL statement vectors. The built-in corpus vector is used to determine whether the user's question is a database query. When the user asks a question, the system retrieves the most relevant information through semantic matching and transmits it to the PLM as a prompt to improve generation quality.

[0169] Relational database (DB): used to store the specific table structure information of the user database (such as field names, primary and foreign key constraints, indexes, etc.), provide metadata for the dialogue module, and make the generated structured queries conform to the actual database structure.

[0170] User database: used to store user data.

[0171] This application provides an accurate database structure foundation for the pre-trained language model by matching target structure information related to the user's target question from the user's database structure information. This allows the generated structured query to conform to the actual database architecture. The structured query is then verified using the user's database structure information, and a verified structured query is output. This resolves the technical issue of the pre-trained language model's lack of understanding of the database structure during generation, which can lead to inaccurate structured query statements. This improves the accuracy of structured query generation.

[0172] Figure 6 The flowchart for the structured query statement generated in this scenario example. Figure 6 As shown in Figure 1, the user submits a target question through the conversation client, such as "Show sales in the Beijing area." The conversation client sends the target question to the conversation module, which calls the encoding model to convert the target question into a vector for subsequent semantic retrieval.

[0173] Based on the target question vector, a multi-dimensional search is performed from the vector database (VDB). The VDB-DOC module retrieves descriptive text related to the target question (e.g., "The sales table contains region and amount fields") and appends it to the prompt. The VDB-QA module retrieves similar question-answer pairs (e.g., "How do I query sales in a certain region?" and "SELECT region, SUM(amount) FROM sales") and appends them to the prompt. The VDB-DDL module retrieves the DDL statements for related tables to supplement table structure constraints. Metadata such as table names, column names, and data types are retrieved from the relational database (DB) to describe the structure of the current user's database.

[0174] It should be noted that due to PLM input restrictions, either the DDL portion retrieved from the vector database or the database structure description portion retrieved from the relational database can be retained in the prompt. When constructing the prompt, the question-answer portion and the description text portion can be omitted.

[0175] Integrate user questions, search context, database structure information, etc. into a complete prompt and submit it to PLM.

[0176] PLM reasoning: Generate a preliminary answer. If a structured query statement can be extracted from the PLM response information, the structured query verification and correction phase will be entered. The verification and correction process is as follows: Figure 4 shown.

[0177] If a structured query statement cannot be extracted, the user's target question is compared with the corpus for similarity. If the semantic similarity between the target question and the questions in the corpus is lower than the threshold, it indicates that the target question may not be a database query question, and an error is returned. If it is higher than the threshold, the prompt is re-integrated, adding more information retrieved from the vector database or relational database. For example, the three relevant data retrieved from the VDB-DDL module can be increased to five, and the structured query statement is re-generated using the supplemented prompt.

[0178] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.

[0179] The structured query statement generation method provided in the embodiment of the present application can be executed by a structured query statement generation device. In the embodiment of the present application, the structured query statement generation method is executed by the structured query statement generation device as an example to illustrate the structured query statement generation device provided in the embodiment of the present application.

[0180] like Figure 7 As shown, the structured query statement generating device includes:

[0181] Matching module 710, for matching target structural information related to the target question from structural information in the user database according to the user's target question;

[0182] A construction module 720 is used to construct prompt information based on the target question and the target structure information;

[0183] An input module 730 is used to input the prompt information into the pre-trained language model to obtain an output result of the pre-trained language model;

[0184] The output module 740 is configured to verify the structured query statement according to the structure information when the structured query statement exists in the output result, and output the structured query statement when the verification passes.

[0185] This application provides an accurate database structure foundation for the pre-trained language model by matching target structure information related to the user's target question from the user's database structure information. This allows the generated structured query to conform to the actual database architecture. The structured query is then verified using the user's database structure information, and a verified structured query is output. This resolves the technical issue of the pre-trained language model's lack of understanding of the database structure during generation, which can lead to inaccurate structured query statements. This improves the accuracy of structured query generation.

[0186] In some embodiments, the matching module 710 may also be used to:

[0187] Match target structure information related to the target problem from the vector database; the vector database stores the structure information of the user database;

[0188] And / or, matching target structure information related to the target problem from a relational database; the relational database stores structure information of the user database.

[0189] In some embodiments, the structured query statement generating apparatus may further include:

[0190] The storage module is used to read the first structural information of the user database; the first structural information includes the table name, column name and table creation statement; convert the first structural information into a vector and store it in the vector database.

[0191] In some embodiments, the storage module may also be used to:

[0192] The method obtains supplementary information associated with a user database input by a user; the supplementary information includes multiple question-answer pairs, multiple description texts, and creation statements of multiple tables; the question-answer pairs include questions and structured query statements matching the questions; the description text includes a business description of the user database; and the supplementary information is stored in a vector database.

[0193] In some embodiments, the storage module may also be used to:

[0194] Storing the vector corresponding to the table name in the first storage module of the vector database;

[0195] The vectors corresponding to the column names of each table are grouped according to the table name and stored in the second storage module of the vector database;

[0196] Storing the vector corresponding to the creation statement of the table of the user database in the third storage module of the vector database;

[0197] Storing the vectors corresponding to the question-answer pairs in a fourth storage module in the vector database;

[0198] Storing the vector corresponding to the description text in a fifth storage vector in the vector database;

[0199] The vector corresponding to the creation statement of the table of supplementary information is stored in the third storage module.

[0200] In some embodiments, the storage module may also be used to:

[0201] Read the second structural information of the user database; the second structural information includes table names, column names and data types; store the table names, column names and data types in a relational database in an associated manner according to a structured format.

[0202] In some embodiments, the building block 720 may also be used to:

[0203] Retrieve target description text and target question-answer pairs related to the target question from the vector database; construct prompt information based on the target question, target structure information, target description text and target question-answer pairs.

[0204] In some embodiments, the output module 740 may also be used to:

[0205] Object name information of the structured query statement is extracted; the object name information includes table name and column name; if the object name information exists in the relational database, the verification is passed; the relational database stores structural information of the user database; the structural information includes object name information of the user database.

[0206] In some embodiments, the output module 740 may also be used to:

[0207] When the object name information does not exist in the relational database, target object name information matching the object name information is retrieved from the vector database; the vector database stores the structural information of the user database; the structural information includes the object name information of the user database; and the prompt information is modified according to the target object name information.

[0208] In some embodiments, the structured query statement generating apparatus may further include:

[0209] The adjustment module is used to calculate the similarity between the target question and the questions in the corpus when there is no structured query statement in the output result; the corpus stores multiple questions classified as database query types; when the similarity is greater than the target threshold, the prompt information is adjusted.

[0210] In some embodiments, the adjustment module may also be used to:

[0211] Increase the amount of target structural information related to the target problem matched from the structural information in the user database; and add the newly added target structural information to the prompt information.

[0212] In some embodiments, the output module 740 may also be used to:

[0213] Execute structured query statements to obtain statistical results corresponding to the target question from the user database; output the statistical results and visualize them.

[0214] For the description of the features in the embodiment corresponding to the structured query statement generating apparatus, reference may be made to the relevant description of the embodiment corresponding to the structured query statement generating method, which will not be described in detail here.

[0215] The embodiment of the present application also provides an electronic device, such as Figure 8 As shown, it includes a memory 802 and a processor 801. The memory 802 stores a computer program, and the processor 801 is configured to run the computer program to execute the steps in any of the above-mentioned embodiments of the method for generating a structured query statement.

[0216] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above-mentioned structured query statement generation method embodiments when running.

[0217] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0218] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the computer program implements the steps of any of the above-mentioned structured query statement generation method embodiments.

[0219] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned structured query statement generation method embodiments are implemented.

[0220] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0221] The above is a detailed introduction to a structured query statement generation method, system, device and electronic device provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.

Claims

1. A method for generating a structured query statement, characterized in that: include: Matching target structure information related to the target question from the structure information in the user database according to the target question of the user; Constructing prompt information based on the target question and the target structure information; including: retrieving a target description text and a target question-answer pair related to the target question from a vector database; constructing prompt information based on the target question, the target structure information, the target description text and the target question-answer pair; including: filling the target question, the target structure information, the target description text and the target question-answer pair into corresponding positions according to a preset prompt information template to obtain the prompt information; wherein the vector database stores supplementary information input by the user, the supplementary information including a plurality of question-answer pairs and a plurality of description texts; the question-answer pair includes a question and a structured query statement matching the question; the description text includes a business description of the user database; Inputting the prompt information into a pre-trained language model to obtain an output result of the pre-trained language model; In the case where a structured query statement exists in the output result, the structured query statement is verified according to the structure information; the method includes: extracting object name information of the structured query statement; the object name information includes table name and column name; in the case where the object name information does not exist in the relational database, retrieving target object name information matching the object name information in the vector database; the vector database and the relational database store structure information of the user database; the structure information includes object name information of the user database; the prompt information is modified according to the target object name information; the method includes: replacing the object name information in the prompt information with the target object name information; If the verification is passed, the structured query statement is output.

2. The method according to claim 1, characterized in that The step of matching target structure information related to the target question from the structure information in the user database according to the target question of the user includes: Matching target structure information related to the target problem from a vector database; the vector database stores the structure information of the user database; And / or, matching target structure information related to the target problem from a relational database; the relational database stores the structure information of the user database.

3. The method according to claim 2, characterized in that The method further comprises: Reading first structural information of the user database; the first structural information includes table name, column name and table creation statement; The first structural information is converted into a vector and stored in the vector database.

4. The method according to claim 3, characterized in that The method further comprises: Obtaining supplementary information associated with the user database input by a user; the supplementary information includes at least one of a plurality of question-answer pairs, a plurality of description texts, and a plurality of table creation statements; the question-answer pair includes a question and a structured query statement matching the question; the description text includes a business description of the user database; The supplemental information is stored in the vector database.

5. The method according to claim 4, characterized in that The vector database includes a plurality of storage modules, and the method further includes: Storing the vector corresponding to the table name in the first storage module of the vector database; Grouping the vectors corresponding to the column names of the respective tables according to the table names, and storing the grouped vectors in the second storage module of the vector database; Storing the vector corresponding to the creation statement of the table of the user database in the third storage module of the vector database; Storing the vectors corresponding to the question-answer pairs in a fourth storage module in the vector database; Storing the vector corresponding to the description text in a fifth storage vector in the vector database; The vector corresponding to the creation statement of the table of supplementary information is stored in the third storage module.

6. The method according to claim 2, characterized in that The method further comprises: Reading second structural information of the user database; the second structural information includes table name, column name and data type; The table name, column name and data type are associated and stored in the relational database in a structured format.

7. The method according to claim 1, characterized in that The verifying the structured query statement according to the structure information includes: If the object name information exists in the relational database, the verification passes.

8. The method according to claim 1, characterized in that The method further comprises: When there is no structured query statement in the output result, calculating the similarity between the target question and questions in the corpus; the corpus stores a plurality of questions classified as database query; When the similarity is greater than a target threshold, the prompt information is adjusted.

9. The method according to claim 8, characterized in that The adjusting of the prompt information includes: increasing the number of target structural information related to the target problem matched from the structural information in the user database; The newly added target structure information is added to the prompt information.

10. The method according to claim 1, characterized in that The method further comprises: Executing the structured query statement to obtain statistical results corresponding to the target question from the user database; Output the statistical results and visualize the statistical results.

11. A structured query statement generation system, characterized in that: include: Conversation client and conversation module; The dialogue client is configured to receive a target question input by a user and send the target question to the dialogue module; The dialogue module is used to implement the steps of the structured query statement generation method according to any one of claims 1 to 10.

12. A structured query statement generating device, characterized in that: include: A matching module, configured to match target structure information related to the target question from the structure information in the user database according to the target question of the user; A construction module, configured to construct prompt information based on the target question and the target structure information; An input module is used to input the prompt information into a pre-trained language model to obtain an output result of the pre-trained language model; including: retrieving a target description text and a target question-answer pair related to the target question from a vector database; constructing prompt information based on the target question, the target structural information, the target description text and the target question-answer pair; including: filling the target question, the target structural information, the target description text and the target question-answer pair into corresponding positions according to a preset prompt information template to obtain the prompt information; wherein the vector database stores supplementary information input by the user, the supplementary information includes multiple question-answer pairs and multiple description texts; the question-answer pair includes a question and a structured query statement matching the question; the description text includes a business description of the user database; An output module is used to verify the structured query statement according to the structural information when there is a structured query statement in the output result; including: extracting object name information of the structured query statement; the object name information includes table name and column name; when the object name information does not exist in the relational database, retrieving target object name information matching the object name information in the vector database; the vector database and the relational database store the structural information of the user database; the structural information includes the object name information of the user database; correcting the prompt information according to the target object name information; including: replacing the object name information in the prompt information with the target object name information; and outputting the structured query statement if the verification passes.

13. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the method for generating a structured query statement according to any one of claims 1 to 10 when executing the computer program.

Citation Information

Patent Citations

  • Structured query statement generation method and device, equipment and medium

    CN117149812A