Structured query statement generation method and device, electronic equipment and storage medium

By filtering and matching query text vectors, we obtain relevant table structures, scene documents and statement question and answer vectors, and generate structured query statements, solving the problem of low accuracy of SQL statements in the existing technology, and achieving more efficient structured query statement generation.

CN119576965APending Publication Date: 2025-03-07PING AN BANK CO LTD
View PDF 0 Cites 7 Cited by

Patent Information

Application Number
CN202411615826.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-12
Publication Date
2025-03-07

AI Technical Summary

Technical Problem

When generating structured query statements, the prior art fails to understand the relevant table structure and data calculation requirements in different scenarios, resulting in low accuracy of generated SQL statements.

Method used

By obtaining the target query text, text encoding is used to obtain the query text vector, and based on the vector, the matching vector is filtered out from the preset candidate table structure definition, scene documents and statement question and answer vectors, the target prompt data is generated, and the statement generation model is used to generate structured query statements.

Benefits of technology

This method can be more accurately applied to the generation of structured query statements in different scenarios, improving the accuracy of generated SQL statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119576965A_ABST
    Figure CN119576965A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a structured query statement generation method and device, electronic equipment and a storage medium, belongs to the technical field of statement generation, and is suitable for the field of financial science and technology. The method comprises the steps of obtaining a target query text; performing text coding on the target query text to obtain a query text vector; screening out a matching table structure definition vector matched with the target query text from the candidate table structure definition vectors based on the query text vector; screening out a matched scene document vector from the candidate scene document vectors based on the query text vector; screening out matched statement question-answer vectors from the candidate statement question-answer vectors based on the query text vector; generating target prompt data based on the matching table structure definition vector, the matching scene document vector and the matching statement question and answer vector; and performing structured query statement generation on the target prompt data based on the statement generation model to obtain a target query statement. According to the embodiment of the invention, the accuracy of the structured query statements generated in different scenes can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of statement generation technology, applicable to the field of financial technology, and in particular to a method and device for generating structured query statements, an electronic device, and a storage medium. Background Art

[0002] Statement generation of Structured Query Language (SQL) refers to the process of generating SQL statements for querying data. Text-to-SQL refers to converting natural language descriptions into corresponding SQL query statements, which can assist non-technical users in quickly querying the database. For example, in the insurance promotion scenario of FinTech, when insurance sales staff need to obtain the operational data of insurance products, they can enter the corresponding query description text in the query system interface. The query system can convert the query description text into SQL statements executable by the database through Text-to-SQL to quickly obtain the queried data.

[0003] At present, the relevant technology usually directly inputs the natural language description text and the relevant table structure into a large language model to output the corresponding SQL statement. However, this method does not have a deep understanding of the relevant table structure and the requirements for data calculation in different scenarios, which makes the accuracy of the generated SQL low, and it is impossible to obtain accurate query results based on the generated SQL. Therefore, how to propose a method that can be applied to the generation of structured query statements in different scenarios and can improve the accuracy of the generated SQL has become a technical problem that needs to be solved urgently. Summary of the invention

[0004] The main purpose of the embodiments of the present application is to propose a method and device for generating a structured query statement, an electronic device, and a storage medium, which are intended to be applicable to the generation of structured query statements in different scenarios and to improve the accuracy of the generated SQL.

[0005] To achieve the above-mentioned purpose, a first aspect of an embodiment of the present application proposes a method for generating a structured query statement, the method comprising:

[0006] Get the target query text;

[0007] Performing text encoding on the target query text to obtain a query text vector;

[0008] Based on the query text vector, a matching table structure definition vector matching the target query text is selected from preset candidate table structure definition vectors;

[0009] Based on the query text vector, a matching scene document vector is screened out from preset candidate scene document vectors, wherein the candidate scene document vector has a candidate business scene, and the business scene applied by the target query text matches the candidate business scene pointed to by the matching scene document vector;

[0010] Based on the query text vector, a matching sentence question and answer vector is screened out from preset candidate sentence question and answer vectors, wherein the candidate sentence question and answer vector is a vector formed based on candidate question texts, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector;

[0011] Prompt data is generated based on the matching table structure definition vector, the matching scene document vector, and the matching sentence question and answer vector to obtain target prompt data;

[0012] A structured query statement is generated for the target prompt data based on a statement generation model to obtain a target query statement.

[0013] In some embodiments, the step of selecting a matching sentence question and answer vector from preset candidate sentence question and answer vectors based on the query text vector includes:

[0014] Extracting a candidate question text vector from the candidate sentence question-answer vector;

[0015] Calculating vector similarity between the candidate question text vector and the query text vector to obtain text vector similarity;

[0016] The matching sentence question and answer vector is determined from the candidate sentence question and answer vectors based on the text vector similarity.

[0017] In some embodiments, the generating of prompt data based on the matching table structure definition vector, the matching scenario document vector, and the matching sentence question and answer vector to obtain target prompt data includes:

[0018] Obtaining the text vector similarity of the matching sentence question and answer vector to obtain a text matching value;

[0019] If the text matching value is less than a preset matching threshold, obtaining a matching query statement from the matching statement question-answer vector;

[0020] Performing sentence content detection on the matching query sentence based on the structured sentence detection model to obtain sentence detection data;

[0021] Optimizing the matching query statement based on the statement detection data, the matching table structure definition vector, and the matching scenario document vector to obtain a first optimized query statement;

[0022] Update the matching sentence question and answer vector based on the first optimized query sentence to obtain an updated sentence question and answer vector;

[0023] Prompt data is generated based on the matching table structure definition vector, the matching scenario document vector and the updated sentence question and answer vector to obtain the target prompt data.

[0024] In some embodiments, determining the matching sentence question-answer vector from the candidate sentence question-answer vectors based on the text vector similarity includes:

[0025] Determine a related sentence question and answer vector from the candidate sentence question and answer vector based on the text vector similarity and a preset similarity threshold, wherein the related sentence question and answer vector includes a related question text vector;

[0026] Extracting keywords from the target query text to obtain target keywords;

[0027] Performing text topic detection on the target keyword based on a topic detection model to obtain a text topic;

[0028] Performing semantic detection on the relevant question text vector and the text topic based on a semantic detection model to obtain a semantic relevance score of the relevant question text vector;

