Correction method and system for time type generation accuracy in Text2SQL (Structured Query Language) task

By constructing a time expression knowledge base and a time inference model, the problem of inaccurate time parsing in LLM in Text2SQL tasks was solved, achieving efficient and accurate SQL generation, simplifying the process and reducing costs.

CN121144331APending Publication Date: 2025-12-16AISINO CORPORATION
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511018295.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-23
Publication Date
2025-12-16

AI Technical Summary

Technical Problem

Existing LLMs have low accuracy in generating SQL statements from natural language containing time information in Text2SQL tasks, especially when parsing complex time information and cross-regional time representations, resulting in insufficient SQL execution accuracy.

Method used

By constructing a knowledge base of over two hundred time expressions and combining it with a Large Language Model (LLM), time entities are extracted and corrected using a time inference model to generate real time. Combined with a knowledge base update mechanism, unified output of time expressions and SQL correction are achieved.

Benefits of technology

It improves the accuracy of time recognition, simplifies the process, reduces costs, and eliminates the need for additional training on large models, thereby enhancing the accuracy and efficiency of SQL generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121144331A_ABST
    Figure CN121144331A_ABST
Patent Text Reader

Abstract

The invention discloses a correction method and system for time type generation accuracy in a Text2SQL task, and the method comprises the steps: creating the Text2SQL task based on a received query problem inputted by a user, and executing the Text2SQL task to convert the query problem into a semantic SQL; extracting a time expression in the semantic SQL, and calling a time inference model to carry out time correction so as to generate real time based on the time expression; the semantic SQL is corrected on the basis of the real time, and the corrected semantic SQL is obtained; and correcting the information of the corrected semantic SQL, converting the corrected semantic SQL into an executable query SQL, carrying out query based on the query SQL, and returning a query result. According to the invention, reasoning of a time expression is realized by using a time conversion algorithm, real time is output, and the accuracy of time identification is improved; time expression extraction, SQL generation and time correction can be completed by calling the large model at a time, the process is simple, and the efficiency is high.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of SQL statement processing, and more particularly, to a correction method and system for time type generation accuracy in a Text2SQL task. BACKGROUND

[0002] LLM (Large Language Model) is a machine learning model that can perform various natural language processing (NLP) tasks, such as creating content, translating text, or parsing sentences. The key feature of LLM is its ability to understand and generate natural language. To achieve this goal, LLM requires a large amount of data and computing resources for training.

[0003] Text2SQL is a process that converts natural language statements into SQL statements that can be recognized by a database, allowing users to interact directly with the database. Thanks to the unstructured processing capabilities of deep learning, Text2SQL technology has developed rapidly, and the core problem analysis module has achieved good results. However, the construction process is too complex, and the domain generalization ability is weak, resulting in the following problems: In the Text2SQL process, the large model has a low accuracy rate when generating SQL statements containing time information. The main problem is the high error rate of complex time information parsing, which ultimately leads to errors in the generated SQL statements.

[0004] Currently, there are still problems in the industry's use of LLM to directly convert date and time into standard time formats, which has led to the fact that the accuracy of SQL execution has always failed to meet the expectations of production use, and there are the following problems:

[0005] (1) Time expression has diversity

[0006] Relative time such as "today", "yesterday", "next week", and specific date and time points; on the other hand, time information is often closely related to the context, requiring the model to have strong contextual understanding ability. In addition, the time representation method in different regions and cultural backgrounds also has differences, further increasing the difficulty of understanding.

[0007] (2) SQL queries may involve specific time points

[0008] Such as "workdays this month", "working hours", "non-working hours", which are not a continuous time, and it is difficult for the large model to give a real time value.

[0009] (3) The accuracy of time resolution affects the accuracy of SQL execution. Incorrect time resolution sometimes causes SQL to be unable to query, and sometimes causes the results of SQL query to be incorrect. For users, an incorrect result may cause the accuracy of early warning, analysis, and decision-making to be incorrect.

[0010] Therefore, there is a need for a correction method for time type generation accuracy in a Text2SQL task. SUMMARY

[0011] The present application provides a correction method and system for time type generation accuracy in a Text2SQL task to solve the problem of how to correct the time generation in a Text2SQL task.

[0012] To solve the above problems, according to one aspect of the present application, a correction method for time type generation accuracy in a Text2SQL task is provided, the method comprising:

[0013] Creating a Text2SQL task based on a received user input query question and executing the Text2SQL task to convert the query question into a semantic SQL;

