A Large Language Model-Based Intelligent Data Query Method Applicable to Electricity Data Query Scenarios
By combining a large language model with semantic decomposition and a Transformer decoder to generate SQL statements for electricity marketing data, the problem of semantic understanding and multi-table joins in electricity marketing data queries in existing technologies has been solved, achieving query results with high accuracy and low failure rate.
Patent Information
- Application Number
- CN202511416277.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2045-09-30
AI Technical Summary
The existing NL2SQL model has difficulty understanding the electricity marketing-specific semantics and indicator logic in the electricity marketing data scenario. It cannot identify the composite calculation logic and the dependency relationship between upstream and downstream indicators, resulting in SQL statement generation errors or query failures. It also lacks the ability to handle multi-table joins and implicit field mapping.
A large language model is used in combination with a semantic decomposition module, a database field matching module, and a prompt word generation module. Keyword vectors are extracted through semantic decomposition, a structured Prompt is constructed, and SQL statements are generated using a Transformer decoder. Syntax errors are then corrected using an NTLR4 syntax tree.
It significantly improves the ability to parse professional terminology and indicator logic in the power industry, automatically identifies the implicit mapping relationship between keywords and database fields, reduces the query failure rate, and improves the accuracy and completeness of SQL generation.
Smart Images

Figure CN120892452B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a large language model-based intelligent data query method suitable for electricity data query scenarios, belonging to the field of machine learning technology. Background Technology
[0002] The scale of electricity data involved in electricity marketing is growing daily. Business personnel need to frequently carry out various data query and analysis tasks in their daily work, such as user profile analysis, daily electricity consumption summary, and market user dynamic tracking. Currently, relevant business personnel rely on traditional SQL query methods for data acquisition and analysis, and are gradually adapting to the "query-based" data access method that directly generates SQL statements from natural language.
[0003] However, due to the typical characteristics of electricity marketing data, such as complex multi-table relationships, rich industry terminology, and deep nesting of indicator logic, existing natural language to SQL methods still face the following challenges in applying electricity marketing data scenarios: Existing NL2SQL models struggle to understand electricity marketing-specific semantics and indicator logic. Most current NL2SQL models are trained on general corpora and lack the ability to understand electricity-specific concepts such as "daily electricity consumption pull rate," "industry year-on-year growth," and "monthly average load." They cannot identify the complex calculation logic and upstream / downstream indicator dependencies inherent in user questions, resulting in generated SQL statements that cannot effectively reproduce business semantics, severely impacting the accuracy and usability of query results. Multi-table joins and implicit field mapping capabilities are weak. Since electricity data is often distributed across multiple business subject tables, complex multi-table join statements need to be constructed during queries. Existing NL2SQL technology struggles to automatically identify business relationships and JOIN paths between implicit fields, often resulting in missing fields, ambiguity conflicts, and other problems, leading to SQL structure errors or incomplete semantics, and a high query failure rate. There is a lack of structured support for time series analysis requirements. Electricity data analysis involves a large amount of typical time-dimensional deduction logic. General models have difficulty recognizing the time comparison rules and calculation formulas involved, and cannot automatically generate SQL statements containing aggregation calculations and multiple time windows, which limits their applicability in marketing business analysis questions. Summary of the Invention
[0004] To address the problems existing in the prior art, this invention proposes a large language model-based intelligent data query method suitable for electricity data query scenarios.
[0005] The technical solution of the present invention is as follows:
[0006] On the one hand, this invention provides a large language model-based intelligent data query method suitable for electricity data query scenarios, including the following steps:
[0007] Semantic decomposition is performed on the user-input query to extract keyword vectors and query features;
[0008] Based on the extracted keyword vectors, database field names are matched to obtain the database field names corresponding to all keyword vectors;
[0009] A structured Prompt is constructed based on the query features and the database field names corresponding to all keyword vectors. The initial database query statement is then generated in the large language model based on the constructed Prompt.
[0010] After repairing the initial database query statement, a database query statement is obtained. The corresponding data is then retrieved from the database using the database query statement and returned to the user.
[0011] Preferably, the specific steps for semantically decomposing the user-input query content are as follows:
[0012] After segmenting the query content into words, keyword vectors are obtained. Then, the keyword vectors are input into the DeBERTa model to extract the context semantic vector of each keyword vector.
[0013] Construct a character feature extraction model, input the query content into the character feature extraction model to extract the features of each character;
[0014] A phrase feature extraction model is constructed. After concatenating all context semantic vectors, the model extracts segments by sliding through a window of a preset number of characters. Multiple segments are obtained and input into the phrase feature extraction model. The phrase feature extraction model outputs the phrase features of each segment.
[0015] All context semantic vectors, character features, and phrase features are fused to obtain a fused feature vector;
[0016] The fused feature vector is input into a bidirectional long short-term memory network to extract the bidirectional latent vector of the fused feature vector. The bidirectional latent vectors are then concatenated to obtain the comprehensive latent vector.
[0017] Dependency arcs between each keyword vector are extracted based on the dependency parsing algorithm. A dependency arc set is constructed based on all dependency arcs. A dependency convolution model is built, and the dependency arc set is input into the dependency convolution model to extract dependency feature vectors.
[0018] The query features of the current query statement are obtained by fusing the dependency feature vector and the comprehensive latent vector.
[0019] Preferably, the specific steps for database field name matching based on the extracted keyword vector are as follows:
[0020] Filter out the valid keyword vectors from all keyword vectors;
[0021] Field name matching is performed in the database based on effective keyword vectors.
[0022] Preferably, the specific steps for constructing a structured Prompt based on query features and the database field names corresponding to all keyword vectors are as follows:
[0023] Linearly project the query features into a continuous vector sequence;
[0024] For each valid keyword vector, the corresponding database field name is encoded and embedded into a continuous vector sequence to obtain the field embedding vector sequence.
[0025] Construct a decoder based on the Transformer model, embed fields into the vector sequence input of the decoder, and output a structured Prompt.
[0026] Preferably, the decoder based on the Transformer model specifically includes a rotational positional encoding attention layer, a local convolutional layer, a feedforward gated fusion layer, and an output layer.
[0027] Preferably, a database syntax tree is constructed using NTLR4, and the syntax tree is used to detect and correct syntax errors in the initial database query statements.
[0028] On the other hand, the present invention also provides a large language model intelligent questioning system suitable for power data query scenarios, including a semantic decomposition module, a database field matching module, a prompt word generation module, and a query module;
[0029] The semantic decomposition module is used to perform semantic decomposition on the query content input by the user to extract keyword vectors and query features;
[0030] The database field matching module is used to match database field names based on the extracted keyword vectors to obtain the database field names corresponding to all keyword vectors.
[0031] The prompt word generation module is used to construct a structured Prompt based on query features and the database field names corresponding to all keyword vectors, and to generate a preliminary database query statement in the large language model based on the constructed Prompt.
[0032] The query module is used to repair the initial database query statement to obtain the database query statement, and then retrieve the corresponding data from the database using the database query statement and return it to the user.
[0033] In another aspect, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the present invention.
[0034] In another aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the method described in the present invention.
[0035] The present invention has the following beneficial effects:
[0036] 1. This invention introduces a semantic decomposition module that integrates contextual semantics, character features, and phrase features. Combined with dependency parsing and dependency convolutional networks, it can deeply understand professional terms and indicator logic in the power industry, such as "daily electricity consumption pull rate" and "year-on-year growth rate". This significantly improves the ability to parse complex business semantics and solves the problem that existing NL2SQL models are unable to restore the semantics of power marketing.
[0037] 2. This invention, through effective keyword filtering and vector matching mechanisms, combined with field embedding and Transformer decoder modeling, can automatically identify the implicit mapping relationship between keywords and database fields, and reasonably construct JOIN paths, solving the problems of missing fields and semantic ambiguity in multi-table queries in existing technologies, and improving the accuracy and completeness of SQL generation.
[0038] 3. This invention constructs a structured Prompt generation module to guide the large language model to output preliminary SQL, and then uses the NTLR4 syntax tree model to automatically correct syntax errors, thereby achieving a closed-loop guarantee from natural language to executable SQL statements, reducing query failure rate and improving user experience. Attached Figure Description
[0039] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0040] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0041] It should be understood that the step numbers used in the text are for ease of description only and are not intended to limit the order in which the steps are performed.
[0042] It should be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0043] The terms “comprising” and “including” indicate the presence of the described feature, whole, step, operation, element and / or component, but do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or collections thereof.
[0044] The term “and / or” refers to any combination of one or more of the associated listed items, as well as all possible combinations, and includes these combinations.
[0045] See Figure 1 A large language model-based intelligent data query method suitable for electricity data query scenarios includes the following steps:
[0046] Semantic decomposition is performed on the user-input query to extract keyword vectors and query features;
[0047] Based on the extracted keyword vectors, database field names are matched to obtain the database field names corresponding to all keyword vectors;
[0048] A structured Prompt is constructed based on the query features and the database field names corresponding to all keyword vectors. The initial database query statement is then generated in the large language model based on the constructed Prompt.
[0049] After repairing the initial database query statement, a database query statement is obtained. The corresponding data is then retrieved from the database using the database query statement and returned to the user.
[0050] In some embodiments, the specific steps for semantically decomposing the query content input by the user are as follows:
[0051] After segmenting the query content into words, keyword vectors are obtained. Then, the keyword vectors are input into the DeBERTa model to extract the context semantic vector of each keyword vector.
[0052] Construct a character feature extraction model, input the query content into the character feature extraction model to extract the features of each character;
[0053] A phrase feature extraction model is constructed. After concatenating all context semantic vectors, the model extracts segments by sliding through a window of a preset number of characters. Multiple segments are obtained and input into the phrase feature extraction model. The phrase feature extraction model outputs the phrase features of each segment.
[0054] All context semantic vectors, character features, and phrase features are fused to obtain a fused feature vector;
[0055] The fused feature vector is input into a bidirectional long short-term memory network to extract the bidirectional latent vector of the fused feature vector. The bidirectional latent vectors are then concatenated to obtain the comprehensive latent vector.
[0056] Dependency arcs between each keyword vector are extracted based on the dependency parsing algorithm. A dependency arc set is constructed based on all dependency arcs. A dependency convolution model is built, and the dependency arc set is input into the dependency convolution model to extract dependency feature vectors.
[0057] The query features of the current query statement are obtained by fusing the dependency feature vector and the comprehensive latent vector.
[0058] In one specific embodiment, both the character feature extraction model and the phrase feature extraction model are constructed based on convolutional neural networks, wherein: the character feature extraction model has three convolutional layers and each convolutional kernel has 32 filters; the phrase feature extraction model has two convolutional layers and each convolutional kernel has 64 filters.
[0059] In one specific embodiment, the DeBERTa-v3 model is used to extract the context semantic vector of each keyword vector;
[0060] In one specific embodiment, the jieba word segmentation algorithm is used to segment the query content into words;
[0061] In one specific embodiment, a gating fusion unit is configured to fuse all context semantic vectors, character features, and phrase features, as shown in the following formula:
[0062] ;
[0063] in: Represents the fused feature vector; This represents the sigmoid activation function; Indicates character characteristics; Indicates character feature weights; Indicates phrase characteristics; Indicates phrase feature weights; Represents a context semantic vector; This indicates element-wise multiplication.
[0064] In a specific embodiment, the fused feature vector is input into a bidirectional long short-term memory network to extract the bidirectional latent vector of the fused feature vector. Then, the bidirectional latent vectors are concatenated to obtain the comprehensive latent vector, as shown in the following formula:
[0065] ;
[0066] ;
[0067] in: This represents the positive latent vector that integrates the feature vectors. Represents the inverse latent vector of the fused feature vectors; Represents the composite implicit vector; This indicates a splicing operation.
[0068] In one specific embodiment, a dependency convolution model is constructed, which includes multiple convolutional layers. The dependency arc set is input into the dependency convolution model to extract dependency feature vectors, as shown in the following formula:
[0069] ;
[0070] in: This indicates the dependency convolution model. The output of the last layer is the dependency feature vector; express Activation function; Represent the set of dependent arcs; Indicates the first The number of dependency arcs for each keyword vector; Indicates in Middle and the first Keyword vectors with dependency arcs between them A set; This indicates the dependency convolution model. Layer weight matrix; Indicates the first The keyword vector in the dependency convolution model Vector representation of a layer;
[0071] In a specific embodiment, the fusion of the dependency feature vector and the comprehensive latent vector is shown in the following formula:
[0072] ;
[0073] ;
[0074] in: Indicates query characteristics; Indicates the adaptive gating coefficient; Represents the dependent eigenvectors; This represents the gating weight vector.
[0075] In some embodiments, the specific steps for matching database field names based on the extracted keyword vectors are as follows:
[0076] Filter out the valid keyword vectors from all keyword vectors;
[0077] Field name matching is performed in the database based on effective keyword vectors.
[0078] In a specific embodiment, the steps for filtering valid keyword vectors from all keyword vectors are as follows:
[0079] All keyword vectors are used as candidate words to construct a candidate word similarity graph. Each node in the candidate word similarity graph corresponds to a candidate word, and the cosine similarity between nodes is used as the edge weight.
[0080] The score for each node is calculated based on the edge weights between nodes, and the score is iterated through a machine learning model, as shown in the following formula:
[0081] ;
[0082] ;
[0083] in: Indicates the first Next iteration node The corresponding score; The damping coefficient is determined iteratively. Indicates word frequency score; Indicates the node The set of nodes outside; Represents a node With nodes The boundary weight between; Represents a node All edge weights combined; Indicates the first Next iteration node The corresponding score; Represents a node TF-IDF score; Represents a node TF-IDF score;
[0084] When the deviation between two consecutive iterations reaches a preset deviation threshold, the iteration stops, the score of each node is obtained, and the candidate words corresponding to the nodes with scores greater than the preset score threshold are selected as effective keyword vectors.
[0085] In one specific embodiment, after mapping the effective keyword vectors and database field names to vectors of the same dimension using the Word2Vec model, the cosine similarity is calculated for each, and the one with the highest cosine similarity is determined to be a successful match.
[0086] In some embodiments, the specific steps for constructing a structured Prompt based on query features and the database field names corresponding to all keyword vectors are as follows:
[0087] Linearly project the query features into a continuous vector sequence;
[0088] For each valid keyword vector, the corresponding database field name is encoded and embedded into a continuous vector sequence to obtain the field embedding vector sequence.
[0089] Construct a decoder based on the Transformer model, embed fields into the vector sequence input of the decoder, and output a structured Prompt.
[0090] In a specific embodiment, the query features are linearly projected into a continuous vector sequence, as shown in the following equation:
[0091] ;
[0092] in: Represents a continuous vector sequence; Represents the linear projection weight matrix; This indicates linear projection bias.
[0093] In a specific embodiment, the database field name corresponding to each valid keyword vector is encoded and embedded into a continuous vector sequence to obtain a field embedding vector sequence, as shown in the following formula:
[0094] ;
[0095] ;
[0096] in: This indicates that the field is embedded in a vector sequence; Indicates the first Database field name encoding; Indicates the total number of database field names; Indicates the first The embedding vectors of each database field name are calculated based on a pre-trained text encoder; Indicates the first Each database field name corresponds to the relative position of the keyword vector within the query content, specifically the position relative to the first character of the query content.
[0097] In some embodiments, the decoder based on the Transformer model specifically includes a rotational positional encoding attention layer, a local convolutional layer, a feedforward gated fusion layer, and an output layer;
[0098] In one specific embodiment, the rotating positional encoding attention layer first performs rotating positional encoding on the encoding of each database field name in the field embedding vector sequence, as shown in the following formula:
[0099] ;
[0100] in: Represents the first position after rotational position encoding Database field name encoding; This indicates a rotary position encoder; Indicates the first Each database field name is encoded in the field embedding vector sequence;
[0101] The original database field name encoding in the field embedding vector sequence is replaced by the rotated position encoding of the database field name encoding to obtain a new field embedding vector sequence. Then, attention weights are extracted through an attention mechanism, as shown in the following formula:
[0102] ;
[0103] ;
[0104] ;
[0105] in: This indicates that the new field is embedded in the vector sequence at the th th . The weight of each database field name encoding; This indicates that the new field is embedded in the vector sequence at the th... A query vector encoded by each database field name; This indicates that the new field is embedded in the vector sequence at the th... A key vector encoded by each database field name; Indicates the attention dimension; A learnable relative position bias table, with the bias value determined based on the distance between two database field name encodings; Represents a learnable query matrix; Represents the learnable key matrix;
[0106] The weighted field embedding vector sequence is obtained by assigning weights to the encoding of each database field name in the new field embedding vector sequence based on attention weights.
[0107] In a specific embodiment, the local convolutional layer consists of multiple depthwise separable convolutional layers, each with a different kernel size. These layers are used to extract local features encoded by each database field name in the weighted field embedding vector sequence. The output of any depthwise separable convolutional layer is shown in the following formula:
[0108] ;
[0109] ;
[0110] in: This indicates the weighted field embedding in the vector sequence. Each database field name is encoded as a preliminary feature extracted through a depthwise separable convolutional layer; This indicates the kernel size of the separable convolutional layer at the current depth; This indicates the separable convolutional layer weights at the current depth; This indicates the weighted field embedding in the vector sequence. Database field name encoding; This indicates that the weighted field is embedded in the vector sequence of the first... Database field name encoding; This represents the weighted field embedding vector sequence of the output of the currently depth-separable convolutional layer. The local features encoded by each database field name are input into the next depthwise separable convolutional layer if the current depthwise separable convolutional layer is not the last layer; otherwise, they are used as the final output. This represents LayerScale (scalability factor); This indicates a normalization operation;
[0111] In one specific embodiment, the feedforward gated fusion layer includes a main channel and a gate channel, as shown in the following formula:
[0112] ;
[0113] ;
[0114] ;
[0115] ;
[0116] in: This indicates the output of the feedforward gated fusion layer; This indicates the main channel output of the feedforward gated fusion layer; Indicates the gate channel output of the feedforward gated fusion layer; This indicates the fusion result of the main channel output and the gate channel output of the feedforward gated fusion layer; This indicates that the weighted field is embedded in a vector sequence; This represents the output weight matrix of the feedforward gated fusion layer; This indicates the output bias of the feedforward gated fusion layer; This represents the output of a local convolutional layer; This represents the main channel weight matrix; Indicates main channel offset; This represents the gate channel weight matrix; Indicates door channel offset;
[0117] In one specific embodiment, the output layer is built on a multilayer perceptron and is used to receive the output of the feedforward gated fusion layer and input the structured Prompt.
[0118] In one specific embodiment, the structured Prompt example is as follows:
[0119] Question: Query the year-on-year comparison of daily electricity consumption and its impact on the economy for large industrial users in a certain region in March 2024;
[0120] Fields: date, city_name, industry_type, daily_energy, year_over_year, pull_rate;
[0121] Objective: Generate an executable SQL statement that satisfies the following:
[0122] 1. Compile daily data for a specific region and major industrial users from March 1, 2024 to March 31, 2024.
[0123] 2. Also provide the daily electricity consumption this year, the daily electricity consumption in the same period last year, the year-on-year growth rate (%), and the contribution rate (%).
[0124] 3. If the `year_over_year` or `pull_rate` field does not exist, please calculate it in the SQL:
[0125] Year-on-year = (This year's electricity consumption - Last year's electricity consumption) / Last year's electricity consumption × 100;
[0126] Pull-up rate = (Today's growth / Monthly cumulative growth) × 100;
[0127] 4. Results are sorted in ascending order by date.
[0128] In some embodiments, a database syntax tree is constructed using NTLR4, and syntax errors in the initial database query statements are detected and corrected using the database syntax tree.
[0129] In some embodiments, a large language model intelligent data query system suitable for power data query scenarios is proposed, including a semantic decomposition module, a database field matching module, a prompt word generation module, and a query module;
[0130] The semantic decomposition module is used to perform semantic decomposition on the query content input by the user to extract keyword vectors and query features;
[0131] The database field matching module is used to match database field names based on the extracted keyword vectors to obtain the database field names corresponding to all keyword vectors.
[0132] The prompt word generation module is used to construct a structured Prompt based on query features and the database field names corresponding to all keyword vectors, and to generate a preliminary database query statement in the large language model based on the constructed Prompt.
[0133] The query module is used to repair the initial database query statement to obtain the database query statement, and then retrieve the corresponding data from the database using the database query statement and return it to the user.
[0134] In some embodiments, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method as described in any embodiment of the present invention.
[0135] In some embodiments, a computer-readable storage medium is provided on which a computer program is stored, which, when executed by a processor, implements the method as described in any embodiment of the present invention.
[0136] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent the existence of A alone, A and B simultaneously, or B alone. A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of singular or plural items. For example, at least one of a, b, and c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, and c can be single or multiple.
[0137] Those skilled in the art will recognize that the units and algorithm steps described in the embodiments disclosed herein can be implemented using electronic hardware, computer software, or a combination of electronic hardware and software. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0138] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0139] In the several embodiments provided in this application, any function, if implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0140] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A large language model-based intelligent data query method suitable for electricity data query scenarios, characterized in that, Includes the following steps: Semantic decomposition is performed on the user-input query to extract keyword vectors and query features; Based on the extracted keyword vectors, database field names are matched to obtain the database field names corresponding to all keyword vectors; A structured Prompt is constructed based on the query features and the database field names corresponding to all keyword vectors. The initial database query statement is then generated in the large language model based on the constructed Prompt. After repairing the initial database query statement, a database query statement is obtained. The corresponding data is then retrieved from the database using the database query statement and returned to the user. The specific steps for semantically decomposing the user-input query content are as follows: After segmenting the query content into words, keyword vectors are obtained. Then, the keyword vectors are input into the DeBERTa model to extract the context semantic vector of each keyword vector. Construct a character feature extraction model, input the query content into the character feature extraction model to extract the features of each character; A phrase feature extraction model is constructed. After concatenating all context semantic vectors, the model extracts segments by sliding through a window of a preset number of characters. Multiple segments are obtained and input into the phrase feature extraction model. The phrase feature extraction model outputs the phrase features of each segment. All context semantic vectors, character features, and phrase features are fused to obtain a fused feature vector; The fused feature vector is input into a bidirectional long short-term memory network to extract the bidirectional latent vector of the fused feature vector. The bidirectional latent vectors are then concatenated to obtain the comprehensive latent vector. Dependency arcs between each keyword vector are extracted based on the dependency parsing algorithm. A dependency arc set is constructed based on all dependency arcs. A dependency convolution model is built, and the dependency arc set is input into the dependency convolution model to extract dependency feature vectors. The query features of the current query statement are obtained by fusing the dependency feature vector and the comprehensive latent vector. The specific steps for database field name matching based on the extracted keyword vectors are as follows: Filter out the valid keyword vectors from all keyword vectors; Field name matching in the database is performed based on effective keyword vectors; The specific steps for constructing a structured Prompt based on query features and the database field names corresponding to all keyword vectors are as follows: Linearly project the query features into a continuous vector sequence; For each valid keyword vector, the corresponding database field name is encoded and embedded into a continuous vector sequence to obtain the field embedding vector sequence. Construct a decoder based on the Transformer model, embed fields into the vector sequence input of the decoder, and output a structured Prompt.
2. The intelligent data query method based on a large language model applicable to electricity data query scenarios according to claim 1, characterized in that, The decoder based on the Transformer model specifically includes a rotational positional encoding attention layer, a local convolutional layer, a feedforward gated fusion layer, and an output layer.
3. The intelligent data query method based on a large language model suitable for electricity data query scenarios according to claim 1, characterized in that, A database syntax tree is built using ANTLR4, and syntax errors in the initial database query statements are detected and corrected using the database syntax tree.
4. A large language model-based intelligent data query system suitable for electricity data query scenarios, characterized in that, The method used in any one of claims 1 to 3 includes a semantic decomposition module, a database field matching module, a prompt word generation module, and a query module; The semantic decomposition module is used to perform semantic decomposition on the query content input by the user to extract keyword vectors and query features; The database field matching module is used to match database field names based on the extracted keyword vectors to obtain the database field names corresponding to all keyword vectors. The prompt word generation module is used to construct a structured Prompt based on query features and the database field names corresponding to all keyword vectors, and to generate a preliminary database query statement in the large language model based on the constructed Prompt. The query module is used to repair the initial database query statement to obtain the database query statement, and then retrieve the corresponding data from the database using the database query statement and return it to the user.
5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the method as described in any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Multi-document intelligent question and answer method and system based on large language model
CN118394897A
Natural language to SQL (Structured Query Language) method and device based on large language model and medium
CN120011392A