A large model-based natural language to SQL conversion method and system

By using an invertible semantic mask tensor with explicit mask bits and implicit semantic embedding, and a differential distillation caching mechanism, the problem of database schema awareness and generalized reasoning in zero-sample or low-resource environments is solved, achieving efficient and accurate natural language to SQL conversion and supporting seamless adaptation to database structure changes.

CN120849451BActive Publication Date: 2026-01-27STATE GRID SICHUAN ELECTRIC POWER CO TIANFU NEW DISTRICT POWER SUPPLY CO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511357543.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-23
Publication Date
2026-01-27
Estimated Expiration
2045-09-23

AI Technical Summary

Technical Problem

Existing technologies struggle to build semantic representation mechanisms that can both explicitly perceive the database schema and perform generalized reasoning without schema assumptions in zero-sample or low-resource environments. This results in weak cross-database generalization capabilities and difficulty in generating high-quality SQL in diverse and complex scenarios.

Method used

A reversible semantic mask tensor with explicit mask bits and implicit semantic embedding is adopted, combined with a differential distillation caching mechanism. The dynamic switching between schema-aware and schema-agnostic states is achieved by switching mask bits. The closed-loop self-optimization process is driven by structural feedback signals to achieve seamless migration and efficient updating of semantic states.

Benefits of technology

It enables seamless migration and efficient adaptation when the database structure changes, improves cross-database generalization ability and SQL generation accuracy, reduces storage and computing overhead, and supports semantic state iteration updates without human intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120849451B_ABST
    Figure CN120849451B_ABST
Patent Text Reader

Abstract

The application discloses a natural language to SQL conversion method and system based on a large model, and comprises the following steps: constructing a reversible semantic mask tensor which simultaneously carries an explicit mask bit and an implicit semantic embedding; binding a differential distillation cache for the reversible semantic mask tensor; performing schema-agnostic semantic projection on the natural language query through the reversible semantic mask tensor with the mask bit being 0; switching the reversible semantic mask tensor to a schema-aware state according to a gradient difference vector provided by the differential distillation cache, and generating a structure-sensitive SQL output; converting the generated SQL execution result into a structure feedback signal and writing back as a new feedback difference vector; when the database structure signature changes, only extending the mask bit length of the reversible semantic mask tensor, and calling the differential distillation cache to perform local differential correction; and issuing a unified mask control instruction to the reversible semantic mask tensor. The application solves the technical problem of how to construct a schema-aware and schema-agnostic semantic representation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a method and system for converting natural language to SQL based on a large model. Background Technology

[0002] Against the backdrop of the rapid development of large-scale model-driven natural language processing technology in recent years, the automatic conversion of natural language to structured query language (SQL) has gradually become a key technical path in intelligent database interfaces, conversational query systems, and low-code development platforms. Traditional methods, which mainly rely on manual feature mapping, template matching, or rule systems, are no longer sufficient to cope with real-world application scenarios where semantic diversity and database structure complexity coexist.

[0003] With breakthroughs in semantic understanding achieved by pre-trained language models, an increasing number of studies are attempting to leverage large models for deep modeling of natural language and combine this with database structural information (i.e., schema) to achieve high-quality SQL generation. However, in practical deployments, the problem of weak cross-database generalization ability remains unresolved due to the highly variable structure of data tables. Especially in zero-shot or low-resource environments, models often lack robust reasoning ability for unknown schemas.

[0004] Existing solutions generally face two conflicting modeling requirements: on the one hand, the model needs to accurately understand the database schema and complete fine-grained field-level matching (i.e., schema-aware); on the other hand, in order to have cross-database generalization capabilities, it is necessary to maintain a certain degree of abstraction and ignoring of the schema in the initial stage (i.e., schema-agnostic). There is still a lack of systematic modeling mechanisms for the conversion between these two semantic states and their impact on the quality of downstream SQL generation.

[0005] Therefore, the current core technical problem is: how to construct a semantic representation mechanism that can both explicitly perceive the database schema and perform generalized reasoning without schema assumptions, that is, how to construct a schema-aware and schema-agnostic semantic representation. Summary of the Invention

[0006] To address the above problems, this invention provides a method and system for converting natural language to SQL based on a large model.

[0007] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0008] On one hand, this invention discloses a natural language to SQL conversion method based on a large model, including:

[0009] Step 1: Construct an invertible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset.

[0010] Step 2: Bind a differential distillation cache to the reversible semantic mask tensor, and only record the gradient difference vector generated by each mask state switch;

[0011] Step 3: Perform schema-agnostic semantic projection on the natural language query using an invertible semantic mask tensor with a mask bit of 0, and generate a structure-independent candidate SQL sketch as a generalization reference.

[0012] Step 4: Based on the gradient difference vector provided by the differential distillation cache, switch the invertible semantic mask tensor to schema-aware state, and generate structure-sensitive SQL output by injecting mask control instructions;

[0013] Step 5: Convert the generated SQL execution result into a structured feedback signal, write it back as a new feedback differential vector, and append it to the differential distillation cache;

[0014] Step 6: When the database structure signature is modified by adding or deleting fields or changing the relationship between tables, only the mask bit length of the reversible semantic mask tensor is extended, and the differential distillation cache is called for local differential correction.

[0015] Step 7: Summarize the structural feedback signals and rearrange the differential distillation cache structure, and issue unified mask control instructions to the reversible semantic mask tensor to achieve semantic state closed-loop switching without manual intervention.

[0016] Furthermore, the differential distillation cache stores the gradient difference vectors generated before and after the mask state switch in key-value pairs, and is limited to the scope of a specified semantic segment to achieve local semantic updates.

[0017] Furthermore, the mask control instructions include three types of sub-instructions: bit order adjustment, mask state flip triggering, and semantic reprojection, to control the fine switching of the reversible semantic mask tensor state at different semantic stages.

[0018] Furthermore, the structural feedback signals include the field matching accuracy, null value distribution, type inference bias, and structural parsing anomaly rate returned by the SQL statement during database execution.

[0019] Furthermore, the structure signature includes field names, field types, field dependency order, and primary and foreign key association paths between tables, and can automatically extend the mask bit length according to changes in the structure signature.

[0020] Furthermore, the structural feedback signal aggregation includes a weighted averaging process of structural feedback signals within a set time window to trigger dynamic rearrangement and compression updates of the differential distillation cache.

[0021] On the other hand, this invention discloses a natural language to SQL conversion system based on a large model, comprising:

[0022] Reversible semantic mask tensor initialization module: Constructs a reversible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset.

[0023] Differential distillation cache module: Binds differential distillation cache to reversible semantic mask tensors, and only records the gradient difference vector generated each time the mask state is switched;

[0024] Semantic sketch generation module: Performs schema-agnostic semantic projection on natural language queries using an invertible semantic mask tensor with mask bits set to 0, generating structure-independent candidate SQL sketches as generalization references;

[0025] Mask-state switching differential injection module: Based on the gradient difference vector provided by the differential distillation cache, the invertible semantic mask tensor is switched to the schema-aware state, and the structure-sensitive SQL output is generated by injecting mask control instructions;

[0026] Execution result driven module: Converts the generated SQL execution result into a structured feedback signal, writes it back as a new feedback differential vector, and appends it to the differential distillation cache;

[0027] Structure signature change module: When the database structure signature changes due to the addition or deletion of fields or changes in the relationship between tables, it only extends the mask bit length of the reversible semantic mask tensor and calls the differential distillation cache for local differential correction;

[0028] The closed-loop mask state self-optimization module summarizes the structural feedback signals and rearranges the differential distillation cache structure. It then issues unified mask control commands to the reversible semantic mask tensor, achieving closed-loop switching of semantic states without manual intervention.

[0029] The technological advancements achieved by this invention compared to existing technologies are as follows:

[0030] First, this invention proposes a reversible semantic mask tensor structure that combines explicit mask bits with implicit semantic embedding. A mask bit value of 1 indicates a schema-aware state, and a mask bit value of 0 indicates a schema-agnostic state. Coupled expression of dual-state semantics is achieved through a shared weight space, supporting on-demand switching of semantics between different schema-aware intensities. Second, a differential distillation caching mechanism is constructed. This mechanism does not store the complete model gradient but instead stores the gradient difference vector before and after the mask state switch in key-value pairs, limiting its effectiveness to local semantic segments, significantly reducing storage and computational overhead, and improving the adaptability of local semantics. Third, a structural signature adaptation mechanism is introduced. The structural signature consists of field names, field types, field dependency order, and primary / foreign key association paths. When the database structure changes, the reversible semantic mask tensor only needs to expand the mask bit length, while the differential distillation cache performs local correction, achieving seamless migration between the old and new structures. Finally, a closed-loop self-optimization process driven by structural feedback signals is designed. By setting a time window, the structural feedback signals (such as field matching accuracy, type inference bias, etc.) are weighted and statistically analyzed. The differential distillation cache structure is dynamically rearranged, and mask control instructions are uniformly issued to achieve semantic state iterative updates without human intervention.