[0014] Extracting a time expression in the semantic SQL and calling a time reasoning model for time correction to generate a real time based on the time expression;

[0015] Correcting the semantic SQL based on the real time to obtain a corrected semantic SQL;

[0016] Correcting information of the corrected semantic SQL, converting the corrected semantic SQL into an executable query SQL, and querying based on the query SQL and returning a query result.

[0017] Preferably, wherein the Text2SQL task is executed to convert the query question into a semantic SQL, comprising:

[0018] Executing the Text2SQL task to convert the query statement into an initial SQL;

[0019] Calling a large language model (LLM) to parse the query question to determine a time entity, and based on an association relationship between the time entity and a rule format time expression in a preset knowledge base, determining a rule format time expression corresponding to the time entity;

[0020] Replacing the time expression in the initial SQL with the rule format time expression corresponding to the time entity to obtain a semantic SQL.

[0021] Preferably, the method further comprises:

[0022] The rule format time expression corresponding to the time entity in the preset knowledge base is retrieved by using the Euclidean distance method, and when it is determined that there is no time expression, the non-existent knowledge is recorded and the preset knowledge base is updated.

[0023] Preferably, the method further comprises:

[0024] When there is no time expression in the semantic SQL, no time correction is performed.

[0025] Preferably, the information of the corrected semantic SQL is corrected, and the corrected semantic SQL is converted into an executable query SQL, comprising:

[0026] The index information and dimension information in the corrected semantic SQL are determined, the index information and dimension information are replaced by actual SQL field information and are parsed to convert the corrected semantic SQL into an executable query SQL.

[0027] According to another aspect of the present application, a correction system for time type generation accuracy in a Text2SQL task is provided, the system comprising:

[0028] A semantic SQL determination unit is configured to create a Text2SQL task based on a received user input query question, and execute the Text2SQL task to convert the query question into a semantic SQL.

[0029] A time correction unit is configured to extract a time expression in the semantic SQL, and call a time reasoning model to perform time correction to generate a real time based on the time expression.

[0030] A semantic SQL correction unit is configured to correct the semantic SQL based on the real time, and obtain a corrected semantic SQL.

[0031] A query SQL determination unit is configured to correct the information of the corrected semantic SQL, and convert the corrected semantic SQL into an executable query SQL, so as to perform a query based on the query SQL and return a query result.

[0032] Preferably, the semantic SQL determination unit executes the Text2SQL task to convert the query question into a semantic SQL, comprising:

[0033] The Text2SQL task is executed to convert the query statement into an initial SQL.

[0034] The query question is parsed by calling the Large Language Model (LLM) to determine the time entity, and the time expression of the rule format corresponding to the time entity is determined based on the association between the time entity and the time expression of the rule format in the preset knowledge base.

[0035] The initial time expression in the SQL is replaced with a time expression in a rule format corresponding to the time entity to obtain semantic SQL.

[0036] Preferably, the semantic SQL determination unit further includes:

[0037] The Euclidean distance system is used to retrieve the time expression in the preset knowledge base that corresponds to the time entity in a regular format. When it is determined that no time expression exists, the non-existent knowledge is recorded and the preset knowledge base is updated.

[0038] Preferably, the time correction unit is further configured to:

[0039] No time correction is performed when the semantic SQL does not contain a time expression.

[0040] Preferably, the query SQL determining unit corrects the information of the modified semantic SQL and converts the modified semantic SQL into executable query SQL, including:

[0041] The indicator information and dimension information in the corrected semantic SQL are determined, and the indicator information and dimension information are replaced with actual SQL field information and parsed to convert the corrected semantic SQL into executable query SQL.

[0042] This invention provides a method and system for correcting the accuracy of time type generation in Text2SQL tasks. The method includes: creating a Text2SQL task based on a received user-input query question and executing the Text2SQL task to convert the query question into semantic SQL; extracting time expressions from the semantic SQL and calling a time inference model for time correction to generate a real time based on the time expressions; correcting the semantic SQL based on the real time to obtain corrected semantic SQL; correcting the information of the corrected semantic SQL and converting it into executable query SQL to perform a query and return the query results. This invention integrates LLM and a knowledge base. By constructing a knowledge base of over two hundred time expressions and combining it with prompt words, it uniformly outputs time entities extracted by a large model as time expressions. It uses a time conversion algorithm to infer the time expressions and output the real time, improving the accuracy of time recognition. When time expressions not added to the knowledge base are detected, knowledge expansion is achieved through knowledge base updates and time inference model updates. Time expression extraction, SQL generation, and time correction can be completed with a single call to the large model, resulting in a simple and efficient process. Attached Figure Description

