Method and system for converting progressive natural language into structured query language

By extracting knowledge units from historical query logs and using a large language model for reasoning, a progressive translation system is constructed. This solves the problems of adaptability and human dependence in existing translation methods, and achieves efficient and flexible translation from natural language to structured query language.

CN120994697APending Publication Date: 2025-11-21FUDAN UNIVERSITY +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510997206.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-18
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing translation methods from natural language to structured query language lack long-term memory and self-evolution capabilities, making them unable to adapt to complex application scenarios. Furthermore, their reliance on manual annotation and model fine-tuning limits the effectiveness of translation.

Method used

By extracting knowledge units from historical translation logs, filtering and piecing them together, and using a large language model for reasoning, a progressive translation system is built, reducing human intervention and achieving self-evolution and optimization.

Benefits of technology

It improves translation accuracy and flexibility, reduces reliance on manual labor, enhances query efficiency and user experience, and adapts to changing needs in different application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994697A_ABST
    Figure CN120994697A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for converting a progressive natural language into a structured query language. The method comprises the following steps: acquiring a historical structured query statement from a collected historical query translation log; performing natural language annotation on the obtained historical structured query statement to construct knowledge unit blocks; screening the constructed knowledge unit blocks to obtain a knowledge unit data set; acquiring newly input natural language query data, and searching knowledge unit blocks matched with the natural language query data from the knowledge unit data set; splicing the natural language query data and the matched knowledge unit blocks, and constructing context prompt words; and reasoning the context cue word based on a large language model, and translating the natural language query data into a structured query language. The experience of historical translation results is dynamically accumulated and reused, the translation ability is continuously optimized, the manual dependence is reduced, the flexibility and adaptability are enhanced, and the query accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of natural language processing and database query technology, targeting scenarios where non-technical users acquire complex structured data, and particularly to a method and system for progressively converting natural language into a structured query language. Background Technology

[0002] With the continuous expansion of data systems and the increasing demand for information technology, structured databases have become a key information storage medium. To analyze and retrieve data from these databases, the traditional approach relies on users manually writing structured query languages ​​(SQL) to access the database. While effective, this method places a high professional barrier on users, making it difficult for ordinary users without a technical background to directly write correct query languages ​​to perform complex queries on the database.

[0003] In recent years, translation technology from natural language to structured query language has received widespread attention. Methods based on large language models have become the mainstream approach due to their strong language understanding and reasoning capabilities. However, most existing methods employ static strategies for translating database query language. Each translation from natural language to structured query language is performed independently, lacking long-term memory and self-evolution capabilities. They cannot accumulate knowledge to optimize subsequent translation processes, nor can they continuously optimize based on user feedback and historical translation experience, thus limiting further improvements in translation quality. The reliance on manual annotation or model fine-tuning also makes existing methods ill-suited for dynamically changing real-world application environments. Summary of the Invention

[0004] To address the aforementioned issues, this invention provides a method and system for progressive natural language to structured query language translation, aiming to solve the problem that current static translation methods for natural language to structured query language cannot adapt to complex application scenarios.

[0005] A progressive approach to converting natural language to a structured query language includes:

[0006] Step A1: Obtain historical structured query statements from the collected historical query translation logs;

[0007] Step A2: Perform natural language annotation on the obtained historical structured query statements to construct knowledge unit blocks;

[0008] Step A3: Filter the constructed knowledge unit blocks to obtain the knowledge unit dataset;

[0009] Step A4: Obtain the newly input natural language query data and search for knowledge unit blocks that match the natural language query data from the knowledge unit dataset;

[0010] Step A5: Concatenate the natural language query data and the matched knowledge unit blocks to construct contextual prompts;

[0011] Step A6 involves reasoning about contextual prompts based on a large language model to translate the natural language query data into a structured query language.

[0012] Furthermore, step A2 includes:

[0013] Step A21: Decompose the historical structured query statement into multiple subquery fragments;

[0014] Step A22: Perform natural language annotation on each subquery segment;

[0015] Step A23: Package the subquery fragment and its corresponding natural language annotation into a knowledge unit block.

[0016] Furthermore, step A3 includes:

[0017] Step A31: Execute the subquery fragment in the knowledge unit block to obtain the first query result;

[0018] Step A32: Filter the knowledge unit blocks based on the first query result of the subquery fragment to obtain a set of candidate knowledge units;