[0029] The matching sentence question-answer vector is determined from the related sentence question-answer vectors based on the semantic relevance score.

[0030] In some embodiments, before selecting a matching scene document vector from preset candidate scene document vectors based on the query text vector, the method further includes:

[0031] Acquire a newly added scenario document and a preset scenario document vector set, wherein the scenario document vector set includes the candidate scenario document vector;

[0032] Performing document matching on the newly added scene documents based on the scene document vector set to obtain similar scene documents;

[0033] Performing document language analysis on the newly added scenario document and the similar scenario document based on a preset language analysis macro model to obtain a document status of the newly added scenario document, wherein the document status is used to indicate whether the newly added scenario document constitutes an update to the similar scenario document or not;

[0034] If the document status is a composition update status, obtaining update feedback data of the newly added scenario document;

[0035] The scene document vector set is updated based on the update feedback data and the newly added scene document.

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

[0037] Execute the target query statement based on a preset statement executor to obtain target query data;

[0038] Acquire object feedback data of the target query data;

[0039] Determine a statement execution score of the target query statement based on the object feedback data, wherein the statement execution score is used to indicate the accuracy of the target query data obtained based on the target query statement;

[0040] If the sentence score is less than the preset score, sentence correction is performed on the target query sentence to obtain a corrected sentence.

[0041] In some embodiments, before selecting a matching sentence question and answer vector from preset candidate sentence question and answer vectors based on the query text vector, the method further includes:

[0042] Acquire a revised document sentence, an associated reply text of the revised document sentence, and a preset sentence question-answer vector set, wherein the sentence question-answer vector set includes the candidate sentence question-answer vector;

[0043] Performing text correction on the associated reply text based on the correction document statement to obtain a corrected reply text;

[0044] The sentence question-answer vector set is updated based on the revised reply text and the revised document sentence.

[0045] To achieve the above-mentioned purpose, a second aspect of an embodiment of the present application provides a structured query statement generating device, the device comprising:

[0046] An acquisition module, used to acquire a target query text;

[0047] An encoding module, used for performing text encoding on the target query text to obtain a query text vector;

[0048] A first screening module, configured to screen out a matching table structure definition vector that matches the target query text from preset candidate table structure definition vectors based on the query text vector;

[0049] A second screening module is used to screen out a matching scene document vector from preset candidate scene document vectors based on the query text vector, wherein the candidate scene document vector has a candidate business scene, and the business scene applied by the target query text matches the candidate business scene pointed to by the matching scene document vector;

[0050] A third screening module is used to screen out a matching sentence question and answer vector from preset candidate sentence question and answer vectors based on the query text vector, wherein the candidate sentence question and answer vector is a vector formed based on a candidate question text, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector;

[0051] A data generation module, used to generate prompt data based on the matching table structure definition vector, the matching scene document vector and the matching sentence question and answer vector to obtain target prompt data;

[0052] The sentence generation module is used to generate a structured query sentence for the target prompt data based on the sentence generation model to obtain a target query sentence.

[0053] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.

[0054] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented.

[0055] The present application proposes a structured query statement generation method and device, electronic device, and storage medium, which obtain a target query text; perform text encoding on the target query text to obtain a query text vector; further, based on the query text vector, filter out a matching table structure definition vector that matches the target query text from a preset candidate table structure definition vector; based on the query text vector, filter out a matching scenario document vector from a preset candidate scenario document vector, wherein the candidate scenario document vector has a candidate business scenario, and the business scenario applied by the target query text matches the candidate business scenario pointed to by the matching scenario document vector; based on the query text vector, filter out a matching sentence question and answer vector from a preset candidate sentence question and answer vector, wherein the candidate sentence question and answer vector is a vector composed of candidate question texts, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector; further, generate prompt data based on the matching table structure definition vector, the matching scenario document vector, and the matching sentence question and answer vector to obtain target prompt data; generate a structured query statement for the target prompt data based on a sentence generation model to obtain a target query statement. Compared to the related art that directly inputs the natural language description text and the related table structure into the large language model to output the corresponding SQL statement without in-depth understanding of the related table structure and the requirements for data calculation in different scenarios, this application can first perform different types of vector matching on the query text vector to obtain the matching table structure definition vector, matching scenario document vector and matching statement question and answer vector, so as to have an in-depth understanding of the related table structure and related business scenarios, and then generate statements for the generated target prompt data based on the statement generation model. In this way, it can be better applied to the generation of structured query statements in different scenarios, and can improve the accuracy of the generated SQL statements. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0057] Figure 2 It is a schematic diagram of a framework of a method for generating a structured query statement provided in an embodiment of the present application;

[0058] Figure 3 yes Figure 1 A flowchart of step S150 in FIG.

[0059] Figure 4 yes Figure 3 A flowchart of step S330 in FIG.

[0060] Figure 5 yes Figure 1 A flowchart of step S160 in FIG.

[0061] Figure 6is a second flow chart of the method for generating a structured query statement provided in an embodiment of the present application;

[0062] Figure 7 This is the third flow chart of the structured query statement generation method provided in the embodiment of the present application;

[0063] Figure 8 This is the fourth flow chart of the structured query statement generation method provided in the embodiment of the present application;

[0064] Fig. 9 It is a structural schematic diagram of a structured query statement generating device provided in an embodiment of the present application;

[0065] Fig.10 It is a hardware structure diagram of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0066] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0067] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0068] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0069] First, some nouns involved in this application are analyzed:

[0070] Artificial Intelligence (AI): It is a new technical science that studies and develops theories, methods, technologies and application systems for simulating, extending and expanding human intelligence. AI is a branch of computer science. AI attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Research in this field includes robots, language recognition, image recognition, natural language processing and expert systems. AI can simulate the information process of human consciousness and thinking. AI is also a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0071] Structured Query Language (SQL): is a standard programming language used to manage and operate relational database management systems (RDBMS). SQL can be used to perform various database operations, including querying, inserting, updating, and managing data. SQL is widely used in various database systems, such as MySQL, PostgreSQL, Oracle, SQL Server, and SQLite.