[0031] In summary, this invention breaks through the limitations of previous natural language to SQL conversion processes, which involved the separation of text semantics and structural information and the difficulty in unifying generalization ability and execution accuracy. For the first time, it achieves unified modeling, split-state execution, and linkage optimization of schema-aware and schema-agnostic semantic representations using a tensor-structured approach, solving the key technical problem of how to construct a schema-aware and schema-agnostic semantic representation. Attached Figure Description

[0032] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.

[0033] In the attached diagram:

[0034] Figure 1 This is a flowchart of the present invention. Detailed Implementation

[0035] The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of the present invention will now be described with reference to the accompanying drawings.

[0036] Example 1

[0037] like Figure 1As shown in this embodiment, a natural language to SQL conversion method based on a large model is disclosed, including:

[0038] Step 1: Construct an invertible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset.

[0039] Step 2: Bind a differential distillation cache to the reversible semantic mask tensor, and only record the gradient difference vector generated by each mask state switch;

[0040] Step 3: Perform schema-agnostic semantic projection on the natural language query using an invertible semantic mask tensor with a mask bit of 0, and generate a structure-independent candidate SQL sketch as a generalization reference.

[0041] Step 4: Based on the gradient difference vector provided by the differential distillation cache, switch the invertible semantic mask tensor to schema-aware state, and generate structure-sensitive SQL output by injecting mask control instructions;

[0042] Step 5: Convert the generated SQL execution result into a structured feedback signal, write it back as a new feedback differential vector, and append it to the differential distillation cache;

[0043] Step 6: When the database structure signature is modified by adding or deleting fields or changing the relationship between tables, only the mask bit length of the reversible semantic mask tensor is extended, and the differential distillation cache is called for local differential correction.

[0044] Step 7: Summarize the structural feedback signals and rearrange the differential distillation cache structure, and issue unified mask control instructions to the reversible semantic mask tensor to achieve semantic state closed-loop switching without manual intervention.

[0045] Step 1 includes:

[0046] In step 1, to construct a reversible semantic mask tensor, the hidden semantic embeddings corresponding to each term are first extracted from the intermediate representation space of the large model based on the original input sequence of the natural language query. These embedding vectors are then grouped and fed into the structure control module to generate tensor units with mask control capabilities. For each semantic embedding unit, a corresponding explicit mask bit is appended. A mask bit of 1 indicates that the unit is in a schema-aware state, meaning that the semantic embedding can be associated with and aligned with field names, table names, or relational paths in the database structure. A mask bit of 0 indicates that the unit is in a schema-agnostic state, meaning that the semantic embedding only retains language ontology features and is decoupled from database structure information.

[0047] All semantic embedding units with explicit mask bits are integrated into a unified tensor structure, denoted as the invertible semantic mask tensor. All semantic embeddings in this tensor are mapped to a shared weight space to ensure spatial consistency of the semantic representation regardless of the current mask bit values. This sharing strategy avoids repeatedly training parameters for the two mask states and also ensures that no unnecessary representation errors are introduced during subsequent switching processes.

[0048] In the meta-information layer of the tensor structure, a mask control instruction slot is reserved for each group of mask bits. This instruction slot is initially empty and is used to receive external differential control signals to control the flipping of the mask bits between the schema-aware state and the schema-agnostic state. The mask control instruction slot does not participate in the model's forward inference; it is only used to respond to differential update signals at specific stages to achieve dynamic adjustment of structural sensitivity.

[0049] To enhance subsequent adaptability, each semantic embedding path is bound to a unique mask label during the initial generation phase. Simultaneously, its semantic origin (such as predicates, objects, operators, etc.) and syntactic dependencies are recorded to support consistency verification of semantic paths under different mask states. This binding process also provides the foundation for the differential recording and semantic tracing of the subsequent differential distillation caching module. During the initialization phase, all mask bits are uniformly set to 0, meaning the model runs in schema-agnostic mode by default. The purpose of this setting is to avoid structural bias during the initial semantic projection, enabling the model to process query intent in a general language pattern, thereby providing basic samples for subsequent structure-aware transformation.