[0019] Step A33: Calculate the confidence score of the knowledge unit block in the candidate knowledge unit set based on the constructed confidence scoring model;

[0020] Step A34: Select knowledge unit blocks with confidence scores higher than the confidence threshold and construct a knowledge unit dataset.

[0021] Furthermore, step A4 includes:

[0022] Step A41: Convert the natural language query data into first vectorized features, and convert the natural language annotations of knowledge unit blocks in the knowledge unit dataset into second vectorized features.

[0023] Step A42: Calculate the semantic similarity between the first vectorized feature and the second vectorized feature;

[0024] Step A43: Obtain knowledge unit blocks that match the natural language query data based on semantic similarity.

[0025] Furthermore, the database to be queried has a database description file;

[0026] Step A6 includes:

[0027] Step A61: Obtain the historical query translation logs corresponding to the knowledge unit blocks in the context prompts as context corpus;

[0028] Step A62: The large language model infers the context prompts based on the context corpus and the description file of the database, and generates multiple candidate structured query statements.

[0029] Step A63: Execute the candidate structured query statement in the database to obtain the second query result;

[0030] Step A64: Based on the second query result, the large language model selects the final structured query statement from the candidate structured query statements, which serves as the translation result of the structured query language translation of the natural language query data.

[0031] A system for progressive natural language to structured query language conversion, for executing the aforementioned method for progressive natural language to structured query language conversion, includes:

[0032] The data parsing module is used to obtain historical structured query statements from the collected historical query translation logs;

[0033] The knowledge construction module, connected to the data parsing module, is used to annotate the acquired historical structured query statements with natural language in order to construct knowledge unit blocks.

[0034] The knowledge filtering module, connected to the knowledge construction module, is used to filter the constructed knowledge unit blocks to obtain a knowledge unit dataset.

[0035] The data input module is used to acquire newly input natural language query data;

[0036] The knowledge matching module connects to the data input module and the knowledge filtering module, and is used to find knowledge unit blocks that match the natural language query data from the knowledge unit dataset.

[0037] The prompt word generation module is connected to the data input module and the knowledge matching module respectively. It is used to concatenate natural language query data and matched knowledge unit blocks to construct context prompt words.

[0038] The translation execution module connects to the prompt word generation module and is used to reason about context prompt words based on a large language model, translating natural language query data into structured query statements.

[0039] Furthermore, the knowledge building module includes:

[0040] Statement decomposition unit, used to decompose historical structured query statements into multiple subquery fragments;

[0041] The fragment annotation unit and the connected statement decomposition unit are used to provide natural language annotations for each subquery fragment.

[0042] The knowledge forming unit connects the fragment annotation unit, packaging the subquery fragment and its corresponding natural language annotation into a knowledge unit block.

[0043] Furthermore, the knowledge filtering module includes:

[0044] The fragment query unit is used to execute subquery fragments within a knowledge unit block in the database to obtain the first query result;

[0045] The knowledge filtering unit, connected to the fragment query unit, is used to filter knowledge unit blocks based on the first query result of the subquery fragment to obtain a set of candidate knowledge units;

[0046] The confidence calculation unit, connected to the knowledge filtering unit, is used to calculate the confidence score of knowledge unit blocks in the candidate knowledge unit set based on the constructed confidence scoring model.

[0047] The knowledge set unit, connected to the confidence calculation unit, is used to filter out knowledge unit blocks with confidence scores higher than the confidence threshold and construct a knowledge unit dataset.

[0048] Furthermore, the knowledge matching module includes:

[0049] Vectorization units are used to convert natural language query data into first vectorized features and to convert natural language annotations of knowledge unit blocks in the knowledge unit dataset into second vectorized features.

[0050] The similarity calculation unit, connected to the vectorization unit, is used to calculate the semantic similarity between the first vectorized feature and the second vectorized feature;

[0051] The matching result unit connects to the similarity calculation unit and is used to obtain knowledge unit blocks that match natural language query data based on semantic similarity.

[0052] Furthermore, the database to be queried has a database description file;

[0053] The translation execution module includes:

[0054] The corpus extraction unit is used to obtain historical query translation logs corresponding to knowledge unit blocks in context prompt words as context corpus;

[0055] The preliminary reasoning unit, connected to the corpus capture unit, is used by the large language model to reason about contextual prompts based on contextual corpus and database description files, generating multiple candidate structured query languages;

