Structured query statement processing method, equipment and product

By receiving processing instructions in a large language model and generating target prompt words, the problem of high maintenance cost of SQL statement processing in the prior art is solved, and more efficient and easy-to-use SQL statement processing is achieved.

CN119322785APending Publication Date: 2025-01-17KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411339374.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-24
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

In the prior art, when generating SQL statements using a large language model, prompt words need to be obtained through the knowledge base maintained by the database system, resulting in high maintenance costs and inability to generate prompt words that fully meet user needs.

Method used

By receiving processing instructions, obtaining available information to generate target prompt words, and using the language model to generate the return value corresponding to the processing instructions, automatically obtaining prompt words that match the user-triggered processing instructions, improving the processing accuracy and ease of use of SQL statements.

Benefits of technology

The knowledge base is not required for users to maintain, which improves the accuracy and ease of use of SQL statement processing, reduces maintenance costs, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322785A_ABST
    Figure CN119322785A_ABST
Patent Text Reader

Abstract

The invention provides a structured query statement processing method, equipment and a product, and the method comprises the steps: responding to a received processing instruction of a structured query statement, obtaining available information based on the instruction type of the processing instruction, and enabling the available information to be used for generating cue words; generating at least one target prompt word based on the available information; and at least one return value corresponding to the processing instruction is generated based on the at least one target prompt word by utilizing a language model, and the format of the return value is determined based on the instruction type. According to the method, the cue word matched with the processing instruction triggered by the user can be automatically obtained, the return value of the processing instruction is generated through the language model, and the accuracy and usability of SQL statement processing are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to a method, device and product for processing structured query statements. Background Art

[0002] Structured Query Language (SQL) is a database query and programming language used to access data, query and manage relational database systems. Manually writing SQL statements to implement database query and management is inefficient and requires a high level of professionalism from the user. If the user's professionalism is not high, the quality of the generated SQL statements may be low. Therefore, the technology of automatically generating SQL statements using large language models (LLM) came into being and gradually became a hot topic.

[0003] In the related art, when a large language model is used to generate SQL statements based on prompt words, due to the specificity of the library table structure, it is often necessary to obtain the prompt words through a knowledge base maintained by the database system maintenance personnel. However, the maintenance cost of the knowledge base is high, and when the database is changed, the relevant information needs to be re-maintained, which increases the cost of generating SQL statements using a large language model. Summary of the invention

[0004] In order to solve the above technical problems, the embodiments of the present disclosure provide a method, device and product for processing a structured query statement.

[0005] According to a first aspect of an embodiment of the present disclosure, a method for processing a structured query statement is provided, comprising:

[0006] In response to receiving a processing instruction of a structured query statement, obtaining available information based on an instruction type of the processing instruction, wherein the available information is used to generate a prompt word;

[0007] Based on the available information, generating at least one target prompt word;

[0008] At least one return value corresponding to the processing instruction is generated based on at least one of the target prompt words by using a language model, and the format of the return value is determined based on the instruction type.

[0009] In some embodiments of the present disclosure, after generating at least one target prompt word based on the available information, the method further includes:

[0010] Based on a lightweight markup language format, at least one of the target prompt words is structured to obtain at least one optimized prompt word corresponding to the at least one target prompt word, wherein the optimized prompt word includes model persona information;

[0011] The using of the language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes:

[0012] Acquire a language model corresponding to the model persona information in each of the optimization prompt words;

[0013] The language model is used to generate a return value corresponding to the processing instruction based on each of the optimization prompt words.

[0014] In still other embodiments of the present disclosure, the instruction type is one of the following instructions: a generation instruction, an optimization instruction, a conversion instruction, and an interpretation instruction;

[0015] The obtaining of available information based on the instruction type of the processing instruction includes:

[0016] In response to the processing instruction being an optimization instruction, obtaining available information including a database type, a table creation statement, and explanation information of a target database;

[0017] In response to the processing instruction being one of a generation instruction, a conversion instruction and an interpretation instruction, available information including a database type and a table creation statement of a target database is obtained.

[0018] In some further embodiments of the present disclosure, the obtaining of available information includes:

[0019] In response to the processing instruction carrying the library table identification information of the target database, the available information is acquired from the database system according to the library table identification information;

[0020] In response to the fact that the processing instruction does not carry the library table identification information of the target database, the available information is acquired according to the text description information in the processing instruction.

[0021] In some other embodiments of the present disclosure, the using of a language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes:

[0022] In response to the processing instruction being an optimization instruction, using a language model, based on at least one of the target prompt words, generating a return value corresponding to each target prompt word, including a database analysis result, an analysis result analysis, and optimization suggestion information;

[0023] In response to the processing instruction being a generation instruction and a conversion instruction, using a language model and based on at least one of the target prompt words, generating a return value including a structured query statement corresponding to each target prompt word;

[0024] In response to the processing instruction being an interpretation instruction, a language model is used to generate a return value corresponding to each target prompt word and including text description information corresponding to the structured query statement based on at least one target prompt word.

[0025] In some other embodiments of the present disclosure, generating at least one target prompt word based on the available information includes:

[0026] At least one target prompt word corresponding to at least one prompt word format is generated based on the available information according to at least one preset prompt word specification assembly parameter.

[0027] In some other embodiments of the present disclosure, after generating at least one return value corresponding to the processing instruction based on at least one target prompt word, the method further includes:

[0028] In response to receiving a scoring parameter based on at least one of the return values ​​from a user, adding each of the scoring parameters to the statistical data of the language model corresponding to the return value;

[0029] Determining a statistical score for each language model based on the statistical data of each language model;

[0030] Based on the statistical scores of the language models, each language model is optimized and iterated.

[0031] In some other embodiments of the present disclosure, the using of a language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes:

[0032] At least one return value corresponding to the processing instruction is generated based on at least one of the target prompt words by using the language model after the optimization iterative processing.

[0033] According to a second aspect of an embodiment of the present disclosure, a device for processing a structured query statement includes:

[0034] An acquisition module, configured to, in response to receiving a processing instruction of a structured query statement, acquire available information based on an instruction type of the processing instruction, wherein the available information is used to generate a prompt word;

[0035] A first generating module, configured to generate at least one target prompt word based on the available information;

[0036] The second generating module is used to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words by using a language model, wherein the format of the return value is determined based on the instruction type.

[0037] In some other embodiments of the present disclosure, it also includes:

[0038] A prompt word optimization module, configured to perform a structural design on at least one of the target prompt words based on a lightweight markup language format, and obtain at least one optimized prompt word corresponding to at least one of the target prompt words, wherein the optimized prompt word includes model character setting information;

[0039] The second generation module comprises:

[0040] A first acquisition submodule is used to acquire a language model corresponding to the model persona information in each of the optimization prompt words;

[0041] The first generating submodule is used to generate a return value corresponding to the processing instruction based on each of the optimization prompt words by using the language model.

[0042] In still other embodiments of the present disclosure, the instruction type is one of the following instructions: a generation instruction, an optimization instruction, a conversion instruction, and an interpretation instruction;

[0043] The acquisition module comprises:

[0044] A second acquisition submodule is used for acquiring available information including a database type, a table creation statement and explanation information of a target database in response to the processing instruction being an optimization instruction;

[0045] The third acquisition submodule is used to acquire available information including a database type and a table creation statement of a target database in response to the processing instruction being one of a generation instruction, a conversion instruction and an interpretation instruction.

[0046] In some further embodiments of the present disclosure, the acquisition module includes:

[0047] A fourth acquisition submodule, configured to, in response to the processing instruction carrying the library table identification information of the target database, acquire the available information from the database system according to the library table identification information;

[0048] The fifth acquisition submodule is used to acquire the available information according to the text description information in the processing instruction in response to the fact that the processing instruction does not carry the library table identification information of the target database.

[0049] In some further embodiments of the present disclosure, the second generating module includes:

[0050] A second generating submodule is used for generating, in response to the processing instruction being an optimization instruction, a return value corresponding to each target prompt word including a database analysis result, an analysis result analysis, and optimization suggestion information based on at least one target prompt word by using a language model;

[0051] A third generation submodule is used for generating a return value including a structured query statement corresponding to each target prompt word by using a language model based on at least one target prompt word in response to the processing instruction being a generation instruction and a conversion instruction;

[0052] The fourth generating submodule is used to generate a return value corresponding to each target prompt word and including text description information corresponding to the structured query statement using a language model based on at least one target prompt word in response to the processing instruction being an interpretation instruction.

[0053] In some other embodiments of the present disclosure, the first generating module is specifically configured to generate at least one target prompt word corresponding to at least one prompt word format based on the available information according to at least one preset prompt word specification assembly parameter.

[0054] In some other embodiments of the present disclosure, it also includes:

[0055] a statistical module, configured to, in response to receiving a scoring parameter from a user based on at least one of the return values, add each of the scoring parameters to the statistical data of the language model corresponding to the return value;

[0056] A determination module, configured to determine a statistical score of each language model based on the statistical data of each language model;

[0057] The iterative optimization module is used to perform iterative optimization processing on each of the language models based on the statistical scores of each of the language models.

[0058] In some other embodiments of the present disclosure, the second generating module is specifically configured to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words by using the language model after the optimized iterative processing.

[0059] According to a third aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided, wherein the storage medium stores computer program instructions, and when the computer program instructions are executed, the method for processing the structured query statement described above is implemented.

[0060] According to a fourth aspect of an embodiment of the present disclosure, an electronic device is provided, the electronic device comprising:

[0061] A memory for storing a computer program product;

[0062] The processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, the method for processing the structured query statement is implemented.

[0063] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including computer program instructions, which implement the above-mentioned method for processing structured query statements when the computer program instructions are executed by a processor.

[0064] Based on the above-mentioned embodiments of the present disclosure, when it is necessary to use a large language model to process SQL statements, available information can be obtained according to the instruction type of the received processing instruction, and a target prompt word can be generated. Then, the language model can be used to generate a return value corresponding to the processing instruction based on the target prompt word. This achieves automatic acquisition of a prompt word that matches the processing instruction triggered by the user, and generates the return value of the processing instruction through the language model, thereby improving the accuracy and ease of SQL statement processing, and improving the processing efficiency of SQL statements.

[0065] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] By describing the embodiments of the present disclosure in more detail in conjunction with the accompanying drawings, the above and other purposes, features and advantages of the present disclosure will become more apparent. The accompanying drawings are used to provide a further understanding of the embodiments of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. In the drawings, the same reference numerals generally represent the same components or steps.

[0067] Figure 1 A flowchart of an embodiment of a method for processing structured query statements disclosed herein;

[0068] Figure 2 A flowchart of another embodiment of the method for processing structured query statements disclosed herein;

