Structured query language error correction method and device and volatile storage medium

By obtaining the correlation scores of the syntax error information output by the syntax detector and the historical error correction example, building error prompt information, and inputting the error correction model for self-optimization, solving the problem of inefficiency of existing SQL error correction technology on complex tasks. , achieving higher error correction accuracy and efficiency.

CN119201968APending Publication Date: 2024-12-27CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202411231217.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

The existing structured query language (SQL) error correction technology relies on a large number of training corpus, and its effects are poor on complex tasks and have low error correction efficiency.

Method used

By obtaining the syntax error information output by the syntax detector, determining the data structure information of the syntax error association table, calculating the correlation score of historical error correction examples, building error prompt information, inputting the error correction model for error correction, and through a self-optimization mechanism Continuously update the error correction results until they are correct.

Benefits of technology

It significantly improves the accuracy and efficiency of SQL error correction, can effectively deal with complex syntax errors and data type errors, and reduces the illusion problem of the error correction model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201968A_ABST
    Figure CN119201968A_ABST
Patent Text Reader

Abstract

The invention discloses a structured query language error correction method and device and a volatile storage medium. The method comprises the steps that first grammar error information output by a grammar detector is acquired, and data structure information of a grammar error association table is determined according to the first grammar error information; determining a correlation score, corresponding to the first grammar error information, of each historical error correction sample, and determining a target error correction sample in each historical error correction sample according to the correlation score; according to the first grammar error information, the data structure information of the grammar error association table and the target error correction sample, constructing error prompt information; inputting the error prompt information into an error correction model, obtaining an error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining an analysis result of the error correction model on the error correction result, and updating the error correction result according to the analysis result. According to the method and the device, the technical problem of low error correction efficiency caused by inaccurate error correction effect of the existing structured query language is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence, and more specifically, to a structured query language error correction method, device, and volatile storage medium. Background Art

[0002] SQL (Structured Query Language) is a powerful language for managing and operating relational databases, and plays a key role in data analysis and reporting. SQL error correction technology is essential to ensure data accuracy and reliability. By detecting and correcting common errors, it improves query performance, enhances data security, improves user experience, and supports data-driven decision-making.

[0003] However, current SQL error correction technology relies on a large amount of training corpus prepared in advance, and can often only solve simple SQL error correction problems, and performs poorly on task sets with a certain degree of difficulty.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiments of the present application provide a structured query language error correction method, device and volatile storage medium to at least solve the technical problem of low error correction efficiency caused by inaccurate error correction effect of existing structured query language.

[0006] According to one aspect of an embodiment of the present application, a structured query language error correction method is provided, comprising: obtaining first grammatical error information output by a grammatical detector, determining data structure information of a grammatical error association table based on the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; determining a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determining a target error correction sample from each historical error correction sample based on the correlation score, wherein the correlation score is used to indicate a degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; constructing error prompt information based on the first grammatical error information, the data structure information of the grammatical error association table, and the target error correction sample; inputting the error prompt information into an error correction model, obtaining an error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining an analysis result of the error correction model on the error correction result, and updating the error correction result based on the analysis result, wherein the error correction result includes a corrected structured query statement, and the analysis result includes a grammatical analysis result and a semantic analysis result of the error correction result.

[0007] Optionally, determining data structure information of the syntax error association table based on the first syntax error information includes: obtaining data structure information of the syntax error association table from a database based on a syntax error association table identifier, wherein the data structure information includes at least one of the following: field name, field type, and field comment.

[0008] Optionally, determining the error correction samples according to the relevance score includes: sorting the historical error correction samples in the database according to the relevance score from large to small; and determining a preset number of historical error correction samples that are at the top of the sort as target error correction samples.

[0009] Optionally, the error prompt information is input into the error correction model, the error correction result returned by the error correction model is obtained, the error correction result is input into the error correction model, the analysis result of the error correction model on the error correction result is obtained, and the error correction result is updated according to the analysis result, including: when the analysis result shows that the error correction result is still erroneous, the analysis result and the error prompt information are input into the error correction model, and the error correction is performed again to obtain an updated error correction result, until the analysis result shows that the error correction result is correct; the error correction result with the latest update time is used as the final error correction result and is output.