[0056] The query execution unit, connected to the preliminary reasoning unit, is used to execute candidate structured query statements in the database to obtain the second query result;

[0057] The result determination unit connects to the query execution unit. Based on the second query result, the large language model selects the final structured query statement from the candidate structured query statements, which serves as the translation result of the structured query language translation of the natural language query data.

[0058] This invention provides a progressive natural language to database query translation method with self-evolution capabilities. It can automatically convert user-input natural language into structured query language for a database, and has the ability to learn from historical translation results, dynamically accumulate and reuse experience from historical translation results, and continuously optimize translation capabilities. Compared to existing static strategies, its beneficial technical effects are as follows:

[0059] Continuous optimization of translation results: This invention learns effective knowledge from historical translation results, enabling dynamic adjustment and optimization of natural language translation into structured query language. This means that as the number of uses increases and the amount of data grows, the system's translation accuracy will gradually improve.

[0060] Reduced reliance on manual intervention: Traditional methods typically require large amounts of manually labeled data to train models, and may also require regular manual maintenance after deployment to adapt to new language expressions or changes in domain-specific needs. In contrast, the method of this invention eliminates the need for manual annotation and model fine-tuning, greatly reducing reliance on manual operations and lowering labor costs and technical barriers.

[0061] Enhanced flexibility and adaptability: Thanks to its self-evolution mechanism, this invention can quickly adapt to changing needs in different application scenarios without altering the core algorithm. Whether facing emerging industry terminology or unique user query habits, the system can flexibly respond and provide accurate SQL translations.

[0062] Improved query efficiency and user experience: Thanks to higher translation accuracy, users of this invention can obtain the data query results they need more quickly, reducing time wastage and repetitive work caused by incorrect queries. This not only improves work efficiency but also enhances the overall user experience. Attached Figure Description

[0063] Figures 1-5 This is a flowchart illustrating the steps of a method for progressive natural language to structured query language according to the present invention.

[0064] Figures 6-10 This is a schematic diagram of the modules of a system for progressive natural language to structured query language according to the present invention. Detailed Implementation

[0065] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0066] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other.

[0067] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, but this is not intended to limit the scope of the invention.

[0068] See Figure 1 This invention provides a method for progressive natural language to structured query language, comprising:

[0069] Step A1: Obtain historical structured query statements from the collected historical query translation logs;

[0070] Step A2: Perform natural language annotation on the obtained historical structured query statements to construct knowledge unit blocks;

[0071] Step A3: Filter the constructed knowledge unit blocks to obtain the knowledge unit dataset;

[0072] Step A4: Obtain the newly input natural language query data and search for knowledge unit blocks that match the natural language query data from the knowledge unit dataset;

[0073] Step A5: Concatenate the natural language query data and the matched knowledge unit blocks to construct contextual prompts;

[0074] Step A6 involves reasoning about contextual prompts based on a large language model to translate the natural language query data into a structured query language.

[0075] This invention utilizes an online reflection and knowledge generation mechanism to automatically learn effective knowledge from historical translation results. This enables dynamic adjustment and optimization of natural language translation into structured query language, constructing a continuously learning, automated translation system that requires no human intervention. This means that the system's translation accuracy will gradually improve with increased usage and data volume. The method eliminates the need for manual annotation and model fine-tuning, significantly reducing reliance on manual operations and lowering labor costs and technical barriers. The self-evolving translation mechanism can quickly adapt to changing needs in different application scenarios without altering the core algorithm. Whether facing emerging industry terminology or unique user query habits, the system can flexibly respond and provide accurate SQL translations. Users of this invention can obtain the required data query results faster, reducing time wasted and repetitive work due to erroneous queries. This not only improves work efficiency but also enhances the overall user experience.

[0076] In step A1, the correct historical query translation log contains domain-specific information about the database, which can serve as supplementary information to provide effective guidance for the subsequent translation process. Domain-specific information refers to the data types, structures, and related rules and restrictions managed by this database, i.e., the database description file.

[0077] In step A1, reusable and successfully executable historical structured query languages ​​are obtained from the collected historical query translation logs.

[0078] See Figure 2 Furthermore, step A2 includes:

[0079] Step A21: Decompose the historical structured query statement into multiple subquery fragments;

[0080] Step A22: Perform natural language annotation on each subquery segment;