[0050] Through the above construction process, the generated reversible semantic mask tensor has three key capabilities: First, the semantic expression state is controllable, and it can switch between schema-aware and schema-agnostic representations; second, the tensor structure is stable, and the semantic space is continuous and perturbation-free during mask switching; third, the structure is scalable, and it can continue to run by expanding the mask dimension when the database structure changes, without retraining the underlying large model.

[0051] Step 2 includes:

[0052] In step 2, in order to achieve efficient local semantic updates of the reversible semantic mask tensor constructed in step 1, a differential distillation caching mechanism is designed and bound. This mechanism adopts a key-value pair storage structure, where each key corresponds to a specific mask control instruction slot or mask bit switching operation, and the value corresponds to the gradient difference vector generated before and after the switching action.

[0053] In practice, the first step is to precisely locate the affected semantic segment range based on the context of the mask bit switching action, i.e., the index interval of the affected region in the invertible semantic mask tensor. The differential distillation cache confines the captured gradient difference vector to this semantic segment range, avoiding interference with unaffected semantic units and ensuring the locality and fine-grainedness of the update. This key-value pair-based organization enables precise tracing and rapid invocation of each mask state switching action, while supporting multi-version differential management of the same mask bit in different contexts. By limiting the effective range of the differential, the locality of semantic updates is guaranteed, avoiding unnecessary perturbations to the global semantic representation.

[0054] The differential distillation cache is connected to the mask control instruction slot in step 1 via an interface, ensuring that the corresponding gradient difference is injected into the relevant semantic fragment in real time each time the mask state changes, completing the local weight adjustment. This mechanism improves the response speed and accuracy to schema-aware and schema-agnostic semantic state switching. In addition, the differential distillation cache can also implement differential version management and timestamp annotation functions, supporting the accumulation and selective rollback of historical differences, providing data support for subsequent self-optimization closed loop.

[0055] In summary, step 2 achieves accurate and efficient updating of the local semantics of the reversible semantic mask tensor by limiting the gradient difference storage and application within the semantic fragment in the form of key-value pairs through differential distillation caching. This provides a solid technical foundation for large models to switch semantic states in natural language to SQL conversion tasks.

[0056] Step 3 includes:

[0057] In practice, the natural language query is first input into the reversible semantic mask tensor constructed in step 1, with its explicit mask bits set to 0 to ensure the tensor is in a schema-agnostic state. In this state, implicit semantic embedding fully leverages its generalization ability, abstracting and extracting the semantic features of the input natural language while ignoring specific database schema information, thus achieving a semantic understanding of the query without structural dependencies.

[0058] Building upon this foundation, a generalized semantic decoder pre-trained on a large model is used to project the schema-agnostic semantic representation into a set of candidate SQL sketches. These sketches focus on expressing query intent and logical structure, eliminating hard-coded constraints on specific fields and table structures, thus significantly improving adaptability to unknown or changing database schemas. The generation of candidate SQL sketches further relies on historical gradient difference vectors stored in a differential distillation cache. This cache, through precisely defined semantic fragment ranges, assists the model in capturing subtle differences in semantic details, ensuring that candidate SQL sketches maintain generalization ability while encompassing potential fuzzy mappings of structural information, laying the foundation for subsequent schema-aware transformations.

[0059] To enhance the robustness of the solution, the generated candidate SQL drafts undergo automatic execution verification simultaneously, acquiring their structural performance and execution feedback. This feedback information is recorded as a structural feedback signal and passed to subsequent steps. This feedback mechanism assists the differential distillation cache in continuously refining the corresponding gradient difference, achieving dynamic adaptation from structure-independent to structure-sensitive transformations. Furthermore, in complex natural language queries involving multiple tables and conditions, the query context is fine-grained based on the implicit embedding of reversible semantic mask tensors, and the slices are projected onto the schema-agnostic space, improving the diversity and coverage of the generated candidate SQL drafts.

[0060] In summary, step 3 achieves generalized projection of natural language queries in the absence or unknown of structural information by synergistically using a reversible semantic mask tensor with a mask bit of 0 and a differential distillation cache, generating highly adaptable candidate SQL sketches, and providing a solid foundation for subsequent fine-grained transformation based on structural feedback.