[0043] Exemplary embodiments of the present invention can be more fully understood by referring to the following figures:

[0044] Figure 1 A flowchart of a method 100 for correcting the accuracy of time type generation in a Text2SQL task according to an embodiment of the present invention;

[0045] Figure 2 This is a general framework diagram according to an embodiment of the present invention;

[0046] Figure 3 A flowchart illustrating the generation of executable query SQL according to an embodiment of the present invention;

[0047] Figure 4 This is a schematic diagram of the structure of a correction system 400 for the accuracy of time type generation in Text2SQL tasks according to an embodiment of the present invention. Detailed Implementation

[0048] Exemplary embodiments of the invention will now be described with reference to the accompanying drawings. However, the invention may be embodied in many different forms and is not limited to the embodiments described herein. These embodiments are provided to fully and completely disclose the invention and to fully convey its scope to those skilled in the art. The terminology used in the exemplary embodiments illustrated in the drawings is not intended to limit the invention. In the drawings, the same units / elements are referred to by the same reference numerals.

[0049] Unless otherwise stated, the terms used herein (including technical terms) have their common meaning as understood by one of ordinary skill in the art. Furthermore, it is understood that terms defined in commonly used dictionaries should be understood to have a meaning consistent with the context of their relevant field, and not to be interpreted as having an idealized or overly formal meaning.

[0050] Figure 1 This is a flowchart of a method 100 for correcting the accuracy of time type generation in a Text2SQL task according to an embodiment of the present invention. Figure 1 As shown, the method for correcting the accuracy of time type generation in Text2SQL tasks provided by this invention integrates LLM and a knowledge base. By constructing a knowledge base of over two hundred time expressions and combining it with prompt words, the time entities extracted by the large model are uniformly output as time expressions. A time conversion algorithm is used to infer the time expressions and output the true time, improving the accuracy of time recognition. When a time expression not added to the knowledge base is detected, knowledge expansion is achieved through a mechanism of knowledge base update and time inference model update. Time expression extraction, SQL generation, and time correction can be completed in a single call to the large model, making the process simple and efficient. The method 100 for correcting the accuracy of time type generation in Text2SQL tasks provided by this invention starts from step 101. In step 101, a Text2SQL task is created based on the received user-input query question, and the Text2SQL task is executed to convert the query question into semantic SQL.

[0051] Preferably, the Text2SQL task is performed to convert the query question into semantic SQL, including:

[0052] Execute the Text2SQL task to convert the query statement into initial SQL;

[0053] The query question is parsed by calling the Large Language Model (LLM) to determine the time entity, and the time expression of the rule format corresponding to the time entity is determined based on the association between the time entity and the time expression of the rule format in the preset knowledge base.

[0054] The initial time expression in the SQL is replaced with a time expression in a rule format corresponding to the time entity to obtain semantic SQL.

[0055] Preferably, the method further includes:

[0056] The Euclidean distance method is used to retrieve the time expression in the preset knowledge base that corresponds to the time entity in a rule format. When it is determined that no time expression exists, the non-existent knowledge is recorded and the preset knowledge base is updated.

[0057] After understanding and considering different implementation methods, this invention decided to use an LLM-based approach with a knowledge base to extract time expressions, and to use a time inference model to infer the time expressions, outputting the actual time. Combined with... Figure 2 As shown, in this invention, the correction method is implemented based on SQL generation, a large model, a knowledge base, a temporal reasoning model, a natural language input interface, and an executable SQL output interface. The SQL generation part can realize semantic SQL generation, temporal correction, SQL correction, and knowledge base update functions.

[0058] Specifically, in this invention, semantic SQL generation is based on the user's question and calls the LLM module to generate preliminary semantic SQL. For example, "SELECT AVG(average total output per head) AS monthly average total output of live pigs FROM query dataset by region WHERE year and month = 'last week' Friday' AND survey subjects = 'Chengdu'".

[0059] For large speech models (LLM), users can choose a suitable large model based on their own situation. The large language model mainly generates semantic SQL based on the SQL input by the user. At the same time, it combines the knowledge base to represent time entities using time expressions in the knowledge base. This requires adding a requirement to the prompt language, such as "representing the question format as a rule format by combining the time of the user's question with the time expression in the knowledge base".