[0069] Figure 3 A flowchart of an embodiment of a method for processing structured query statements disclosed herein;

[0070] Figure 4 A flowchart of an embodiment of the present disclosure for iteratively optimizing each language model;

[0071] Figure 5 A schematic diagram of generating SQL statements using a language model according to the present disclosure;

[0072] Figure 6 A schematic diagram of optimizing SQL statements by using language model parsing according to the present disclosure;

[0073] Figure 7 A schematic diagram of the structure of an embodiment of a device for processing structured query statements disclosed in the present invention;

[0074] Figure 8 A schematic diagram of the structure of another embodiment of the apparatus for processing structured query statements disclosed herein;

[0075] Fig. 9 It is a structural diagram of an electronic device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0076] The exemplary embodiments according to the present disclosure will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all the embodiments of the present disclosure, and it should be understood that the present disclosure is not limited to the exemplary embodiments described here.

[0077] It should be noted that the relative arrangement of components and steps, the numerical expressions and numerical values ​​set forth in these embodiments do not limit the scope of the present disclosure unless specifically stated otherwise.

[0078] Those skilled in the art can understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and neither represent any specific technical meaning nor indicate the necessary logical order between them.

[0079] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two or more than two.

[0080] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.

[0081] In addition, the term "and / or" in this disclosure is only a description of the association relationship of associated objects, indicating that there may be three relationships, such as A and / or B, which can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this disclosure generally indicates that the associated objects before and after are in an "or" relationship.

[0082] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.

[0083] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.

[0084] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.

[0085] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.

[0086] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.

[0087] The embodiments of the present disclosure can be applied to electronic devices such as terminal devices, computer systems, servers, etc., which can operate with many other general or special computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments and / or configurations suitable for use with electronic devices such as terminal devices, computer systems or servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, large computer systems, and distributed cloud computing technology environments including any of the above systems, etc.

[0088] Electronic devices such as terminal devices, computer systems, servers, etc. can be described in the general context of computer system executable instructions (such as program modules) executed by computer systems. Generally, program modules can include routines, programs, target programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in a distributed cloud computing environment. In a distributed cloud computing environment, tasks can be performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can be located on local or remote computing system storage media including storage devices.

[0089] SUMMARY OF THE DISCLOSURE

[0090] In the process of implementing the present disclosure, the inventors found that when using a large language model to process SQL statements, for example, generating SQL statements, optimizing SQL statements, interpreting SQL statements, converting SQL statements, etc., it is often necessary to obtain prompt words through a knowledge base maintained by a database system maintenance personnel, resulting in high maintenance costs for SQL statement processing and the problem that prompt words that fully meet user needs cannot necessarily be generated. The knowledge base is a library that integrates database table information and prompt words containing each library table information. The knowledge base is difficult to maintain and has poor usability.

[0091] In the processing method of structured query statements provided by the present disclosure, a target prompt word can be automatically generated according to the processing instruction triggered by the user, and then a language model is used to generate a return value corresponding to the processing instruction based on the target prompt word. This solution can not only ensure the accuracy of the generated return value, but also does not require the user to maintain a knowledge base.

[0092] Exemplary Methods

[0093] Figure 1 FIG. 1 is a flow chart of an embodiment of a method for processing structured query statements disclosed in the present invention. Figure 1 The method shown includes steps 101 to 103. Each step is described below.

[0094] In step 101, in response to receiving a processing instruction of a structured query statement, available information is obtained based on the instruction type of the processing instruction, and the available information is used to generate a prompt word.

[0095] Among them, the processing instruction is used to indicate the instruction for processing the SQL statement. The instruction can be triggered by the user through the interface. For example, when the user connects to the database system, entering the text "query the undeleted data in tb-task-record in store-accounting to calculate the number of each business code" in the system interface can trigger a processing instruction for generating an SQL statement. Entering "SELECT*FROM rt-invoice-check-record" in the interface for optimizing SQL statements in the system interface can trigger the processing instruction for optimizing the SQL statement.

[0096] In the present disclosure, the instruction type of the processing instruction is used to indicate the type of operation that can be performed on the SQL statement. The instruction type of the processing instruction may include: generation instruction, optimization instruction, conversion instruction, and interpretation instruction. Among them, the generation instruction is an instruction for generating an SQL statement. Using the generation instruction, an SQL statement can be automatically generated based on the information input by the user; the optimization instruction is an instruction for analyzing the SQL statement described by the user and outputting optimization suggestions. Using the optimization instruction, the SQL statement input by the user can be analyzed and optimization suggestions for the SQL statement and the optimization suggestions for optimizing the database table targeted by the SQL statement can be output. The conversion instruction is an instruction for converting an SQL statement, for example, converting an SQL statement for an SQL database table into an SQL statement for an Oracle database table; the interpretation instruction is an instruction for interpreting the SQL statement input by the user.

[0097] As an example, see Figure 5, which shows a schematic diagram of generating SQL statements based on the generation instruction. When the user enters "query the undeleted data in tb-task-record in store-accounting to calculate the number of each business code", the system can automatically generate the following SQL statement:

[0098] SELECT info-code,COUNT(*)AS count

[0099] FROM store_accounting.tb_task_record

[0100] WHERE is_delete=0

[0101] GROUP BY info_code