[0061] Step 4 includes:

[0062] In practice, the gradient difference vector required for the corresponding mask state switching is first extracted from the differential distillation cache and used as the basis for updating the local weights of the invertible semantic mask tensor. Subsequently, based on this gradient information and the structural feedback signal of the execution feedback, a mask control instruction set containing three types of sub-instructions—position adjustment, mask state flip triggering, and semantic reprojection—is generated.

[0063] The bit order adjustment sub-instruction finely adjusts the arrangement of mask bits in the reversible semantic mask tensor to match the current database structure signature and query semantic features, achieving precise correspondence between semantic fragments. This process ensures the continuity and integrity of the tensor's implicit semantic embedding during switching. The mask state flip trigger sub-instruction explicitly instructs the reversible semantic mask tensor to switch from the schema-agnostic state (mask bit 0) to the schema-aware state (mask bit 1), activating semantic weights related to specific database schemas, thereby improving the ability to identify and reason about fields, tables, and relationships. The semantic reprojection sub-instruction calls the reprojection module in the large model to re-encode the implicit semantic embedding after the mask state switch, integrates specific schema information, remaps the semantic features of natural language queries, and generates refined and structure-sensitive SQL statement candidates.

[0064] This mask control instruction set injects reversible semantic mask tensors into the preset mask control instruction slots in step 1, enabling fine-grained switching and dynamic adjustment of the tensor state. At this stage, structure-sensitive SQL is output. Through accurate mapping of specific fields, tables, and relationships in the schema, the consistency between SQL semantics and the database schema is significantly improved. Combined with the gradient differential update mechanism of differential distillation caching, this step not only completes the state switching but also provides a more accurate semantic foundation for subsequent structural correctness feedback, ensuring the execution effect and structural rationality of the generated SQL.

[0065] In summary, step 4 utilizes bit order adjustment, mask state flip triggering, and semantic reprojection sub-instructions in the mask control instructions to achieve dynamic schema-aware switching of the reversible semantic mask tensor, ensuring high-quality conversion from natural language to structure-sensitive SQL.

[0066] Step 5 includes:

[0067] In practice, the structure-sensitive SQL generated in step 4 is executed in the target database, and multi-dimensional structure feedback signals are collected in real time during the execution process. These structure feedback signals include, but are not limited to: the matching accuracy of the fields returned by the SQL statement, reflecting the consistency between the fields and the query intent; the distribution of null values, revealing data integrity and potential omissions; type inference bias, assessing the degree of matching between field types and semantic inference; and the structure parsing anomaly rate, monitoring potential structural errors in SQL parsing and execution.

[0068] The aforementioned structural feedback signals are normalized and fused across multiple dimensions to form a quantifiable feedback feature vector. This feature vector is then converted into a new feedback difference vector, accurately characterizing the deviation between the current SQL structure performance and the expected semantic target. This feedback difference vector is appended to the differential distillation cache bound in step 2, achieving closed-loop optimization of the reversible semantic mask tensor state switching. Through a continuous feedback mechanism, the differential distillation cache can adjust and refine subsequent gradient difference vectors, improving the accuracy and efficiency of mask state switching. Furthermore, based on the feedback difference vector, mask control instructions can be dynamically adjusted to assist in the refined execution of bit order adjustment and semantic reprojection in step 4, further enhancing the adaptability of the SQL structure to the database schema.

[0069] In summary, step 5 achieves continuous self-correction and optimization of the reversible semantic mask tensor switching strategy through the generation and differential injection of structure feedback signals driven by the execution results, ensuring that the accuracy of natural language to SQL conversion steadily improves in multiple iterations.

[0070] Step 6 includes:

[0071] In practice, the system first monitors changes to the database structure signature, which includes field names, field types, field dependency order, and primary / foreign key relationships between tables. If a field addition, deletion, or change in the primary / foreign key relationship path between tables is detected, an automatic mask length expansion mechanism is triggered.

