SQL knowledge base data generation method and system based on large model

By combining a large language model and a relation vector injection retrieval model with a syntax constraint decoding mechanism, the SQL knowledge base is dynamically expanded, solving the problems of high dependence on labeled data and low generation accuracy in existing technologies, and achieving efficient and reliable SQL generation and adaptive enhancement.

CN121764962APending Publication Date: 2026-03-31JIANGSU HONGXIN SYST INTEGRATION
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-19
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

Existing Text-to-SQL technology relies on large-scale, high-quality labeled data, which makes it difficult to adapt to complex database schemas and queries. The generated SQL has low accuracy, and the static knowledge base has high update costs and cannot adapt to dynamic changes.

Method used

An initial knowledge base is constructed using a large language model. The knowledge base is dynamically expanded by combining a relational vector injection retrieval model and a grammatical constraint decoding mechanism. SQL statements adapted to the query context are generated, and query semantics and database patterns are fused through semantic encoding and graph neural networks.

Benefits of technology

It significantly reduces the reliance on labeled data, improves the accuracy and adaptability of SQL generation, supports continuous iteration and self-expansion of the knowledge base, and enhances the system's generalization ability in practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121764962A_ABST
    Figure CN121764962A_ABST
Patent Text Reader

Abstract

The invention discloses an SQL knowledge base data generation method and system based on a large model. The method comprises the following steps: constructing an initial knowledge base by utilizing a large language model based on a seed data set; then, extended knowledge entries are generated through a context example guide model, and dynamic growth of the knowledge base is achieved; a relation vector is injected into a retrieval model, query semantics and a database mode structure are fused, and related entries are retrieved from a knowledge base; performing context optimization on a retrieval result through a large language model; and finally, generating an accurate SQL statement according with a target database mode in combination with a grammar constraint decoding mechanism. The system comprises an initial knowledge base construction module, a knowledge base expansion module, a relation perception retrieval module, a context knowledge optimization module and an SQL generation module. According to the Text-to-SQL task scheduling method, the dependence on the annotated data is effectively reduced, the support for complex query and a dynamic mode is enhanced, and the generalization ability and the reliability of the Text-to-SQL task in practical application are remarkably 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, specifically to a method and system for generating SQL knowledge base data based on a large model. Background Technology

[0002] With the rapid development of natural language processing technology, the Text-to-SQL task has become one of the core technologies for implementing natural language interface databases. This task aims to automatically convert user queries in natural language into structured SQL statements, enabling non-expert users to interact directly with the database without needing to master SQL syntax. It is widely used in scenarios such as intelligent customer service, business data analysis, and knowledge base queries.

[0003] However, existing Text-to-SQL technologies still face the following problems: Traditional methods typically rely on large-scale, high-quality labeled datasets for supervised training. However, labeling is costly, and labeled data is often limited to specific domains or simple query scenarios, making it difficult to cover complex and diverse real-world query needs, resulting in insufficient generalization ability of the model in practical applications.

[0004] Existing methods often use static knowledge bases or rule bases to support SQL generation, but the construction of knowledge bases requires a lot of manual design, and the cost of updating and maintaining them is high, making it difficult to adapt to dynamically changing database patterns and query requirements.

[0005] When faced with scenarios involving multi-table joins, nested queries, and complex combinations of conditions, existing models often struggle to accurately understand the deep relationship between query semantics and database schema, resulting in logical or structural deviations in the generated SQL statements.

[0006] Some methods employ retrieval-enhanced generation strategies, but the retrieval module typically relies solely on the semantic similarity of the query text, ignoring the structural information of the database schema. This results in poor adaptation of the retrieved examples to the context of the current query, affecting the accuracy of subsequent SQL generation.

[0007] The generated SQL statements often contain syntax errors or reference non-existent table or field names, and lack an effective mechanism to constrain the output to be valid SQL that conforms to the target database schema. Summary of the Invention

[0008] The purpose of this invention is to provide a method for generating SQL knowledge base data based on a large model, in order to solve the problems of existing technologies that rely heavily on a large amount of labeled data, are difficult to adapt to complex database patterns and queries, and have low accuracy in generating SQL.