[0072] SQL statement generation refers to the process of generating SQL statements for querying data. Text-to-SQL refers to converting natural language descriptions into corresponding SQL query statements, which can assist non-technical users in quickly querying the database, that is, providing a mechanism for non-technical users to communicate directly with the database. For example, in the insurance promotion scenario of financial technology, when insurance sales personnel (i.e. non-technical users, and also operation personnel, etc.) need to obtain the operation data of insurance products, technical developers need to write SQL statements according to the needs of the former, extract data, and form offline data tables or online reports. The conversion between product managers, operation personnel and database data needs to be performed by developers, which reduces the efficiency of data acquisition. With Text-to-SQL technology, the data requirements described by non-technical users in natural language can be directly converted into SQL statements that can be executed by the database, which greatly improves the efficiency of data acquisition. That is, non-technical personnel can enter the corresponding query description text in the query system interface, and the query system can convert the query description text into SQL statements that can be executed by the database through Text-to-SQL to quickly obtain the queried data.

[0073] At present, the relevant technology usually directly inputs the natural language description text and the relevant table structure into the large language model to output the corresponding SQL statement. However, this method does not go deep into the relevant table structure and the requirements for data calculation in different scenarios, that is, it usually uses public data on the Internet for training, and lacks private data and business rule definitions in different business scenarios. At the same time, when the required information knowledge is available, for some complex SQL statements, the large model used by the relevant technology may not be generated correctly due to insufficient capabilities. As a result, the accuracy of the generated SQL is low, and it is impossible to obtain accurate query results based on the generated SQL. Therefore, how to propose a method for generating structured query statements that can be applied to different scenarios and can improve the accuracy of the generated SQL has become a technical problem that needs to be solved urgently.

[0074] Based on this, the embodiments of the present application provide a method and device for generating a structured query statement, an electronic device, and a storage medium, which can be applicable to the generation of structured query statements in different scenarios and can improve the accuracy of the generated SQL.

[0075] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0076] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0077] The structured query statement generation method provided in the embodiment of the present application relates to the field of artificial intelligence technology. The structured query statement generation method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server side, and can also be software running in a terminal or a server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc.; the server side can be configured as an independent physical server, or a server cluster or a distributed system composed of multiple physical servers, and can also be configured to provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms and other basic cloud computing services. Cloud servers; software can be applications that implement structured query statement generation methods, etc., but are not limited to the above forms.

[0078] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0079] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing on data related to the identity or characteristics of the object, such as queries and statement executions based on database tables constructed based on object information, the permission or consent of the object will be obtained first, and the collection, use and processing of these data will comply with relevant laws, regulations and standards. In addition, when the embodiment of the present application needs to obtain sensitive personal information of the object, the separate permission or separate consent of the object will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the separate permission or separate consent of the object, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.

[0080] See also Figure 1 , Figure 1 is an optional flow chart of a method for generating a structured query statement provided in an embodiment of the present application. In some embodiments of the present application, Figure 1The method may specifically include but is not limited to steps S110 to S170.

[0081] Step S110, obtaining a target query text;

[0082] Step S120, performing text encoding on the target query text to obtain a query text vector;

[0083] Step S130, selecting a matching table structure definition vector that matches the target query text from preset candidate table structure definition vectors based on the query text vector;

[0084] Step S140, filtering out matching scene document vectors from preset candidate scene document vectors based on the query text vector;

[0085] Step S150, selecting matching sentence question and answer vectors from preset candidate sentence question and answer vectors based on the query text vector;

[0086] Step S160, generating prompt data based on the matching table structure definition vector, the matching scenario document vector, and the matching sentence question and answer vector to obtain target prompt data;

[0087] Step S170 , generating a structured query statement for the target prompt data based on the statement generation model to obtain a target query statement.

[0088] In step S110 of some embodiments, the target query text refers to the query request entered by the target object on the input page of the database query system (a system that can implement the structured query statement generation method of the present application), and is usually a text expressed in natural language. That is to say, the target object enters a question or query request through the interface, and the system receives and records the input. The target object can be a non-technical person, and it is necessary to use the database query system to generate a corresponding target query statement from the input target query text. For example, if the target object is a business person, the target query text can be a business person's point question about reissue, such as "how many reissues have been generated in the past week, and how many points have been reissued".

[0089] It should be noted that the structured query statement generation method of the present application can be packaged into a plug-in tool, which can be connected to the database system for generating and optimizing the natural language received by the database system. The structured query statement generation method of the present application can also be packaged into an independent tool for users to use for statement questions, so as to generate optimized statements that meet user needs.

[0090] In step S120 of some embodiments, in order to facilitate subsequent vector matching, the present application may convert the natural language text into a machine-processable numerical vector, that is, the target query text may be input into a pre-trained embedding model for text encoding to obtain a query text vector. At this time, the embedding model may be constructed based on a structure such as word embedding, a Transformer model, etc., to convert the target query text into a vector representation in a high-dimensional space.

[0091] Please note that Figure 2 , Figure 2 It is a schematic diagram of a structured query statement generation method provided by an embodiment of the present application. The target object inputs the target query text in the interface, and after being processed by the embedded model, the query text vector is output. Furthermore, the query text vector can be matched with the pre-built vector database to fully consider the specific scenario configuration such as the relevant table structure and the calculation of business scenario indicators when generating the statement later.

[0092] In step S130 of some embodiments, since the large model used in the related art does not understand the business table structure when generating statements, and does not understand the API supported by the specific database type and version, it is impossible to generate a directly executable SQL statement, that is, the generated SQL statement is prone to syntax errors when executed. Based on this, the present application can pre-construct a table structure definition vector set, which stores the candidate table structure definition vectors of multiple candidate database tables, and the table structure definition vectors of any two candidate database tables are not the same. In this way, at least one matching table structure definition vector that matches the target query text can be screened out from the preset candidate table structure definition vector based on the query text vector. In other words, the matching table structure definition vector is used to represent the table structure definition vector of the candidate database table associated with the target query text. In this way, it can be determined which table structures in the database are associated with the target query text, select the table related to the problem, provide the business table structure description required by the statement generation model, that is, match the table structure definition vector, and perform table routing at the same time, which can solve the problem of selecting related tables in many business tables.

[0093] It should be noted that the candidate table structure definition vector refers to a vector form generated based on the table structure information of the candidate database table. The table structure information may include the column name, data type, key (primary key, foreign key), index, constraint (such as non-null, uniqueness), etc. The table structure definition vector set is a set built based on the data definition language (Data Definition Language, DDL), which can be a subset of the SQL language and is used to define and manage the object structure in the database, such as tables, indexes, views, etc. DDL statements include CREATE, ALTER and DROP, etc.