[0010] Optionally, after obtaining the error correction result returned by the error correction model, the method further includes: inputting the error correction result into the grammar detector; obtaining second grammar error information output by the grammar detector; inputting the second grammar error information and error prompt information into the error correction model for re-correction.

[0011] Optionally, the error correction result is run, and when the run is successful, the error correction result is determined to be correct; when the error correction result is determined to be correct, the error correction result is output as the final error correction result.

[0012] Optionally, a structured query language to be detected is obtained, and the language type of the structured query language to be detected is determined; based on the language type, the grammatical rules of the structured query language to be detected are determined; based on the grammatical rules of the structured query language to be detected, a corresponding grammar detector is determined, wherein the output information format of each grammar detector is unified.

[0013] According to another aspect of an embodiment of the present application, a structured query language error correction device is also provided, including: an acquisition module, used to acquire first grammatical error information output by a grammatical detector, and determine data structure information of a grammatical error association table based on the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; a determination module, used to determine a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determine a target error correction sample from the historical error correction samples based on the correlation score, wherein the correlation score is used to represent the first grammatical error information The similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; a construction module, used to construct error prompt information according to the first grammatical error information, the data structure information of the grammatical error association table and the error correction sample; an error correction module, used to input the error prompt information into the error correction model, obtain the error correction result returned by the error correction model, input the error correction result into the error correction model, obtain the analysis result of the error correction model on the error correction result, and update the error correction result according to the analysis result, wherein the error correction result includes the corrected structured query statement, and the analysis result includes the grammatical analysis result and the semantic analysis result of the error correction result.

[0014] According to another aspect of an embodiment of the present application, a non-volatile storage medium is provided, in which a program is stored, wherein when the program is running, a device where the non-volatile storage medium is located is controlled to execute a structured query language error correction method.

[0015] According to another aspect of an embodiment of the present application, an electronic device is provided, including: a memory and a processor, the processor being configured to run a program stored in the memory, wherein the structured query language error correction method is executed when the program is run.

[0016] According to another aspect of an embodiment of the present application, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the structured query language error correction method is implemented.

[0017] In an embodiment of the present application, the first grammatical error information output by the grammar detector is obtained, and based on the first grammatical error information, the data structure information of the grammatical error association table is determined, wherein the first grammatical error information includes the location where the grammatical error occurs, the grammatical error type, and the grammatical error association table identifier; the correlation score corresponding to each historical error correction sample and the first grammatical error information is determined, and the target error correction sample is determined in each historical error correction sample based on the correlation score, wherein the correlation score is used to indicate the degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; based on the first grammatical error information, the data structure information of the grammatical error association table and the target error correction sample, error prompt information is constructed; and the error prompt information is input into the error correction model , obtain the error correction result returned by the error correction model, input the error correction result into the error correction model, obtain the analysis result of the error correction model on the error correction result, and update the error correction result based on the analysis result, wherein the error correction result includes the corrected structured query statement, and the analysis result includes the syntax analysis result and the semantic analysis result of the error correction result. By obtaining the structural information of the syntax error association table and the related historical error samples based on the information detected by the syntax detector, and inputting the above information into the error correction model for correction and continuous optimization, the purpose of improving the error correction accuracy of the structured query language is achieved, thereby achieving the technical effect of improving the error correction efficiency of the structured query language, and then solving the technical problem of low error correction efficiency caused by the inaccurate error correction effect of the existing structured query language. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 It is a structural schematic diagram of a computer terminal (mobile device) provided according to an embodiment of the present application;

[0020] Figure 2 It is a flow chart of a structured query language error correction method provided according to an embodiment of the present application;

[0021] Figure 3 It is an overall architecture diagram of a pre-grammar detector provided according to an embodiment of the present application;

[0022] Figure 4 It is a schematic diagram of a large model reflection process provided according to an embodiment of the present application;

[0023] Figure 5 A schematic diagram of a structured query language error correction process is provided according to an embodiment of the present application;

[0024] Figure 6It is a schematic diagram of the structure of a structured query language error correction device provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

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

[0027] In order to better understand the embodiments of the present application, the technical terms involved in the embodiments of the present application are explained as follows:

[0028] Large model: Large language model (LLM) is usually a natural language processing model with large-scale parameters and computing power. Large models are trained with a large amount of data and parameters to generate human-like text or answer natural language questions. Large language models are widely used in natural language processing, text generation, and intelligent dialogue.

[0029] Few-shot learning: A machine learning paradigm that aims to train a model to learn with only a small number of samples, usually only one or two samples per category. The motivation for this learning style is that in many real-world scenarios, collecting large amounts of labeled data is time-consuming and expensive. To achieve this, few-shot learning models typically use techniques such as transfer learning, meta-learning, and specific neural network architectures. Few-shot learning has applications in many fields such as natural language processing, computer vision, and robotics, and can significantly improve the performance of machine learning models with limited data.

[0030] Table Schema: In the database field, it refers to the definition of the organization and structure of data in the database. It includes the definition of all tables in the database, the names and types of fields, and the relationships between data (such as primary key and foreign key constraints). The table schema of the database is a blueprint that defines the structure of the tables in the database. The schema specifies the columns, data types, constraints, and relationships of the table. It defines the type of data that each column can hold, such as integers, strings, or dates, and specifies any constraints, such as primary keys, foreign keys, or unique constraints. The schema also defines the relationships between tables, such as one-to-one, one-to-many, or many-to-many relationships. The schema helps ensure the consistency and integrity of the data in the database and makes it easier for developers and end users to access and manipulate the data. By defining the structure of the data, the schema provides organization and structure to the database, making it easier to manage and use.

[0031] Prompt engineering: A natural language processing technique used specifically in machine learning models to improve the model's ability to understand and respond to user input. This approach involves carefully crafting input prompts, which are text provided to the model that are intended to guide the model to generate a specific type of answer or perform a specific task. Prompt engineering is often used to optimize the performance of chatbots, text generation models, and other language processing applications. By tuning and optimizing prompts, the quality of the model's output can be significantly improved, making it more accurate, relevant, and user-friendly. This approach relies on a deep understanding of the model's behavior and creatively constructing inputs that can stimulate optimal performance. Prompt engineering is one of the key techniques for improving model interactivity and flexibility, especially for application scenarios that require highly customized responses.

[0032] Self-refine: A technique used in machine learning and artificial intelligence that allows a model to improve its performance through continuous training and adjustment without external intervention. This approach typically involves using the model's output to guide its subsequent training process, allowing the model to learn from its mistakes and gradually improve its accuracy and efficiency. During the self-refine process, the model may adopt various strategies, such as increasing data diversity, adjusting learning rates, or modifying network structures to adapt to changing data patterns and improve generalization capabilities, including improving the initial LLM (Large Language Model) output through iterative feedback. The specific steps are to use LLM to generate an output, and then allow the same model to provide multi-faceted feedback for its own output. Finally, the same model improves and optimizes its previously generated output through its own feedback. This self-optimization capability is particularly important for long-term systems, as they need to adapt to new data and environmental changes to maintain their effectiveness and relevance. In some cases, self-refine can also involve the model self-generating training data or self-adjusting training parameters to improve its autonomy and adaptability.

[0033] NL2SQL (Natural Language to Structured Query Language): Convert natural language to SQL statements A natural language processing technology that aims to convert natural language questions into structured query language (SQL) queries. It allows users to interact with the database through natural language without having to learn SQL syntax. NL2SQL achieves this goal by parsing and understanding natural language questions and converting them into corresponding SQL queries. It uses various techniques such as syntax analysis, semantic role labeling, and execution action recognition to determine the tables, columns, and relations involved in the question. It then generates an SQL query to retrieve the required information from the database. NL2SQL is useful in many application areas, including chatbots, data visualization tools, and data analysis software, making it easier for non-technical users to access and analyze data.

[0034] Natural Language Processing (NLP): A branch of artificial intelligence and linguistics that aims to enable computers to understand, interpret, and generate human language. The goal of NLP is to bridge the gap between human language and computers, enabling computers to process and analyze text and speech data in a similar way to humans. NLP technologies include language translation, sentiment analysis, text classification, named entity recognition, speech recognition and generation, etc. These technologies have applications in various fields such as healthcare, finance, customer service, education, and entertainment. NLP enables machines to analyze and understand the complexity of human language, thereby achieving more natural and intuitive human-computer interaction.