[0009] To achieve the above objectives, the technical solution provided by this invention is: a method for generating SQL knowledge base data based on a large model, comprising the following steps: S1: Obtain a seed dataset. Based on the seed dataset, use a large language model to generate initial knowledge entries and build an initial knowledge base. The seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements. S2: For query and database schema pairs in the knowledge base, use a large language model combined with contextual examples to generate extended knowledge entries. After deduplication and filtering, update the knowledge base to obtain the updated knowledge base. S3: For the input target natural language query and its corresponding target database pattern, a relational vector injection retrieval model is used to retrieve relevant knowledge items from the updated knowledge base; S4: Input the retrieved knowledge entries, target natural language query, and target database schema into the large language model to generate optimized knowledge that is adapted to the current query context; S5: Input the optimized knowledge, target natural language query, and target database schema into the SQL generation prompt template, and drive the large language model to generate the final SQL statement under the guidance of the syntax constraint decoding mechanism.

[0010] To optimize the above technical solution, the specific measures also include: In step S1, the step of generating initial knowledge entries based on the seed dataset using a large language model and constructing an initial knowledge base specifically includes: Obtain a seed dataset, and based on the natural language queries and database patterns in the seed dataset, use the first prompt template to drive the large language model to generate candidate knowledge entries. Furthermore, a semantic coding model is used to encode all generated candidate knowledge entries, and the entries are sorted based on the similarity of the encoded vectors. The knowledge entries most relevant to the corresponding labeled SQL statements are then selected from the candidate knowledge entries. The selected knowledge items are compiled to form an initial knowledge base.

[0011] In step S2, the process of generating extended knowledge entries using a large language model combined with contextual examples, and updating them to the knowledge base after deduplication and filtering, specifically involves: For the current query and database schema pair in the knowledge base, retrieve multiple semantically similar examples from the knowledge base. Each example contains a natural language query, a database schema, and annotated SQL statements to form a context example set. Furthermore, based on the current query, database schema, and the aforementioned set of context examples, a second suggestion template is constructed, and the large language model is driven to generate extended knowledge entries related to the current query and database schema. This process is represented as follows:

[0012]

[0013] in, A collection of contextual examples built from labeled SQL statements. To expand the knowledge entries, As the initial knowledge base, For natural language queries, The database schema is used; the generated extended knowledge entries are deduplicated and semantically filtered, and qualified entries are updated to the knowledge base to obtain the updated knowledge base.

[0014] In step S3, the relation vector injection retrieval model specifically includes: The target natural language query is encoded into a query semantic vector using a semantic coding model. ; The target database schema is constructed as a schema relation graph, and a graph neural network is used to encode the schema relation graph to obtain a global relation vector. ; Furthermore, the query semantic vector is further processed through a gating fusion mechanism. With global relation vector The data is then fused to form a joint query vector for retrieval. ; The calculation process of the gating fusion mechanism is expressed as follows: First, the query semantic vector With global relation vector Concatenate the vectors to obtain the input vector. ; Then, calculate and update the gating. and resetting the gate :

[0015]

[0016] Calculate candidate hidden state :

[0017] By updating the gating system and fusing the current query semantics with the candidate states, a joint query vector is output:

[0018] in, This represents a vector concatenation operation. For activation function, For element-wise multiplication, , and This is the weight matrix. , , This is a bias term.

[0019] Furthermore, in step S3, the use of a relation vector injection retrieval model to retrieve relevant knowledge items from the updated knowledge base specifically includes: Employing a relation vector injection retrieval model, from the updated knowledge base The search returned the target natural language query. Most relevant front A set of related knowledge items is denoted as ___. .

[0020] In step S4, generating optimization knowledge adapted to the current query context specifically includes: Furthermore, the retrieved relevant knowledge entries, target natural language queries, and target database schemas are input into the knowledge optimization suggestion template. Drive the generation and optimization of knowledge in large language models The process is represented as follows:

[0021]

[0022] in, This is a database schema.

[0023] In step S5, the process of inputting the optimized knowledge, target natural language query, and target database schema into the SQL generation model, and generating the final SQL statement under the guidance of the syntax constraint decoding mechanism, specifically includes: Furthermore, the optimization knowledge, the target natural language query, and the target database schema are input into the SQL generation prompt template. This drives the large language model to generate the final SQL statement, and the process is represented as follows:

[0024]

[0025] in, For natural language queries, To optimize the knowledge set, Database schema; The syntax constraint decoding mechanism is as follows: during the process of model decoding to generate SQL lexical sequences, a dynamic set of valid lexical units is maintained to restrict the candidate lexical unit set to the range of table names, field names, and SQL syntax keywords that actually exist in the target database schema.