[0081] Step A23: Package the subquery fragment and its corresponding natural language annotation into a knowledge unit block.

[0082] Step A1 includes extracting historical structured query statements from historical query translation logs, removing semantic duplicates from the historical structured query statements, executing the historical structured query statements in the database to obtain query execution results, clustering the historical structured query statements based on the query execution results, selecting representative historical structured query statements from each cluster, eliminating redundant and erroneous statements, and forming a set of historical structured query statements. Then, in step A2, natural language annotations are applied to the historical structured query statements in the set to construct knowledge unit blocks. In step A2, a nested chained reasoning strategy is used to annotate the acquired historical structured query language with natural language to construct knowledge unit blocks. The nested chained reasoning strategy consists of nested inner and outer reasoning chains.

[0083] Specifically, in step A21, the outer reasoning chain is used to decompose the complete historical structured query language from top to bottom into multiple subquery fragments with independent semantic functions, ensuring that each subquery fragment has complete semantic information.

[0084] Specifically, in step A22, the inner inference chain is used to generate a natural language explanation for each subquery fragment that can describe its operational intent, forming a human-readable semantic annotation, i.e., the natural language annotation corresponding to the subquery fragment. The natural language annotation focuses on explaining the purpose and semantic meaning of the operation, and explicitly requires the annotation stage to pay attention to the semantic drift of the database query statement caused by the aggregation operation.

[0085] By using step-by-step reasoning to construct a complete chain of thought, the continuity and interpretability of reasoning are ensured.

[0086] Specifically, in step A23, each pair of subquery fragments and its natural language annotation are packaged into a knowledge unit block, and all knowledge unit blocks are treated as atomic semantic fragments.

[0087] See Figure 3 Furthermore, step A3 includes:

[0088] Step A31: Execute the subquery fragment in the knowledge unit block to obtain the first query result;

[0089] Step A32: Filter the knowledge unit blocks based on the first query result of the subquery fragment to obtain a set of candidate knowledge units;

[0090] Step A33: Calculate the confidence score of the knowledge unit block in the candidate knowledge unit set based on the constructed confidence scoring model;

[0091] Step A34: Select knowledge unit blocks with confidence scores higher than the confidence threshold and construct a knowledge unit dataset.

[0092] Step A3 mainly involves quality screening of knowledge unit blocks, discarding knowledge units with semantic errors or ambiguity, and ensuring that only semantically valid, correctly executed, and transferable knowledge unit blocks are used for subsequent example selection and subsequent translation tasks.

[0093] In step A32, semantic clustering and deduplication are mainly performed based on the first query result. The first query result of the subquery fragments of each knowledge unit block is compared with the first query result of the database. Knowledge units with empty first query results are deleted. Among multiple subquery fragments with the same first query result, one subquery fragment is selected as the representative and the rest are deleted to reduce redundancy and obtain a candidate knowledge unit set, that is, the consistency check of the first query result is performed.

[0094] The reliability and generalization ability of the generated knowledge unit blocks are evaluated. The structured query statements in each knowledge unit block are executed and validated in the target database. Then, low-quality knowledge unit blocks are filtered out, and only high-quality knowledge unit blocks are retained to form a knowledge unit dataset, which is then stored.

[0095] Specifically, the confidence scoring model employs a probability-based filtering mechanism, constructed based on the feasibility of executing the structured query, the completeness of its semantic information, and its degree of matching with the original query intent. The model generates a confidence score for each knowledge unit block. Based on a set confidence threshold, knowledge unit blocks with confidence scores below the threshold are filtered out, retaining only those with high confidence to form the knowledge unit dataset and store it.

[0096] See Figure 4 Furthermore, step A4 includes:

[0097] Step A41: Convert the natural language query data into first vectorized features, and convert the natural language annotations of knowledge unit blocks in the knowledge unit dataset into second vectorized features.

[0098] Step A42: Calculate the semantic similarity between the first vectorized feature and the second vectorized feature;

[0099] Step A43: Obtain knowledge unit blocks that match the natural language query data based on semantic similarity.

[0100] Both the user-input natural language query data and the natural language annotations in the knowledge unit dataset are embedded (i.e., both are vectorized). Then, the cosine similarity between the input natural language query data and the natural language annotations of different knowledge units is calculated using vectors as the semantic similarity. The top-K most relevant knowledge unit blocks are selected as the knowledge unit blocks that match the natural language query data.

