Interactive data query and display method and system based on large language model
Through interactive data query and display methods based on large language models, the problems of high professional requirements for users, low efficiency and poor flexibility of traditional data query methods are solved, and efficient, convenient and flexible data query and display are achieved.
Patent Information
- Application Number
- CN202411781183.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-04-29
AI Technical Summary
Traditional data query methods have high professional requirements for users, are inefficient when processing large-scale data sets and are difficult to feedback results in real time. The SQL query language automatic generation solution requires pre-constructing a fixed query request format and SQL template, resulting in poor flexibility and complex operation of data visualization tools.
An interactive data query and display method based on a large language model is adopted. By obtaining the user's natural language query request, identifying the query intent and key entities, generating structured query parameters, rewriting the query request to comply with the standard query syntax, using the large language model to generate SQL query statements, and automatically generating a chart for results display.
It improves the convenience and user experience of data query, reduces the incompleteness and error of user input, improves the accuracy and efficiency of query, and enhances the flexibility and user-friendliness of data visualization.
Smart Images

Figure CN119903165A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data query, and in particular to an interactive data query and display method and system based on a large language model. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] The inventors found that traditional data query methods rely on SQL query language or other scripting languages, which require users to have certain programming knowledge, and are inefficient when processing large-scale data sets and difficult to provide real-time feedback results; at the same time, although there are some automatic generation solutions for SQL query language, these solutions often require pre-building a fixed query request format and a matching template for the solidified SQL query language, resulting in poor template fixation and flexibility. Secondly, although existing data visualization tools can generate charts to help users understand data, they usually require pre-defined data formats and query conditions, have low flexibility, and are more complex to operate for non-professional users. Summary of the invention
[0004] The present invention provides an interactive data query and display method and system based on a large language model to solve the problems that traditional solutions have high professional requirements for users, are inefficient when processing large-scale data sets, and are difficult to provide real-time feedback; as well as some automatic generation solutions for SQL query languages, but these solutions often require pre-building a matching template between a fixed query request format and a solidified SQL query language, resulting in poor template fixation and flexibility; and, although traditional solutions can generate charts to help users understand data, they usually require pre-defined data formats and query conditions, have low flexibility, and have high operational complexity for non-professional users.
[0005] According to a first aspect of an embodiment of the present invention, there is provided an interactive data query and display method based on a large language model, comprising:
[0006] Obtaining user query requests and the business database used for querying;
[0007] Based on the user query request, obtaining the query intent classification result of the user query request and the key entities in the user query request; generating structured query parameters based on the obtained query intent classification result and the key entities;
[0008] Based on the generated structured query parameters, the user query request is rewritten to conform to the standard query syntax through interactive processing;
[0009] Construct query hints based on the rewritten user query, and generate SQL query statements based on the constructed query hints through a pre-trained large language model;
[0010] Based on the generated SQL query statement, obtain data query results from the business database used for query;
[0011] Based on the query results, a chart is automatically generated to display the query results, wherein the chart type is determined according to the chart display type of the user's historical query results.
[0012] Furthermore, based on the generated structured query parameters, the user query request is rewritten through interactive processing to conform to the standard query syntax, specifically: based on the query intent classification results in the structured query parameters, the user query request is supplemented with the user intent content; and based on the user's historical query requests, the missing information in the current user query request is determined through comparative analysis; for the missing information in the determined query request, the user is reminded to supplement it through a message prompt, or the missing information is supplemented based on the content in the user's historical query requests and the user is prompted to confirm.
[0013] Furthermore, the query prompt words are constructed based on the rewritten user query, and the query prompt words include: the rewritten user query request, possible target data tables in the business database, key entity information, and constraints set by the user; wherein the possible target data tables in the business database are determined by data tables whose probability of appearing in the user's historical query requests meets preset requirements and data tables set by the user based on experience.
[0014] Furthermore, the training of the large language model is specifically as follows: obtaining several natural language query requests, and determining key entities and intent classifications in the natural language query requests through expert judgment; manually determining the SQL query statements corresponding to the natural language query requests based on the obtained key entities and intent classification results; constructing a data set based on several natural language query requests and their corresponding SQL query statements; and fine-tuning the pre-trained large language model based on the constructed data set to obtain a trained large language model.
[0015] Furthermore, based on the user query request, the query intent classification result of the user query request and the key entities in the user query request are obtained, specifically: performing word segmentation and labeling processing on the obtained user query request; based on the user query request after word segmentation and labeling processing, obtaining the key entities in the user query request through a pre-trained named entity recognition model; based on the user query request, obtaining the user intent classification result through a pre-trained intent classification model.
[0016] Furthermore, the construction of the business database for query is specifically as follows: obtaining business data from different business systems and performing corresponding preprocessing; based on the preprocessed business data from different business systems, according to the logical relationship between the business data from different business systems, performing data integration to form a number of data tables; and realizing the construction of the business database based on the obtained data tables.
[0017] According to a second aspect of an embodiment of the present invention, there is provided an interactive data query and display system based on a large language model, comprising:
[0018] A data acquisition unit, which is used to acquire a user query request and a business database for query;
[0019] A structured parameter generating unit, which is used to obtain the query intent classification result of the user query request and the key entities in the user query request based on the user query request; and generate structured query parameters based on the obtained query intent classification result and the key entities;
[0020] A query unit, which is used to rewrite the user query request to conform to the standard query syntax through interactive processing based on the generated structured query parameters; construct query prompt words based on the rewritten user query, and generate SQL query statements based on the constructed query prompt words through a pre-trained large language model; based on the generated SQL query statement, obtain data query results from the business database used for query;
[0021] A display unit is used to automatically generate a chart based on the query result to display the query result, wherein the chart type is determined according to the chart display type of the user's historical query result.
[0022] According to a third aspect of an embodiment of the present invention, there is provided an electronic device, comprising a memory, a processor, and a computer program stored and running on the memory, wherein when the processor executes the program, the method for interactive data query and display based on a large language model is implemented.
[0023] According to a fourth aspect of an embodiment of the present invention, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the interactive data query and display method based on a large language model is implemented.
[0024] According to a fifth aspect of an embodiment of the present invention, a computer program product is provided, on which a computer program is stored, and when the program is executed by a processor, the interactive data query and display method based on a large language model is implemented.
[0025] One or more of the above technical solutions have the following beneficial effects:
[0026] The present invention provides an interactive data query and display method and system based on a large language model. In the scheme, users can input query requests through natural language without having SQL knowledge, thereby improving the convenience of query and user experience.
[0027] The scheme of the present invention rewrites the user query request to conform to the standard query syntax through interactive processing based on the structured query parameters generated by the query request input by the user, and dynamically generates prompt words in combination with the rewritten user query request and auxiliary information input through human-computer interaction and the like, guides the large language model to generate high-quality SQL query statements, reduces the incompleteness and errors of the user input through multi-source data fusion and dynamic prompt word generation, and improves the accuracy and efficiency of the query.
[0028] The solution of the present invention combines the user's historical records with the generation of dynamic prompt words, can cover a wider range of query scenarios, and improve the generalization ability of the model.
[0029] The solution described in the present invention is based on the chart display type of the user's historical query results, and automatically generates corresponding display charts according to the user's preferences, which greatly improves the user satisfaction; at the same time, through the interactive adjustment of the chart parameters, it can effectively improve the visualization effect of the query results, making it easier for users to understand and analyze data.
[0030] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0032] Figure 1 The present invention is a flowchart of an interactive data query and display method based on a large language model described in an embodiment of the present invention. DETAILED DESCRIPTION
[0033] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0034] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.
[0035] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0036] In one or more embodiments, this embodiment provides an interactive data query and display method based on a large language model, which specifically includes the following processing procedures:
[0037] Step 1: Obtain the user query request and the business database used for query;
[0038] In specific implementations, the embodiments of the present disclosure are applicable to situations where a large language model is used to convert data query requests expressed in natural language into SQL statements, and optimized SQL query statements are generated in combination with user historical data and wide table information, and SQL statements are used for data query.
[0039] In a specific implementation, the construction of the business database for query is specifically as follows: obtaining business data of different business systems and performing corresponding preprocessing; based on the preprocessed business data of different business systems, according to the logical relationship between the business data of different business systems, data integration is performed to form a number of data tables; based on the obtained data tables, the construction of the business database is realized, specifically, Figure 1 As shown, the construction of the business database specifically includes the following processing procedures:
[0040] S101: Identify the source of business data and access it. This data may be scattered in multiple systems or platforms, such as marketing systems, metering systems, customer service systems, etc. In order to effectively collect this data, it is necessary to establish a data access mechanism to ensure real-time or scheduled synchronization of data. Common data access methods include API interface calls, direct database connections, file imports, etc. For different data sources, it is necessary to select the appropriate access method and ensure the security and reliability of data transmission.
[0041] S102: To integrate scattered metadata into multiple large wide tables, you need to design a suitable data model. The design of large wide tables should consider the following aspects:
[0042] According to business needs, select necessary fields to ensure data integrity and relevance. For example, select fields such as timestamp, device ID, voltage, current, power, and power consumption.
[0043] Aggregate data of the same dimension, such as by time, device, region, etc. For example, summarize electricity consumption data by time granularity such as hour, day, week, month, etc.
[0044] The data in different tables are linked together through JOIN operations to form a comprehensive large wide table. For example, the real-time data in the metering system is linked with the electricity consumption data in the marketing system to form a complete power operation data table.
[0045] S103: Database table structure information is vectorized and stored in the vector library. In order to improve the efficiency and accuracy of data query, the database table structure information must be vectorized and stored in the vector library to prepare for the recall of subject entities, time entities, business entities and indicator entities when generating SQL. The specific steps are as follows:
[0046] Extract table structure information from the target database, including table name, field name, field type, field description, etc. For example, extract the structure information of the equipment status table from the marketing system.
[0047] The extracted table structure information is vectorized. Natural language processing techniques (such as Word2Vec, BERT, etc.) can be used to convert text information such as field names and field descriptions into vector representations. For example, "Device ID" is converted into a vector representation.
[0048] The vectorized table structure information is stored in a vector library, such as Faiss, Annoy, etc. The vector library supports efficient vector search and similarity calculation, and can be used to quickly match user query intent and corresponding table structure information.
[0049] Step 2: Based on the user query request, obtain the query intent classification result of the user query request and the key entities in the user query request; based on the obtained query intent classification result and the key entities, generate structured query parameters;
[0050] In a specific implementation, based on the user query request, the query intent classification result of the user query request and the key entities in the user query request are obtained, specifically: the obtained user query request is segmented and labeled; based on the user query request after the segmentation and labeling processing, the key entities in the user query request are obtained through a pre-trained named entity recognition model; based on the user query request, the user intent classification result is obtained through a pre-trained intent classification model.
[0051] In a specific implementation, the generated structured query parameters are used to rewrite the user query request through interactive processing to conform to the standard query syntax, specifically: based on the query intent classification results in the structured query parameters, the user query request is supplemented with the user intent content; and based on the user's historical query requests, the missing information in the current user query request is determined through comparative analysis; for the missing information in the determined query request, the user is reminded to supplement it through a message prompt, or the missing information is supplemented based on the content in the user's historical query requests and the user is prompted to confirm.
[0052] In the specific implementation, the obtained user query request is first preprocessed accordingly. The main steps of the preprocessing include:
[0053] Text cleaning: Remove irrelevant characters and punctuation marks in query requests to ensure that the text is clean and standardized.
[0054] Word segmentation: Use word segmentation tools (such as Jieba) to split query requests into words or phrases for easy subsequent processing.
[0055] Part-of-speech tagging: Tag the results after word segmentation to identify key information such as nouns, verbs, and time. For example:
[0056] The user submits a query request: "What is the power consumption of substation A from October 1 to October 7, 2023?" After preprocessing, the segmentation and part-of-speech tagging results are as follows:
[0057] From (time) October 1 (time) to (preposition) October 7 (time) in 2023, (punctuation) how much (verb) is the (particle) electricity consumption (noun) of substation A (noun) (interrogative pronoun)?
[0058] Use a pre-trained named entity recognition (NER) model to identify key entities in a query request. These entities may include:
[0059] Time entities: such as "October 1, 2023" and "October 7".
[0060] Location entity: such as "A substation".
[0061] Indicator entity: such as "electricity consumption".
[0062] The result of entity recognition can be represented as a dictionary, for example:
[0063] {
[0064] "time_range":["2023-10-01","2023-10-07"],
[0065] "location":"Substation A",
[0066] "meter ic": "electricity consumption"
[0067] }
[0068] Use the pre-trained intent classification model to identify the user's query intent. The intent classification model can classify the user's query request into different query types, such as:
[0069] Equipment status query, power consumption statistics, fault analysis, and cost accounting;
[0070] For example, for the above query request, the model may classify it as "electricity consumption statistics".
[0071] According to the results of intent classification, the identified entities are filled into the corresponding slots to form structured query parameters. For example:
[0072] {
[0073] "intent":"Power consumption statistics",
[0074] "parameters":{
[0075] "start_date":"2023-10-01",
[0076] "end_date":"2023-10-07",
[0077] "stat ion_id":"Substation A"
[0078] }
[0079] }
[0080] Step 3: Based on the generated structured query parameters, the user query request is rewritten to conform to the standard query syntax through interactive processing; query prompt words are constructed based on the rewritten user query, and SQL query statements are generated based on the constructed query prompt words through a pre-trained large language model; data query results are obtained based on the generated SQL query statements;
[0081] In a specific implementation, the query prompt words are constructed based on the rewritten user query, and the query prompt words include: the rewritten user query request, possible target data tables in the business database, key entity information, and constraints set by the user; wherein the possible target data tables in the business database are determined by data tables whose probability of appearing in the user's historical query requests meets preset requirements and data tables set by the user based on experience.
[0082] S301: Automatically rewrite the user's query request to comply with standard query syntax;
[0083] Rewrite the user's current input according to the user's historical messages:
[0084] In order to handle the missing information in the user's query request, the system can use the user's historical messages to supplement it. The specific steps are as follows:
[0085] Get historical query requests: Get relevant query requests from the user's historical query records. These historical records can be stored in the database, with each user having a separate history table.
[0086] Identify missing information: Analyze the current user's query request and identify missing information. For example, if the user only provides the substation name but not the time range, the system needs to identify this.
[0087] Supplement missing information: Supplement missing information in the current query request based on relevant information in historical query records. For example, if the user frequently queries data for the most recent month, the data for the current month can be used by default.
[0088] Generate supplemented query request: regenerate structured query parameters with the supplemented information and generate new SQL query statements.
[0089] For example, suppose the user currently inputs "What is the power consumption of substation A?" The system finds from the historical records that the user often queries the data of the last month. The system will automatically add the time range and generate a new query request:
[0090] {
[0091] "intent":"Power consumption statistics",
[0092] "parameters":{
[0093] "start_date":"2023-10-01",
[0094] "end_date":"2023-10-31",
[0095] "stat ion_id":"Substation A"
[0096] }
[0097] }
[0098] Handling ambiguous and incomplete requests:
[0099] If the user's query request is ambiguous or incomplete, the system will try to supplement or correct it based on the context or other known information. For example, if the user only provides the substation name but not the time range, the data for the current month can be used by default. If it is still uncertain, the system can prompt the user to enter more information.
[0100] Through the above steps, the system can effectively identify the user's query intent and generate optimized query statements. In particular, by utilizing the user's historical messages, the system can automatically supplement the missing information in the current query request, ensure the accuracy and efficiency of the query, and provide users with a concise and easy-to-use data query experience.
[0101] S302: constructing query prompt words based on the rewritten user query request; generating SQL query statements based on the query prompt words through a pre-trained large language model;
[0102] Before building a query prompt, you need to recall relevant information from a pre-built wide table. The wide table contains multiple related fields to ensure the comprehensiveness and accuracy of the query. The specific steps are as follows:
[0103] Determine the target wide table: Determine the target wide table to be queried based on the user's query intent and structured query parameters. For example, if the user queries power usage, the target wide table may be the power_usage table.
[0104] Recall wide table information: Recall relevant field information from the target wide table. This field information includes table name, field name, field type, field description, etc. For example, recall fields such as status_id, date, and electricity_consumption from the power_usage table.
[0105] Recall database enumeration information: In order to ensure the accuracy and effectiveness of the generated SQL query statement, the system needs to recall the enumeration information in the database. The specific steps are as follows:
[0106] Determine the enumeration field: Based on the user's query intent and structured query parameters, determine the enumeration field that needs to be queried. For example, if the user queries the device status, the enumeration field may be status.
[0107] Recall enumeration information: Recall the enumeration value and description of the enumeration field from the database. For example, recall the enumeration value of the `` field from the device_status table, such as "normal", "fault", "under maintenance", etc.
[0108] In order to improve the accuracy and efficiency of SQL query statements generated by large language models, the system needs to build prompt words. Prompt words include user query requests, target wide table information, enumeration information, etc. The specific contents are as follows:
[0109] ###begin###
[0110] User query request: What is the power consumption of substation A from October 1 to October 7, 2023?
[0111] Target wide table: power_usage
[0112] Field information:
[0113] -stat ion_id (substation ID)
[0114] -date(date)
[0115] -electricity_consumption (electricity consumption)
[0116] -device_status (substation status)
[0117] Enumeration information: device_status: "normal", "fault", "under maintenance"
[0118] Require:
[0119] 1. Query the total electricity consumption of substation A from October 1 to October 7, 2023.
[0120] 2. Make sure the syntax of the SQL query statement is correct.
[0121] 3. If there are multiple conditions, please use AND to connect.
[0122] 4. Please use the SUM function to calculate the total electricity consumption.
[0123] Please generate a SQL query statement that meets the above requirements.
[0124] ###end###
[0125] Generate preliminary SQL query statement:
[0126] Based on the constructed prompt words, use the large language model to generate preliminary SQL query statements. The SQL query statement should include basic table selection, field selection, and conditional filtering. For example:
[0127] SELECT SUM(e lectr icity_consumpt ion)AS tota l_e lectr icity
[0128] FROM power_usage
[0129] WHERE stat ion_id = 'Substation A'
[0130] AND date BETWEEN'2023-10-01'AND'2023-10-07';
[0131] In one or more embodiments, the obtained SQL query statement needs to be optimized as follows:
[0132] In order to improve the efficiency and accuracy of the query, the generated preliminary SQL query statement is optimized. The main steps of optimization include:
[0133] Index selection: Choose the right index to improve query speed. For example, make sure there are indexes on the status_id and date fields.
[0134] Table join optimization: If the query involves multiple tables, optimize the order and method of table joins to reduce unnecessary table joins.
[0135] Optimize query conditions: simplify query conditions and reduce redundant filter conditions. For example, merge time range conditions.
[0136] The optimized SQL query statement is as follows:
[0137] SELECT SUM(e lectr icity_consumpt ion)AS tota l_e lectr icity
[0138] FROM power_usage
[0139] WHERE stat ion_id = 'Substation A'
[0140] AND date>='2023-10-01'
[0141] AND date <= '2023-10-07';
[0142] Step 303: Execute the SQL query statement to obtain the query result;
[0143] Send the optimized SQL query statement to the database server for execution and obtain the required data from the database. The specific steps are as follows:
[0144] Connect to database: Establish a connection with the database and ensure the stability and security of the connection.
[0145] Execute query: Send the optimized SQL query statement to the database server for execution.
[0146] Get results: Get query results from the database and return them to the system.
[0147] Process query results: process the query results to ensure the accuracy and completeness of the data. The specific steps are as follows: Data verification: verify the correctness and completeness of the query results to ensure that the data meets expectations.
[0148] Data conversion: Convert query results into a suitable format for subsequent display and analysis. For example, convert query results into JSON format.
[0149] In a specific implementation, the training of the large language model is specifically as follows: obtaining a number of natural language query requests, and determining the key entities and intent classifications in the natural language query requests through expert judgment; manually determining the SQL query statements corresponding to the natural language query requests based on the obtained key entities and intent classification results; constructing a data set based on a number of natural language query requests and their corresponding SQL query statements; and fine-tuning the pre-trained large language model based on the constructed data set to obtain a trained large language model.
[0150] Specifically, the training of the large language model includes the following processing steps:
[0151] (1) Dataset construction
[0152] In the power system data query scenario, collecting text-to-SQL query mapping data for training models is a key step. This data can come from multiple channels, including:
[0153] Historical query records: Historical query records are extracted from the user query logs of the power system. These records usually contain the user's natural language queries and corresponding SQL query statements.
[0154] Expert annotation: Invite experts in the power system field to annotate natural language queries and generate corresponding SQL query statements. Experts can provide high-quality annotated data to ensure the accuracy and professionalism of the data.
[0155] Synthetic data: Synthetic query data is generated through scripts or tools. This data can cover various query scenarios and enhance the generalization ability of the model.
[0156] The collected data needs to be cleaned and preprocessed to ensure data quality and consistency.
[0157] The process of pairing natural language queries with corresponding SQL query statements. The main tasks of annotation include:
[0158] Entity recognition: Identify key entities in natural language queries, such as device IDs, time ranges, locations, etc.
[0159] Intent classification: Determine the user's query intent, such as querying device status, counting power consumption, analyzing faults, etc.
[0160] Slot filling: Fill the identified entities into the corresponding positions of the SQL query statement.
[0161] SQL annotation: Generate SQL query statements corresponding to natural language queries manually to ensure the correctness and effectiveness of SQL statements.
[0162] The data set can be organized in a CSV file or a database table. Each record contains the above information. The specific organization of the data set is shown in Table 1:
[0163] Table 1 Organization of the dataset
[0164]
[0165] (2) Fine-tuning the Large Language Model
[0166] Use the labeled data to fine-tune the selected model. The specific steps are as follows:
[0167] Data preprocessing: Convert natural language queries and SQL query statements into an input format acceptable to the model. For example, use BERT's tokenizer to convert natural language queries into token sequences.
[0168] Model configuration: Set the model's hyperparameters, such as learning rate, batch size, number of training rounds, etc. The choice of these parameters will affect the training effect of the model.
[0169] Training process: Divide the data set into a training set and a validation set, use the training set to train the model, and use the validation set to validate it. During the training process, save the model checkpoint regularly for subsequent use.
[0170] Performance evaluation: Evaluate the performance of the model on the validation set. Common evaluation indicators include accuracy, recall, F1 score, etc. Adjust the model's hyperparameters based on the evaluation results until appropriate performance is achieved.
[0171] To further improve the performance of the model, the following optimization measures can be taken:
[0172] Data enhancement: Generate more training data through data enhancement technology to enhance the generalization ability of the model.
[0173] Multi-task learning: Simultaneously train multiple related tasks, such as entity recognition, intent classification, SQL generation, etc., to improve the overall performance of the model.
[0174] Model pruning: Prune the model to reduce the number of model parameters and improve the model's reasoning speed.
[0175] Mixed precision training: Use mixed precision training technology to speed up training and reduce video memory usage.
[0176] Model deployment:
[0177] After fine-tuning is completed, the model is deployed to the production environment to process users' natural language query requests in real time. The specific steps of deployment include:
[0178] Model export: Export the trained model to a deployable format, such as TensorFlow SavedModel, PyTorch TorchScript, etc.
[0179] Service construction: Build model services, provide API interfaces, receive users' natural language query requests, and return corresponding SQL query statements.
[0180] Performance monitoring: Monitor the performance of the model and update the model regularly to ensure the accuracy and stability of the model.
[0181] Step 4: Based on the query results, a chart is automatically generated to display the query results, wherein the chart type is determined according to the display type of the user's historical query results.
[0182] Automatically generate charts based on query results and adjust chart parameters to optimize display effects; the choice of chart type depends on the type of information the user wants to express, the characteristics of the data, and the audience's ability to understand.
[0183] In a specific implementation, the selection of the chart type is determined based on the chart display type of the user's historical query results. The following are some common chart types and their applicable situations:
[0184] Bar chart: suitable for comparing quantities or proportions of different categories.
[0185] Horizontal bar charts can be used to display long labels or when more vertical space is needed.
[0186] Line chart: Suitable for showing trends over time, and can also be used to compare time series data of multiple categories.
[0187] Pie chart: shows the proportion of each part to the whole. Usually used to show the composition structure.
[0188] Histogram: Displays the frequency of data distribution. Used to explore the distribution pattern of data.
[0189] In one or more implementations, in order to dynamically adjust the details of the chart (such as axis scales, label positions, etc.) according to the amount and complexity of the data, the solution described in this embodiment designs a flexible and adaptable method to process different data sets, specifically:
[0190] First, we conduct a preliminary analysis of the data to understand its range and distribution characteristics. This includes determining the maximum and minimum values of the data, as well as calculating statistical indicators such as the mean and standard deviation. These analyses can help us better understand the data and provide a basis for subsequent adjustments to the details of the chart.
[0191] After determining the basic properties of the data, you can start to consider how to automatically set the parameters of the chart, including:
[0192] For numerical data, the axis scale can be automatically set according to the range and distribution of the data. For example, in Matplotlib, we can use the functions in the matplotlib.ticker module to customize the position and format of the scale. In addition, we also need to consider how to automatically set the position and style of labels and titles. For example, when there are many data points, the labels can be automatically rotated to avoid overlap; when the amount of data is large, the font size can be appropriately reduced to ensure that all labels are clearly visible.
[0193] In one or more embodiments, in order to optimize the display effect of the chart, the solution needs to adjust the chart parameters according to the data characteristics and user preferences. The specific steps are as follows:
[0194] Color adjustment: Choose a suitable color scheme to ensure the beauty and readability of the chart. For example, use different colors to distinguish the power consumption of different substations.
[0195] Label settings: Set the chart title, axis labels, legend, etc. to ensure the clarity and comprehensibility of the chart, for example:
[0196] Set the title to "Electricity consumption of substation A from October 1 to October 7, 2023".
[0197] Scale adjustment: adjust the scale of the coordinate axis according to the range and distribution of the data to ensure the display effect of the data. For example, adjust the scale range of the Y axis to ensure that the trend of electricity consumption is clearly visible.
[0198] Data point markers: Add data point markers to the chart to help users view specific data. For example, add data point markers to a line chart to show the power consumption at each time point.
[0199] Interactive functions: Add interactive functions, such as hovering the mouse to display detailed data, clicking to switch chart types, etc., to improve user experience.
[0200] Once the basic parameters of the chart are set, the initial chart can be generated. At this point, a mechanism is needed to adjust the details of the chart according to the amount and complexity of the data. For example, if the number of data points is small, the label can maintain a larger font size, and when the number of data points increases, the font size of the label should be reduced accordingly. In addition, the density of the scale can be adjusted according to the distribution characteristics of the data, ensuring that the scale can accurately reflect the changes in the data, but not too dense to cause confusion.
[0201] Finally, to make charts more useful and easy to operate, these features can be integrated into the user interface. This allows users to adjust the details of the chart through simple interactions such as sliders or drop-down menus. For example, users can select different data sets and see the chart update immediately. In addition, responsive design can be implemented to ensure that the chart displays well on different screen sizes and devices.
[0202] In one or more embodiments, corresponding to the method described in Embodiment 1, this embodiment provides an interactive data query and display system based on a large language model, including:
[0203] A data acquisition unit, which is used to acquire a user query request and a business database for query;
[0204] A structured parameter generating unit, which is used to obtain the query intent classification result of the user query request and the key entities in the user query request based on the user query request; and generate structured query parameters based on the obtained query intent classification result and the key entities;
[0205] A query unit, which is used to rewrite the user query request to conform to the standard query syntax through interactive processing based on the generated structured query parameters; construct query prompt words based on the rewritten user query, and generate SQL query statements based on the constructed query prompt words through a pre-trained large language model; based on the generated SQL query statement, obtain data query results from the business database used for query;
[0206] A display unit is used to automatically generate a chart based on the query result to display the query result, wherein the chart type is determined according to the chart display type of the user's historical query result.
[0207] It can be understood that the system described in this embodiment corresponds to the method described in Example 1, and its technical details have been described in detail in Example 1 and will not be repeated here.
[0208] In further embodiments, there is also provided:
[0209] An electronic device includes a memory and a processor, and computer instructions stored in the memory and executed on the processor, wherein when the computer instructions are executed by the processor, the method described in Embodiment 1 is performed. For the sake of brevity, no further description is given here.
[0210] It should be understood that in this embodiment, the processor may be a central processing unit CPU, and the processor may also be other general-purpose processors, digital signal processors DSP, application-specific integrated circuits ASIC, off-the-shelf programmable gate arrays FPGA or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0211] The memory may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include a non-volatile random access memory. For example, the memory may also store information about the device type.
[0212] A computer-readable storage medium is used to store computer instructions. When the computer instructions are executed by a processor, the method described in embodiment 1 is completed.
[0213] The method in the first embodiment can be directly embodied as a hardware processor, or a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware. To avoid repetition, it will not be described in detail here.
[0214] Those skilled in the art will appreciate that the units, i.e., algorithm steps, of the various examples described in the present embodiment can be implemented in electronic hardware or in a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0215] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An interactive data query and display method based on a large language model, characterized in that: include: Obtaining user query requests and the business database used for querying; Based on the user query request, obtaining a query intent classification result of the user query request and a key entity in the user query request; Generate structured query parameters based on the query intent classification results and key entities; Based on the generated structured query parameters, the user query request is rewritten to conform to the standard query syntax through interactive processing; Construct query hints based on the rewritten user query, and generate SQL query statements based on the constructed query hints through a pre-trained large language model; Based on the generated SQL query statement, obtain data query results from the business database used for query; Based on the query results, a chart is automatically generated to display the query results, wherein the chart type is determined according to the chart display type of the user's historical query results.
2. The interactive data query and display method based on a large language model as claimed in claim 1, characterized in that: Based on the generated structured query parameters, the user query request is rewritten through interactive processing to comply with the standard query syntax, specifically: based on the query intent classification results in the structured query parameters, the user query request is supplemented with the user intent content; and based on the user's historical query requests, the missing information in the current user query request is determined through comparative analysis; for the missing information in the determined query request, the user is reminded to supplement it through a message prompt, or the missing information is supplemented based on the content in the user's historical query requests and the user is prompted to confirm.
3. The interactive data query and display method based on a large language model as claimed in claim 1, characterized in that: The query prompt words are constructed based on the rewritten user query, and the query prompt words include: the rewritten user query request, possible target data tables in the business database, key entity information, and constraints set by the user; wherein the possible target data tables in the business database are determined by data tables whose probability of appearing in the user's historical query requests meets preset requirements and data tables set by the user based on experience.
4. The interactive data query and display method based on a large language model as claimed in claim 1, characterized in that: The training of the large language model specifically includes: obtaining a number of natural language query requests, determining the key entities and intent classifications in the natural language query requests by expert judgment; manually determining the SQL query statements corresponding to the natural language query requests based on the obtained key entities and intent classification results; constructing a data set based on the several natural language query requests and their corresponding SQL query statements; and fine-tuning the pre-trained large language model based on the constructed data set to obtain a trained large language model.
5. The interactive data query and display method based on a large language model as claimed in claim 1, characterized in that: The step of obtaining the query intent classification result of the user query request and the key entities in the user query request based on the user query request specifically comprises: performing word segmentation and tagging processing on the obtained user query request; Based on the user query request after word segmentation and tagging, the key entities in the user query request are obtained through a pre-trained named entity recognition model; based on the user query request, the user intent classification result is obtained through a pre-trained intent classification model.
6. The interactive data query and display method based on a large language model as claimed in claim 1, characterized in that: The construction of the business database for query is specifically as follows: obtaining business data of different business systems and performing corresponding preprocessing; based on the preprocessed business data of different business systems and according to the logical relationship between the business data of different business systems, performing data integration to form a number of data tables; The business database is constructed based on the obtained data tables.
7. An interactive data query and display system based on a large language model, characterized in that: include: A data acquisition unit, which is used to acquire a user query request and a business database for query; A structured parameter generating unit, which is used to obtain the query intent classification result of the user query request and the key entities in the user query request based on the user query request; Generate structured query parameters based on the query intent classification results and key entities; A query unit, which is used to rewrite the user query request to conform to the standard query syntax through interactive processing based on the generated structured query parameters; construct query prompt words based on the rewritten user query, and generate SQL query statements based on the constructed query prompt words through a pre-trained large language model; based on the generated SQL query statement, obtain data query results from the business database used for query; A display unit is used to automatically generate a chart based on the query result to display the query result, wherein the chart type is determined according to the chart display type of the user's historical query result.
8. An electronic device comprising a memory, a processor and a computer program stored and running on the memory, characterized in that: When the processor executes the program, an interactive data query and display method based on a large language model as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, an interactive data query and display method based on a large language model as described in any one of claims 1 to 6 is implemented.
10. A computer program product having a computer program stored thereon, characterized in that: When the program is executed by a processor, an interactive data query and display method based on a large language model as described in any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Structured query language generation method and device based on large model, equipment and medium
CN120561139A
SQL intelligent generation method and system for business query
CN120873005A
A method and system for generating SQL intelligence for a service query
CN120873005B
Database natural language query autoregression intention classification method and system
CN120995178A
Knowledge enhancement method and system of heat supply industry data insight based on large language model
CN121031737A