[0026] As another important technical solution, this invention also provides a SQL knowledge base data generation system based on a large model, comprising: The initial knowledge base construction module is used to obtain a seed dataset, and based on the seed dataset, to generate initial knowledge entries using a large language model to construct the initial knowledge base; wherein, the seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements; The knowledge base extension module is used to generate extended knowledge entries for query and database schema pairs in the knowledge base by using a large language model and contextual examples. After deduplication and filtering, the extended knowledge entries are updated to the knowledge base, resulting in an updated knowledge base. The relation-aware retrieval module is used to retrieve relevant knowledge entries from the updated knowledge base for the input target natural language query and its corresponding target database pattern using a relation vector injection retrieval model. The context knowledge optimization module is used to input the retrieved knowledge entries, target natural language queries, and target database patterns into the large language model to generate optimized knowledge that is adapted to the current query context. The SQL generation module is used to input optimization knowledge, target natural language queries, and target database schema into the SQL generation prompt template, and, guided by the syntax constraint decoding mechanism, drive the large language model to generate the final SQL statement.

[0027] The present invention also proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements a method for generating SQL knowledge base data based on a large model as described above.

[0028] The present invention also proposes a computer-readable storage medium storing a computer program that enables a computer to execute a SQL knowledge base data generation method based on a large model as described above.

[0029] Compared with the prior art, the beneficial effects of the present invention are: This invention significantly reduces the reliance on large-scale manually labeled data by introducing a large language model to construct and dynamically expand the SQL knowledge base. Only a small amount of seed data is needed to start and continuously enrich the knowledge base content, effectively alleviating the problems of high labeling costs and limited data coverage in traditional Text-to-SQL methods.

[0030] This invention innovatively employs a relation vector injection retrieval model, which deeply integrates the semantic information of natural language queries with the structural relationships of database schemas. This enhances the retrieval process's ability to perceive query context and database schemas, thereby improving the relevance and adaptability of retrieval results and providing more accurate knowledge support for subsequent SQL generation.

[0031] This invention, through the synergistic effect of the context knowledge optimization module and the syntax constraint decoding mechanism, enables the system to dynamically incorporate relevant retrieved knowledge when generating SQL and strictly constrain the output to be legal syntax that conforms to the target database pattern. This significantly reduces the occurrence of invalid table names, field name references, and syntax errors, thereby significantly improving the accuracy and reliability of SQL generation.

[0032] This invention supports continuous iteration and self-expansion of the knowledge base, enabling it to adapt to dynamically changing database models and diverse and complex query requirements. It enhances the system's generalization ability and adaptability in practical applications, providing efficient and scalable technical support for the implementation of natural language interface databases. Attached Figure Description

[0033] Figure 1 : A schematic diagram of the workflow in an embodiment of the present invention. Detailed Implementation The present invention will be further described in detail below through specific embodiments, but it should not be construed as limiting the scope of the subject matter of the present invention to the following embodiments. All technologies implemented based on the above content of the present invention fall within the scope of the present invention.

[0034] The following is an explanation of some of the terms used in this invention: Text-to-SQL is a natural language processing task designed to automatically convert human-generated questions in natural language into Structured Query Language (SQL) statements. This task allows users to query databases without needing to master SQL syntax. It has wide applications in scenarios such as intelligent customer service and data analysis, and is one of the key technologies for implementing Natural Language Interface Databases (NLIDB).

[0035] A database schema is the structural definition of a database, describing how data objects are organized and their relationships. It includes database elements such as tables, fields, constraints, views, indexes, and triggers. Tables consist of rows and columns, fields represent data attributes, and relationships are established between tables through foreign keys. Views are virtual tables that simplify query operations, and indexes improve query efficiency. Triggers and stored procedures are automatically executed operations or database program logic. The database schema not only provides a framework for data organization but also ensures data consistency, security, and integrity through constraints and access control. Through schema definition, the database achieves a clear data structure and efficient data management.

[0036] The technical solution of the present invention will be further described in detail below with reference to specific embodiments: In some implementations, such as Figure 1 As shown, this invention provides a method for generating SQL knowledge base data based on a large model, including the following steps: S1: Obtain a seed dataset. Based on the seed dataset, use a large language model to generate initial knowledge entries and build an initial knowledge base. The seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements. In step S1, the step of generating initial knowledge entries based on the seed dataset using a large language model and constructing an initial knowledge base specifically includes: Obtain a seed dataset, and based on the natural language queries and database patterns in the seed dataset, use the first prompt template to drive the large language model to generate candidate knowledge entries. In some implementations, the seed dataset is derived from existing Text-to-SQL labeled data, such as public datasets like Spider and WikiSQL. Each dataset includes a natural language query, the corresponding database schema (including table structure, field types, foreign key relationships, etc.), and manually labeled standard SQL statements.