[0072] Under this mechanism, the mask bit length of the reversible semantic mask tensor is automatically adjusted based on the number of newly added or removed fields and the complexity of the relationships. Newly added mask bits are initialized to the default state, ensuring that the tensor maintains schema-aware and schema-agnostic bimorphic compatibility while adapting to the latest database structure. After expanding the mask bits, the differential distillation cache bound in step 2 is invoked to perform local differential correction on the newly added or changed parts. The differential distillation cache utilizes previously accumulated gradient difference vectors and structural feedback signals to dynamically adjust the weights and semantic embeddings corresponding to the new mask bits, achieving incremental semantic adaptation without requiring a complete retraining of the large model. This local differential correction effectively avoids the impact of database structure signature changes on the entire semantic representation, ensuring the stability and efficient response capability of the natural language to SQL conversion process.

[0073] In summary, step 6 ensures that the reversible semantic mask tensor dynamically adapts to database schema changes by automatically expanding the mask bits driven by structural signature changes and by local correction of differential distillation caching, thus maintaining the consistency and integrity of schema-aware and schema-agnostic semantic representations.

[0074] Step 7 includes:

[0075] In practice, structural feedback signals corresponding to multiple natural language queries are collected within a set time window. These signals are then weighted and averaged, with the weights dynamically adjusted based on the timeliness and accuracy of the feedback signals. This weighted averaging process effectively filters out noise and highlights recent and high-confidence feedback information.

[0076] Based on the weighted aggregation of structural feedback signals, dynamic rearrangement and compression updates of the differential distillation cache are triggered. The rearrangement process optimizes the storage structure of gradient difference vectors in the cache, improving access efficiency; the compression update removes redundant and outdated difference information, ensuring the cache's lightweight nature and timeliness. Subsequently, rearranged and compressed optimized mask control instructions are uniformly issued to the reversible semantic mask tensor, achieving fine-grained and unified management of mask bits. These mask control instructions cover bit order adjustment, mask state flip triggering, and semantic reprojection, ensuring smooth closed-loop switching of the semantic state of the reversible semantic mask tensor during multiple iterations. This closed-loop switching mechanism requires no manual intervention, automatically adapts to dynamic changes in natural language queries and database structures, and continuously improves the generalization ability and execution accuracy of large models in natural language to SQL conversion tasks.

[0077] In summary, step 7 achieves an efficient self-optimizing closed loop for the reversible semantic mask tensor through weighted summarization of structural feedback signals and intelligent rearrangement and compression of differential distillation buffer, ensuring long-term stable and efficient operation.

[0078] Example 2

[0079] This embodiment discloses a natural language to SQL conversion system based on a large model, including:

[0080] Reversible semantic mask tensor initialization module: Constructs a reversible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset.

[0081] Differential distillation cache module: Binds differential distillation cache to reversible semantic mask tensors, and only records the gradient difference vector generated each time the mask state is switched;

[0082] Semantic sketch generation module: Performs schema-agnostic semantic projection on natural language queries using an invertible semantic mask tensor with mask bits set to 0, generating structure-independent candidate SQL sketches as generalization references;

[0083] Mask-state switching differential injection module: Based on the gradient difference vector provided by the differential distillation cache, the invertible semantic mask tensor is switched to the schema-aware state, and the structure-sensitive SQL output is generated by injecting mask control instructions;

[0084] Execution result driven module: Converts the generated SQL execution result into a structured feedback signal, writes it back as a new feedback differential vector, and appends it to the differential distillation cache;

[0085] Structure signature change module: When the database structure signature changes due to the addition or deletion of fields or changes in the relationship between tables, it only extends the mask bit length of the reversible semantic mask tensor and calls the differential distillation cache for local differential correction;

[0086] The closed-loop mask state self-optimization module summarizes the structural feedback signals and rearranges the differential distillation cache structure, and issues unified mask control instructions to the reversible semantic mask tensor to achieve semantic state closed-loop switching without manual intervention.

[0087] The modules in Embodiment 2 are used to implement the functions in Embodiment 1. This embodiment can be implemented by a system including a processor and a memory. The memory stores computer program instructions, which, when executed by the processor, implement the natural language to SQL conversion method based on a large model according to Embodiment 1 of this application. The system also includes other components well known to those skilled in the art, such as a communication bus and a communication interface. Their settings and functions are known in the art and will not be described in detail here.

[0088] In this application, the aforementioned memory can be any tangible medium containing or storing a program that can be used or combined with an instruction execution system, system, or device. For example, a computer-readable storage medium can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc., or any other medium that can be used to store required information and can be accessed by an application, module, or both. Any such computer storage medium can be part of a device or accessible to or connected to a device. Any application or module described in this application can be implemented using computer-readable / executable instructions that can be stored or otherwise retained by such a computer-readable medium.