[0101] The high-quality knowledge unit blocks selected by the confidence score have high semantic accuracy and execution reliability. Based on the calculation of semantic similarity, the most semantically relevant knowledge unit blocks in the knowledge unit dataset are dynamically selected as examples. By introducing these examples and adopting a context learning strategy, the structured knowledge of specific database domains can be added to the large language model, effectively guiding the large language model to generate database query language that is semantically aligned with the database, thus forming a knowledge-enhanced translation of natural language query data.

[0102] In step A41, the semantic embedding model is used to vectorize the natural language query data given by the user and the natural language annotation of the knowledge unit block is vectorized. In step A42, the vector retrieval engine is used to retrieve the knowledge unit blocks in the knowledge unit dataset and calculate the cosine similarity with the vector representation of the natural language query data in turn. This cosine similarity is used as the semantic similarity, and the Top-K examples with the most semantic similarity are selected.

[0103] See Figure 5 Furthermore, the database to be queried has a database description file;

[0104] Step A6 includes:

[0105] Step A61: Obtain the historical query translation logs corresponding to the knowledge unit blocks in the context prompts as context corpus;

[0106] Step A62: The large language model infers the context prompts based on the context corpus and the description file of the database, and generates multiple candidate structured query statements.

[0107] Step A63: Execute the candidate structured query statement in the database to obtain the second query result;

[0108] Step A64: Based on the second query result, the large language model selects the final structured query statement from the candidate structured query statements, which serves as the translation result of the structured query language translation of the natural language query data.

[0109] Specifically, the database description file includes information such as table names, field names, field types, primary keys, and foreign keys.

[0110] K examples selected based on semantic similarity are concatenated with the natural language query data to be executed to form contextual prompts, which are then input into a large language model for inference. The natural language query data is translated into structured database query language by utilizing the language understanding and generation capabilities built into the large language model.

[0111] The output of large language models is unstable. To improve the accuracy of translation results, this method implements a multi-path generation strategy, which generates multiple candidate structured query statements for a natural language query, executes the generated candidate statements in the database, and selects the final output based on the execution result, i.e., the second query result, using a consensus voting mechanism.

[0112] Candidate queries are filtered through execution verification and consistency voting mechanisms, using indicators such as consistency of execution query results and self-explanatory completeness to select the final structured query. The final output is the structured query language that best matches the user's intent, serving as the final translation of the natural language query data.

[0113] Specifically, in step A6, you can either directly return only the translated final structured query statement, or you can directly execute the final structured query statement in the database and return the query results to the user, thus achieving end-to-end natural language database access capabilities.

[0114] This invention exhibits stable execution performance during the structured query generation stage. Through a "reflection and knowledge accumulation" strategy, it fully leverages historical translation results for learning, continuously improving its translation capabilities. As a plug-and-play component, it offers strong operability in unfamiliar real-world database scenarios and automatically expands and updates the knowledge unit dataset based on continuously accumulated translation history without manual annotation or model fine-tuning, constantly optimizing query translation quality. During operation, users simply express their query intent using natural language. The system dynamically selects the knowledge unit block that best matches the input semantics from the knowledge unit dataset based on the current database description file, driving the large language model to generate high-quality structured query statements.

[0115] See Figure 6 The present invention also provides a system for progressive natural language to structured query language conversion, for executing the aforementioned method for progressive natural language to structured query language conversion, comprising:

[0116] The data parsing module (1) is used to obtain historical structured query statements from the collected historical query translation logs;

[0117] The knowledge construction module (2) is connected to the data parsing module (1) and is used to annotate the obtained historical structured query statements with natural language in order to construct knowledge unit blocks.

[0118] The knowledge filtering module (3) is connected to the knowledge construction module (2) and is used to filter the constructed knowledge unit blocks to obtain the knowledge unit dataset.

[0119] The data input module (4) is used to obtain newly input natural language query data;

[0120] The knowledge matching module (5) is connected to the data input module (4) and the knowledge filtering module (3) respectively, and is used to find knowledge unit blocks that match the natural language query data from the knowledge unit dataset;

[0121] The prompt word generation module (6) is connected to the data input module (4) and the knowledge matching module (5) respectively. It is used to concatenate the natural language query data and the matched knowledge unit blocks to construct context prompt words.