[0102] See also Figure 6 , which shows a schematic diagram of generating SQL optimization information based on optimization instructions. When the user enters "SELECT*FROM rt-invoice-check-record" and triggers the processing instruction to optimize the SQL statement, the large language model can output information such as database analysis results, analysis result parsing, and decomposition optimization suggestions. Based on the analysis result parsing, the user can clarify the relevant information of the SQL statement entered, such as the table name to be queried, index information, etc.; and based on the analysis optimization suggestions, the user can be prompted on how to optimize the SQL statement, how to maintain and optimize the queried database table, etc.

[0103] The available information indicates the information used to generate the target prompt word. For different instruction types, the available information is not exactly the same. For example, for optimization instructions, the available information may include the database type of the target database, table creation statements, and explanation information; for generation instructions, conversion instructions, and explanation instructions, the available information includes the database type of the target database and table creation statements.

[0104] Among them, the database type can be determined according to the current connection. In the present disclosure, the user can connect to the database through Java code. For example, if the current connection is database1 connected to the SQL database, the database type is SQL database and the database identifier is database1. The table creation statement is a statement used when creating a database table, such as create table statement, primary key constraint, unique constraint, foreign key constraint, not null constraint, check constraint, default constraint, etc. The table creation statement can be stored in the database system. Explaining the EXPLAIN information can display the execution plan of the database table, including the index used, the number of rows scanned, whether a temporary table is used, etc.

[0105] In some embodiments, when the processing instruction includes the library table identification information of the target database, available information can be obtained from the database system according to the library table identification information, wherein the library table identification information is used to indicate information that can identify the database and the database table, such as the database name and the database table name. Exemplarily, in the instruction "query the undeleted data in tb-task-record in store-accounting to calculate the number of each business code", the database name store-accounting and the database table name tb-task-record are included, so the table creation statement and explanation information can be directly obtained from the database system according to the database name and the data table name.

[0106] In other embodiments, when the processing instruction does not contain the library table identification information of the target database, available information can be generated based on the text description information in the processing instruction. For example, the processing instruction is "query the number of boys in the student table". Since the processing instruction does not contain the identification information of the student table, the system can obtain the available information student through semantic recognition based on the "student table". Student may not be the real name of the student table, but an SQL statement can be generated based on this information.

[0107] In step 102, at least one target prompt word is generated based on available information.

[0108] The target prompt word is a prompt word obtained by assembling available information according to prompt word specification assembly parameters. The prompt word is an artificial intelligence prompt word, which is a word that uses natural language to guide or inspire a large language model to complete a specific processing task. The prompt word specification assembly parameters are used to indicate the specification for generating available information into a target prompt word.

[0109] In some optional embodiments, one or more target prompt words may be generated based on a set of available information. The contents of different target prompt words may be the same, but the description forms are different. For example, prompt word 1 and prompt word 2 are generated based on the available information. The available information content contained in prompt word 1 and prompt word 2 is the same, but the description order is different.

[0110] In step 103, at least one return value corresponding to the processing instruction is generated based on at least one target prompt word using a language model, and the format of the return value is determined based on the instruction type.

[0111] The language model may be a GPT (Generative Pre-Trained Transformer), which may be pre-trained based on a large number of training samples. The trained language model may output a corresponding return value for an input prompt word.

[0112] In some optional implementations, a large number of training samples may be collected in advance, each of which may include various prompt word training samples, and each of which carries a corresponding return value sample label. The initial model is trained using a large number of training samples, that is, by inputting a large number of training samples into the large language model, the large language model learns the return value sample labels corresponding to these training samples, so that after the large language model is trained, the return value labels corresponding to each training sample can be accurately predicted.

[0113] In some optional implementations, the language model may be a model managed by an intelligent assistant. When the language model is a model managed by an intelligent assistant, the target prompt word may be further structurally optimized, and the optimized prompt word may be input into the corresponding language model to obtain a return value.

[0114] The return value is used to indicate the information output by the large language model, and different formats of return values ​​can be output corresponding to different instruction types. In response to the processing instruction being an optimization instruction, the language model is used to generate, based on at least one target prompt word, a return value corresponding to each target prompt word, including database analysis results, analysis result parsing, and optimization suggestion information; in response to the processing instruction being a generation instruction and a conversion instruction, the language model is used to generate, based on at least one target prompt word, a return value corresponding to each target prompt word, including structured query statements; in response to the processing instruction being an interpretation instruction, the language model is used to generate, based on at least one target prompt word, a return value corresponding to each target prompt word, including text description information corresponding to the structured query statement.

[0115] Through the above steps 101 to 103, when it is necessary to use a large language model to process SQL statements, available information can be obtained according to the instruction type of the received processing instruction, and a target prompt word can be generated. Then, the language model is used to generate a return value corresponding to the processing instruction based on the target prompt word. This achieves automatic acquisition of a prompt word that matches the processing instruction triggered by the user, and generates the return value of the processing instruction through the language model, thereby improving the accuracy and ease of SQL statement processing, and improving the processing efficiency of SQL statements.

[0116] Figure 2 1 is a flowchart of determining a reusable component from the source code of a target application program of the present disclosure. The present disclosure embodiment takes how to determine a reusable component from the source code as an example for illustrative description. Figure 2 The method shown includes steps 201 to 205. Each step is described below.

[0117] In step 201, in response to receiving a processing instruction of a structured query statement, available information is obtained based on the instruction type of the processing instruction, and the available information is used to generate a prompt word.

[0118] In step 202, at least one target prompt word is generated based on available information.

[0119] In some optional implementations, the specific implementation of steps 201-202 can be found in Figure 1 Steps 101 and 102 of the illustrated embodiment are not described in detail here.