[0060] The knowledge base of this invention stores various preset time expressions, examples of which are shown in Table 1. Based on the large language model and knowledge base, the time format in the question format can be uniformly output using a regular time expression format.

[0061] Table 1 Time Expression Table

[0062]

[0063] In addition, the present invention can also judge the return status of time expressions based on the knowledge base update module. If there are time expressions that do not exist in the knowledge base, they can be updated according to rules, so that the question-answering system becomes more and more accurate with use.

[0064] In this invention, after obtaining the query statement input by the user, a Text2SQL task is created and executed to convert the query statement into initial SQL; then, a Large Language Model (LLM) is called to parse the query question to determine the time entity, and based on the association between the time entity and the time expression of the rule format in the preset knowledge base, the time expression of the rule format corresponding to the time entity is determined; then, the time expression in the initial SQL is replaced with the time expression of the rule format corresponding to the time entity to obtain semantic SQL.

[0065] In step 102, the time expression in the semantic SQL is extracted, and the time inference model is called to perform time correction in order to generate the real time based on the time expression.

[0066] Preferably, the method further includes:

[0067] No time correction is performed when the semantic SQL does not contain a time expression.

[0068] In this invention, a time expression can be extracted based on a time correction function, and a time inference model can be called to generate the real time for time correction. The time inference model converts the time expression into the real time through a model algorithm, and the real time needs to be obtained by calling an interface in the program. For example, 'last Friday' can be replaced with 2025-05-05. Furthermore, if it is determined that a time expression does not exist, no replacement is performed.

[0069] In step 103, the semantic SQL is corrected based on the real time to obtain the corrected semantic SQL.

[0070] In step 104, the information of the modified semantic SQL is corrected, and the modified semantic SQL is converted into executable query SQL to perform a query based on the query SQL and return the query result.

[0071] Preferably, the modification of the information in the modified semantic SQL, converting the modified semantic SQL into executable query SQL, includes:

[0072] The indicator information and dimension information in the corrected semantic SQL are determined, and the indicator information and dimension information are replaced with actual SQL field information and parsed to convert the corrected semantic SQL into executable query SQL.

[0073] In this invention, the actual time and the time in the semantic SQL are replaced to obtain the corrected semantic SQL. Since semantic SQL cannot be executed directly, the dimensions and metrics of the corrected semantic SQL also need to be modified and converted into executable SQL. Specifically, the metrics, dimensions, and other information in the semantic SQL are replaced with actual SQL field information and parsed into executable query SQL, so as to perform a query based on the query SQL and return the query results.

[0074] like Figure 3 As shown, the specific steps for performing conversational data queries using the method of the present invention are as follows:

[0075] First, the knowledge base needs to be pre-configured. Step 1 is to define and import the knowledge base, and steps 2-8 are the processes of SQL generation and time correction.

[0076] Specifically, including:

[0077] Step 1: Define the knowledge base: Install the time expression format defined in the knowledge base module above to define the knowledge base and upload it to associate with the large model.

[0078] Step 2: User inputs SQL to generate query: The user inputs the data query they wish to retrieve on the interface, and the system interface is called to send the query to the SQL generation module.

[0079] Step 3: Use the large model to convert the question into semantic SQL: The SQL generation module automatically calls the large model to generate preliminary semantic SQL. For example, "SELECT AVG(Average Total Output Value per Head) AS Monthly Average Total Output Value of Live Pigs FROM Query Dataset by Region WHERE Year / Month = 'Last Week' Friday' AND Survey Subject = 'Chengdu'".

[0080] Step 4: Extract the time expression from the SQL. For example, the system automatically extracts the time expression 'last Friday' from the previous step.

[0081] Step 5: Use the time inference model to generate the real time. For example, use the time inference model to convert 'last Friday' to '2025-05-05'.

[0082] Step 6: Complete the SQL time correction and update the knowledge base for any non-existent time expressions.

[0083] Step 7: Correct the dimensional metrics of the semantic SQL and convert them into executable SQL.

[0084] Step 8: Output executable SQL: Return the executable SQL to the user or program through the interface to perform SQL queries and return the query results.