[0035] Encoder-decoder: A deep learning architecture that is commonly used for natural language processing tasks such as machine translation, text summarization, and question-answering systems. This architecture consists of two main parts: an encoder and a decoder. The encoder converts the input text or speech into a fixed-size vector representation that captures the key information in the input data. The decoder then uses this vector representation to generate outputs, such as translated text or a summary answer to a question. Encoders and decoders typically use different types of neural networks, such as recurrent neural networks (RNNs) or convolutional neural networks (CNNs), depending on the task. One of the key advantages of the encoder-decoder architecture is that it can handle variable-length input and output sequences, making it well suited for processing natural language. In addition, it can easily integrate attention mechanisms, further enhancing its performance and interpretability.

[0036] Hallucination problem: Large machine learning models, especially deep learning models, often face the hallucination problem, in which the predictions or outputs generated by the model are inaccurate or unrealistic. This can be due to a variety of factors, including insufficient training data, overfitting, lack of interpretability, and limitations in the model architecture and training process. The hallucination problem can cause the model to perform poorly in real-world scenarios or even make misleading predictions. This is particularly important in fields such as healthcare and finance, where incorrect predictions can have serious consequences. Solving the hallucination problem requires developing more robust and transparent model architectures, improving the quality of training data, using regularization techniques to reduce overfitting, and developing better model interpretability methods to help users understand the model's decision-making process and detect potential hallucination outputs.

[0037] BM25 (Best Matching 25): A ranking algorithm used in information retrieval and search engines that evaluates the relevance of query terms to documents by calculating the frequency of query terms in documents (term frequency TF) and the inverse document frequency (IDF) in the document collection. Its calculation formula combines factors such as term frequency, document frequency, and document length to achieve accurate sorting of search results.

[0038] In the related technologies, there are two main types of SQL error correction technologies based on NLP technology. The first is the traditional model SQL error correction using sequence to sequence (Seq2Seq) or encoder-decoder models for SQL error correction. This technology requires the preparation of a certain amount of SQL error correction training corpus in advance. By learning the training corpus, the original erroneous query is converted into a corrected query. Its effect is highly dependent on the training corpus, and its understanding and generalization of SQL semantics are poor, and it often performs poorly on a task set with a certain degree of difficulty. The second is the SQL error correction technology based on a large model: natural language is understood by training a large amount of text data and SQL corpus, but the existing solutions only prompt the large model with simple prompt words and prompt samples. This simple technical solution can often only solve simple SQL error correction problems, and complex syntax errors and data type errors cannot be solved. In addition, large models often have hallucination problems or generate invalid answers that cannot solve the problem.

[0039] In order to solve the above problems, relevant solutions are provided in the embodiments of the present application, which are described in detail below.

[0040] According to an embodiment of the present application, a method embodiment of a structured query language error correction method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0041] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 The hardware structure block diagram of a computer terminal (or mobile device) for implementing the structured query language error correction method is shown. Figure 1As shown, the computer terminal 10 (or mobile device 10) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.

[0042] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0043] The memory 104 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the structured query language error correction method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, the structured query language error correction method described above is realized. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0044] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0045] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or mobile device).

[0046] In the above operating environment, the embodiment of the present application provides a structured query language error correction method, such as Figure 2 As shown, the method comprises the following steps:

[0047] Step S202, obtaining first grammatical error information output by the grammar detector, and determining data structure information of a grammatical error association table according to the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier;

[0048] In some embodiments of the present application, the original SQL is input into the pre-grammar detection small model: the pre-grammar detection small model will output SQL grammar error information (including error type, error details, error type code), locate the SQL grammar error position, and also output all table names associated with the SQL, that is, the syntax error associated table identifier. Through all the table names output by the pre-grammar detection small model, the database is queried to obtain the data structure information of the corresponding table, including field names and comments, etc.

[0049] Specifically, the pre-grammar detector is a hot-pluggable module. Different SQL languages ​​have different SQL grammar rules. Whether it is MySQL or HiveSQL, you can insert their own pre-grammar detection modules. However, the output of the pre-grammar detection module must uniformly contain the following information:

[0050] 1.SQL syntax error location information:

[0051] The SQL statement error position, that is, the index of the position where the syntax check module detects a syntax error in a given SQL statement.