[0037] The prompt template includes the query text, database schema description, and generation task instructions, guiding the model to output knowledge fragments related to the current query and schema, such as query intent summary, condition mapping description, and join relationship hints.

[0038] A semantic coding model is used to encode all generated candidate knowledge entries, and the entries are sorted based on the similarity of the encoded vectors. The knowledge entries most relevant to the corresponding labeled SQL statements are then selected from the candidate knowledge entries. Preferably, the generated candidate knowledge entries undergo semantic filtering. The Sentence-BERT semantic encoding model is used to encode the generated entries and the labeled SQL statements into vectors. Cosine similarity is then calculated, and the entry closest to the labeled SQL is selected as valid knowledge and stored in the knowledge base. This process significantly reduces noise and improves the initial quality of the knowledge base.

[0039] The selected knowledge items are compiled to form an initial knowledge base.

[0040] S2: For query and database schema pairs in the knowledge base, use a large language model combined with contextual examples to generate extended knowledge entries. After deduplication and filtering, update the knowledge base to obtain the updated knowledge base. In step S2, the process of generating extended knowledge entries using a large language model combined with contextual examples, and updating them to the knowledge base after deduplication and filtering, specifically involves: For the current query and database schema pair in the knowledge base, retrieve multiple semantically similar examples from the knowledge base. Each example contains a natural language query, a database schema, and annotated SQL statements to form a context example set. Based on the current query, database schema, and the aforementioned set of context examples, a second suggestion template is constructed, and the large language model is driven to generate extended knowledge entries related to the current query and database schema. This process is represented as follows:

[0041]

[0042] in, A collection of contextual examples built from labeled SQL statements. To expand the knowledge entries, As the initial knowledge base, For natural language queries, The database schema is used; the generated extended knowledge entries are deduplicated and semantically filtered, and qualified entries are updated to the knowledge base to obtain the updated knowledge base.

[0043] In some implementations, deduplication is based on vector similarity thresholds; quality verification can be combined with rule filtering (such as removing obviously irrelevant or contradictory content) and model self-evaluation (such as having a large model score the readability and relevance of the generated content). Only entries that pass the verification will be added to the knowledge base, thereby achieving a dual increase in the scale and quality of the knowledge base.

[0044] S3: For the input target natural language query and its corresponding target database pattern, a relational vector injection retrieval model is used to retrieve relevant knowledge items from the updated knowledge base; The target natural language query is encoded into a query semantic vector using a semantic coding model. ; The target database schema is constructed as a schema relation graph, and a graph neural network is used to encode the schema relation graph to obtain a global relation vector. ; Preferably, the query semantic vector is fused using a gating fusion mechanism. With global relation vector The data is then fused to form a joint query vector for retrieval. ; The calculation process of the gating fusion mechanism is expressed as follows: First, the query semantic vector With global relation vector Concatenate the vectors to obtain the input vector. ; Then, calculate and update the gating. and resetting the gate :

[0045]

[0046] Calculate candidate hidden state :

[0047] By updating the gating system and fusing the current query semantics with the candidate states, a joint query vector is output:

[0048] in, This represents a vector concatenation operation. For activation function, For element-wise multiplication, , and This is the weight matrix. , , This is a bias term.

[0049] Employing a relation vector injection retrieval model, from the updated knowledge base The search returned the target natural language query. Most relevant front A set of related knowledge items is denoted as ___. .

[0050] S4: Input the retrieved knowledge entries, target natural language query, and target database schema into the large language model to generate optimized knowledge that is adapted to the current query context; In step S4, generating optimization knowledge adapted to the current query context specifically includes: Input the retrieved relevant knowledge entries, target natural language query, and target database schema into the knowledge optimization prompt template. Drive the generation and optimization of knowledge in large language models The process is represented as follows:

[0051]

[0052] in, This is a database schema.

[0053] S5: Input the optimized knowledge, target natural language query, and target database schema into the SQL generation prompt template, and drive the large language model to generate the final SQL statement under the guidance of the syntax constraint decoding mechanism.

[0054] Input the optimization knowledge, the target natural language query, and the target database schema into the SQL generation prompt template. This drives the large language model to generate the final SQL statement, and the process is represented as follows:

[0055]

[0056] in, For natural language queries, To optimize the knowledge set, Database schema; Preferably, the syntax constraint decoding mechanism is as follows: during the process of model decoding to generate SQL lexical sequences, a dynamic set of valid lexical units is maintained, including the actual table names and field names in the target database, as well as SQL syntax keywords (such as SELECT, WHERE, JOIN, etc.). This restricts the candidate lexical unit set to the range of the actual table names, field names, and SQL syntax keywords in the target database schema, effectively avoiding the reference of invalid table names and field names and significantly reducing the syntax error rate.

[0057] In some embodiments, the present invention further includes a feedback iteration step, which performs syntax checking, simulated execution, and result verification on the generated SQL statement; if the verification fails, the target natural language query, the target database schema, the generated SQL statement, and the error information constitute feedback data, which is used to trigger the expansion and update of the knowledge base or to optimize the parameters of the relation vector injection retrieval model and the SQL generation model.

[0058] In another embodiment of the present invention, a SQL knowledge base data generation system based on a large model is proposed, comprising: The initial knowledge base construction module is used to obtain a seed dataset, and based on the seed dataset, to generate initial knowledge entries using a large language model to construct the initial knowledge base; wherein, the seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements; The knowledge base extension module is used to generate extended knowledge entries for query and database schema pairs in the knowledge base by using a large language model and contextual examples. After deduplication and filtering, the extended knowledge entries are updated to the knowledge base, resulting in an updated knowledge base. The relation-aware retrieval module is used to retrieve relevant knowledge entries from the updated knowledge base for the input target natural language query and its corresponding target database pattern using a relation vector injection retrieval model. The context knowledge optimization module is used to input the retrieved knowledge entries, target natural language queries, and target database patterns into the large language model to generate optimized knowledge that is adapted to the current query context. The SQL generation module is used to input optimization knowledge, target natural language queries, and target database schema into the SQL generation prompt template, and, guided by the syntax constraint decoding mechanism, drive the large language model to generate the final SQL statement.

[0059] In another embodiment of the present invention, an electronic device is proposed, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements a method for generating SQL knowledge base data based on a large model as described above.

[0060] In another embodiment of the present invention, a computer-readable storage medium is provided storing a computer program that causes a computer to execute a large-model-based SQL knowledge base data generation method as described above.

[0061] In the embodiments disclosed in this application, a computer storage medium may be a tangible medium that may contain or store programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of computer storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0062] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Any simple modifications, equivalent substitutions, and improvements made by those skilled in the art to the above embodiments without departing from the scope of the technical solution of the present invention, based on the technical essence of the present invention, shall still fall within the protection scope of the technical solution of the present invention.

Claims

1. A method for generating SQL knowledge base data based on a large model, characterized in that, Includes the following steps: S1: Obtain a seed dataset. Based on the seed dataset, use a large language model to generate initial knowledge entries and build an initial knowledge base. The seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements. S2: For query and database schema pairs in the knowledge base, use a large language model combined with contextual examples to generate extended knowledge entries. After deduplication and filtering, update the knowledge base to obtain the updated knowledge base. S3: For the input target natural language query and its corresponding target database pattern, a relational vector injection retrieval model is used to retrieve relevant knowledge items from the updated knowledge base; S4: Input the retrieved knowledge entries, target natural language query, and target database schema into the large language model to generate optimized knowledge that is adapted to the current query context; S5: Input the optimized knowledge, target natural language query, and target database schema into the SQL generation prompt template, and drive the large language model to generate the final SQL statement under the guidance of the syntax constraint decoding mechanism.

2. The method for generating SQL knowledge base data based on a large model according to claim 1, characterized in that: In step S1, the step of generating initial knowledge entries based on the seed dataset using a large language model and constructing an initial knowledge base specifically includes: Obtain a seed dataset, and based on the natural language queries and database patterns in the seed dataset, use the first prompt template to drive the large language model to generate candidate knowledge entries. A semantic coding model is used to encode all generated candidate knowledge entries, and the entries are sorted based on the similarity of the encoded vectors. The knowledge entries most relevant to the corresponding labeled SQL statements are then selected from the candidate knowledge entries. The selected knowledge items are compiled to form an initial knowledge base.