[0085] This invention combines an LLM (Limited Least Metric) model, a knowledge base, and a time expression inference algorithm. It generates a knowledge base from over two hundred time expressions using a built-in knowledge base. Multiple times that are the same but have different expressions are replaced with synonyms to form a unified time expression. When converting text to semantic SQL using the LLM model, time entities use the unified time expression. During the conversion from semantic SQL to SQL, SQL correction is performed, and the time inference algorithm is called to convert the unified time expression into the actual time. If there is an undefined time expression, the time generated by the LLM model is used, and the time expression is validated, added to the knowledge base, and the time inference model is updated. This invention enhances the time understanding and conversion capabilities of the LLM model by adding time expressions to the knowledge base, unifies the language expression of time as much as possible, simplifies the subsequent time inference conversion process, and enhances accuracy, thus improving the accuracy of SQL generation. Furthermore, it eliminates the need for additional training of the LLM model, facilitates the updating of the knowledge base and inference model, reduces workload, and only requires a single call to the LLM model during SQL generation, without increasing time complexity.

[0086] This invention enhances the time understanding and conversion capabilities of large models by adding time expressions to the knowledge base, unifies the language expression of time as much as possible, simplifies the subsequent time inference conversion process and enhances accuracy, improves the accuracy of SQL generation, and at the same time does not require additional training of large models. The knowledge base and inference model are easy to update, reducing the workload. Only one call to the large model is needed when generating SQL, without increasing the time complexity at all.

[0087] The method for correcting the accuracy of time type generation in Text2SQL tasks provided by this invention has the following advantages:

[0088] (1) Solve the problem of limited ability to extract time expressions from general large models and improve the accuracy of SQL generation in Text2SQL;

[0089] (2) Through the optimization of knowledge base and prompt words, there is no need to train a large model. SQL generation and correction optimization can be completed by calling a large model once. Optimization can be carried out by updating the knowledge base. It is low cost and easy to use.

[0090] (3) In addition to being used in Text2SQL applications, time inference methods can also be used in other scenarios where accurate real time needs to be extracted.

[0091] Figure 4 This is a schematic diagram of the structure of a correction system 400 for the accuracy of time type generation in Text2SQL tasks according to an embodiment of the present invention. Figure 4As shown, the correction system 400 for the accuracy of time type generation in Text2SQL tasks provided by the embodiments of the present invention includes: a semantic SQL determination unit 401, a time correction unit 402, a semantic SQL correction unit 403, and a query SQL determination unit 404.

[0092] Preferably, the semantic SQL determination unit 401 is used to create Text2SQL based on the query question received from the user input.

[0093] Preferably, the semantic SQL determination unit 401 performs the Text2SQL task to convert the query question into semantic SQL, including:

[0094] Execute the Text2SQL task to convert the query statement into initial SQL;

[0095] The query question is parsed by calling the Large Language Model (LLM) to determine the time entity, and the time expression of the rule format corresponding to the time entity is determined based on the association between the time entity and the time expression of the rule format in the preset knowledge base.

[0096] The initial time expression in the SQL is replaced with a time expression in a rule format corresponding to the time entity to obtain semantic SQL.

[0097] Preferably, the semantic SQL determination unit 401 further includes:

[0098] The Euclidean distance system is used to retrieve the time expression in the preset knowledge base that corresponds to the time entity in a regular format. When it is determined that no time expression exists, the non-existent knowledge is recorded and the preset knowledge base is updated.

[0099] Preferably, the time correction unit 402 is used to extract the time expression in the semantic SQL and call the time inference model to perform time correction, so as to generate the real time based on the time expression.

[0100] Preferably, the time correction unit 402 is further configured to:

[0101] No time correction is performed when the semantic SQL does not contain a time expression.

[0102] Preferably, the semantic SQL correction unit 403 is used to correct the semantic SQL based on the real time to obtain the corrected semantic SQL.

[0103] Preferably, the query SQL determination unit 404 is used to correct the information of the corrected semantic SQL, convert the corrected semantic SQL into executable query SQL, perform a query based on the query SQL, and return the query result.

[0104] Preferably, the query SQL determining unit 404 corrects the information of the modified semantic SQL and converts the modified semantic SQL into executable query SQL, including:

[0105] The indicator information and dimension information in the corrected semantic SQL are determined, and the indicator information and dimension information are replaced with actual SQL field information and parsed to convert the corrected semantic SQL into executable query SQL.

[0106] The time type generation accuracy correction system 400 in the Text2SQL task of this embodiment corresponds to the time type generation accuracy correction method 100 in the Text2SQL task of another embodiment of this invention, and will not be described again here.