[0120] In step 203, at least one target prompt word is structured based on a lightweight markup language format to obtain at least one optimized prompt word corresponding to the at least one target prompt word, wherein the optimized prompt word includes model persona information.

[0121] Among them, lightweight markup language (markdown) is a language that can convert documents written by users in an easy-to-read and easy-to-write plain text format into valid HyperText Markup Language (HTML) documents. The markdown language has the characteristics of plain text tags. By using lightweight markup language, the target prompt words can be structured to obtain optimized prompt words. When SQL analysis and generation and other processing operations are performed through the assembled target prompt words, it may not be stable. After optimizing the target prompt words in the markdown format, and then using the large language model for SQL analysis and generation, the return value is more stable and accurate. Optimized prompt words are used to indicate prompt words in the markdown format. Model personality information is used to indicate personality information in the prompt words formatted by markdown.

[0122] In some optional implementations, the markdown format includes the following:

[0123] -Role: Used to analyze the target prompt and select one or more roles that are most suitable for executing the target prompt.

[0124] -Background: Used to analyze the target prompt word, think about why the user asks this question, and state the reasons, background, and context for the user to ask this question.

[0125] -Attention: Used to analyze target prompt words, determine the user's desire for the task, and provide positive emotional stimulation.

[0126] -Profile: used to describe the selected character.

[0127] -Skills: Determine the abilities that the above character should have.

[0128] -Goals: Based on the identified roles, think of a list of tasks that the user needs to do, and by completing these tasks, the problem can be solved.

[0129] -Constraints: Based on the determined role, think about the rules that the role should abide by to ensure that the role can complete the task excellently.

[0130] -OutputFormat (output format) Based on the determined role, when thinking about the format in which the output should be produced, the return value can be clear and logical.

[0131] -Workflow: Based on the determined role, the workflow of the role when performing the task is disassembled, which requires analyzing the target prompt words and giving supplementary information suggestions.

[0132] -Suggestions: Based on the target prompt words, determine the task list that needs to be given to the large language model to ensure that the determined role can complete the SQL analysis and generation tasks.

[0133] After optimizing the target prompt words through the above markdown format, the optimized prompt words are input into the large language model. The large language model can better identify the user's processing requirements and complete the analysis and generation needs of the corresponding SQL.

[0134] For example, Role:SQL Analysis Expert\.

[0135] Profile\n:Version:0.1\n-Language: Chinese.

[0136] Description: You are a professional SQL analysis expert. Your goal is to help users solve SQL query problems and provide optimization suggestions.

[0137] Skill-1: Understand and analyze SQL query statements, and provide optimization suggestions for SQL query statements.

[0138] Skill-2: Convert natural language into SQL statements based on the user's description information. If the user's question contains the database version, ensure that the SQL statement is executable by that version.

[0139] Rules: Only questions about SQL query statements can be answered, not other types of questions; maintain a professional and friendly attitude, and be willing to help users solve problems; clarify user requirements and give qualified responses, and think step by step based on all the information provided.

[0140] Workflow: Users will ask you questions about SQL query statements; you need to provide answers and optimization suggestions based on the questions; if the user's question is to generate a table creation statement, the table creation statement must include an auto-increment id and be named in the a_b format. The field must contain a default value and comment, and the default value cannot be NULL; if the user's question includes the database version, ensure that the SQL is an SQL statement that can be executed by that version; if the user's question is beyond your ability, you need to tell the user that you cannot answer it.

[0141] Suggestions: As a<SQL Analysis Expert> You must comply with <rules>You must use the default <language>When talking to users, you should <base-prompt>Create prompts and output only optimized prompts.

[0142] In step 204, a language model corresponding to the model persona information in each optimization prompt word is obtained.

[0143] Among them, there may be multiple language models in the technical solution of the present disclosure, or a language model may have multiple language sub-models corresponding to the model character information, thereby determining the version information of the large language model to be used based on the optimized prompt words after markdown formatting.

[0144] In step 205, a language model is used to generate a return value corresponding to the processing instruction based on each optimization prompt word.

[0145] The present disclosure uses prompt words in markdown format to help a large language model interpret and maintain prompt words, improve the usability of prompt words, and further improve the stability and accuracy of SQL processing by the large language model according to the prompt words.