3. The method for generating SQL knowledge base data based on a large model according to claim 1, characterized in that: In step S2, the process of generating extended knowledge entries using a large language model combined with contextual examples, and updating them to the knowledge base after deduplication and filtering, specifically involves: For the current query and database schema pair in the knowledge base, retrieve multiple semantically similar examples from the knowledge base. Each example contains a natural language query, a database schema, and annotated SQL statements to form a context example set. Based on the current query, database schema, and the aforementioned set of context examples, a second suggestion template is constructed, and the large language model is driven to generate extended knowledge entries related to the current query and database schema. This process is represented as follows: in, A collection of contextual examples built from annotation-based SQL statements. To expand the knowledge entries, As the initial knowledge base, For natural language queries, The database schema is used; the generated extended knowledge entries are deduplicated and semantically filtered, and qualified entries are updated to the knowledge base to obtain the updated knowledge base.

4. The method for generating SQL knowledge base data based on a large model according to claim 1, characterized in that: In step S3, the relation vector injection retrieval model specifically includes: The target natural language query is encoded into a query semantic vector using a semantic coding model. ; The target database schema is constructed as a schema relation graph, and a graph neural network is used to encode the schema relation graph to obtain a global relation vector. ; The query semantic vector is obtained through a gating fusion mechanism. With global relation vector The data is then fused to form a joint query vector for retrieval. ; The calculation process of the gating fusion mechanism is expressed as follows: First, the query semantic vector With global relation vector Concatenate the vectors to obtain the input vector. ; Then, calculate and update the gating. and resetting the gate : Calculate candidate hidden state : By updating the gating system and fusing the current query semantics with the candidate states, a joint query vector is output: in, This represents a vector concatenation operation. For activation function, For element-wise multiplication, , and This is the weight matrix. , , This is a bias term.

5. The method for generating SQL knowledge base data based on a large model according to claim 1, characterized in that: In step S3, the relation vector injection retrieval model is used to retrieve relevant knowledge items from the updated knowledge base, specifically including: Employing a relation vector injection retrieval model, from the updated knowledge base The search returned the result to the target natural language query. Most relevant front A set of related knowledge items is denoted as ___. .

6. The method for generating SQL knowledge base data based on a large model according to claim 5, characterized in that: In step S4, generating optimization knowledge adapted to the current query context specifically includes: Input the retrieved relevant knowledge entries, target natural language query, and target database schema into the knowledge optimization prompt template. Drive the generation and optimization of knowledge in large language models The process is represented as follows: in, This is a database schema.

7. The method for generating SQL knowledge base data based on a large model according to claim 1, characterized in that: In step S5, the process of inputting the optimized knowledge, target natural language query, and target database schema into the SQL generation model, and generating the final SQL statement under the guidance of the syntax constraint decoding mechanism, specifically includes: Input the optimization knowledge, the target natural language query, and the target database schema into the SQL generation prompt template. This drives the large language model to generate the final SQL statement, and the process is represented as follows: in, For natural language queries, To optimize the knowledge set, Database schema; The syntax constraint decoding mechanism is as follows: during the process of model decoding to generate SQL lexical sequences, a dynamic set of valid lexical units is maintained to restrict the candidate lexical unit set to the range of table names, field names, and SQL syntax keywords that actually exist in the target database schema.

8. A SQL knowledge base data generation system based on a large model, characterized in that, include: The initial knowledge base construction module is used to obtain a seed dataset, and based on the seed dataset, to generate initial knowledge entries using a large language model to construct the initial knowledge base; wherein, the seed dataset contains multiple sets of data, each set of data including natural language queries, corresponding database schemas, and labeled SQL statements; The knowledge base extension module is used to generate extended knowledge entries for query and database schema pairs in the knowledge base by using a large language model and contextual examples. After deduplication and filtering, the extended knowledge entries are updated to the knowledge base, resulting in an updated knowledge base. The relation-aware retrieval module is used to retrieve relevant knowledge entries from the updated knowledge base for the input target natural language query and its corresponding target database pattern using a relation vector injection retrieval model. The context knowledge optimization module is used to input the retrieved knowledge entries, target natural language queries, and target database patterns into the large language model to generate optimized knowledge that is adapted to the current query context. The SQL generation module is used to input optimization knowledge, target natural language queries, and target database schema into the SQL generation prompt template, and, guided by the syntax constraint decoding mechanism, drive the large language model to generate the final SQL statement.

9. An electronic device, characterized in that, include: The present invention includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements a method for generating SQL knowledge base data based on a large model as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program causes the computer to execute a method for generating SQL knowledge base data based on a large model as described in any one of claims 1 to 7.