[0122] The translation execution module (7) and the prompt word generation module (6) are used to reason about the context prompt words based on the large language model and translate the natural language query data into a structured query statement.

[0123] This invention utilizes an online reflection and knowledge generation mechanism to automatically learn effective knowledge from historical translation results. This enables dynamic adjustment and optimization of natural language translation into structured query language, constructing a continuously learning, automated translation system that requires no human intervention. This means that the system's translation accuracy will gradually improve with increased usage and data volume. The method eliminates the need for manual annotation and model fine-tuning, significantly reducing reliance on manual operations and lowering labor costs and technical barriers. The self-evolving translation mechanism can quickly adapt to changing needs in different application scenarios without altering the core algorithm.

[0124] join Figure 7 Furthermore, the knowledge building module (2) includes:

[0125] The statement decomposition unit (21) is used to decompose the historical structured query statement into multiple subquery fragments;

[0126] The fragment annotation unit (22) and the connection statement decomposition unit (21) are used to perform natural language annotations on each subquery fragment;

[0127] The knowledge forming unit (23) connects the fragment annotation unit (22) and packages the subquery fragment and the corresponding natural language annotation into a knowledge unit block.

[0128] A nested chain reasoning strategy is employed to annotate the acquired historical structured query language with natural language to construct knowledge unit blocks. The nested chain reasoning strategy consists of nested inner and outer reasoning chains.

[0129] The outer reasoning chain is used to decompose the complete historical structured query language from top to bottom into multiple subquery fragments with independent semantic functions, ensuring that each subquery fragment has complete semantic information.

[0130] The inner reasoning chain generates a natural language explanation for each subquery fragment, illustrating its operational intent, thus forming a human-readable semantic annotation—the natural language annotation corresponding to the subquery fragment. A complete thought chain is constructed using step-by-step reasoning to ensure the continuity and interpretability of the reasoning.

[0131] Each pair of subquery fragments and its natural language annotation are packaged into a knowledge unit block, and all knowledge unit blocks are treated as atomic semantic fragments.

[0132] join Figure 8 Furthermore, the knowledge filtering module (3) includes:

[0133] The fragment query unit (31) is used to execute the subquery fragment in the knowledge unit block in the database to obtain the first query result;

[0134] The knowledge filtering unit (32) and the connection fragment query unit (31) are used to filter the knowledge unit blocks according to the first query result of the subquery fragment to obtain a set of candidate knowledge units.

[0135] The confidence calculation unit (33) is connected to the knowledge filtering unit (32) and is used to calculate the confidence score of the knowledge unit block in the candidate knowledge unit set based on the constructed confidence scoring model;

[0136] The knowledge set unit (34) is connected to the confidence calculation unit (33) to filter out knowledge unit blocks with confidence scores higher than the confidence threshold and construct a knowledge unit dataset.

[0137] The knowledge filtering module (3) mainly performs quality filtering on knowledge unit blocks, discarding knowledge units with semantic errors or semantic ambiguity, and ensuring that only knowledge unit blocks that are semantically valid, execute correctly and have transferability are used for subsequent example selection and subsequent translation tasks.

[0138] The knowledge filtering unit (32) mainly performs semantic clustering and deduplication based on the first query result, compares the first query result of the subquery fragments of each knowledge unit block with the first query result of the database, deletes knowledge units with empty first query results, selects one subquery fragment as a representative from multiple subquery fragments with the same first query result, deletes the remaining subquery fragments to reduce redundancy, and obtains a candidate knowledge unit set, that is, performs a consistency check of the first query result.

[0139] Based on the set confidence threshold, knowledge unit blocks with confidence levels below the threshold are filtered out, and only knowledge unit blocks with high confidence levels are retained to form a knowledge unit dataset and store it.

[0140] join Figure 9 Furthermore, the knowledge matching module (5) includes:

[0141] Vectorization unit (51) is used to convert natural language query data into first vectorized features and convert natural language annotations of knowledge unit blocks in knowledge unit dataset into second vectorized features.

[0142] The similarity calculation unit (52) is connected to the vectorization unit (51) for calculating the semantic similarity between the first vectorized feature and the second vectorized feature;

[0143] The matching result unit (53) connects to the similarity calculation unit (52) and is used to obtain knowledge unit blocks that match natural language query data based on semantic similarity.