[0146] like Figure 3 As shown, a flowchart for implementing SQL processing according to the processing instructions input by the user is illustrated. When the user triggers the SQL-related processing instructions through the interface, the database type can be determined according to the connection when the processing instruction is triggered, and then the processing instruction is analyzed to see whether it carries the library table identification information. If there is the library table identification information, the table creation statement can be queried in the database system according to the library table identification information. If there is no library table identification information, the library table information can be determined according to the text description information in the processing instruction (the library table information may not be the information of the real database table, that is, it is not the library table identification information of the real database table; in addition, it can also be analyzed whether the processing instruction needs to analyze the performance. If the performance needs to be analyzed, the corresponding EXPLAIN explanation information is obtained according to the database type, and the table creation statement, database type and EXPLAIN explanation information are used as available information. Then, multiple target prompt words are assembled according to the available information, and then the target prompt words are optimized according to the markdown format, and the large language model is called to obtain the return value.

[0147] The database type is determined according to the connection when the processing instruction is triggered, which is used to indicate that the database type is determined according to the database in which the processing instruction is triggered by the user.

[0148] It should be noted that Figure 3 Each target prompt word in can be input into the same language model or into different language models.

[0149] In order to implement the technical solution disclosed in the present invention, a variety of design patterns can be used to manage different database types and prompt words. For example, design patterns such as adapter pattern and factory pattern can be used. Different language models are provided for different prompt words, or one prompt word is input into multiple language models, etc., so as to optimize and iterate the language model or prompt word according to the return value of each language model. For example, prompt word 1 is input into language model 1 and language model 2, and the language model with better effect can be determined by comparing the output results of language model 1 and language model 2, or prompt word 1 and prompt word 2 are input into the language model, and the prompt word with better effect can be determined by comparing the output results of prompt word 1 and prompt word 2.

[0150] In this implementation, a technical solution for managing different database types and prompt words is implemented through different design patterns, which helps to iteratively optimize large language models, obtain language models and prompt words that better meet user needs, and improve the accuracy and stability of SQL processing.

[0151] Figure 4 It is a flowchart of an embodiment of the present disclosure for iteratively optimizing each language model. Figure 1 Based on the embodiment shown, after receiving each return value, the iterative optimization of the language model can also be implemented through the following steps. Figure 4 As shown, the following steps are included:

[0152] In step 401, in response to receiving a scoring parameter from a user based on at least one return value, each scoring parameter is added to the statistical data of the language model corresponding to the return value.

[0153] Among them, the scoring parameter refers to the score given by the user to each return value, which is used to indicate the user's satisfaction with each return value. The scoring parameter can be in the form of a scoring level or a specific score. When a large language model outputs multiple return values ​​for multiple prompt words, or when multiple large language models output multiple return values ​​for multiple prompt words, or when multiple large language models output multiple return values ​​for one prompt word, the user can set scoring parameters for the above multiple return values ​​to indicate the user's satisfaction with each return value. Correspondingly, after the system receives the scoring parameters provided by the user based on each return value, the scoring parameters can be added to the statistical data of the language model corresponding to the return value. The statistical data of each language model is used to indicate the statistical data of the scoring parameters of the return value output by the language model.

[0154] Exemplarily, for example, language model 1 outputs 5 return values ​​for 5 different prompt words, and the scoring parameters of each return value are excellent, excellent, excellent, excellent, and excellent, then the statistical data of language model 1 is 5 excellents; or, language model 1 outputs 5 return values ​​for 5 different prompt words, and the scoring parameters of each return value are 85 points, 90 points, 95 points, 70 points, and 90 points, then the statistical data of language model 1 is 85 points, 90 points, 95 points, 70 points, and 90 points.

[0155] In step 402, a statistical score of each language model is determined based on the statistical data of each language model.

[0156] The statistical score is a score obtained by statistical processing based on the statistical data, and the statistical score can be obtained by averaging the statistical scores. For example, language model 1 outputs 5 return values ​​for 5 different prompt words, and the scoring parameters of each return value are 85 points, 90 points, 95 points, 70 points, and 90 points. The statistical data of language model 1 are 85 points, 90 points, 95 points, 70 points, and 90 points. After averaging, the statistical score is 86 points.

[0157] In some optional implementations, the score with the largest proportion in the statistical data can also be used as the statistical score; in other optional implementations, the two values ​​with the highest and lowest scores in the statistical data can be filtered and then averaged. The technical solution disclosed in this disclosure does not limit how to obtain the statistical score of the language model.

[0158] In step 403, each language model is optimized and iteratively processed based on the statistical score of each language model.

[0159] In some optional implementations, the optimization iterative process can be understood as a process of optimizing the language model. For example, the system currently has three language models A, B, and C. If the statistical score of model A is low, model A can be iteratively optimized or fine-tuned.

[0160] In a specific implementation, since the language model disclosed in the present invention may be an Assistant-based language model, iterative optimization of the language model may be achieved by modifying the personality information of the language model through the Assistant.

[0161] In some optional implementations, the optimization iterative process of the model may be periodically performed based on the statistical score of the language model, for example, the optimization iterative process of the model may be performed once every week.

[0162] After the language model is iteratively optimized, the optimized iteratively processed language model may be used to generate at least one return value corresponding to the processing instruction based on at least one target prompt word.

[0163] In the disclosed embodiment, an implementation method for iteratively optimizing a large language model is disclosed, which helps to obtain a language model that better meets user needs and improves the accuracy and stability of SQL processing.

[0164] Exemplary Devices

[0165] Figure 7 FIG. 1 is a schematic diagram of a structure of an embodiment of a processing device for structured query statements disclosed in the present invention. Figure 7 As shown, the device comprises:

[0166] An acquisition module 71 is used for, in response to receiving a processing instruction of a structured query statement, acquiring available information based on an instruction type of the processing instruction, and the available information is used to generate a prompt word;

[0167] A first generating module 72, configured to generate at least one target prompt word based on available information;

[0168] The second generating module 73 is used to generate at least one return value corresponding to the processing instruction by using the language model based on at least one target prompt word, and the format of the return value is determined based on the instruction type.

[0169] Figure 8 A schematic diagram of the structure of another embodiment of the apparatus for processing structured query statements disclosed in the present invention. Figure 8 As shown, in Figure 7 On the basis of the illustrated embodiment, in some implementations of the present disclosure, the device further includes: a prompt word optimization module 74, configured to perform a structured design on at least one target prompt word based on a lightweight markup language format, and obtain at least one optimized prompt word corresponding to the at least one target prompt word, wherein the optimized prompt word includes model persona information;

[0170] The second generation module 73 includes:

[0171] The first acquisition submodule 731 is used to acquire the language model corresponding to the model persona information in each optimization prompt word;

[0172] The first generation submodule 732 is used to generate a return value corresponding to the processing instruction based on each optimization prompt word by using the language model.

[0173] In still other embodiments of the present disclosure, the instruction type is one of the following instructions: a generation instruction, an optimization instruction, a conversion instruction, and an interpretation instruction;

[0174] The acquisition module 71 includes:

[0175] The second acquisition submodule 711 is used to acquire available information including a database type, a table creation statement, and explanation information of a target database in response to the processing instruction being an optimization instruction;

[0176] The third acquisition submodule 712 is used to acquire available information including a database type and a table creation statement of a target database in response to the processing instruction being one of a generation instruction, a conversion instruction and an interpretation instruction.

[0177] In some other embodiments of the present disclosure, the acquisition module 71 includes

[0178] The fourth acquisition submodule 713 is used to obtain available information from the database system according to the library table identification information of the target database in response to the processing instruction carrying the library table identification information of the target database;

[0179] The fifth acquisition submodule 714 is used to acquire available information according to the text description information in the processing instruction in response to the fact that the processing instruction does not carry the library table identification information of the target database.

[0180] In some further embodiments of the present disclosure, the second generation module 73 includes:

[0181] The second generation submodule 733 is used to generate a return value including database analysis results, analysis result parsing and optimization suggestion information corresponding to each target prompt word by using a language model and based on at least one target prompt word in response to the processing instruction being an optimization instruction;

[0182] The third generation submodule 734 is used to generate a return value including a structured query statement corresponding to each target prompt word by using a language model based on at least one target prompt word in response to the processing instruction being a generation instruction and a conversion instruction;

[0183] The fourth generating submodule 735 is used to generate a return value corresponding to each target prompt word including text description information corresponding to the structured query statement using a language model based on at least one target prompt word in response to the processing instruction being an interpretation instruction.

[0184] In some other embodiments of the present disclosure, the first generating module 72 is specifically configured to generate at least one target prompt word corresponding to at least one prompt word format according to at least one preset prompt word specification assembly parameter and based on available information.

[0185] In some other embodiments of the present disclosure, it also includes:

[0186] A statistics module 75, configured to, in response to receiving a scoring parameter from a user based on at least one return value, add each scoring parameter to the statistical data of the language model corresponding to the return value;

[0187] A determination module 76, configured to determine a statistical score of each language model based on the statistical data of each language model;

[0188] The iterative optimization module 77 is used to perform iterative optimization processing on each language model based on the statistical score of each language model.

[0189] In some other embodiments of the present disclosure, the second generation module 73 is specifically configured to generate at least one return value corresponding to the processing instruction based on at least one target prompt word by using the language model after the optimized iterative processing.

[0190] It should be pointed out that the modules in the present device can be decomposed and / or reassembled, and such decomposition and / or reassembly should be regarded as equivalent solutions of the present device.

[0191] The exemplary embodiment of the device corresponds to the exemplary method described above, and the relevant contents can be referenced and quoted to each other. The beneficial technical effects corresponding to the exemplary embodiment of the device can refer to the corresponding beneficial technical effects of the exemplary method described above, and will not be repeated here.

[0192] Exemplary electronic devices, computer program products, and computer-readable storage media

[0193] An embodiment of the present disclosure further provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, a method for processing a structured query statement of any of the above embodiments of the present disclosure is implemented.

[0194] Below, reference Fig. 9 An electronic device according to an embodiment of the present disclosure is described, in which a device for implementing the method according to an embodiment of the present disclosure may be integrated. Fig. 9 A structural diagram of an electronic device provided in an exemplary embodiment of the present disclosure, such as Fig. 9 As shown, the electronic device includes one or more processors 91, one or more computer-readable storage media memory 92, and a computer program stored in the memory and executable on the processor. When executing the program in the memory 92, the above-mentioned structured query statement processing method can be implemented.

[0195] Specifically, in practical applications, the electronic device may further include components such as an input device 93 and an output device 94, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown). Those skilled in the art will appreciate that Fig. 9 The structure of the electronic device shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or certain components, or different component arrangements.