[0094] It should be noted that if Figure 2 As shown, the vector database pre-built in the present application includes a table structure definition vector set, a scenario document vector set and a sentence question and answer vector set. Among them, for the collected candidate table structure definition data, candidate scenario documents and candidate sentence questions and answers (including candidate question texts and text query sentences that solve the candidate question texts), the present application can provide an interface for adding three types of data, and the data is vectorized through the embedded model, indexed and stored in three vector sets. In other words, the present application can form a proprietary knowledge base with these three types of vector data, and perform data and memory expansion on the subsequent sentence generation model based on the large model. And the process of matching the input target query text using three vector sets in the present application is also equivalent to the process of retrieval augmentation generation (RAG), that is, by retrieving an external knowledge base (such as the three vector sets of the present application), the question input is supplemented, thereby ensuring a more accurate and up-to-date output of the large model. Among them, the table structure definition vector set can include vectors V01 to vectors V0N, and N (N is a positive integer) represents the total number of candidate table structure definition vectors stored in the table structure definition vector set.

[0095] In step S140 of some embodiments, the present application can determine which business scenario the content of the target object query is more suitable for by matching and screening the query text vector with the preset candidate scenario document vector, so as to screen out at least one matching scenario document vector. Among them, the scenario document vector set includes multiple candidate scenario document vectors, each candidate scenario document vector has a corresponding candidate business scenario, and any two candidate business scenarios are different. The business scenario applied by the target query text matches the candidate business scenario pointed to by the matching scenario document vector. In this way, by matching and screening the query text vector with the preset candidate scenario document vector, documents related to the target query text can be selected, and the information such as the term explanation, business data calculation rules, and indicator calculation formula required for the business scenario applied by the target query text can be provided for subsequent sentence generation, thereby improving the accuracy of sentence generation. For example, if the problem of the business personnel involves some exclusive business rules, for example, the source of the points issuance must be that the user has participated in a certain activity, so each record has an associated activity code and name, and some activities are reissue activities used by customer service to compensate users, then the retrieved matching scenario document vector can contain the identification rules of the reissue activity, and the retrieved results can be used together when the sentence generation model is subsequently input, so as to improve the accuracy of sentence generation.

[0096] It should be noted that the candidate scenario document vector refers to the vector form of the business scenario document of the pre-acquired candidate business scenario. The business scenario document refers to various documents and materials related to the candidate business scenario, which may include requirement specifications, user manuals, flow charts, contract agreements, etc. Figure 2 As shown, the scene document vector set may include M (M is a positive integer) candidate scene document vectors, which may be represented as vector V11 to vector V1M.

[0097] In step S150 of some embodiments, the present application may filter out matching sentence question and answer vectors from preset candidate sentence question and answer vectors based on the query text vector. The candidate sentence question and answer vector is in the form of a vector composed of a candidate question text input historically and a text query sentence that successfully solves the candidate question text. In other words, the candidate sentence question and answer vector may correspond to the candidate question text and the text query sentence, and the candidate sentence question and answer vector may be a vector obtained by concatenating the vector of the candidate question text and the vector of the text query sentence. The target query text matches the candidate question text pointed to by the candidate sentence question and answer vector.

[0098] It should be noted that the statement question and answer vector set may include multiple candidate statement question and answer vectors, and each candidate statement question and answer vector is a combination vector composed of a candidate question text and a corresponding text query statement, which can improve the efficiency of statement generation and thus improve the efficiency of data query. The target query text matches the candidate question text pointed to by the candidate statement question and answer vector. For example, if the statistical question raised by the business is more complicated, such as calculating the median of the total points issued to each user within thirty days. The SQL statement for calculating the median is more complicated, and according to the original capabilities of the model, the SQL answer may be wrong. The retrieved candidate statement question and answer vector may contain a combination of SQL statements for calculating the median, the candidate question text is "median of user points balance", and the text query statement is "select costomer_no, middle_numfrom..." In this way, when the retrieved results are input into the subsequent statement generation model, the accuracy of statement generation can be improved. If Figure 2 As shown, the sentence question and answer vector set may include P (P is a positive integer) candidate sentence question and answer vectors, which may be represented as vector V21 to vector V2P.

[0099] It should be noted that this application can constitute a one-shot or few-shot learning input for the sentence generation model by selecting historical questions and answers related to the target query text (i.e., matching sentence question and answer vectors), thereby enhancing the SQL statement generation capability.

[0100] See also Figure 3 , Figure 3It is a specific flow chart of step S150 provided in an embodiment of the present application. In some embodiments of the present application, step S150 may specifically include but is not limited to steps S310 to S330.

[0101] Step S310, extracting a candidate question text vector from the candidate sentence question-answer vector;

[0102] Step S320, calculating vector similarity between the candidate question text vector and the query text vector to obtain text vector similarity;

[0103] Step S330, determining a matching sentence question and answer vector from the candidate sentence question and answer vectors based on the text vector similarity.

[0104] In step S310 of some embodiments, since the candidate sentence question and answer vector can be a vector obtained by concatenating the vector of the candidate question text and the vector of the text query sentence, the candidate question text vector can be extracted from the candidate sentence question and answer vector to provide a basis for subsequent similarity calculation.

[0105] In step S320 of some embodiments, further, the degree of match between the candidate question text and the target query text can be determined by calculating the similarity between the candidate question text vector and the query text vector. The method for calculating the vector similarity can be cosine similarity, cross entropy, etc., which are not specifically limited here, to measure the similarity between two vectors. Cosine similarity is determined by calculating the ratio of the dot product of two vectors and the product of the corresponding modulus. The closer the value is to 1, the higher the similarity.

[0106] In step S330 of some embodiments, the candidate sentence question and answer vectors can be further arranged in descending order based on the text vector similarity, and K (K is a positive integer, such as 4, 5, etc.) matching sentence question and answer vectors with higher text vector similarity are obtained from the candidate sentence question and answer vectors.