[0052] The error location information is mainly used to guide the large model to pay more attention to the error location and improve the accuracy of the large model's error correction. Experiments have shown that the error correction effect is best when the error location prompt information is provided in both Chinese and English.

[0053] 2. Detailed error information of SQL statement:

[0054] The detailed error information of SQL statements includes both syntax and content.

[0055] Syntax side: The syntax checker of the front-end model needs to output detailed syntax error information of a given SQL, such as keyword spelling errors, function usage errors, and character errors.

[0056] Content side: The syntax parser of the front-end syntax detection module is used to structure the output table and field names and types, and compare them with the recalled table schema information to finally construct an error prompt message.

[0057] 3. Unique error code:

[0058] For each type of error, a unique error code needs to be assigned to facilitate few-shot recall and input into the large model for error correction instances to improve the accuracy of error correction.

[0059] Figure 3 The overall architecture of a pre-syntax detector is shown as Figure 3 As shown in the figure, after the SQL syntax detector, the syntax detector generates detailed error information, including content-side information and syntax-side information, where the content-side information is used to obtain the data structure information of the corresponding association table in the database, and the error information code is used by the few-sample model to query similar error samples from the historical error correction data in the database. The so-called hot pluggability means that the detection module architecture of all SQL-type languages ​​can be as shown in the figure. As long as the output information is less than or equal to the error information summary, online access can be completed. Regardless of HiveSQL or MySQL, it can accurately adapt to SQL error correction tasks of different syntax types.

[0060] Step S204, determining the correlation scores corresponding to each historical error correction sample and the first grammatical error information, and determining a target error correction sample from each historical error correction sample according to the correlation scores, wherein the correlation scores are used to indicate the degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record;

[0061] In some embodiments of the present application, a model is trained using a few-shot learning paradigm. The model uses the grammatical error information obtained through a pre-grammar detection small model to search the SQL error correction history database for historical question and answer records with the highest similarity to the grammatical error information, and obtains the topN (N>=2) results as example outputs.

[0062] Specifically, the target error correction sample is determined by calculating the correlation score of the current error information and the historical error correction syntax error information. Correlation score = cosine of error code + error information BM25 + pre-processed error information vectorization. The higher the correlation score, the more relevant the recalled example is to the current one.

[0063] Step S206, constructing error prompt information according to the first grammatical error information, the data structure information of the grammatical error association table and the target error correction sample;

[0064] In some embodiments of the present application, the syntax analysis output (including error information and error location) of the front-end syntax detection small model, the data structure information of the associated table, and the historical error correction examples recalled based on the error information are integrated to construct prompt words, and the model is required to think about error correction step by step from the perspective of a SQL expert and output the error correction results.

[0065] Step S208, input the error prompt information into the error correction model, obtain the error correction result returned by the error correction model, input the error correction result into the error correction model, obtain the analysis result of the error correction model on the error correction result, and update the error correction result based on the analysis result, wherein the error correction result includes the corrected structured query statement, and the analysis result includes the grammatical analysis result and semantic analysis result of the error correction result.

[0066] In some embodiments of the present application, the prompt word is input into the big model, the initial return result of the big model is obtained, and the prompt word and the initial output of the big model are input into the big model again, so that the big model can reflect and provide feedback. When computing resources are insufficient or timeliness requirements are high, the front-end grammar small model can also be used to perform grammar detection again as a reflection, and then provide feedback according to the rules. The feedback provided is input into the big model again, so that the big model thinks step by step according to the feedback. Finally, the big model is continuously optimized and output according to the feedback until a satisfactory answer is obtained. Specifically, after the big model reflects, it considers that the current error correction result is correct, that is, it is considered to be a satisfactory answer; use the SQL executor to run the SQL statement, and a successful run is a satisfactory answer.

[0067] Specific. Figure 4 A schematic diagram of a large model reflection process is shown, Figure 4As shown, firstly, preliminary error correction is performed, and the SQL to be corrected and the information of the preceding syntax detection module are input into the large model to obtain the first error correction result of the large model; after the preliminary error correction, the large model is reflected, and the first error correction result of the large model is given to the large model, so that the large model can reflect on the SQL to be corrected and the detection information of the preceding module, and the reflection result is required to include the reflection information on the last result in terms of syntax, semantics and type. Based on the reflection of the large model, the final error correction is performed, and the error prompt information and the reflection result are input into the large model, and the error correction is performed again in combination with the reflection result, so that the large model can rethink according to the previous reflection result to avoid the previous order problem, so as to improve the final error correction accuracy. After adding the reflection information, the problems of error correction illusion, wrong error correction and missed error correction of the large model are mainly solved.