[0196] The processor 91 can be a central processing unit (CPU) or other forms of processing units with the ability to process structured query statements and / or the ability to execute instructions. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 92, and calling data stored in the memory 92, thereby monitoring the electronic device as a whole.

[0197] The memory 92 may store one or more computer program products, and the memory may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The above-mentioned volatile memory may include, for example, random access memory (RAM) and / or cache memory (cache), etc. The above-mentioned non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program products may be stored on a computer-readable storage medium, and the processor 91 may run the computer program products to implement the above-mentioned structured query statement processing method of each embodiment of the present disclosure and / or other desired functions.

[0198] The input device 93 can be used to receive input digital or character information. The input device 93 can include a keyboard, a mouse, a joystick, etc. related to user settings and function control.

[0199] The output device 94 can output various information to the outside, including the determined distance information, direction information, etc. The output device 94 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0200] The electronic device may also include a power supply for supplying power to various components, which may be logically connected to the processor 91 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply may also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0201] Of course, to simplify, Fig. 9 Only some of the components related to the present disclosure in the electronic device are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device may further include any other appropriate components.

[0202] In addition to the above-mentioned methods and devices, an embodiment of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the method for processing structured query statements according to various embodiments of the present disclosure described in the above-mentioned "Exemplary Method" section of this specification.