[0107] It should be noted that the process of performing vector matching on the matching table structure definition vector and the matching scene document vector can be referred to in the above steps S310 to S330, that is, respectively performing vector similarity calculations on the candidate table structure definition vector and the query text vector, and on the candidate scene document vector and the query text vector, so as to select multiple matching table structure definition vectors and matching scene document vectors according to vector similarity, which will not be described in detail here. In this way, by performing vector retrieval using vector similarity, vectors related to the target query text can be found.

[0108] See also Figure 4 , Figure 4It is a specific flow chart of step S330 provided in an embodiment of the present application. In some embodiments of the present application, step S330 may specifically include but is not limited to steps S410 to S450.

[0109] Step S410, determining a relevant sentence question and answer vector from the candidate sentence question and answer vectors based on the text vector similarity and a preset similarity threshold;

[0110] Step S420, extracting keywords from the target query text to obtain target keywords;

[0111] Step S430, performing text topic detection on the target keyword based on the topic detection model to obtain the text topic;

[0112] Step S440, performing semantic detection on the relevant question text vector and the text topic based on the semantic detection model to obtain a semantic relevance score of the relevant question text vector;

[0113] Step S450, determining a matching sentence question and answer vector from related sentence question and answer vectors based on the semantic relevance score.

[0114] In step S410 of some embodiments, the present application may determine the relevant sentence question and answer vector from the candidate sentence question and answer vectors based on the text vector similarity and the preset similarity threshold, so as to screen out the sentence question and answer vectors whose similarity with the target query text at the vector level exceeds the preset similarity threshold. Specifically, the text vector similarity and the preset similarity threshold may be numerically compared, and if the text vector similarity is greater than or equal to the preset similarity threshold, the candidate sentence question and answer vector corresponding to the text vector similarity is used as the relevant sentence question and answer vector. The preset similarity threshold is to ensure that the question text corresponding to the selected relevant sentence question and answer vector is semantically close enough to the target query text.

[0115] In step S420 of some embodiments, since irrelevant texts are inevitably introduced for certain questions, if the sentence generation model completely relies on the matched vectors, it may not be able to accurately distinguish which are related to the topic and which are not. Even if it is stated that the retrieved texts are for reference only, irrelevant texts will mislead the sentence generation model and reduce the generation accuracy. Therefore, the relevant sentence question and answer vectors can be further screened to eliminate the sentence question and answer vectors corresponding to irrelevant question texts to improve the accuracy of sentence generation. Based on this, the keywords that best represent the query intent can be extracted from the target query text. Specifically, natural language processing techniques, such as TF-IDF, TextRank or other keyword extraction algorithms, can be used to identify the most important words or phrases from the target query text. These words or phrases can represent the core content of the query text.

[0116] In step S430 of some embodiments, the subject or field of the target query text may be further determined based on the target keyword. Specifically, a topic detection model constructed based on a topic model (such as LDA) or a deep learning model (such as BERT) may be used to analyze the extracted target keywords, thereby identifying the subject of the target query text. This helps to further narrow the search scope and find the question-answer pairs most relevant to the query subject.

[0117] In step S440 of some embodiments, the degree of semantic matching between the relevant question text and the target query text may be further evaluated. Specifically, a semantic detection model (such as a model built based on machine learning, a large model, etc.) may be used to perform semantic detection on the relevant question text vector and the determined text topic, and determine the degree of matching between the relevant question text corresponding to the relevant question text vector and the text topic, that is, to obtain a semantic relevance score corresponding to each relevant question text vector.

[0118] In step S450 of some embodiments, further, the question-answer pair that is most semantically matching with the target query text can be further screened out from the sentence question-answer vectors that have been determined to be relevant, that is, at least one candidate question text vector with a high semantic relevance score is used as the final matching sentence question-answer vector. This means that this question-answer pair is semantically closest to the query requirement of the target object, and therefore is most likely to provide the answer required by the target object.

[0119] In the above embodiment, the present application can use a semantic detection model built based on a large model to perform a step of screening the recalled relevant sentence question and answer vectors. After vector similarity retrieval, the alternative relevant sentence question and answer vectors and text topics are sent to a semantic detection model that is good at language analysis and summarization (which can be built based on general large models such as Baichuan and Qianwen) to perform semantic relevance analysis, eliminate irrelevant text, and thus improve the efficiency and accuracy of sentence generation.

[0120] In step S160 of some embodiments, after retrieving the matching table structure definition vector, matching scenario document vector and matching sentence question and answer vector, target prompt data can be generated based on these vectors to provide information prompts for the sentence generation model, thereby generating more accurate sentences. That is to say, the text query vector of the target query text is retrieved in three sets in the vector database according to the vector cosine similarity to obtain three subsets, namely, the DDL (DDLs, containing multiple matching table structure definition vectors), documents (DOCs, containing multiple matching scenario document vectors) and SQL question and answer combinations (SQLs, containing multiple matching sentence question and answer vectors) that are most relevant to the question semantics. Furthermore, prompt data generation can be performed according to a preset format template and a prompt data generation model, and the generated example can be shown as follows:

[0121] "Here are the table DDLs that might be relevant:

[0122] [DDLs]

[0123] The following are possible descriptions:

[0124] [DOCs]

[0125] Here are some possibly related questions and SQL answers for reference:

[0126] [SQLs]

[0127] The example is complete. Please generate the corresponding SQL statement based on the above information. Just generate the SQL statement without adding any explanation or comments. My question is:

[0128] [target query text]".

[0129] It should be noted that the preset format template can be flexibly adjusted according to actual needs without limitation.

[0130] See also Figure 5 , Figure 5 It is a specific flow chart of step S160 provided in an embodiment of the present application. In some embodiments of the present application, step S160 may specifically include but is not limited to steps S510 to S560.

[0131] Step S510, obtaining the text vector similarity of the matching sentence question and answer vector to obtain a text matching value;

[0132] Step S520, if the text matching value is less than the preset matching threshold, obtaining a matching query statement from the matching statement question-answer vector;

[0133] Step S530, performing sentence content detection on the matching query sentence based on the structured sentence detection model to obtain sentence detection data;

[0134] Step S540, optimizing the matching query statement based on the statement detection data, the matching table structure definition vector, and the matching scenario document vector to obtain a first optimized query statement;

[0135] Step S550, updating the matching sentence question and answer vector based on the first optimized query sentence to obtain an updated sentence question and answer vector;

[0136] Step S560, generating prompt data based on the matching table structure definition vector, the matching scene document vector, and the updated sentence question and answer vector to obtain target prompt data.