[0068] In some embodiments of the present application, the structured query language error correction process includes syntax detector detection, table query, sample query, prompt word construction and large model loop error correction steps. Figure 5 A structured query language error correction flow chart is shown, such as Figure 5 As shown, first, the error information is detected through the small pre-grammar detection model (i.e., the pre-grammar detector), and the associated table structure information and target error samples are obtained based on the error information. The prompt words are constructed based on the above information and input into the large model. The large model outputs the error correction results, and reflection is performed based on the error correction results. The error is corrected again based on the reflection results, and the optimized error correction results are output.

[0069] Through the above steps, the front-end syntax check module can be used to perform a comprehensive syntax analysis on the SQL to be corrected, solve the problem of syntax error perception, and provide good hot pluggability (supporting multiple SQL languages ​​and various checkers at the same time). Then, the table Schema information is obtained through the parsed SQL association table to assist the large model in verifying the type and name of the fields in the SQL, solving the problem of large model illusion and realizing field name correction. Then, through the error information results of the front-end model, simple and difficult correction examples are recalled and written into Prompt for the large model to prompt learning, so as to improve the accuracy of error correction. Finally, the results of the large model modification are self-reflected again to solve the problems of large model illusion and invalid answers, thereby comprehensively and effectively improving the overall effect of SQL error correction.

[0070] Specifically, this application has the following advantages:

[0071] 1. Through the front-end syntax detector, SQL syntax error information and error location are obtained and provided to the big model, so that the big model can obtain more SQL error information, making the big model error correction and positioning problem more accurate, and the overall error correction accuracy is significantly improved; through the front-end syntax detector, the table name associated with the SQL statement is obtained, and the table Schema information is recalled through the table name, which solves the big model hallucination problem and the problem of SQL statement field name and type errors; through the front-end syntax detector, SQL syntax error information is obtained, and historical error correction matching similarity is performed based on the syntax error information. The most similar examples of historical error correction questions and answers are added to Prompt and provided to the big model as error correction examples, so that the big model has the ability to accurately solve difficult SQL error correction problems.

[0072] 2. Add a large model reflection module (self-refine): Add a large model reflection module to improve the initial SQL error correction results of the large model through internal feedback and refinement mechanisms. This reflection module does not require supervised training data, additional training, reinforcement learning, etc. It only needs an LLM as a generator, feedback and refiner at the same time, thereby improving the completeness and accuracy of SQL error correction.

[0073] The present application embodiment provides a structured query language error correction device, Figure 6 is a schematic diagram of the structure of the device, such as Figure 6 As shown, the device includes: an acquisition module 60, which is used to acquire first grammatical error information output by a grammar detector, and determine data structure information of a grammatical error association table according to the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; a determination module 62, which is used to determine a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determine a target error correction sample in the historical error correction sample according to the correlation score, wherein the correlation score is used to indicate the correlation between the first grammatical error information and the first in each historical error correction record. The similarity degree of the grammatical error information; a construction module 64, used to construct error prompt information according to the first grammatical error information, the data structure information of the grammatical error association table and the error correction sample; an error correction module 66, inputting the error prompt information into the error correction model, obtaining the error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining the analysis result of the error correction model on the error correction result, and updating the error correction result according to the analysis result, wherein the error correction result includes the corrected structured query statement, and the analysis result includes the grammatical analysis result and the semantic analysis result of the error correction result.

[0074] In some embodiments of the present application, the acquisition module 60 determines the data structure information of the syntax error association table based on the first syntax error information, including: acquiring the data structure information of the syntax error association table from the database based on the syntax error association table identifier, wherein the data structure information includes at least one of the following: field name, field type, and field comment.

[0075] In some embodiments of the present application, the determination module 62 determines the error correction samples based on the correlation scores, including: sorting the historical error correction samples in the database from large to small according to the correlation scores; and determining a preset number of historical error correction samples that are at the top of the sort as target error correction samples.