[0203] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0204] In addition, an embodiment of the present disclosure may also be a computer-readable storage medium having computer program instructions stored thereon. When the computer program instructions are executed by a processor, the processor executes the steps of the method for processing structured query statements according to various embodiments of the present disclosure described in the above “Exemplary Method” section of this specification.

[0205] Computer readable storage media can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0206] The basic principles of the present disclosure are described above in conjunction with specific embodiments. However, it should be noted that the advantages, strengths, effects, etc. mentioned in the present disclosure are only examples and not limitations, and it cannot be considered that these advantages, strengths, effects, etc. are required by each embodiment of the present disclosure. In addition, the specific details disclosed above are only for the purpose of illustration and ease of understanding, and are not limitations. The above details do not limit the present disclosure to the necessity of adopting the above specific details to be implemented.

[0207] Each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the system embodiment, since it basically corresponds to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0208] A person of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0209] The method and apparatus of the present disclosure may be implemented in many ways. For example, the method and apparatus of the present disclosure may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above order of steps for the method is for illustration only, and the steps of the method of the present disclosure are not limited to the order specifically described above, unless otherwise specifically stated. In addition, in some embodiments, the present disclosure may also be implemented as a program recorded in a recording medium, which includes machine-readable instructions for implementing the method according to the present disclosure. Therefore, the present disclosure also covers a recording medium storing a program for executing the method according to the present disclosure.

[0210] The description of the present disclosure is given for the purpose of illustration and description, and is not intended to be exhaustive or to limit the present disclosure to the disclosed form. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiments are selected and described in order to better illustrate the principles and practical applications of the present disclosure, and to enable those of ordinary skill in the art to understand the present disclosure and thereby design various embodiments with various modifications suitable for specific uses. < / language> < / rules>

Claims

1. A method for processing a structured query statement, characterized in that: include: In response to receiving a processing instruction of a structured query statement, obtaining available information based on an instruction type of the processing instruction, wherein the available information is used to generate a prompt word; Based on the available information, generating at least one target prompt word; At least one return value corresponding to the processing instruction is generated based on at least one of the target prompt words by using a language model, and the format of the return value is determined based on the instruction type.

2. The method according to claim 1, characterized in that After generating at least one target prompt word based on the available information, the method further includes: Based on a lightweight markup language format, at least one of the target prompt words is structured to obtain at least one optimized prompt word corresponding to the at least one target prompt word, wherein the optimized prompt word includes model persona information; The using of the language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes: Acquire a language model corresponding to the model persona information in each of the optimization prompt words; The language model is used to generate a return value corresponding to the processing instruction based on each of the optimization prompt words.

3. The method according to any one of claims 1-2, characterized in that: The instruction type is one of the following instructions: a generation instruction, an optimization instruction, a conversion instruction, and an interpretation instruction; The obtaining of available information based on the instruction type of the processing instruction includes: In response to the processing instruction being an optimization instruction, obtaining available information including a database type, a table creation statement, and explanation information of a target database; In response to the processing instruction being one of a generation instruction, a conversion instruction and an interpretation instruction, available information including a database type and a table creation statement of a target database is obtained.

4. The method according to any one of claims 1 to 3, characterized in that: The available information obtained includes: In response to the processing instruction carrying the library table identification information of the target database, the available information is acquired from the database system according to the library table identification information; In response to the fact that the processing instruction does not carry the library table identification information of the target database, the available information is acquired according to the text description information in the processing instruction.

5. The method according to any one of claims 1 to 4, characterized in that: The using of the language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes: In response to the processing instruction being an optimization instruction, using a language model, based on at least one of the target prompt words, generating a return value corresponding to each target prompt word, including a database analysis result, an analysis result analysis, and optimization suggestion information; In response to the processing instruction being a generation instruction and a conversion instruction, using a language model and based on at least one of the target prompt words, generating a return value including a structured query statement corresponding to each target prompt word; In response to the processing instruction being an interpretation instruction, a language model is used to generate a return value corresponding to each target prompt word and including text description information corresponding to the structured query statement based on at least one target prompt word.

6. The method according to any one of claims 1 to 5, characterized in that: The step of generating at least one target prompt word based on the available information comprises: At least one target prompt word corresponding to at least one prompt word format is generated based on the available information according to at least one preset prompt word specification assembly parameter.

7. The method according to any one of claims 1 to 6, characterized in that: After generating at least one return value corresponding to the processing instruction based on at least one of the target prompt words, the method includes: In response to receiving a scoring parameter based on at least one of the return values ​​from a user, adding each of the scoring parameters to the statistical data of the language model corresponding to the return value; Determining a statistical score for each language model based on the statistical data of each language model; Based on the statistical scores of the language models, each language model is optimized and iterated.

8. The method according to claim 7, characterized in that The using of the language model to generate at least one return value corresponding to the processing instruction based on at least one of the target prompt words includes: Using the language model after the optimization iterative processing, at least one return value corresponding to the processing instruction is generated based on at least one of the target prompt words.

9. An electronic device, comprising: A memory for storing a computer program product; A processor is used to execute the computer program product stored in the memory, and when the computer program product is executed, it implements the method described in any one of claims 1 to 8.

10. A computer program product comprising computer program instructions, characterized in that When the computer program instructions are executed by a processor, the method described in any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • SQL (Structured Query Language) statement optimization suggestion generation method and device, medium and electronic equipment

    CN120067140A