[0137] In step S510 and step S520 of some embodiments, the text vector similarity of each matching sentence question and answer vector is used as a text matching value, which is used to indicate the degree of match between the candidate question text indicated by the matching sentence question and answer vector and the target query text. Further, it is determined whether the matching sentence question and answer vector is close enough to the user's query requirements to decide whether to use the sentence question and answer vector. If the text matching value is less than the preset matching threshold, indicating that the current matching degree is insufficient, the sentence can be optimized and prompt data can be generated to allow the sentence generation model to decide whether to use the sentence.

[0138] It should be noted that the preset matching threshold can be 1. At this time, if the text matching value is equal to the preset matching threshold, it means that the target query text is exactly the same as the candidate question text indicated by the matching sentence question and answer vector. At this time, there is no need to perform a sentence generation model, and the matching query sentence indicated by the matching sentence question and answer vector can be directly returned as the target query sentence.

[0139] In step S530 of some embodiments, further, when the text matching value is less than a preset matching threshold, content detection can be performed on the matching query statement based on a structured sentence detection model (which can be a model built based on machine learning, deep learning model, etc.) to identify possible problems or deficiencies in the statement and generate sentence detection data.

[0140] In step S540 of some embodiments, further, the matching query statement can be optimized based on the statement detection data, the matching table structure definition vector, and the matching scenario document vector, which can include correcting syntax errors and adjusting the query logic to adapt to the specific table structure and business scenario, so that the generated first optimized query statement is more accurate and efficient.

[0141] In step S550 and step S560 of some embodiments, further, the first optimized query statement may be used to update the matching query statement corresponding to the matching statement question and answer vector, thereby updating the matching statement question and answer vector to obtain an updated statement question and answer vector. Prompt data is generated based on the matching table structure definition vector, the matching scenario document vector, and the updated statement question and answer vector to obtain target prompt data. In this way, the accuracy and applicability of the generation of the target query statement can be improved, and finally a query result that better meets the user's needs can be queried.

[0142] See also Figure 6 , Figure 6 It is another optional flow chart of the structured query statement generation method provided by the embodiment of the present application. In some embodiments of the present application, before step S140, the structured query statement generation method provided by the present application may further include but not limited to steps S610 to S650.

[0143] Step S610, obtaining a newly added scene document and a preset scene document vector set;

[0144] Step S620, performing document matching on the newly added scene documents based on the scene document vector set to obtain similar scene documents;

[0145] Step S630, performing document language analysis on the newly added scenario document and similar scenario documents based on a preset language analysis macro model to obtain the document status of the newly added scenario document;

[0146] Step S640: if the document status is a composition update status, obtain update feedback data of the newly added scenario document;

[0147] Step S650: updating the scene document vector set based on the updated feedback data and the newly added scene document.

[0148] It should be noted that since the documents and question-answer combinations are described in natural language and lack unique identification methods, it is difficult to determine whether similar texts already exist when new data is added. In the case of multi-person team maintenance, it is easy to have duplicate information or contradictory new and old data, which affects the quality of data retrieval. Based on this, this application also designs an update mechanism to improve the direct data insertion method, which can improve the efficiency and quality of data updates.

[0149] In step S610 and step S620 of some embodiments, the present application may first obtain the newly added scenario document and the preset scenario document vector set, and perform document matching on the newly added scenario document based on the scenario document vector set to obtain similar scenario documents. That is, when inserting text data (i.e., newly added scenario documents), the present application may first perform a search in the vector database for the data to be added by the retrieval module, and retrieve several pieces of data (i.e., similar scenario documents, such as 5 pieces) that are semantically similar to the data to be added.

[0150] In step S630 of some embodiments, the newly added scenario document and the similar scenario document can further be input into a preset language analysis model to determine whether they constitute an update to the existing data, and obtain the document status of the newly added scenario document, which is used to indicate whether the newly added scenario document constitutes an update to the similar scenario document or not.

[0151] In step S640 and step S650 of some embodiments, if the document status is in the update status, update feedback data of the newly added scenario document can be obtained, and the update feedback data can be feedback data of whether the newly added scenario document can be updated, which is further confirmed by the target object. And the scenario document vector set can be updated based on the update feedback data and the newly added scenario document. That is,

[0152] It should be noted that the process of updating the scene document vector set based on the update feedback data and the newly added scene document can specifically include: if the update feedback data represents that the target object can be updated, the newly added scene document is used to replace the similar scene document to update the scene document vector set; if the update feedback data represents that the target object cannot be updated, the newly added scene document is added to the scene document vector set to update the scene document vector set.

[0153] It should be noted that if the document status is not an update status, the newly added scene document is added to the scene document vector set to update the scene document vector set. When adding new data, the application can also normalize the data to improve the accuracy of the model in determining whether it constitutes an update.

[0154] See also Figure 7 , Figure 7 It is another optional flow chart of the structured query statement generation method provided by the embodiment of the present application. In some embodiments of the present application, before step S150, the structured query statement generation method provided by the present application may further include but not limited to steps S710 to S730.

[0155] Step S710, obtaining a revised document sentence, a related reply text of the revised document sentence, and a preset sentence question-answer vector set;

[0156] Step S720, performing text correction on the associated reply text based on the correction document statement to obtain a corrected reply text;

[0157] Step S730, updating the sentence question-answer vector set based on the revised reply text and the revised document sentence.

[0158] In step S710 of some embodiments, when adding or modifying SQL, the modified document statement to be modified, the associated reply text of the modified document statement, and the preset statement question-answer vector set can be obtained first. These modified document statements may contain errors or need to be updated to maintain the accuracy of statement generation. The associated reply text is the previous answer to the relevant question.

[0159] In step S720 of some embodiments, the associated reply text is modified accordingly based on the content of the revised document statement, which may include updating terminology, correcting error information, adjusting the structure of the answer, etc., to ensure that the reply text matches the revised document statement, and a revised reply text is obtained. At this time, the revised reply text is equivalent to the above-mentioned candidate question text.

[0160] In step S730 of some embodiments, the revised reply text and the revised document sentence are further used as a new sentence question and answer combination to update the sentence question and answer vector set. This may involve recalculating the vector, adjusting the vector weight, or adding a new vector representation to ensure that the vector set can accurately reflect the latest document sentence and reply text information.