[0107] The present invention has been described with reference to a few embodiments. However, it will be apparent to those skilled in the art that other embodiments besides those disclosed above fall equivalently within the scope of the present invention.

[0108] Generally, all terms used in this invention are interpreted according to their ordinary meaning in the art, unless otherwise expressly defined herein. All references to “a / the / the [device, component, etc.]” ​​are openly interpreted as at least one instance of said device, component, etc., unless otherwise expressly stated. The steps of any method disclosed herein need not be performed in the exact order disclosed unless explicitly stated otherwise.

[0109] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0110] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0111] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0112] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0113] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the present invention.

Claims

1. A method for correcting the accuracy of time type generation in Text2SQL tasks, characterized in that, The method includes: A Text2SQL task is created based on the query question received from the user input, and the Text2SQL task is executed to convert the query question into semantic SQL; Extract the time expression from the semantic SQL and call the time inference model to perform time correction, so as to generate the real time based on the time expression; The semantic SQL is corrected based on the real time to obtain the corrected semantic SQL. The information of the modified semantic SQL is corrected, and the modified semantic SQL is converted into executable query SQL to perform a query based on the query SQL and return the query result.

2. The method according to claim 1, characterized in that, Execute the Text2SQL task to convert the query question into semantic SQL, including: Execute the Text2SQL task to convert the query statement into initial SQL; The query question is parsed by calling the Large Language Model (LLM) to determine the time entity, and the time expression of the rule format corresponding to the time entity is determined based on the association between the time entity and the time expression of the rule format in the preset knowledge base. The initial time expression in the SQL is replaced with a time expression in a rule format corresponding to the time entity to obtain semantic SQL.

3. The method according to claim 2, characterized in that, The method further includes: The Euclidean distance method is used to retrieve the time expression in the preset knowledge base that corresponds to the time entity in a rule format. When it is determined that no time expression exists, the non-existent knowledge is recorded and the preset knowledge base is updated.

4. The method according to claim 1, characterized in that, The method further includes: No time correction is performed when the semantic SQL does not contain a time expression.

5. The method according to claim 1, characterized in that, The information of the revised semantic SQL is corrected, and the revised semantic SQL is converted into executable query SQL, including: The indicator information and dimension information in the corrected semantic SQL are determined, and the indicator information and dimension information are replaced with actual SQL field information and parsed to convert the corrected semantic SQL into executable query SQL.

6. A system for correcting the accuracy of time type generation in Text2SQL tasks, characterized in that, The system includes: A semantic SQL determination unit is used to create a Text2SQL task based on a query question received from user input, and to execute the Text2SQL task to convert the query question into semantic SQL. The time correction unit is used to extract the time expression in the semantic SQL and call the time inference model to perform time correction in order to generate the real time based on the time expression; A semantic SQL correction unit is used to correct the semantic SQL based on the real time and obtain the corrected semantic SQL. The query SQL determination unit is used to correct the information of the modified semantic SQL, convert the modified semantic SQL into executable query SQL, perform a query based on the query SQL, and return the query result.

7. The system according to claim 6, characterized in that, The semantic SQL determination unit executes the Text2SQL task to convert the query question into semantic SQL, including: Execute the Text2SQL task to convert the query statement into initial SQL; The query question is parsed by calling the Large Language Model (LLM) to determine the time entity, and the time expression of the rule format corresponding to the time entity is determined based on the association between the time entity and the time expression of the rule format in the preset knowledge base. The initial time expression in the SQL is replaced with a time expression in a rule format corresponding to the time entity to obtain semantic SQL.

8. The system according to claim 7, characterized in that, The semantic SQL determination unit further includes: The Euclidean distance system is used to retrieve the time expression in the preset knowledge base that corresponds to the time entity in a rule format. When it is determined that no time expression exists, the non-existent knowledge is recorded and the preset knowledge base is updated.

9. The system according to claim 6, characterized in that, The time correction unit is further configured to: No time correction is performed when the semantic SQL does not contain a time expression.

10. The system according to claim 6, characterized in that, The query SQL determining unit corrects the information of the modified semantic SQL and converts the modified semantic SQL into executable query SQL, including: The indicator information and dimension information in the corrected semantic SQL are determined, and the indicator information and dimension information are replaced with actual SQL field information and parsed to convert the corrected semantic SQL into executable query SQL.

Citation Information

Patent Citations

  • NL2SQL method based on LLM multi-table adaptive selection

    CN117112732A

  • Natural language conversion method and system oriented to time sequence database

    CN118780247A