[0144] Both the user-input natural language query data and the natural language annotations in the knowledge unit dataset are embedded (i.e., both are vectorized). Then, the cosine similarity between the input natural language query data and the natural language annotations of different knowledge units is calculated using vectors as the semantic similarity. The top-K most relevant knowledge unit blocks are selected as the knowledge unit blocks that match the natural language query data.

[0145] join Figure 10 Furthermore, the database to be queried has a database description file;

[0146] Translation execution module (7) includes:

[0147] Corpus extraction unit (71) is used to obtain the historical query translation logs corresponding to the knowledge unit blocks in the context prompt words as context corpus;

[0148] The preliminary reasoning unit (72) is connected to the corpus capture unit (71), which is used by the large language model to reason about the context prompt words based on the context corpus and the description file of the database, and to generate multiple candidate structured query languages.

[0149] The query execution unit (73) is connected to the preliminary reasoning unit (72) and is used to execute candidate structured query statements in the database to obtain the second query result;

[0150] The result determination unit (74) is connected to the query execution unit (73). The large language model selects the final structured query statement from the candidate structured query statements based on the second query result, which is used as the translation result of the structured query language translation of the natural language query data.

[0151] Specifically, the database description file includes information such as table names, field names, field types, primary keys, and foreign keys.

[0152] The output of large language models is unstable. To improve the accuracy of translation results, this method implements a multi-path generation strategy, which generates multiple candidate structured query statements for a natural language query, executes the generated candidate statements in the database, and selects the final output based on the execution result, i.e., the second query result, using a consensus voting mechanism.

[0153] Candidate queries are filtered through execution verification and consistency voting mechanisms, using indicators such as consistency of execution query results and self-explanatory completeness to select the final structured query. The final output is the structured query language that best matches the user's intent, serving as the final translation of the natural language query data.

[0154] This invention performs knowledge parsing and verification on natural language input, ultimately providing knowledge-enhanced query language translation. Without introducing manual costs, it possesses the ability to automatically accumulate and learn domain knowledge. By guiding a large language model to perform semantically enhanced reasoning, it gradually improves translation accuracy in complex query scenarios. Experiments on multiple public datasets have verified that this invention can improve the accuracy of complex query tasks and possesses sustainable learning and plug-and-play characteristics. It exhibits particularly strong stability in challenging translation tasks and is applicable to complex real-world database query scenarios.

[0155] The above are merely preferred embodiments of the present invention and are not intended to limit the implementation methods and protection scope of the present invention. Those skilled in the art should recognize that any equivalent substitutions and obvious changes made based on the description and illustrations of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for progressively converting natural language to structured query language, characterized in that, include: Step A1: Obtain historical structured query statements from the collected historical query translation logs; Step A2: Perform natural language annotation on the obtained historical structured query statements to construct knowledge unit blocks; Step A3: Filter the constructed knowledge unit blocks to obtain a knowledge unit dataset; Step A4: Obtain newly input natural language query data, and search for the knowledge unit block that matches the natural language query data from the knowledge unit dataset; Step A5: Concatenate the natural language query data and the matched knowledge unit blocks to construct contextual prompts; Step A6: Based on the large language model, reason about the contextual prompts and translate the natural language query data into a structured query language.

2. The method for progressive natural language to structured query language as described in claim 1, characterized in that, Step A2 includes: Step A21: Decompose the historical structured query statement into multiple sub-query fragments; Step A22: Perform natural language annotation on each of the subquery segments; Step A23: Package the subquery fragment and the corresponding natural language annotation into a knowledge unit block.

3. The method for progressive natural language to structured query language as described in claim 1, characterized in that, Step A3 includes: Step A31: Execute the sub-query fragment in the knowledge unit block to obtain the first query result; Step A32: Filter the knowledge unit block according to the first query result of the subquery fragment to obtain a candidate knowledge unit set; Step A33: Calculate the confidence score of the knowledge unit block in the candidate knowledge unit set based on the constructed confidence scoring model; Step A34: Select the knowledge unit blocks whose confidence scores are higher than the confidence threshold, and construct the knowledge unit dataset.

4. The method for progressive natural language to structured query language as described in claim 1, characterized in that, Step A4 includes: Step A41: Convert the natural language query data into a first vectorized feature, and convert the natural language annotations of the knowledge unit blocks in the knowledge unit dataset into a second vectorized feature; Step A42: Calculate the semantic similarity between the first vectorized feature and the second vectorized feature; Step A43: Obtain the knowledge unit block that matches the natural language query data based on the semantic similarity.