[0161] In the above embodiment, the present application can reversely correct the ambiguous or incomplete query description according to the given SQL to avoid misleading the subsequent generation due to overly concise or ambiguous queries. Through this process, the system can ensure that the document sentences and the associated reply texts remain up-to-date and accurate, while updating the sentence question-answer vector set to improve the response quality and accuracy of the system.

[0162] In step S170 of some embodiments, the sentence generation model may be a model for generating structured sentences based on a large model, and the large model used may be ChatGLM, QianWen-72B, Vicuna-13B, Fauxpilot, etc., without specific limitation. Based on this, the present application may input the target prompt data into the sentence generation model to obtain a sentence for querying the question requirements of the target query text.

[0163] See also Figure 8 , Figure 8 It is another optional flow chart of the structured query statement generation method provided by the embodiment of the present application. In some embodiments of the present application, after step S170, the structured query statement generation method provided by the present application may further include but not limited to steps S810 to S840.

[0164] Step S810, executing the target query statement based on a preset statement executor to obtain target query data;

[0165] Step S820, obtaining object feedback data of target query data;

[0166] Step S830, determining a statement execution score of the target query statement based on the object feedback data;

[0167] Step S840: If the sentence score is less than the preset score, sentence correction is performed on the target query sentence to obtain a corrected sentence.

[0168] In step S810 of some embodiments, the preset statement executor is equivalent to a SQL executor, combined with Figure 2 After obtaining the target query statement, the application can use the preset statement executor to execute the target query statement to retrieve or calculate the required data. This execution process will retrieve data from the data source or perform calculations according to the query statement, and finally obtain the target query data.

[0169] In step S820 of some embodiments, further, in combination with Figure 2 , this application can collect object feedback data about the target query data. The object feedback data can be the evaluation of the target query data by the target object obtained from the data user or the relevant quality control mechanism to evaluate the quality and accuracy of the data. And the object feedback data may come from the actual use experience of the target object, automated test results or other quality assessment methods, which are not specifically limited here.

[0170] In step S830 of some embodiments, further, based on the object feedback data, the present application may use a preset evaluation standard or algorithm to determine the statement execution score of the target query statement, and the statement execution score is used to indicate the accuracy of the target query data obtained based on the target query statement. This score can be a numerical score, a grade rating, or other forms of evaluation, which is used to quantify the accuracy and effectiveness of the execution of the target query statement.

[0171] In step S840 of some embodiments, further, when the execution result of the target query statement does not meet the preset standard, that is, the statement score is less than the preset score, it indicates that there may be a problem with the target query statement, and the target query statement can be corrected.

[0172] It should be noted that the present application can also provide a feedback interface, where users can choose whether the result is correct and whether to make corrections, and finally add the correct result to the "SQL question and answer combination" set, that is, update the statement question and answer vector set to form training data.

[0173] In the above embodiments, the present application can adjust and optimize the target query statement according to the scoring results and object feedback data to improve its accuracy and execution effect, and finally obtain a corrected statement to ensure the quality and accuracy of the query results.

[0174] It should be noted that the non-Company software tools or components appearing in the embodiments of the present application are merely examples and do not represent actual use.

[0175] The structured query statement generation method provided in the embodiment of the present application uses RAG (i.e., first matching different types of vectors of the query text vector to obtain the matching table structure definition vector, the matching scenario document vector, and the matching statement question and answer vector) to generate prompt data, which can solve the problems of insufficient time and space breadth of large model training data and insufficient SQL generation capability of large models that may exist in Text-To-SQL tasks. In addition, compared with training and fine-tuning vertical domain models, the method provided by the present application has the advantages of low training cost, strong interpretability, and traceability of answer basis. At the same time, it has strong flexibility, and the training data is stored in the vector database. In the future, a better large model base will appear, which can be seamlessly switched between different large models without having to re-enter and train knowledge base data. It can be used in combination with training vertical models to improve model generation capabilities. Therefore, the present application can better apply to the generation of structured query statements in different scenarios compared to the method of deeply understanding the relevant table structure and the requirements for data calculation in different scenarios, thereby improving the accuracy of the generated SQL statements.

[0176] See also Fig. 9 The embodiment of the present application also provides a structured query statement generating device, which can implement the above structured query statement generating method, and the device includes:

[0177] An acquisition module 910 is used to acquire a target query text;

[0178] An encoding module 920 is used to perform text encoding on the target query text to obtain a query text vector;

[0179] A first screening module 930 is used to screen out a matching table structure definition vector that matches the target query text from preset candidate table structure definition vectors based on the query text vector;

[0180] A second screening module 940 is used to screen out a matching scenario document vector from preset candidate scenario document vectors based on the query text vector, wherein the candidate scenario document vector has a candidate business scenario, and the business scenario applied by the target query text matches the candidate business scenario pointed to by the matching scenario document vector;

[0181] A third screening module 950 is used to screen out matching sentence question and answer vectors from preset candidate sentence question and answer vectors based on the query text vector, wherein the candidate sentence question and answer vector is a vector formed based on the candidate question text, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector;

[0182] A data generation module 960 is used to generate prompt data based on the matching table structure definition vector, the matching scene document vector and the matching sentence question and answer vector to obtain target prompt data;

[0183] The statement generation module 970 is used to generate a structured query statement for the target prompt data based on the statement generation model to obtain a target query statement.

[0184] The specific implementation of the structured query statement generating device of the embodiment of the present application is basically the same as the specific implementation of the structured query statement generating method described above, and will not be repeated here.

[0185] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above structured query statement generation method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.

[0186] See also Fig.10 , Fig.10 The hardware structure of an electronic device of another embodiment includes:

[0187] The processor 1010 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present application;

[0188] The memory 1020 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1020 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1020, and the processor 1010 calls and executes the structured query statement generation method of the embodiment of this application;

[0189] Input / output interface 1030, used to implement information input and output;

[0190] The communication interface 1040 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);

[0191] Bus 1050 , which transmits information between various components of the device (e.g., processor 1010 , memory 1020 , input / output interface 1030 , and communication interface 1040 );

[0192] The processor 1010 , the memory 1020 , the input / output interface 1030 , and the communication interface 1040 are connected to each other in communication within the device via a bus 1050 .