[0076] In some embodiments of the present application, the error correction module 66 inputs the error prompt information into the error correction model, obtains the error correction result returned by the error correction model, inputs the error correction result into the error correction model, obtains the analysis result of the error correction result by the error correction model, and updates the error correction result based on the analysis result, including: when the analysis result shows that the error correction result is still erroneous, inputting the analysis result and the error prompt information into the error correction model, performing error correction again to obtain an updated error correction result, until the analysis result shows that the error correction result is correct; and outputting the error correction result with the latest update time as the final error correction result.

[0077] In some embodiments of the present application, after the error correction module 66 obtains the error correction result returned by the error correction model, the method also includes: inputting the error correction result into the grammar detector; obtaining the second grammar error information output by the grammar detector; inputting the second grammar error information and the error prompt information into the error correction model for re-correction.

[0078] In some embodiments of the present application, the error correction result is run, and when the run is successful, it is determined that the error correction result is correct; when the error correction result is determined to be correct, the error correction result is output as the final error correction result.

[0079] In some embodiments of the present application, a structured query language to be detected is obtained, and the language type of the structured query language to be detected is determined; based on the language type, the grammatical rules of the structured query language to be detected are determined; based on the grammatical rules of the structured query language to be detected, a corresponding grammar detector is determined, wherein the output information format of each grammar detector is unified.

[0080] It should be noted that the various modules in the above-mentioned structured query language error correction device can be program modules (for example, a set of program instructions that implement a certain specific function) or hardware modules. For the latter, it can be expressed in the following forms, but is not limited to this: the expression form of each of the above-mentioned modules is a processor, or the functions of each of the above-mentioned modules are implemented by a processor.

[0081] The embodiment of the present application provides a non-volatile storage medium, in which a program is stored, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the following structured query language error correction method: obtaining first grammatical error information output by a grammar detector, and determining data structure information of a grammatical error association table based on the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; determining a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determining a target in each historical error correction sample based on the correlation score. Error correction samples, wherein the correlation score is used to indicate the degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; error prompt information is constructed based on the first grammatical error information, the data structure information of the grammatical error association table and the target error correction sample; the error prompt information is input into the error correction model, the error correction result returned by the error correction model is obtained, the error correction result is input into the error correction model, the analysis result of the error correction model on the error correction result is obtained, and the error correction result is updated based on the analysis result, wherein the error correction result includes the corrected structured query statement, and the analysis result includes the grammatical analysis result and the semantic analysis result of the error correction result.

[0082] An embodiment of the present application provides an electronic device, including: a memory and a processor, the processor is used to run a program stored in the memory, wherein the program executes the following structured query language error correction method when it is run: obtaining first grammatical error information output by a grammatical detector, determining data structure information of a grammatical error association table based on the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; determining a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determining a target error correction sample from each historical error correction sample based on the correlation score, wherein the correlation score is used to indicate the degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; constructing error prompt information based on the first grammatical error information, the data structure information of the grammatical error association table, and the target error correction sample; inputting the error prompt information into an error correction model, obtaining an error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining an analysis result of the error correction model on the error correction result, and updating the error correction result based on the analysis result, wherein the error correction result includes a corrected structured query statement, and the analysis result includes a grammatical analysis result and a semantic analysis result of the error correction result.

[0083] The embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, the following structured query language error correction method is implemented: obtaining first grammatical error information output by a grammatical detector, determining data structure information of a grammatical error association table based on the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; determining a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determining a target error correction sample from each historical error correction sample based on the correlation score, wherein the correlation score is used to indicate the degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; constructing error prompt information based on the first grammatical error information, the data structure information of the grammatical error association table, and the target error correction sample; inputting the error prompt information into an error correction model, obtaining an error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining an analysis result of the error correction model on the error correction result, and updating the error correction result based on the analysis result, wherein the error correction result includes a corrected structured query statement, and the analysis result includes a grammatical analysis result and a semantic analysis result of the error correction result.

[0084] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

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

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

[0087] 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.

[0088] 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 relevant technology or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc. Various media that can store program codes.

