LLM-based long text SQL generation method, system and device and medium
By constructing a dual knowledge base and verification mechanism, the problems of excessively long LLM prompts and low accuracy caused by the QAR ultra-wide table are solved, realizing efficient and accurate SQL generation and low-threshold queries for operation and maintenance personnel, which is suitable for aviation operation and maintenance scenarios.
Patent Information
- Application Number
- CN202511495322.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-20
- Publication Date
- 2026-01-13
AI Technical Summary
In the field of aviation operations and maintenance, the 1500+ information items in the QAR ultrawide table result in excessively long LLM prompts, low SQL generation accuracy, high professional threshold for operations and maintenance personnel, and a lack of verification mechanisms.
A dual knowledge base is constructed, consisting of an SQL question-and-answer knowledge base and a QAR parameter acquisition knowledge base. Initial SQL statements are generated using preset templates, and syntax and business logic are validated, with error messages provided until validation passes.
It improved SQL generation accuracy by more than 35%, lowered the professional threshold for operation and maintenance personnel by more than 50%, adapted to the personalized query needs of different airlines, and achieved efficient QAR data query.
Smart Images

Figure CN121327092A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the technical field of aircraft data processing and natural language processing, in particular to a long text SQL generation method, system and device based on LLM and a medium. BACKGROUND
[0002] In the field of aviation operation and maintenance, QAR data, as core data reflecting the flight state and equipment operation parameters of an aircraft, contains more than 1500 information items such as flight attitude, engine performance and avionics system state, and is usually stored in the form of a "super-wide table" in an OTS business database. When querying a specific QAR parameter, an operation and maintenance personnel needs to manually write an SQL statement, which has the following technical pain points:
[0003] ①High professional threshold: operation and maintenance personnel need to master both QAR parameter business meaning and SQL syntax, and newbies have high learning costs;
[0004] ②Difficult to process super-wide tables: QAR data super-wide tables contain more than 1500 information items, directly embedding table structures into LLM prompt words will result in long text, which exceeds the context window limit of LLM, and long text prompts will significantly reduce the accuracy of LLM generated SQL;
[0005] ③Lack of verification mechanism: existing text2sql methods only rely on single model output, and do not perform business logic and syntax verification on generated SQL statements, which is prone to query result deviation or execution errors. SUMMARY
[0006] The technical task of the application is to provide a long text SQL generation method, system, device and medium based on LLM to solve the problems of QAR super-wide tables (containing more than 1500 information items) leading to long LLM prompt words, low SQL generation accuracy, high professional threshold for operation and maintenance personnel and lack of verification mechanism in the prior art.
[0007] The technical task of the application is achieved in the following manner: a long text SQL generation method based on LLM, which is as follows:
[0008] A dual-knowledge base including a SQL question and answer pair knowledge base and a QAR parameter acquisition knowledge base is constructed; wherein the SQL question and answer pair knowledge base stores "natural language query-target SQL" paired data in the historical QAR parameter query scene, which is used to provide SQL generation reference for LLM in the same scene; the QAR parameter acquisition knowledge base is obtained based on business field splitting of QAR super-wide tables in OTS business data, which is used to provide accurate QAR parameter-table structure mapping relationship for LLM;
[0009] The QAR parameter query natural language text input by the user is received, and the SQL question and answer pair knowledge base and the QAR parameter acquisition knowledge base are respectively searched to obtain matched reference contents;
[0010] The matched reference contents are constructed into a prompt according to a preset template, the prompt is input into an LLM, and an initial SQL statement is generated; wherein the preset template includes task instructions, SQL references of similar scenarios (from the SQL question and answer pair knowledge base), parameter table structure references (from the QAR parameter acquisition knowledge base), syntax requirements, and user query texts;
[0011] The initial SQL statement is subjected to syntax checking and business logic checking based on the reference contents of the dual knowledge base, and it is determined whether the checking is passed:
[0012] If the checking is passed, a target SQL is output;
[0013] If the checking is not passed, error information is fed back to the LLM for re-generation until the checking is passed.
[0014] As a preferred, the SQL question and answer pair knowledge base is stored in a structured manner of "one question and answer one chapter"; specifically as follows:
[0015] Data collection: collect historical QAR parameter query records in the aviation operation and maintenance scene, filter effective samples, and each sample contains "natural language query and corresponding target SQL statement;
[0016] Chapter division: create an independent chapter for each effective "natural language query-target SQL" paired sample, each chapter content includes chapter identification, problem description, target SQL and annotation description, and multi-dimensional index is established based on "aircraft model-parameter category-query type"; wherein the chapter identification is composed of "aircraft model+query parameter category+query time range"; the problem description adopts standardized user natural language query text; the target SQL refers to the correct SQL statement after syntax checking and business verification; the annotation description refers to the business logic explanation of the key clauses in the SQL statement.
[0017] As a preferred, the QAR parameter acquisition knowledge base is constructed as follows: for the QAR super-wide table containing 1500+ information items in the OTS, the business domain is split according to the three-level splitting strategy of "aircraft model-aircraft component-user self-defined scene", and a scene-based parameter set is generated, and each split parameter set stores the mapping relationship of "parameter name-database table name-field name-data type-business meaning-value range"; specifically as follows:
[0018] First-level splitting, i.e. aircraft model dimension: the super-wide table is split into multiple aircraft model sub-libraries according to the aircraft model, each sub-library only contains QAR parameters of the corresponding aircraft model, avoiding confusion of cross-aircraft model parameters;
[0019] Secondary splitting, namely the aircraft component dimension: within each aircraft type sub-library, it is further split according to the aircraft system components, and each component sub-library contains all the QAR parameters associated with the corresponding component;
[0020] The three-level splitting, namely the user-defined scenario dimension, allows operations and maintenance personnel to customize the splitting of component sub-libraries based on high-frequency query scenarios, generating scenario-based parameter sets;
[0021] The aircraft components include the engine system, avionics system, flight control system, and hydraulic system; user-defined scenarios include takeoff phase parameter monitoring, fault diagnosis parameter groups, and regular maintenance parameter statistics.
[0022] As a preferred approach, the SQL question-and-answer knowledge base is specifically retrieved as follows: based on the matching index of "aircraft type (A320)," "parameter category (flight control system - aileron deflection angle)," and "time range (last 7 days)" in the user query, the "natural language query - target SQL" matching content of the Top 5 similar chapters is obtained;
[0023] Retrieve QAR parameters to obtain the knowledge base: Follow the path "Aircraft type: A320 - Component: Flight Control System - Scenario: Real-time Monitoring" to obtain the table name (qar_a320_fcs), field name (aileron_deflect), and value range (-15°-15°) corresponding to "Aileron deflection angle".
[0024] As a preferred format, the Prompt should be as follows:
[0025] Task: Generate an SQL statement to query the QAR parameters of an aircraft based on a user query. The specific requirements are: referencing similar scenarios, use the SQL statement: {SQL Q-answer pairs with the top 5 matching content in the knowledge base}; based on the parameter table structure: {QAR parameters to retrieve knowledge base search results}; syntax requirements: compatible with MySQL 8.0, including WHERE conditions (time range, parameter thresholds), SELECT specifying fields, and prohibiting SELECT *.
[0026] User query: {Natural language text entered by the user};
[0027] Please output a unique, directly executable SQL statement and briefly explain the correspondence between the fields and parameters in the SQL.
[0028] As a preferred option, the syntax verification specifically involves checking whether the SELECT clause, WHERE condition, and table association logic of the initial SQL conform to the specifications based on the syntax structure of similar SQL queries in the SQL question-and-answer knowledge base, such as determining whether the time range field is correctly referenced.
[0029] The business logic verification specifically includes: obtaining a knowledge base based on QAR parameters, checking whether the field name in the SQL matches the parameters, and whether the parameter threshold is within the value range (such as whether "> 5°" is within "-15° ~ 15°").
[0030] More preferably, the LLM includes Deepseek R1, Qwen2.5;
[0031] The SQL statement is adapted to MySQL8.0 or Oracle database.
[0032] An LLM-based long text SQL generation system for executing the LLM-based long text SQL generation method as described above; the system comprises:
[0033] A dual-knowledge base construction module for constructing a dual-knowledge base comprising a SQL question and answer pair knowledge base and a QAR parameter acquisition knowledge base; wherein the SQL question and answer pair knowledge base stores "natural language query-target SQL" pairing data in the historical QAR parameter query scenario, and is used to provide SQL generation reference for the same scenario for the LLM; the QAR parameter acquisition knowledge base is obtained based on QAR super-wide tables in OTS business data for business domain splitting, and is used to provide accurate QAR parameter-table structure mapping relationship for the LLM;
[0034] A reference content acquisition module for receiving user input QAR parameter query natural language text, retrieving the SQL question and answer pair knowledge base and the QAR parameter acquisition knowledge base respectively, and acquiring matching reference content;
[0035] An LLM inference module for constructing a Prompt according to a preset template based on the matching reference content, inputting the Prompt into the LLM, and generating an initial SQL statement;
[0036] A verification module for performing syntax verification and business logic verification on the initial SQL statement based on the reference content of the dual-knowledge base, and determining whether the verification is passed:
[0037] If the verification is passed, the target SQL is output;
[0038] If the verification is not passed, the error information is fed back to the LLM for re-generation until the verification is passed.
[0039] An electronic device comprising a memory and at least one processor;
[0040] The memory has a computer program stored thereon;
[0041] The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the LLM-based long text SQL generation method as described above.
[0042] A computer readable storage medium, the computer readable storage medium has a computer program stored therein, the computer program can be executed by a processor to implement the LLM-based long text SQL generation method as described above.
[0043] The LLM-based long text SQL generation method, system, device and medium of the application have the following advantages:
[0044] (I) The application divides the super-wide table of 1500+ information items into a lightweight parameter set through three-level splitting of "aircraft model-aircraft component-user custom scenario", avoids long prompt words, reduces the interference of LLM in processing redundant information, improves the SQL generation efficiency, and solves the problem of super-wide table prompt words;
[0045] (II) In the dual-knowledge base collaborative mechanism, the SQL question and answer pair knowledge base provides scenario reference, and the QAR parameter acquisition knowledge base provides accurate table structure, forming a "reference-verification" closed loop, and further reducing SQL syntax errors and business logic deviations in combination with the verification module. According to tests, the SQL generation accuracy is improved by more than 35% compared with the traditional text2sql method, effectively improving the accuracy and reliability;
[0046] (III) The operation and maintenance personnel of the application do not need to master the SQL syntax and super-wide table structure, but can obtain the target SQL through natural language, which significantly reduces the professional threshold of aviation operation and maintenance data query, improves the query efficiency by more than 50%, and reduces the use threshold:
[0047] (IV) The application supports user-defined scene splitting through the QAR parameter acquisition knowledge base, which can dynamically adjust the parameter set according to the operation and maintenance requirements, adapt to the personalized query requirements of different airlines; the SQL question and answer pair knowledge base can continuously expand samples through incremental learning, further optimize the LLM generation effect, and have high expansibility;
[0048] (V) The application solves the problems of long prompt words, low accuracy and lack of verification in existing methods by constructing a dual-knowledge base collaborative mechanism and a super-wide table business splitting strategy, improves the SQL generation accuracy and adds a verification link, does not need to prepare a training set, meets the efficient query requirements of QAR parameters in the aviation operation and maintenance scene, is suitable for quickly generating structured SQL query statements through natural language in the aviation operation and maintenance scene, and realizes efficient retrieval of QAR data;
[0049] (VI) The application constructs a "double knowledge base driving + Prompt engineering optimization" core architecture, wherein the SQL question and answer pair knowledge base stores historical "natural language query-target SQL" pairs to provide scene reference, and the QAR parameter acquisition knowledge base is divided into a lightweight parameter set by "aircraft model-aircraft component-user customized scene" three-level splitting to provide accurate table structure mapping. On the process, first, the double knowledge base is retrieved to construct Prompt and input LLM to generate initial SQL, and then the syntax and business logic are checked by the verification module. If it does not pass, it will feedback error to guide LLM to regenerate, and finally output qualified SQL. It can effectively solve the problem of super-wide table prompt words. The test shows that the SQL generation accuracy is improved by more than 35% compared with the traditional method, the operation and maintenance query efficiency is improved by more than 50%, the use threshold is reduced, and the expansibility is high, which can adapt to the personalized needs of different airlines. BRIEF DESCRIPTION OF DRAWINGS
[0050] The application will be further described below in conjunction with the drawings.
[0051] FIG. 1 is a flow chart of a long text SQL generation method based on LLM. Figure 1 FIG. 1 is a flow chart of a long text SQL generation method based on LLM. DETAILED DESCRIPTION
[0052] The application will be further described below in conjunction with the drawings.
[0053] Embodiment 1:
[0054] As shown in FIG. 1, the embodiment provides a long text SQL generation method based on LLM, which specifically includes the following steps: Figure 1 S1, constructing a double knowledge base including a SQL question and answer pair knowledge base and a QAR parameter acquisition knowledge base; wherein the SQL question and answer pair knowledge base stores "natural language query-target SQL" pair data under the QAR parameter query scene, which is used to provide reference for LLM to generate SQL of the same type of scene; and the QAR parameter acquisition knowledge base is obtained based on the QAR super-wide table in OTS business data, which is used to provide accurate QAR parameter-table structure mapping relationship for LLM;
[0055] S2, receiving the QAR parameter query natural language text input by the user, retrieving the SQL question and answer pair knowledge base and the QAR parameter acquisition knowledge base respectively, and obtaining the matched reference content;
[0056]
[0057] S3, constructing the matched reference content according to a preset template to generate a prompt, inputting the prompt into the LLM to generate an initial SQL statement; wherein the preset template includes task description, SQL reference of similar scenarios (from the SQL question and answer pair knowledge base), parameter table structure reference (from the QAR parameter acquisition knowledge base), syntax requirements and user query text;
[0058] S4, performing syntax verification and business logic verification on the initial SQL statement based on the reference content of the double knowledge base, and determining whether the verification is passed:
[0059] ①If the verification is passed, output the target SQL;
[0060] ②If the verification is not passed, feedback error information to the LLM to regenerate until the verification is passed.
[0061] The structured storage mode of "one question and answer one chapter" is adopted in the step S1 of the embodiment to construct the SQL question and answer pair knowledge base; specifically as follows:
[0062] S101, data collection: collecting historical QAR parameter query records in the aviation operation and maintenance scene, screening effective samples, and each sample containing "natural language query and corresponding target SQL statement";
[0063] S102, chapter division: creating an independent chapter for each effective "natural language query-target SQL" paired sample, each chapter content including chapter identification, problem description, target SQL and annotation description, and establishing multi-dimensional index based on "aircraft model-parameter category-query type"; wherein the chapter identification is composed of "aircraft model+query parameter category+query time range"; the problem description adopts standardized user natural language query text; the target SQL refers to the correct SQL statement after syntax verification and business verification; the annotation description refers to the business logic explanation of the key clauses in the SQL statement.
[0064] The construction of the QAR parameter acquisition knowledge base in step S1 of the embodiment is specifically: for the QAR super-wide table containing 1500+ information items in the OTS, performing business domain division according to the three-level splitting strategy of "aircraft model-aircraft component-user self-defined scene" to generate a scene-based parameter set, and each split parameter set stores the mapping relationship of "parameter name-database table name-field name-data type-business meaning-value range"; specifically as follows:
[0065] First-level splitting, i.e. aircraft model dimension: splitting the super-wide table into multiple aircraft model sub-libraries according to the aircraft model, each sub-library containing only the QAR parameters of the corresponding aircraft model to avoid cross-aircraft parameter confusion;
[0066] Secondary split, i.e. aircraft component dimension: within each aircraft model sub-library, further split by aircraft system component, each component sub-library contains all QAR parameters associated with the corresponding component;
[0067] For example: engine system sub-library: contains EGT (exhaust gas temperature), N1 (low pressure rotor speed), N2 (high pressure rotor speed) and other parameters;
[0068] Avionics system sub-library: contains GPS positioning, radio communication frequency, navigation data and other parameters;
[0069] Third-level split, i.e. user-defined scenario dimension: allows maintenance personnel to further split component sub-libraries according to high-frequency query scenarios to generate scenario-based parameter sets; for example, the "take-off phase parameter group" contains take-off roll distance, wheel lifting speed, take-off thrust and other parameters;
[0070] Among them, the aircraft components include engine system, avionics system, flight control system and hydraulic system; user-defined scenarios include take-off phase parameter monitoring, fault troubleshooting parameter group and periodic maintenance parameter statistics.
[0071] The retrieval SQL question and answer pair knowledge base in step S2 of the embodiment is specifically: based on the matching index of "aircraft model, i.e. A320", "parameter category, i.e. flight control system-aileron deflection angle" and "time range (recent 7 days)", the Top5 similar chapter "natural language query-target SQL" pairing content is obtained.
[0072] The retrieval QAR parameter acquisition knowledge base in step S2 of the embodiment is specifically: according to the path of "aircraft model, i.e. A320-component, i.e. flight control system-scenario, i.e. real-time monitoring", the information of the table name (qar_a320_fcs), field name (aileron_deflect) and value range (-15°-15°) corresponding to "aileron deflection angle" is obtained.
[0073] The Prompt format in step S3 of the embodiment is as follows:
[0074] Task: generate SQL statements for querying aircraft QAR parameters according to user queries, which meet the requirements: refer to similar scenario SQL: {Top5 pairing content of SQL question and answer pair knowledge base}; according to parameter table structure: {retrieval results of QAR parameter acquisition knowledge base}; syntax requirements: adapt to MySQL8.0, contain WHERE condition (time range, parameter threshold), SELECT specified field, prohibit SELECT*;
[0075] User query: {natural language text input by the user};
[0076] Please output the unique, directly executable SQL statement, and briefly explain the correspondence between the fields in the SQL and the parameters.
[0077] The syntax verification in step S4 of the embodiment is specifically: based on the syntax structure of the same type of SQL in the SQL question and answer pair knowledge base, checking whether the SELECT clause, WHERE condition, and table association logic of the initial SQL conform to the specification, for example, judging whether the time range field is correctly referenced.
[0078] The business logic verification in step S4 of the embodiment is specifically: based on the QAR parameter acquisition knowledge base, checking whether the field name in the SQL matches the parameter and whether the parameter threshold is within the value range (such as whether “>5°” is within “-15°-15°”).
[0079] The LLM in the embodiment includes Deepseek R1 and Qwen2.5.
[0080] The SQL statement is adapted to MySQL8.0 or Oracle database.
[0081] Embodiment 2
[0082] The embodiment provides an LLM-based long text SQL generation system, which is used to execute the LLM-based long text SQL generation method as in Embodiment 1; the system comprises:
[0083] A double-knowledge base construction module is configured to construct a double-knowledge base comprising a SQL question and answer pair knowledge base and a QAR parameter acquisition knowledge base; the SQL question and answer pair knowledge base stores “natural language query-target SQL” pairing data in the historical QAR parameter query scene, and is used to provide SQL generation reference for the same type of scene for the LLM; the QAR parameter acquisition knowledge base is obtained based on QAR super-wide tables in OTS business data through business domain splitting, and is used to provide accurate QAR parameter-table structure mapping relationship for the LLM;
[0084] A reference content acquisition module is configured to receive a QAR parameter query natural language text input by a user, retrieve the SQL question and answer pair knowledge base and the QAR parameter acquisition knowledge base respectively, and acquire matched reference content;
[0085] An LLM reasoning module is configured to construct a Prompt according to a preset template based on the matched reference content, input the Prompt into the LLM, and generate an initial SQL statement;
[0086] A verification module is configured to perform syntax verification and business logic verification on the initial SQL statement based on the reference content of the double-knowledge base, and determine whether the verification is passed:
[0087] If the verification is passed, the target SQL is output.
[0088] If the check fails, feedback error information to LLM to regenerate until the check passes.
[0089] The construction process of the SQL question and answer pair knowledge base in this embodiment is specifically: collecting "natural language query-target SQL" paired samples of historical QAR parameter queries, creating an independent chapter for each sample, each chapter containing chapter identification, question description, target SQL and annotation description, and establishing a multi-dimensional index based on "aircraft model-parameter category-query type".
[0090] The construction process of the QAR parameter acquisition knowledge base in this embodiment is specifically: for the QAR super-wide table containing 1500+ information items in the OTS, performing business domain splitting according to a three-level splitting strategy of "aircraft model-aircraft component-user-defined scene", each split parameter set stores a mapping relationship of "parameter name-database table name-field name-data type-business meaning-value range", and the parameter mapping storage specifically stores information such as "parameter name-database table name-field name-data type-business meaning-value range" corresponding to each split parameter set.
[0091] Specifically, the business domain splitting according to the three-level splitting strategy of "aircraft model-aircraft component-user-defined scene" includes the following steps:
[0092] First-level splitting (aircraft model dimension): split the super-wide table into multiple aircraft model sub-libraries according to the aircraft model, each sub-library only contains QAR parameters of the corresponding aircraft model, to avoid cross-aircraft model parameter confusion;
[0093] Second-level splitting (aircraft component dimension): within each aircraft model sub-library, further split according to the aircraft system component, each component sub-library contains all QAR parameters associated with the component, for example:
[0094] Engine system sub-library: contains EGT (exhaust gas temperature), N1 (low-pressure rotor speed), N2 (high-pressure rotor speed) and other parameters;
[0095] Avionics system sub-library: contains GPS positioning, radio communication frequency, navigation data and other parameters;
[0096] Third-level splitting (user-defined scene dimension): allows maintenance personnel to perform custom splitting on the component sub-library according to high-frequency query scenarios to generate scenario-based parameter sets, for example, the "takeoff phase parameter group" contains takeoff roll distance, wheel lifting speed, takeoff thrust and other parameters.
[0097] The aircraft components in this embodiment include the engine system, avionics system, flight control system, and hydraulic system.
[0098] The user-defined scene in the embodiment includes take-off phase parameter monitoring, fault troubleshooting parameter group, and periodic maintenance parameter statistics.
[0099] The preset template in the embodiment includes task description, similar scene SQL reference (from the SQL question and answer pair knowledge base), parameter table structure reference (from the QAR parameter acquisition knowledge base), syntax requirements, and user query text.
[0100] The working process of the verification module in the embodiment is as follows:
[0101] 1. Syntax verification: based on the syntax structure of similar SQL in the SQL question and answer pair knowledge base, the SELECT clause, WHERE condition, and table association logic of the initial SQL are checked.
[0102] 2. Business verification: based on the QAR parameter acquisition knowledge base, the matching of field names and parameters in the initial SQL and the consistency of parameter threshold values and value ranges are checked.
[0103] The LLM in the embodiment includes Deepseek R1 and Qwen 2.5, and the SQL statement is adapted to MySQL 8.0 or Oracle database.
[0104] Embodiment 3
[0105] The embodiment also provides an electronic device including a memory and a processor.
[0106] The memory stores computer execution instructions.
[0107] The processor executes the computer execution instructions stored in the memory, so that the processor executes the LLM-based long text SQL generation method in any embodiment of the application.
[0108] The processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), ready-to-program gate arrays (FPGAs), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The processor can be a microprocessor, or the processor can be any conventional processor.
[0109] The memory can be used to store computer programs and / or modules, and the processor can realize various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application program required by a function, etc.; and the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can also include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state memory devices.
[0110] Embodiment 4
[0111] The embodiment also provides a computer readable storage medium, in which a plurality of instructions are stored, the instructions are loaded by a processor to make the processor execute the LLM-based long text SQL generation method in any embodiment of the application. Specifically, a system or device provided with a storage medium can be provided, the storage medium stores software program codes for realizing the functions of any one of the above embodiments, and the computer (or CPU or MPU) of the system or device reads and executes the program codes stored in the storage medium.
[0112] In this case, the program codes read from the storage medium can realize the functions of any one of the above embodiments, and therefore the program codes and the storage medium storing the program codes constitute a part of the application.
[0113] Embodiments of the storage medium for providing the program codes include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RYM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program codes can be downloaded from a server computer via a communication network.
[0114] In addition, it should be clear that not only the program codes read by the computer can be executed, but also part or all of the actual operations can be completed by the operating system and the like operating on the computer based on the instructions of the program codes, so as to realize the functions of any one of the above embodiments.
[0115] In addition, it can be understood that the program codes read from the storage medium can be written into the memory provided in the expansion board inserted into the computer or the memory provided in the expansion unit connected to the computer, and then part or all of the actual operations can be executed by the CPU and the like installed on the expansion board or the expansion unit based on the instructions of the program codes, so as to realize the functions of any one of the above embodiments.
[0116] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the present application; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions described in the foregoing embodiments can still be modified, or some or all of the technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for generating long text SQL based on LLM, characterized in that, The method is as follows: A dual knowledge base is constructed, comprising an SQL question-answering pair knowledge base and a QAR parameter acquisition knowledge base. The SQL question-answering pair knowledge base stores "natural language query-target SQL" pairing data in historical QAR parameter query scenarios, which is used to provide LLM with SQL generation references for similar scenarios. The QAR parameter acquisition knowledge base is obtained by splitting the QAR ultrawide table in the OTS business data into business domains, which is used to provide LLM with accurate QAR parameter-table structure mapping relationships. Receive the natural language text query input by the user using QAR parameters, and retrieve the SQL question-answering knowledge base and the QAR parameter knowledge base respectively to obtain the matching reference content; The matching reference content is used to construct a Prompt according to a preset template. The Prompt is then input into the LLM to generate the initial SQL statement. The preset template includes task description, SQL references for similar scenarios, parameter table structure references, syntax requirements, and user query text. Based on the reference content from the dual knowledge bases, the initial SQL statement undergoes syntax and business logic validation, and a determination is made as to whether the validation passes. If the validation passes, the target SQL will be output. If the verification fails, an error message is sent to the LLM to regenerate until the verification passes.
2. The method for generating long text SQL based on LLM according to claim 1, characterized in that, The SQL question-and-answer knowledge base is constructed using a structured storage method of "one question and answer per chapter"; the details are as follows: Data collection: Collect historical QAR parameter query records in aviation operation and maintenance scenarios, filter valid samples, and each sample contains "natural language query and corresponding target SQL statement"; Chapter Division: An independent chapter is created for each valid "Natural Language Query - Target SQL" paired sample. Each chapter includes a chapter identifier, problem description, target SQL, and comments. A multi-dimensional index is built based on "device model - parameter category - query type". The chapter identifier consists of "device model + query parameter category + query time range". The problem description uses standardized user natural language query text. The target SQL refers to the correct SQL statement that has passed syntax validation and business verification. The comments are the business logic explanations of the key clauses in the SQL statement.
3. The method for generating long text SQL based on LLM according to claim 1, characterized in that, The construction of the QAR parameter acquisition knowledge base involves: For the QAR ultrawide table containing over 1500 information items in the OTS, a three-level splitting strategy of "aircraft type - aircraft component - user-defined scenario" is used to split the business domain, generating scenario-based parameter sets. Each split parameter set stores a mapping relationship of "parameter name - database table name - field name - data type - business meaning - value range"; specifically as follows: First-level splitting, i.e., aircraft type dimension: the ultrawide table is split into multiple aircraft type sub-databases according to the aircraft type. Each sub-database only contains the QAR parameters of the corresponding aircraft type to avoid cross-aircraft type parameter confusion; Secondary splitting, namely the aircraft component dimension: within each aircraft type sub-library, it is further split according to the aircraft system components, and each component sub-library contains all the QAR parameters associated with the corresponding component; The three-level splitting, namely the user-defined scenario dimension, allows operations and maintenance personnel to customize the splitting of component sub-libraries based on high-frequency query scenarios, generating scenario-based parameter sets; The aircraft components include the engine system, avionics system, flight control system, and hydraulic system; user-defined scenarios include takeoff phase parameter monitoring, fault diagnosis parameter groups, and regular maintenance parameter statistics.
4. The method for generating long text SQL based on LLM according to claim 1, characterized in that, The SQL question-and-answer knowledge base is retrieved by matching the index based on the user's query for "aircraft type (A320)," "parameter category (flight control system - aileron deflection angle)," and "time range," and obtaining the "natural language query - target SQL" matching content of the top 5 similar chapters. Retrieve QAR parameters to access the knowledge base: Follow the path "Aircraft type: A320 - Component: Flight Control System - Scenario: Real-time Monitoring" to obtain the table name, field name, and value range information corresponding to "Aileron Deflection Angle".
5. The method for generating long text SQL based on LLM according to claim 1, characterized in that, The Prompt format is as follows: Task: Generate an SQL statement to query the QAR parameters of an aircraft based on a user query. The specific requirements are: referencing similar scenarios, use the SQL statement: {SQL Q-answer pairs with the top 5 matching content in the knowledge base}; based on the parameter table structure: {QAR parameters to retrieve knowledge base search results}; syntax requirements: compatible with MySQL 8.0, including WHERE conditions and SELECT specifying fields, but prohibiting SELECT *. User query: {Natural language text entered by the user}; Please output a unique, directly executable SQL statement and briefly explain the correspondence between the fields and parameters in the SQL.
6. The method for generating long text SQL based on LLM according to claim 1, characterized in that, The syntax verification specifically involves checking whether the SELECT clause, WHERE condition, and table join logic of the initial SQL conform to the specifications based on the syntax structure of similar SQL queries in the SQL question-and-answer knowledge base. The business logic validation specifically involves: obtaining the knowledge base based on QAR parameters, and checking whether the field names in the SQL match the parameters and whether the parameter thresholds are within the range of values.
7. The method for generating long text SQL based on LLM according to any one of claims 1 to 6, characterized in that, LLM includes Deepseek R1 and Qwen2.5; SQL statements are compatible with MySQL 8.0 or Oracle databases.
8. A long text SQL generation system based on LLM, characterized in that, This system is used to execute the LLM-based long text SQL generation method as described in any one of claims 1 to 7; the system includes: The dual knowledge base construction module is used to build two knowledge bases, including an SQL question-answering pair knowledge base and a QAR parameter acquisition knowledge base. The SQL question-answering pair knowledge base stores "natural language query-target SQL" pairing data in historical QAR parameter query scenarios, which is used to provide LLM with SQL generation references for similar scenarios. The QAR parameter acquisition knowledge base is obtained by splitting the QAR ultrawide table in the OTS business data into business domains, which is used to provide LLM with accurate QAR parameter-table structure mapping relationships. The reference content acquisition module is used to receive the natural language text of the QAR parameter query input by the user, and retrieve the matching reference content by searching the SQL question-answering knowledge base and the QAR parameter acquisition knowledge base respectively. The LLM inference module is used to construct a Prompt based on a preset template from the matched reference content. The Prompt is then input into the LLM to generate the initial SQL statement. The validation module performs syntax and business logic validation on the initial SQL statement based on the reference content from the dual knowledge bases, and determines whether the validation passes. If the validation passes, the target SQL will be output. If the verification fails, an error message is sent to the LLM to regenerate until the verification passes.
9. An electronic device, characterized in that, include: Memory and at least one processor; The memory contains computer programs; The at least one processor executes the computer program stored in the memory, causing the at least one processor to perform the LLM-based long text SQL generation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that can be executed by a processor to implement the LLM-based long text SQL generation method as described in any one of claims 1 to 7.
Citation Information
Cited By
Text generation method based on large language model
CN122113890A