[0193] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned structured query statement generating method is implemented.

[0194] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0195] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0196] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or a combination of certain steps, or different steps.

[0197] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0198] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.

[0199] The terms "first", "second", "third", "fourth", etc. (if any) in the specification of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0200] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.

[0201] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0202] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0203] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0204] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including multiple instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), disk or optical disk and other media that can store programs.

[0205] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.

Claims

1. A method for generating a structured query statement, characterized in that: The method comprises: Get the target query text; Performing text encoding on the target query text to obtain a query text vector; Based on the query text vector, a matching table structure definition vector matching the target query text is selected from preset candidate table structure definition vectors; Based on the query text vector, a matching scene document vector is screened out from preset candidate scene document vectors, wherein the candidate scene document vector has a candidate business scene, and the business scene applied by the target query text matches the candidate business scene pointed to by the matching scene document vector; Based on the query text vector, a matching sentence question and answer vector is screened out from preset candidate sentence question and answer vectors, wherein the candidate sentence question and answer vector is a vector formed based on candidate question texts, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector; Prompt data is generated based on the matching table structure definition vector, the matching scene document vector, and the matching sentence question and answer vector to obtain target prompt data; A structured query statement is generated for the target prompt data based on a statement generation model to obtain a target query statement.

2. The method according to claim 1, characterized in that The step of selecting a matching sentence question-answer vector from preset candidate sentence question-answer vectors based on the query text vector includes: Extracting a candidate question text vector from the candidate sentence question-answer vector; Calculating vector similarity between the candidate question text vector and the query text vector to obtain text vector similarity; The matching sentence question and answer vector is determined from the candidate sentence question and answer vectors based on the text vector similarity.

3. The method according to claim 2, characterized in that The generating of prompt data based on the matching table structure definition vector, the matching scenario document vector and the matching sentence question and answer vector to obtain target prompt data includes: Obtaining the text vector similarity of the matching sentence question and answer vector to obtain a text matching value; If the text matching value is less than a preset matching threshold, obtaining a matching query statement from the matching statement question-answer vector; Performing sentence content detection on the matching query sentence based on the structured sentence detection model to obtain sentence detection data; Optimizing the matching query statement based on the statement detection data, the matching table structure definition vector, and the matching scenario document vector to obtain a first optimized query statement; Update the matching sentence question and answer vector based on the first optimized query sentence to obtain an updated sentence question and answer vector; Prompt data is generated based on the matching table structure definition vector, the matching scenario document vector and the updated sentence question and answer vector to obtain the target prompt data.

4. The method according to claim 2, characterized in that: The determining the matching sentence question-answer vector from the candidate sentence question-answer vectors based on the text vector similarity includes: Determine a related sentence question and answer vector from the candidate sentence question and answer vector based on the text vector similarity and a preset similarity threshold, wherein the related sentence question and answer vector includes a related question text vector; Extracting keywords from the target query text to obtain target keywords; Performing text topic detection on the target keyword based on a topic detection model to obtain a text topic; Performing semantic detection on the relevant question text vector and the text topic based on a semantic detection model to obtain a semantic relevance score of the relevant question text vector; The matching sentence question-answer vector is determined from the related sentence question-answer vectors based on the semantic relevance score.

5. The method according to any one of claims 1 to 4, characterized in that: Before selecting a matching scene document vector from preset candidate scene document vectors based on the query text vector, the method further includes: Acquire a newly added scenario document and a preset scenario document vector set, wherein the scenario document vector set includes the candidate scenario document vector; Performing document matching on the newly added scene documents based on the scene document vector set to obtain similar scene documents; Performing document language analysis on the newly added scenario document and the similar scenario document based on a preset language analysis macro model to obtain a document status of the newly added scenario document, wherein the document status is used to indicate whether the newly added scenario document constitutes an update to the similar scenario document or not; If the document status is a composition update status, obtaining update feedback data of the newly added scenario document; The scene document vector set is updated based on the update feedback data and the newly added scene document.

6. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: Execute the target query statement based on a preset statement executor to obtain target query data; Acquire object feedback data of the target query data; Determine a statement execution score of the target query statement based on the object feedback data, wherein the statement execution score is used to indicate the accuracy of the target query data obtained based on the target query statement; If the sentence score is less than the preset score, sentence correction is performed on the target query sentence to obtain a corrected sentence.

7. The method according to claim 1, characterized in that Before selecting a matching sentence question-answer vector from preset candidate sentence question-answer vectors based on the query text vector, the method further includes: Acquire a revised document sentence, an associated reply text of the revised document sentence, and a preset sentence question-answer vector set, wherein the sentence question-answer vector set includes the candidate sentence question-answer vector; Performing text correction on the associated reply text based on the correction document statement to obtain a corrected reply text; The sentence question-answer vector set is updated based on the revised reply text and the revised document sentence.

8. A structured query statement generating device, characterized in that: The device comprises: An acquisition module, used to acquire a target query text; An encoding module, used for performing text encoding on the target query text to obtain a query text vector; A first screening module, configured to screen out a matching table structure definition vector that matches the target query text from preset candidate table structure definition vectors based on the query text vector; A second screening module is used to screen out a matching scene document vector from preset candidate scene document vectors based on the query text vector, wherein the candidate scene document vector has a candidate business scene, and the business scene applied by the target query text matches the candidate business scene pointed to by the matching scene document vector; A third screening module is used to screen out a matching sentence question and answer vector from preset candidate sentence question and answer vectors based on the query text vector, wherein the candidate sentence question and answer vector is a vector formed based on a candidate question text, and the target query text matches the candidate question text pointed to by the candidate sentence question and answer vector; A data generation module, used to generate prompt data based on the matching table structure definition vector, the matching scene document vector and the matching sentence question and answer vector to obtain target prompt data; The sentence generation module is used to generate a structured query sentence for the target prompt data based on the sentence generation model to obtain a target query sentence.

9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • SQL query generation method and system for complex language question based on LLM

    CN119917522A

  • Multi-modal auxiliary precision manufacturing database interaction method based on large model

    CN120104817A

  • A multimodal assisted precision manufacturing database interaction method based on large models

    CN120104817B

  • Standard problem reconstruction method for natural language number checking

    CN120106082A

  • Table-based query method and device, computer equipment, readable storage medium and program product

    CN120316147A