[0089] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A structured query language error correction method, characterized in that: include: Acquire first grammatical error information output by the grammar detector, and determine data structure information of a grammatical error association table according to the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; Determine a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determine a target error correction sample from each historical error correction sample according to the correlation score, wherein the correlation score is used to indicate a degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; Constructing error prompt information according to the first grammatical error information, the data structure information of the grammatical error association table and the target error correction sample; Input the error prompt information into an error correction model, obtain the error correction result returned by the error correction model, input the error correction result into the error correction model, obtain the analysis result of the error correction model on the error correction result, and update the error correction result based on the analysis result, wherein the error correction result includes a corrected structured query statement, and the analysis result includes a grammatical analysis result and a semantic analysis result of the error correction result.

2. The structured query language error correction method according to claim 1, characterized in that: Determining data structure information of a grammatical error association table according to the first grammatical error information includes: The data structure information of the grammatical error association table is obtained from the database according to the grammatical error association table identifier, wherein the data structure information includes at least one of the following: field name, field type and field comment.

3. The structured query language error correction method according to claim 1, characterized in that: Determining the error correction sample according to the correlation score includes: According to the relevance score, the historical error correction samples in the database are sorted from large to small according to the relevance score; A preset number of historical error correction samples that are at the front of the sort are determined as target error correction samples.

4. The structured query language error correction method according to claim 1, characterized in that: Inputting the error prompt information into an error correction model, obtaining an error correction result returned by the error correction model, inputting the error correction result into the error correction model, obtaining an analysis result of the error correction model on the error correction result, and updating the error correction result according to the analysis result includes: In the case where the analysis result shows that the error correction result still has errors, the analysis result and the error prompt information are input into the error correction model, and the error correction is performed again to obtain an updated error correction result, until the analysis result shows that the error correction result is correct; The error correction result with the latest update time is taken as the final error correction result and output.

5. The structured query language error correction method according to claim 4, characterized in that: After obtaining the error correction result returned by the error correction model, the method further includes: inputting the error correction result into the grammar detector; Acquire second grammar error information output by the grammar detector; The second grammatical error information and the error prompt information are input into the error correction model for further error correction.

6. The structured query language error correction method according to claim 4, characterized in that: The method further comprises: Running the error correction result, and if the running is successful, determining that the error correction result is correct; When it is determined that the error correction result is correct, the error correction result is output as the final error correction result.

7. The structured query language error correction method according to claim 1, characterized in that: Before obtaining the first grammatical error information output by the grammar detector, the method further includes: Acquire a structured query language to be detected, and determine the language type of the structured query language to be detected; Determining the grammatical rules of the structured query language to be detected according to the language type; According to the grammatical rules of the structured query language to be detected, a corresponding grammar detector is determined, wherein the output information format of each grammar detector is unified.

8. A structured query language error correction device, characterized in that: include: An acquisition module, used for acquiring first grammatical error information output by a grammatical detector, and determining data structure information of a grammatical error association table according to the first grammatical error information, wherein the first grammatical error information includes a grammatical error occurrence location, a grammatical error type, and a grammatical error association table identifier; a determination module, configured to determine a correlation score corresponding to each historical error correction sample and the first grammatical error information, and determine a target error correction sample from the historical error correction samples according to the correlation score, wherein the correlation score is used to indicate a degree of similarity between the first grammatical error information and the first grammatical error information in each historical error correction record; A construction module, used to construct error prompt information according to the first grammatical error information, the data structure information of the grammatical error association table and the error correction sample; An error correction module is used to input the error prompt information into an error correction model, obtain the error correction result returned by the error correction model, input the error correction result into the error correction model, obtain the analysis result of the error correction model on the error correction result, and update the error correction result based on the analysis result, wherein the error correction result includes a corrected structured query statement, and the analysis result includes a grammatical analysis result and a semantic analysis result of the error correction result.

9. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the structured query language error correction method according to any one of claims 1 to 7.

10. An electronic device, characterized in that: include: A memory and a processor, wherein the processor is used to run a program stored in the memory, wherein the structured query language error correction method according to any one of claims 1 to 7 is executed when the program is run.

11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the structured query language error correction method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Error recognition method and device for structured query statement, equipment and storage medium

    CN120492474A

  • system

    JP2026140309A

  • system

    JP2026140375A