5. The method for progressive natural language to structured query language as described in claim 1, characterized in that, The database to be queried has a database description file; Step A6 includes: Step A61: Obtain the historical query translation log corresponding to the knowledge unit block in the context prompt words as context corpus; Step A62: The large language model infers the context prompt words based on the context corpus and the description file of the database, and generates multiple candidate structured query statements; Step A63: Execute the candidate structured query statement in the database to obtain the second query result; Step A64: The large language model selects the final structured query statement from the candidate structured query statements based on the second query result, and uses it as the translation result of the structured query language translation of the natural language query data.

6. A system for progressive natural language to structured query language, characterized in that, A method for performing a progressive natural language to structured query language as described in any one of claims 1-5, comprising: The data parsing module is used to obtain historical structured query statements from the collected historical query translation logs; The knowledge construction module, connected to the data parsing module, is used to perform natural language annotation on the acquired historical structured query statements to construct knowledge unit blocks. The knowledge filtering module, connected to the knowledge construction module, is used to filter the constructed knowledge unit blocks to obtain a knowledge unit dataset; The data input module is used to acquire newly input natural language query data; The knowledge matching module is connected to the data input module and the knowledge filtering module respectively, and is used to find the knowledge unit block that matches the natural language query data from the knowledge unit dataset. The prompt word generation module is connected to the data input module and the knowledge matching module respectively, and is used to concatenate the natural language query data and the matched knowledge unit blocks to construct context prompt words; The translation execution module, connected to the prompt word generation module, is used to reason about the context prompt words based on a large language model and translate the natural language query data into a structured query statement.

7. The system for progressive natural language to structured query language as described in claim 6, characterized in that, The knowledge construction module includes: The statement decomposition unit is used to decompose the historical structured query statement into multiple subquery fragments; The fragment annotation unit, connected to the statement decomposition unit, is used to perform natural language annotation on each of the subquery fragments; The knowledge forming unit connects to the fragment annotation unit and packages the subquery fragment and the corresponding natural language annotation into a knowledge unit block.

8. The system for progressive natural language to structured query language as described in claim 6, characterized in that, The knowledge filtering module includes: The fragment query unit is used to execute the sub-query fragment in the knowledge unit block in the database to obtain the first query result; A knowledge filtering unit, connected to the segment query unit, is used to filter the knowledge unit block based on the first query result of the sub-query segment to obtain a candidate knowledge unit set. A confidence calculation unit, connected to the knowledge filtering unit, is used to calculate the confidence score of the knowledge unit block in the candidate knowledge unit set based on the constructed confidence scoring model; The knowledge set unit, connected to the confidence calculation unit, is used to filter out knowledge unit blocks whose confidence scores are higher than the confidence threshold, and construct the knowledge unit dataset.

9. A system for progressive natural language to structured query language as described in claim 6, characterized in that, The knowledge matching module includes: A vectorization unit is used to convert the natural language query data into a first vectorized feature and to convert the natural language annotations of the knowledge unit blocks in the knowledge unit dataset into a second vectorized feature. A similarity calculation unit, connected to the vectorization unit, is used to calculate the semantic similarity between the first vectorized feature and the second vectorized feature; The matching result unit, connected to the similarity calculation unit, is used to obtain the knowledge unit block that matches the natural language query data based on the semantic similarity.

10. A system for progressive natural language to structured query language as described in claim 6, characterized in that, The database to be queried has a database description file; The translation execution module includes: The corpus extraction unit is used to obtain the historical query translation logs corresponding to the knowledge unit blocks in the context prompt words as context corpus; The preliminary reasoning unit, connected to the corpus capture unit, is used by the large language model to reason about the context prompt words based on the context corpus and the description file of the database, and to generate multiple candidate structured query languages; The query execution unit, connected to the preliminary reasoning unit, is used to execute the candidate structured query statement in the database to obtain the second query result; The result determination unit is connected to the query execution unit. The large language model selects the final structured query statement from the candidate structured query statements based on the second query result, which serves as the translation result of the structured query language translation of the natural language query data.

Citation Information

Cited By

  • Text-to-structured query implementation method and device and storage medium

    CN121579509A