[0089] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A natural language to SQL conversion method based on a large model, characterized in that, include: Step 1: Construct an invertible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset. Step 2: Bind a differential distillation cache to the reversible semantic mask tensor, and only record the gradient difference vector generated by each mask state switch; Step 3: Perform schema-agnostic semantic projection on the natural language query using an invertible semantic mask tensor with a mask bit of 0, and generate a structure-independent candidate SQL sketch as a generalization reference. Step 4: Based on the gradient difference vector provided by the differential distillation cache, switch the invertible semantic mask tensor to schema-aware state, and generate structure-sensitive SQL output by injecting mask control instructions; Step 5: Convert the generated SQL execution result into a structured feedback signal, write it back as a new feedback differential vector, and append it to the differential distillation cache; Step 6: When the database structure signature is modified by adding or deleting fields or changing the relationship between tables, only the mask bit length of the reversible semantic mask tensor is extended, and the differential distillation cache is called for local differential correction. Step 7: Summarize the structural feedback signals and rearrange the differential distillation cache structure, and issue unified mask control instructions to the reversible semantic mask tensor to achieve semantic state closed-loop switching without manual intervention.

2. The natural language to SQL conversion method based on a large model according to claim 1, characterized in that, The differential distillation cache stores the gradient difference vectors generated before and after the mask state switch in key-value pairs and is limited to the scope of a specified semantic segment to achieve local semantic updates.

3. The natural language to SQL conversion method based on a large model according to claim 1, characterized in that, The mask control instructions include three types of sub-instructions: bit order adjustment, mask state flip triggering, and semantic reprojection, to control the fine switching of the reversible semantic mask tensor state at different semantic stages.

4. The natural language to SQL conversion method based on a large model according to claim 1, characterized in that, The structural feedback signals include the field matching accuracy, null value distribution, type inference bias, and structural parsing anomaly rate returned by the SQL statement during database execution.

5. The natural language to SQL conversion method based on a large model according to claim 1, characterized in that, The structure signature includes field names, field types, field dependency order, and primary and foreign key association paths between tables, and can automatically expand the mask bit length according to changes in the structure signature.

6. The natural language to SQL conversion method based on a large model according to claim 5, characterized in that, The structure feedback signal aggregation includes a weighted averaging process of structure feedback signals within a set time window to trigger dynamic rearrangement and compression updates of the differential distillation cache.

7. A natural language to SQL conversion system based on a large model, characterized in that, include: Reversible semantic mask tensor initialization module: Constructs a reversible semantic mask tensor that carries both explicit mask bits and implicit semantic embedding. A mask bit of 1 indicates a schema-aware state, and a mask bit of 0 indicates a schema-agnostic state. The weight space is shared, and an empty mask control instruction slot is preset. Differential distillation cache module: Binds differential distillation cache to reversible semantic mask tensors, and only records the gradient difference vector generated each time the mask state is switched; Semantic sketch generation module: Performs schema-agnostic semantic projection on natural language queries using an invertible semantic mask tensor with mask bits set to 0, generating structure-independent candidate SQL sketches as generalization references; Mask-state switching differential injection module: Based on the gradient difference vector provided by the differential distillation cache, the invertible semantic mask tensor is switched to the schema-aware state, and the structure-sensitive SQL output is generated by injecting mask control instructions; Execution result driven module: Converts the generated SQL execution result into a structured feedback signal, writes it back as a new feedback differential vector, and appends it to the differential distillation cache; Structure signature change module: When the database structure signature changes due to the addition or deletion of fields or changes in the relationship between tables, it only extends the mask bit length of the reversible semantic mask tensor and calls the differential distillation cache for local differential correction; The closed-loop mask state self-optimization module summarizes the structural feedback signals and rearranges the differential distillation cache structure, and issues unified mask control instructions to the reversible semantic mask tensor to achieve semantic state closed-loop switching without manual intervention.

Citation Information

Patent Citations

  • Database query method and system based on self-attention syntactic perception

    CN116910086A

  • METHOD AND SYSTEM FOR SEMANTIC APPEARANCE TRANSFER USING SPLICING ViT FEATURES

    US20240419382A1