Temporal data natural language query method and related apparatus
Patent Information
- Application Number
- CN202611217187.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-12
- Publication Date
- 2026-10-16
AI Technical Summary
[0007]针对现有技术中的问题,本申请的目的在于提供一种时序数据自然语言查询方法及相关装置,以解决现有技术在时序数据库查询场景下查询语句生成准确性低的问题
[0024] Specifically, by retrieving target knowledge entries that match the natural language question from the knowledge base, and using the business description information and data acquisition information in the target knowledge entries to assist in generating query statements, the system can reuse the data access logic corresponding to existing business scenarios, improve the efficiency of business knowledge utilization in the natural language query process, and thus improve the accuracy and adaptability of query statement generation.
Smart Images

Figure CN122925432A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and related apparatus for natural language querying time-series data. Background Technology
[0002] With the development of the Industrial Internet, the Internet of Things, and intelligent monitoring systems, time-series data is widely used in equipment condition monitoring, production process analysis, energy management, and environmental monitoring. Time-series databases, as specialized databases for storing and analyzing time-series data, are typically used to store measurement data, operational status data, and business performance data with time attributes.
[0003] In related technologies, users typically use database query languages (such as SQL) to query and analyze data in time-series databases. Users need to write corresponding query statements based on the target database's data organization method, table structure, field definitions, and query syntax rules to obtain the required data results.
[0004] As data scale and business scenarios continue to expand, the data types and structures stored in time-series databases are becoming increasingly complex. Data from different business scenarios often exhibit strong domain characteristics. When users perform data queries, they not only need to understand the table structure and field information in the database, but also need to grasp the relationships between business data and the corresponding query methods. When users are unfamiliar with the database structure or query syntax, it is difficult to directly construct accurate query statements based on actual needs.
[0005] In recent years, based on the development of natural language processing technology, the use of large language models to generate database query statements based on user-input natural language descriptions has been increasingly applied in data query scenarios. This type of method can generate corresponding query statements by understanding the semantics of the user's input question, thereby reducing the operational complexity of users directly writing query statements.
[0006] At this point, how to improve the accuracy of query statement generation when performing time-series database queries based on natural language is a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0007] To address the problems in the prior art, the purpose of this application is to provide a natural language query method and related apparatus for time-series data, so as to solve the problem of low accuracy in query statement generation in time-series database query scenarios.
[0008] The first aspect of this disclosure provides a method for natural language querying time-series data, comprising: The system receives a natural language question input by a user targeting a time-series database; obtains pattern enhancement information corresponding to the target time-series database, including the database's structural information; retrieves target knowledge entries matching the natural language question from a knowledge base, including business description information and associated data acquisition information; generates a query statement for accessing the target time-series database based on the natural language question, pattern enhancement information, and target knowledge entries; and executes the query statement to obtain the query results.
[0009] In some implementations, the natural language query method for time-series data also includes generating a query analysis report based on the natural language question and the query results.
[0010] In some implementations, a query analysis report is generated based on the natural language question and the query results, including: obtaining corresponding reference data based on the data acquisition information in the target knowledge item, constructing a data view context; and generating a query analysis report based on the natural language question, the query statement, the query results, and the data view context.
[0011] In some implementations, generating a query analysis report based on natural language questions and query results also includes: Access the target time-series database based on the data acquisition information to execute the data acquisition logic bound to the data acquisition information; when the data acquisition logic fails to execute or the corresponding reference data is not obtained, retain the business description information of the target knowledge item and inject it into the data view context, and replace the corresponding data with a preset error message or empty table format.
[0012] In some implementations, when generating the query statement, a query view context is generated based on the business description information and data acquisition information in the target knowledge entry; when generating the query analysis report, corresponding reference data is obtained based on the data acquisition information, and a data view context is generated based on the corresponding reference data.
[0013] In some implementations, a query statement for retrieving query data from a target time-series database is generated based on natural language questions, pattern enhancement information, and target knowledge entries, including: Based on the structural information in the pattern enhancement information and the business description information and data acquisition information in the target knowledge entries, a query context is constructed; based on the natural language question and the query context, the large language model is invoked to generate the query statement.
[0014] In some implementations, the large language model is invoked based on the natural language question and query context to generate a query statement. This also includes: invoking the large language model to generate a query statement based on the natural language question and query context, or generating a rejection text containing a rejection flag.
[0015] In some implementations, the time-series data natural language query method further includes: detecting a rejection flag in the rejection text output by the large language model; if a rejection flag is detected, not executing the query statement, and returning the rejection reason corresponding to the rejection text.
[0016] In some implementations, obtaining pattern enhancement information corresponding to the target time series database includes: sampling based on the target table in the target time series database to obtain real example values; and constructing pattern enhancement information based on structural information and real example values.
[0017] In some implementations, the target knowledge entry also includes target data source association information; there is a correspondence between the business description information, target data source association information and data acquisition information in the target knowledge entry.
[0018] A second aspect of this disclosure provides a time-series data natural language query apparatus, comprising: The system comprises the following modules: a receiving module, which receives a natural language question input by the user for a target time-series database; an acquisition module, which acquires pattern enhancement information corresponding to the target time-series database, including the database's structural information; a retrieval module, which retrieves target knowledge entries from a knowledge base that match the natural language question, including business description information and associated data acquisition information; a query statement generation module, which generates a query statement for accessing the target time-series database based on the natural language question, pattern enhancement information, and target knowledge entries; and a query module, which executes the query statement and obtains the query results.
[0019] A third aspect of this disclosure provides an electronic device comprising: A processor; and a memory storing executable instructions for the processor; wherein the processor is configured to execute the time-series data natural language query method of any of the above embodiments by executing the executable instructions.
[0020] The fourth aspect of this disclosure provides a computer-readable storage medium for storing a program, characterized in that, when the program is executed, it implements the time-series data natural language query method of any of the above embodiments.
[0021] The fifth aspect of this disclosure provides a computer program product having a computer program stored thereon, which, when executed by a processor, implements the time-series data natural language query method of any of the above embodiments.
[0022] The time-series data natural language query method and related apparatus proposed in this disclosure have the following advantages: As described above, by receiving a natural language question input by a user for a target time series database, obtaining the pattern enhancement information corresponding to the target time series database, and retrieving target knowledge entries that match the natural language question from the knowledge base; further, based on the natural language question, pattern enhancement information, and target knowledge entries, generating a query statement for accessing the target time series database, and executing the query statement to obtain the query results.
[0023] Through the above methods, this embodiment of the invention can incorporate the structural information of the target time-series database and the data acquisition information associated with the business scenario into the query statement generation process in natural language query scenarios. This allows for simultaneous reference to database structural features and business semantic information when generating query statements. Compared to the prior art where users need to manually write query statements based on database structure and query syntax, this embodiment of the invention reduces the difficulty of converting natural language questions into database query statements, improves the matching degree between query statements and the target time-series database, and enhances the automation of the query process.
[0024] Specifically, by retrieving target knowledge entries that match the natural language question from the knowledge base, and using the business description information and data acquisition information in the target knowledge entries to assist in generating query statements, the system can reuse the data access logic corresponding to existing business scenarios, improve the efficiency of business knowledge utilization in the natural language query process, and thus improve the accuracy and adaptability of query statement generation. Attached Figure Description
[0025] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.
[0026] Figure 1 A flowchart illustrating a natural language query method for time-series data provided in this embodiment of the disclosure; Figure 2 This is a schematic diagram illustrating the overall architecture and data interaction of a time-series data natural language query system provided in an embodiment of this disclosure; Figure 3 A schematic diagram illustrating the specific process of a natural language query and analysis method for time-series data provided in this embodiment of the disclosure; Figure 4 A schematic diagram of a dual-view context morphology transformation structure for a target knowledge entry provided in an embodiment of this disclosure; Figure 5 A schematic block diagram of a time-series data natural language query device provided in this embodiment of the disclosure; Figure 6 A schematic block diagram of another time-series data natural language query device provided in the embodiments of this disclosure; Figure 7 This is a schematic diagram of the hardware structure of an electronic device suitable for implementing the above-described time-series data natural language query method according to an embodiment of the present disclosure. Detailed Implementation
[0027] To make the technical solution, the technical problem solved, and the technical effects of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the described embodiments are merely exemplary embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Those skilled in the art can make various modifications and variations to the embodiments without departing from the spirit and scope of the present invention, and all such modifications and variations should be considered to fall within the scope of protection of the present invention.
[0028] Techniques, methods, and apparatus known to those skilled in the art are not discussed in detail where appropriate, but should be considered part of this specification. In all examples shown herein, any specific numerical values or parameters should be interpreted as exemplary only and not as limiting the invention.
[0029] Research into related technologies revealed that in time-series database query scenarios, user natural language descriptions typically emphasize business meaning, while database data is organized in structural forms such as tables, fields, and data types. This semantic difference can lead to inaccurate matching of data structures and business relationships within the target database when generating queries based solely on natural language. Furthermore, business analysis needs across different domains often rely on specific data acquisition methods. Generating queries based solely on natural language descriptions may fail to fully leverage existing data query experience, impacting the accuracy and applicability of the generated queries.
[0030] Therefore, how to improve the accuracy of query statement generation when performing time-series database queries based on natural language, and make the generated query statements more suitable for the data structure and business query requirements of the target time-series database, has become a technical problem that urgently needs to be solved in this field.
[0031] Figure 1 This diagram illustrates a flowchart of a natural language query method for time-series data provided by an embodiment of this disclosure. The execution entity of this natural language query method can be a computing device with data processing capabilities, such as an electronic device, a server, or a server cluster. The electronic device can be deployed on a cloud server, a local server, or other computing environment capable of interacting with the target time-series database.
[0032] The time-series data natural language query method provided in this disclosure can be applied to application scenarios based on time-series data natural language query, such as industrial internet, equipment monitoring, energy management, and IoT data analysis. Users can describe the data content to be queried in natural language. The time-series data natural language query system generates a query statement based on the information input by the user and the data characteristics corresponding to the target time-series database, and obtains the query data from the target time-series database based on the query statement.
[0033] like Figure 1 As shown, the time-series data natural language query method provided in this disclosure includes, but is not limited to, the following steps: Step 110: Receive natural language questions input by the user for the target time series database; Step 120: Obtain the schema enhancement information corresponding to the target time series database. The schema enhancement information includes the structural information of the target time series database. Step 130: Retrieve target knowledge entries that match the natural language question from the knowledge base, wherein the target knowledge entries include business description information and data acquisition information associated with the business description information; Step 140: Based on the natural language question, pattern enhancement information, and target knowledge entries, generate a query statement for accessing the target time series database; Step 150: Execute the query statement and obtain the query results.
[0034] In the above implementation, natural language questions are used to describe the data content that the user expects to obtain from the target time-series database. For example, the user can input questions describing information such as device operating status, indicator trends, and historical data query conditions.
[0035] The target time-series database can be used to store data with time attributes, such as device-collected data, sensor data, operational status data, and business indicator data. This disclosure does not limit the specific type of the target time-series database.
[0036] In this embodiment of the disclosure, pattern enhancement information is used to describe the data organization structure of the target time series database, so as to assist in the subsequent generation of query statements adapted to the target time series database based on natural language questions.
[0037] The schema enhancement information can include database structure information, table structure information, field information, and relationships between fields in the target time-series database. For example, schema enhancement information can include the database name, table name, field name, field type, and field attributes in the target database.
[0038] In this embodiment, the knowledge base is used to store information related to business data queries. Target knowledge entries can represent data query experience corresponding to a specific business scenario. Target knowledge entries include at least business description information and data acquisition information associated with the business description information.
[0039] Business description information is used to describe the target business scenario, the meaning of data, or business phenomena. For example, business description information can be used to describe changes in the status of a device, the trend of a business indicator, or a certain type of data characteristic.
[0040] Data acquisition information describes the method of acquiring data corresponding to the business description information. For example, data acquisition information may include the query statement, query parameters, query logic, or other information that indicates the acquisition of the corresponding data for accessing the target time-series database.
[0041] The query statement is used to access the target time-series database to obtain query data corresponding to the natural language question. After generating the query statement, it can be sent to the target time-series database for execution to obtain the corresponding query results.
[0042] Through the above steps, this embodiment of the invention can generate a query statement for accessing the target time series database based on the natural language question input by the user, combined with the pattern enhancement information corresponding to the target time series database and the business query information in the knowledge base, and execute the query statement to obtain the query result.
[0043] Compared to existing technologies where users need to manually write query statements based on database structure and query syntax, this disclosure introduces pattern enhancement information corresponding to the target time-series database, enabling the query statement generation process to reference the target database's data structure. Simultaneously, by retrieving knowledge entries associated with the natural language problem, the query statement generation process can combine existing business data to obtain information, thereby improving the information matching capability between the natural language problem and the target time-series database, and enhancing the accuracy and adaptability of the generated query statements.
[0044] In one implementation, step 110 involves receiving a natural language question input by the user for the target time-series database, including: Natural language questions that obtain user input to retrieve query data from a target time-series database.
[0045] Natural language questions are used to describe a user's data query needs, and may include the data content the user expects to obtain, the data analysis objective, or the data query conditions. For example, natural language questions may involve querying the operating status of a target device, analyzing the trend of indicator changes, analyzing abnormal events, or querying statistical information, etc., and this disclosure does not limit these aspects.
[0046] In some implementations, a user can input a natural language question through a user terminal, which can then send the natural language question to a processing device that performs a time-series data natural language query method via a network.
[0047] In one implementation, the natural language question can be associated with a specified target time-series database. The target time-series database stores data organized along a time dimension, which may include device operation data, sensor-collected data, business monitoring data, or other data with time attributes.
[0048] In some implementations, the target time series database may be specified by the user, or it may be determined based on the query scenario information input by the user, the pre-configured target data source association, or other methods. This disclosure does not limit this.
[0049] By receiving natural language questions input by users, the user's data query requirements can be transformed into input information in the subsequent query processing. Based on the natural language questions, information corresponding to the target time series database can be further obtained, and query statements for accessing the target time series database can be generated.
[0050] In some implementations, in step 120 above, the structural information corresponding to the target time-series database can be obtained. This structural information may include, but is not limited to, data source identifier, database name, data table name, and field information. The field information may include field name, field type, field category, and field description information, used to describe the organization of queryable data in the target time-series database.
[0051] In one implementation, structural information can be obtained by accessing the metadata information acquisition interface corresponding to the target time series database; structural information can also be obtained by reading pre-stored database schema description information; structural information can also be obtained through other information acquisition methods that can characterize the data organization structure of the target time series database, and this disclosure does not limit this.
[0052] For example, when the target time-series database uses a table model for data organization, the corresponding table structure information can be obtained by querying the database system tables. Specifically, the following types of metadata queries can be performed: select database,table_name,column_name,datatype,category,comment from information_schema.columns where database != 'information_schema' Based on the query results, the field information can be organized according to the database name and the data table name to obtain the corresponding data table structure information.
[0053] Furthermore, to improve the ability of pattern enhancement information to represent the characteristics of actual data, data sampling can be performed based on the target table in the target time series database to obtain real example values corresponding to the structural information, and then the real example values can be added to the pattern enhancement information.
[0054] For example, you can execute the following on the target data table you have obtained: select from {database.table} limit 1 Real example values can be used to reflect the form in which the corresponding field takes values in actual data. For example, for a time field, real example values can reflect the actual representation of time data; for an enumerated field, real example values can reflect the actual range of values that the field can take.
[0055] In one alternative implementation, when the target table does not contain data, or the sampled field value is empty, the actual example value of the corresponding field can be set to an empty value or a preset placeholder information, and the pattern enhancement information can continue to be generated without interrupting the subsequent query process due to the lack of actual example values.
[0056] It should be noted that the real example value is an optional component of the pattern enhancement information. Even when valid sampled data is unavailable, pattern enhancement information can still be generated based on structural information. This disclosure does not limit the specific methods for obtaining the structural information or the real example value.
[0057] In this implementation, by acquiring pattern enhancement information that includes structural information and real example values, the subsequent query generation process can simultaneously refer to the data organization structure and actual field value characteristics of the target time series database, thereby improving the compatibility between the generated query and the target time series database.
[0058] In this embodiment of the disclosure, in step 130 above, the knowledge base is used to store knowledge information related to business data queries in the target time-series database. The knowledge base may include multiple knowledge entries, each of which describes the data query requirements and corresponding data acquisition methods under a specific business scenario.
[0059] Specifically, each knowledge entry may include business description information and data acquisition information associated with the business description information. The business description information describes the business meaning, business scenario, data purpose, or data analysis requirements corresponding to the target data; the data acquisition information describes the method of acquiring business data, such as the query statement, query template, data interface information, or other information that can indicate the data acquisition logic used to access the target time-series database, which is not limited in this disclosure.
[0060] In one implementation, multiple knowledge entries in a knowledge base can be matched based on a natural language question to determine the target knowledge entry corresponding to the natural language question. For example, one or more candidate knowledge entries matching the natural language question can be determined based on the semantic correlation between the natural language question and the business description information in each knowledge entry, and the target knowledge entry can be determined from the candidate knowledge entries.
[0061] In one alternative implementation, the knowledge entry as a whole can be used as a retrieval unit for comprehensive matching based on the business description information, data acquisition information and other related information in the knowledge entry.
[0062] For example, knowledge entries can be organized according to a preset data structure and stored in the knowledge base as searchable text units. Knowledge entries may include identification information, business description information, target data source association information, and data acquisition information. The target data source association information can be used to determine the data source corresponding to the data acquisition information.
[0063] In one implementation, a retrieval request can be sent to a knowledge base based on the natural language question, and the corresponding target knowledge entry can be determined based on the semantic matching result. Further, after determining the target knowledge entry, a query view context can be generated based on the business description information and data acquisition information in the target knowledge entry. The query view context is used to provide business semantic information and data acquisition methods associated with the natural language question, to assist in generating a query statement for accessing the target time-series database.
[0064] In one optional implementation, for the same target knowledge item, different forms of knowledge context can be generated according to the needs of different processing stages. Specifically, during the query statement generation stage, the query view context can be generated; during the query analysis report generation stage, corresponding reference data can be obtained based on the data acquisition information in the target knowledge item, and a data view context can be generated based on the business description information and the reference data.
[0065] The data acquisition information is used to indicate the method of acquiring data corresponding to the business description information, and its specific form is not limited. In one embodiment, the data acquisition information can be an executable query statement; in other embodiments, the data acquisition information can also be a query template, an interface call description, or other information that can represent the data acquisition logic, and this disclosure does not limit it in this regard.
[0066] In this way, target knowledge items can be associated with business semantic information and data acquisition logic at the same time, and query view context and data view context can be formed according to the different needs of the query generation stage and the query analysis report generation stage, respectively. This allows the query statement generation process to refer to existing business data acquisition methods, while the query analysis report generation process can analyze based on actual data related to the business scenario.
[0067] Specifically, when generating query statements for accessing the target time-series database, a query view context can be generated based on the business description information and data acquisition information in the target knowledge entries.
[0068] The query view context is used to provide the large language model with data query reference information related to natural language issues. It can include the business meaning description of the target knowledge item, data acquisition information, and information that helps generate query statements, such as query conditions and query field information reflected by the data acquisition information.
[0069] For example, when the business description information in the target knowledge entry is used to describe the changes in the operating indicators of a certain device, the data source and query logic corresponding to the operating indicator can be determined through data acquisition information, and the business description information and data acquisition information can be organized to form a query view context.
[0070] In one implementation, the query view context can be combined with the structural information in the schema enhancement information to form a query context for generating query statements. The query context can simultaneously include the data structure information of the target time-series database, business semantic information, and data retrieval logic.
[0071] Furthermore, a large language model can be invoked based on the natural language question and query context to generate query statements for retrieving query data from the target time-series database.
[0072] It should be noted that the query view context is not used to directly replace the query results in the target time series database, but rather as auxiliary information in the query statement generation process, enabling the generated query statement to be associated with the corresponding data source and data acquisition logic.
[0073] In addition, when generating query analysis reports, corresponding data can be obtained based on the data acquisition information in the target knowledge entries, and a data view context can be generated based on the acquired data.
[0074] Specifically, the target time-series database can be accessed according to the data acquisition logic corresponding to the data acquisition information to obtain data associated with the target knowledge items, and the data can be organized into a data view context.
[0075] The data view context is used to provide the data basis for the generation of query analysis reports, which may include the data content and the corresponding business description information.
[0076] In one implementation, the data view context can be input into the report generation model along with the natural language question, the query statement, and the query results obtained by executing the query statement to generate a corresponding query analysis report.
[0077] This implementation constructs query view context and data view context for the query generation stage and report generation stage respectively. This allows the query statement generation process to focus on using business knowledge to help determine the data acquisition logic, while the query analysis report generation process is based on the actual acquired data content for analysis. This avoids the mixing of business reference information in the query statement generation stage and data content in the report analysis stage, thereby improving the accuracy and reliability of the query processing process.
[0078] In one implementation, the target knowledge entry may further include target data source association information, which is used to characterize the data source corresponding to the business description information.
[0079] Specifically, a correspondence can be established between business description information, target data source association information, and data acquisition information to form an association description structure for specific business data. The business description information describes the business meaning corresponding to the target data, such as describing the business indicators, equipment status, operational events, or analysis objects represented by the target data; the target data source association information indicates the data source corresponding to the business description information, such as the target time-series database, target data table, or target data set; and the data acquisition information describes the method of acquiring the corresponding data from the target data source, such as the query statement, query template, or other data access logic used to acquire the corresponding data.
[0080] In one implementation, the target data source association information may include the target database name, data table identifier, or other information that can characterize the data source, which is not limited in this disclosure.
[0081] When performing knowledge retrieval, the corresponding target knowledge entries can be determined from the knowledge base based on the semantic relationship between natural language questions and business description information. Based on the target data source association information and data acquisition information in the target knowledge entries, a query statement for accessing the target time series database can be constructed.
[0082] By establishing a correspondence between business description information, target data source association information, and data acquisition information, knowledge entries can simultaneously carry business semantic information, data source information, and data acquisition logic. This links business domain knowledge with the data access logic in the target time-series database, enhancing the mapping capability between natural language problems and business data in the target time-series database.
[0083] In one implementation, when a large language model is invoked to generate a query statement based on a natural language question and a query context, the large language model can also determine whether a query statement for retrieving the corresponding data can be generated based on the natural language question and the query context.
[0084] Specifically, the query context can include the structural information corresponding to the target time-series database, as well as the business description information and data acquisition information in the target knowledge entries related to the natural language problem. The large language model can determine the data objects related to the natural language problem based on the structural information, and determine the corresponding data query method based on the business description information and data acquisition information.
[0085] When the large language model determines, based on the query context, that it cannot generate a query statement to retrieve relevant data based on existing information, it can generate a rejection text containing a rejection flag; when the large language model determines that it can generate the corresponding query statement, it generates a query statement to access the target time series database.
[0086] The rejection flag can be used to indicate that the current natural language question cannot generate a corresponding query statement based on the current query context. The specific form of the rejection flag can be set according to actual application needs, such as using preset characters, preset strings, or preset fields; this disclosure does not limit this.
[0087] Furthermore, in one implementation, after obtaining the output of the large language model, the output can be detected to determine whether it contains a rejection flag.
[0088] When the output contains a rejection flag, it can be determined that the large language model has not generated an executable query statement. At this point, the subsequent database access and query analysis report generation process will not be executed. Instead, the reason for rejection in the rejection text will be directly extracted and returned to the user.
[0089] By using the above method, when it is impossible to generate query statements for obtaining relevant data based on existing patterns, information enhancement, and target knowledge entries, the subsequent processing flow can be terminated before the query is executed, avoiding invalid database access operations, thereby reducing resource consumption caused by invalid query requests and improving the processing efficiency of the natural language query process.
[0090] In one implementation, the large language model can be a model trained based on machine learning algorithms for processing natural language information, which can generate corresponding text output based on the input text information.
[0091] In this embodiment of the disclosure, the large language model can perform semantic understanding of natural language problems, and combine the target time-series database structure information in the query context with the business description information and data acquisition information corresponding to the target knowledge entries to determine the data acquisition logic corresponding to the natural language problem, and generate a query statement for accessing the target time-series database.
[0092] Furthermore, the large language model can determine whether a query statement can be generated to retrieve data corresponding to the natural language question based on the query context. When the corresponding data retrieval method cannot be determined based on the query context, the large language model can output a rejection text containing a rejection flag, so that the system can stop the subsequent query processing based on the rejection flag.
[0093] In one implementation, after generating a query statement for retrieving query data from a target time series database, the query statement can be submitted to the target time series database execution module, and the query statement can be executed through the target time series database to obtain the corresponding query results.
[0094] The query results may include data records, statistical results, or datasets in the target time-series database that correspond to the natural language problem. The specific format of the query results can be determined based on the query object, query conditions, and data processing logic contained in the query statement, and this disclosure does not impose any limitations on this.
[0095] Furthermore, the query results can be formatted to form input data for generating subsequent query analysis reports.
[0096] In one implementation, before executing a query statement, a data access connection can be established between the target time series database and the target time series database based on the database connection information corresponding to the target time series database, and a query statement can be sent to the target time series database through the data access connection so that the target time series database can execute the query statement.
[0097] For example, when a query is used to retrieve device operating status data within a specified time range, the target time series database can retrieve data based on the target data table, target field, and time range conditions in the query and return the corresponding time series data as the query result.
[0098] In one implementation, the query results can be encapsulated according to a preset data format to facilitate further data processing based on the query results. For example, the query results can be encapsulated into a data structure containing a time field and at least one data field, or organized according to the data structure corresponding to the query results; this disclosure does not limit this approach.
[0099] In one implementation, when an exception occurs during the execution of a query statement, the corresponding execution exception information can be obtained and fed back to the calling end for subsequent processing.
[0100] By executing query statements generated based on natural language questions, pattern enhancement information, and target knowledge entries, the system can obtain query results corresponding to natural language questions from the target time-series database, thus realizing the transformation of natural language query requirements into database query operations.
[0101] In some implementations, the time-series data natural language query method may also include the step of generating a query analysis report based on the natural language question and the query results.
[0102] Specifically, after obtaining the query results, they can be further analyzed and processed to generate a query analysis report corresponding to the natural language question. This report can be used to summarize, analyze, or interpret the query results, enabling users to understand the data in the target time-series database in natural language terms.
[0103] In one implementation, to improve the accuracy of data references in the query analysis report, corresponding reference data can be obtained based on the data acquisition information in the target knowledge entry, and a data view context can be constructed.
[0104] Specifically, the data acquisition information in the target knowledge entry can be used to describe the data acquisition method associated with the corresponding business description information. For example, the data acquisition information may include query statements, query templates, or other data access information that can obtain the target data for retrieving relevant business data.
[0105] Before generating the query analysis report, the corresponding data source can be accessed based on the data acquisition information to obtain reference data associated with the target knowledge item, and a data view context can be constructed based on the reference data. The data view context can be used to represent the actual data content corresponding to the business description information, thereby enabling analysis based on actual data when generating the query analysis report.
[0106] Furthermore, when generating a query analysis report, natural language questions, query statements, query results, and data view context can be used as the basis for report generation. By analyzing the query purpose corresponding to the natural language question, the data characteristics in the query results, and the related data in the data view context, a query analysis report can be generated.
[0107] The specific format of the query analysis report can be set according to actual application needs. For example, the query analysis report may include data change trend analysis, abnormal data analysis, key indicator summary, cause analysis, or other forms of data analysis content, and this disclosure does not limit this.
[0108] It should be noted that the query results represent the data results obtained after executing the query statement generated based on the user's current natural language question in the target time-series database; the data view context represents the reference data obtained based on the data retrieval information associated with the knowledge entries. By utilizing both the query results and the data view context, the query analysis report can not only analyze based on the current query results, but also conduct a comprehensive analysis by combining data related to the business scenario.
[0109] In some alternative implementations, the data view context may also be generated based on pre-stored data snapshots, cached data, or other data acquisition methods, and is not limited to accessing the target time-series database to obtain data when generating the query analysis report. This disclosure does not limit this.
[0110] By using the above methods, based on the completion of natural language queries for time-series data, a query analysis report is further generated based on the query results and the data view context associated with business knowledge, thereby realizing data analysis and processing based on the query results and improving the information expression ability and business analysis ability of the query results.
[0111] In some implementations, during the process of generating the query analysis report, corresponding data acquisition logic can be executed based on the data acquisition information in the target knowledge entry to obtain reference data corresponding to the target knowledge entry.
[0112] Specifically, the data acquisition information can be associated with the data acquisition logic used to acquire business data. The data acquisition logic may include query statements, query templates, data access instructions, or other forms of data acquisition description information, which are not limited in this disclosure.
[0113] In one implementation, when the data acquisition information includes a query statement, the corresponding target query statement can be determined based on the data acquisition information, and the target time series database can be accessed to execute the target query statement to obtain the corresponding reference data; when the data acquisition information includes other forms of data acquisition description information, the corresponding data access process can be invoked based on the data acquisition description information to obtain the required reference data.
[0114] Furthermore, during the execution of data retrieval logic, situations may arise where execution fails or valid reference data is not obtained. For example, the query statement corresponding to the data retrieval logic may fail to execute, return no valid data, or the query result may be empty.
[0115] In the above situation, the business description information in the target knowledge entry can be retained and injected into the data view context, while the corresponding data content can be replaced with a preset error message or an empty data representation.
[0116] For example, when the data retrieval logic fails, a message indicating the failure can be generated in the data view context; when the data retrieval logic succeeds but does not return valid data, the corresponding field information can be retained in the data view context, and empty data can be used to indicate that the corresponding reference data has not been retrieved.
[0117] By using the above method, even if the data acquisition logic corresponding to some knowledge items cannot be executed normally, the business description information in the target knowledge item can still be used to participate in the generation of query analysis reports, avoiding the interruption of the entire query analysis process due to a single data acquisition anomaly, and improving the robustness of the query analysis process.
[0118] like Figure 2 As shown, this disclosure provides a time-series data natural language query system, including an orchestration controller (SeekController) 210, a query generation module 220, a report generation module 230, a database session service 240, and a knowledge base service 250.
[0119] In one implementation, the orchestration controller 210 is used to implement input and orchestration functions. Specifically, the orchestration controller 210 provides a network interface service (e.g., an HTTP interface) to receive natural language questions input by users, and coordinates the data interaction between the query generation module 220, the report generation module 230, the database session service 240, and the knowledge base service 250 through a unified query processing entry point (e.g., the / solve interface) to orchestrate and control the entire time-series data natural language query process.
[0120] The database session service 240 can be implemented based on the database session service module (e.g., SessionServiceImpl) 241. During the query generation phase, the database session service module 241 can access the metadata information of the target time-series database (e.g., query information_schema) through a structure acquisition interface (e.g., getContentSchema), and perform real sample value sampling through the sampling module 242 (e.g., obtain sample records through LIMIT 1) to generate schema enhancement information (i.e., schema grounding text) to assist in the generation of query statements.
[0121] During the query execution and report generation phase, the database session service module 241 can execute the generated query statement through the data reading interface (e.g., getRawStringData) and perform formatting processing on the returned results (e.g., time format conversion and maximum row count truncation) to obtain real data that can be processed by the large language model.
[0122] The knowledge base service 250 can be implemented based on the knowledge base service module (e.g., RAGServiceImpl), which uses the retrieval engine (e.g., RAGFlow) 251 and the knowledge item module 252 to implement the retrieval and lifecycle management of knowledge items.
[0123] The retrieval engine 251 is used to retrieve target knowledge entries based on natural language questions; the knowledge entry module 252 is used to provide two different stages of injection for the same matching target knowledge entry retrieved: During the query generation phase, business description information and data acquisition information are extracted to construct the query view context; during the report generation phase, the corresponding logic is executed based on the data acquisition information to obtain the actual data and construct the data view context.
[0124] Specifically, the natural language query process for time-series data is divided into a query generation stage that focuses on determinism and a report generation stage that focuses on expressiveness: The query generation phase is completed by the query generation module 220. The query generation module 220 includes a query context assembly unit 221, a first model invocation unit 222, and a query statement generation unit 223.
[0125] The query context assembly unit 221 calls the database session service 240 to obtain schema enhancement information and the knowledge base service 250 to obtain the query view context. It then assembles the schema enhancement information, the query view context, and the natural language question to form query hint information. The query view context provides business semantics and data acquisition method constraints, while the schema enhancement information provides the database structure and actual data characteristics.
[0126] The first model calling unit 222 calls the large language model to generate a query statement based on the query prompt information. Explicit reasoning content can be suppressed through parameter configuration (such as disabling the thought chain) and / or output constraints to improve the determinism of the generation.
[0127] The query statement generation unit 223 is used to output the generation result. If the generation result is a rejection text containing a rejection identifier, the orchestration controller 210 stops the subsequent database access and report generation process and directly returns the reason for rejection; if the generation result is an executable query statement, the orchestration controller 210 enters the report generation stage.
[0128] The report generation phase is completed by the report generation module 230. The report generation module 230 includes a report context assembly unit 231, a second model invocation unit 232, and an analysis report generation unit 233.
[0129] The report context assembly unit 231 obtains the real data returned and formatted after the database session service 240 executes the query statement, and at the same time obtains the knowledge base service 250 to execute the obtained data view context in real time for the same target knowledge item, and assembles the natural language question, query statement, real data and data view context together to form a report prompt information.
[0130] The second model invocation unit 232, based on the report prompts, uses a strategy suitable for text analysis to invoke the large language model to generate a query analysis report.
[0131] The analysis report generation unit 233 is used to output a structured query analysis report that includes a summary of query results, detailed data analysis, and query conclusions, and may include source information (such as referenced_files).
[0132] In the above manner, this embodiment of the invention, for the same target knowledge item, injects a query view context to assist in generating query statements during the query generation stage, and injects a data view context built based on real-time data to assist in generating analysis reports during the report generation stage, thereby achieving decoupling and efficient utilization of the dual views of knowledge items.
[0133] In this embodiment of the disclosure, combined with Figure 2 The architecture of the time-series data natural language query system shown is as follows: Figure 3 As shown, the specific process of the natural language query method for time series data may include the following steps.
[0134] Step 310: Receive natural language questions from the user.
[0135] The orchestration controller receives natural language questions from the user regarding the target time-series database. These natural language questions describe the data content the user expects to obtain from the target time-series database, such as the status of the target device, operating trends, and historical changes.
[0136] Step 320: Assembly query prompt information
[0137] In one implementation, the time-series data natural language query system can assemble the runtime context using a query prompt template (e.g., SQL_prompt_pre.txt), filling the corresponding slots in the query prompt template with pattern-enhanced text generated based on pattern enhancement information, query view context generated based on target knowledge entries, and natural language questions to generate query prompt information.
[0138] The query view context can be obtained through the query view generation interface (e.g., retrieveKnowledgeWithSQL) in the Knowledge Base Service (RAGServiceImpl). The query view context includes the business description information of the target knowledge item and the data retrieval information associated with that business description information.
[0139] In one implementation, a query context can be constructed based on schema enhancement information and the query view context, and the information corresponding to the query context can be assembled into the query suggestion template. Therefore, the query suggestion information may include: (1) Pattern enhancement information generated based on the target time series database; (2) The query view context generated based on the target knowledge entries; (3) Natural language problem.
[0140] Furthermore, the query suggestion template can also include grammatical constraint information corresponding to the target time series database. This grammatical constraint information can be pre-configured in the query suggestion template as fixed reference content for the target time series database and input into the large language model along with the query suggestion information. For example, when the target time series database is IoTDB, the grammatical constraint information can include the query syntax structure, rules for using aggregation functions, usage of time downsampling functions, and time format requirements, etc.
[0141] Furthermore, pattern-enhanced text can organize pattern-enhancing information according to a preset format. For example, for a target data table, pattern-enhanced text can be generated according to the following structured format: Table name: {database.table} Field name, field description, field category, data type, example value {column_name},{comment},{category},{datatype},{example_value} This information is then input into the large language model as part of the query suggestion information. In one implementation, when the real example value extracted through sampling is empty or the target table is empty, the corresponding example value placeholder (such as {example_value}) is output as empty (i.e., no example content is filled), and this does not affect the process of generating query statements based on pattern enhancement information.
[0142] In this way, the large language model can simultaneously obtain the data organization structure of the target time series database and the actual value information of the corresponding fields, thereby improving the matching degree between the generated query statement and the actual data of the target time series database.
[0143] It should be understood that the syntax constraint information may be adjusted according to the type, version and execution rules of the target time series database, and this disclosure does not limit it.
[0144] It should be noted that the acquisition of pattern enhancement information and the retrieval of target knowledge items can be performed after receiving the natural language question, and the assembly of the corresponding information can be completed when generating query prompt information. This disclosure does not limit this.
[0145] Step 330: Call the large language model to generate query statements.
[0146] Specifically, the large language model is invoked based on the assembled query prompts to generate query statements for accessing the target time-series database.
[0147] In one implementation, the large language model combines pattern enhancement information, query view context, and grammatical constraint information (such as the downsampling and aggregation grammar rules of IoTDB) in the query hints to determine the target query object, query fields, and query conditions, and generates a query statement that conforms to the execution rules of the target time-series database.
[0148] Furthermore, during the query generation phase, the output form of the large language model can be constrained by configuring model interface parameters (e.g., setting thinking=disabled to disable explicit reasoning output of the thinking chain) and / or output constraint methods, and by adopting a deterministic model calling strategy (e.g., configuring a lower sampling temperature parameter).
[0149] The output of the large language model includes: (1) An executable query statement (e.g., a single SELECT query statement) used to access the target time-series database; or (2) Rejection text containing a preset rejection flag (e.g., rejection text starting with UNRELATED:). The rejection text indicates that, based on the current pattern enhancement information and the target knowledge item, it is impossible to obtain valid data corresponding to the natural language question from the target time series database.
[0150] Step 340: Determine if a rejection flag is included.
[0151] The time-series data natural language query system detects the output of the large language model and determines whether the output (such as the beginning of the text) contains a preset rejection flag (e.g., UNRELATED:).
[0152] If the output contains a rejection flag, determine that the output text will not be executed as a query statement, and proceed to step 341. If no rejection flag is detected and an executable query statement is generated, proceed to step 350.
[0153] Step 341: Return the reason for refusal and terminate the subsequent process.
[0154] When a rejection flag is detected, the time-series data natural language query system extracts the reason for rejection from the rejection text after removing the rejection flag (for example, by using the string substring method sql.substring(11) to extract the reason text after removing the UNRELATED: prefix) and returns it to the user.
[0155] At the same time, the time-series data natural language query system triggers an early stop-loss mechanism, terminating subsequent database query execution and query analysis report generation processes to avoid performing redundant database access operations for invalid issues.
[0156] Step 350: Execute the query statement to obtain the query results.
[0157] Once a valid query statement is generated, the time-series data natural language query system executes the query statement in the corresponding target time-series database through the database session service's data reading interface (e.g., getRawStringData(sql,databaseName)) based on the target data source association information, and performs formatted preprocessing on the returned raw query results to obtain real data suitable for subsequent report generation.
[0158] In one implementation, formatting preprocessing includes: Based on the convention that the first column of the query results is a time field (the large language model can be guided to retain the time field through constraints in the query prompt template), the timestamp in the first column is uniformly converted into a preset time format (e.g., yyyy-MM-dd HH:mm:ss.SSS) so that subsequent reports can accurately identify changes in the time series. Set a maximum threshold for the number of rows to read (e.g., limit the maximum number of rows to 2000). When the query results exceed this threshold, a preset number of data rows will be truncated to control the context scale of the input to the large language model.
[0159] It should be noted that the above-described time field formatting is based on the result column conventions in natural language query scenarios for time-series data. These conventions can be guided by query constraints in the query suggestion template; for example, prompting the large language model to retain the time field according to the needs of time-series analysis when generating the query statement.
[0160] In this implementation, by formatting the query results, the subsequent query analysis report generation process can be based on data content with a clear time expression format, thereby improving the correspondence between the analysis results and the actual time-series data change process.
[0161] Step 360: Assembly report prompt information.
[0162] After obtaining the query results, the time-series data natural language query system assembles report prompts to generate a query analysis report. The report prompts can be built based on a report prompt template (e.g., Report_prompt.txt) and include: (1) The problem of natural language input by users; (2) Query statements used to obtain query results; (3) The query results obtained by executing the query statement (i.e., the formatted real data); (4) Data view context generated based on target knowledge entries.
[0163] The data view context can be obtained through the data view generation interface of the knowledge base service (e.g., retrieveKnowledgeWithData). Specifically, the knowledge base service executes the corresponding data retrieval logic based on the data retrieval information in the target knowledge entry, obtains the corresponding reference data in real time, and organizes it into a data view context by combining it with business description information.
[0164] In one implementation, when an error occurs during the execution of the data acquisition logic or the acquired reference data is empty, the business description information of the target knowledge item is retained and injected into the data view context, and the corresponding reference data content is replaced with a preset error message text or an empty table format to ensure the structural integrity of the data view context.
[0165] Step 370: Call the large language model to generate a query analysis report.
[0166] The time-series data natural language query system generates query analysis reports by calling a large language model based on report prompts. In one implementation, the report generation stage can use model parameter configurations different from those in the query statement generation stage, such as setting a higher sampling temperature parameter (e.g., setting the temperature to 1) to improve the expressive richness and analytical depth of the report generation process.
[0167] Step 380: Output the query analysis report.
[0168] The time-series data natural language query system outputs a query analysis report according to a preset report structure, which may include: (1) Summary of query results; (2) Detailed data analysis; (3) Query conclusion.
[0169] Furthermore, the query analysis report can also include source information (e.g., recorded through the referenced_files field) to record the knowledge items, query data, or data sources referenced during the report generation process, enabling users to trace the data basis corresponding to the analysis results.
[0170] Through the above process, the present invention generates query statements by utilizing pattern enhancement information and query view constraints of target knowledge items in the query generation stage, and further generates structured analysis reports by combining the actual query results with the data view context constructed based on real-time reference data in the report generation stage. This achieves fully automated and highly robust processing from natural language input to accurate time-series data query and multi-dimensional analysis report output.
[0171] In the above implementation, the target knowledge entry serves as a knowledge unit that associates business semantic information with the target time-series database data access logic, and is used to assist in generating query statements and query analysis reports.
[0172] In one implementation, such as Figure 4 As shown, target knowledge items can adopt the following structured data structure: { "title": "Entry Identifier", "description": "Business description information", "databaseName": "Target data source association information", "sql": "Data retrieval information" } Among them, title serves as the unique identifier or name of the target knowledge item; description is used to record the business semantic description or business phenomenon (e.g., describing the business phenomenon corresponding to the change of "wind speed at wind farm 0303" within the target time period); databaseName is used to associate the target data source information (e.g., the target database name); sql serves as a specific implementation of data acquisition information and is used to describe the execution logic of acquiring data from the corresponding data source (including query statements, query templates, or interface call information, etc.).
[0173] In this way, the understanding of business phenomena in domain experience and the corresponding data acquisition logic are jointly precipitated into searchable knowledge units, forming a relational structure between business semantics, data sources, and data acquisition logic.
[0174] In one implementation, such as Figure 4 As shown, the knowledge base service (RAGServiceImpl) can generate two context injection patterns for different processing stages based on the retrieved target knowledge entries: (1) Query view context (used in the query generation phase) By using a query view generation interface (such as `retrieveKnowledgeWithSQL`), business description information and data acquisition information are extracted from the target knowledge item to generate the query view context (corresponding to...). Figure 4 (Refer to query view 421). Example organization format is as follows: ===== Filename: {title} ===== Content Description: {description} Data Query SQL: {sql} When the target knowledge item does not contain corresponding data retrieval information, a preset prompt message can be output. The query view context is input into the large language model as part of the query prompt message, assisting the large language model in determining query elements such as query fields, filtering conditions, and time windows by referring to similar business scenarios.
[0175] (2) Data view context (used in the report generation phase)
[0176] Through data view generation interfaces (such as `retrieveKnowledgeWithData`), the corresponding data retrieval logic is executed based on the data retrieval information (such as calling `getRawStringData(sql, databaseName)`), retrieving reference data `reference_data` (not a static snapshot) of the target database in real time under the current state. This data is then combined with business description information to form a data view context (corresponding to...). Figure 4 (Data view 422 in the example). The example organization format is as follows: ===== Filename: {title} ===== Content Description: {description} data: {reference_data} When the data retrieval logic fails or the retrieved data is empty, the business description information can be retained, and the reference data can be replaced with the corresponding preset error message text or empty table format.
[0177] like Figure 4 As shown, the same target knowledge item (target knowledge item 410) generates different types of context information according to the needs of different processing stages: a query view context (query view 421) is injected in the query generation stage to provide business semantics and data acquisition methods; a data view context (data view 422) is injected in the report generation stage to provide real-time synchronized actual reference data. Through this dual-view mechanism, the decoupling and efficient utilization of knowledge items at different stages are achieved.
[0178] Furthermore, during the generation of the data view context, when an anomaly or emptiness occurs in obtaining the corresponding reference data, a fault tolerance and degradation mechanism is triggered to retain the business description information in the target knowledge entry and to handle different anomaly situations: Execution failure: When the data retrieval logic encounters an error, the reference data will be replaced with "Failed to retrieve data" and the corresponding error log information; Empty data: When the data retrieval logic executes successfully but returns an empty result, the reference data will be replaced with an empty table format containing only field names; Configuration empty: When the data acquisition information itself is empty, output the preset "no related data" prompt message.
[0179] The above-mentioned fault tolerance and degradation mechanism avoids the interruption of the overall query and analysis process due to abnormal acquisition of data for a single knowledge item, and significantly improves the system's resilience and robustness.
[0180] Furthermore, to improve the determinism of the query generation process and the expressive power of the query analysis report, this disclosure adopts a two-stage specialized large language model invocation strategy.
[0181] In the above Figure 3 In step 330, in one implementation, the query generation phase generates a query statement for accessing the target time-series database based on the natural language question, pattern enhancement information, and the query view context. Since query statement generation primarily involves the conversion from natural language to database query language, the query generation phase can employ a deterministic constraint strategy.
[0182] Specifically, explicit reasoning content output by the large language model can be suppressed through model interface parameter configuration and / or output constraints. For example, in a large language model service that supports corresponding interface parameters, setting `thinking={type:disabled}` will prevent the large language model from outputting explicit reasoning content. For streaming output scenarios, the `reasoning_content` returned by the model can also be filtered, outputting only the query statement body.
[0183] In one implementation, the output of the query generation phase can be constrained to a single query statement, such as a query statement starting with SELECT; or, when the corresponding query path cannot be determined based on the natural language question, pattern enhancement information, and target knowledge item, the output can contain a rejection text with a preset rejection flag, such as text starting with UNRELATED:.
[0184] Unlike the query generation phase, the report generation phase is used to generate user-oriented data analysis content based on the query results, requiring higher levels of text organization and expression skills. Therefore, the report generation phase can employ different model parameter configurations than the query generation phase.
[0185] For example, the report generation phase can employ a model configuration suitable for the analysis task and set the sampling temperature parameter to 1 to enhance the richness of the analysis content. Simultaneously, the output format can be constrained through report prompt templates, ensuring that the query analysis report includes summaries, detailed analysis, and conclusions, along with referenced_files traceability information.
[0186] In one implementation, when the query generation stage is unable to generate a query statement for obtaining the corresponding data based on existing pattern enhancement information and target knowledge entries, the large language model can output a rejection text containing a rejection flag.
[0187] The time-series natural language query system can detect rejection markers in the output of large language models. For example, when the output begins with "UNRELATED:", the text content after removing the rejection marker can be extracted as the reason for rejection and returned directly to the user.
[0188] At this point, the time-series data natural language query system no longer executes subsequent query statements or generates query analysis reports, thereby reducing invalid database access and model calls.
[0189] In one implementation, to ensure that the query results are adapted to the subsequent data display requirements, the query suggestion template may also include constraint information regarding the format of the query results.
[0190] For example, for natural language queries on time-series data, the generated query statement can be constrained to include the time field as much as possible; for queries involving aggregate functions or time downsampling functions (such as avg, date_bin), the generated results can be constrained to alias the output fields to improve the consistency of the query result field structure.
[0191] By using the above methods, the query results can meet the database execution requirements while improving their compatibility with subsequent data analysis or visualization modules.
[0192] In some implementations, the natural language query method for time-series data provided in this disclosure can also be adjusted according to actual application needs.
[0193] For example, the knowledge retrieval process corresponding to a natural language question can further include a keyword extraction step. Specifically, keywords for knowledge retrieval can be extracted based on the natural language question, and knowledge item retrieval can be performed based on the keywords to improve the matching accuracy of knowledge items. In one implementation, the natural language question can also be directly used as the retrieval input to perform knowledge item retrieval.
[0194] In some implementations, query suggestion templates and report suggestion templates can be replaced or optimized according to the target application scenario. For example, different versions of query suggestion templates or report suggestion templates can be used, and the suggestion content can be adjusted while keeping the two-stage processing architecture of query generation and report generation unchanged.
[0195] Furthermore, the large language model can be invoked through a unified model invocation interface, which can connect to different types of large language model services, including those deployed in the cloud or locally. The query generation model and report generation model can be configured separately according to application requirements.
[0196] Furthermore, the retrieval parameters in the knowledge retrieval process can be adjusted based on the size of the knowledge base, the characteristics of the domain, and the retrieval results. For example, parameters such as the similarity threshold, vector similarity weight, and recall quantity in knowledge retrieval can be configured.
[0197] It should be understood that the above embodiments are only optional embodiments of this disclosure, and this disclosure does not limit the specific values of the parameters.
[0198] The natural language query method for time-series data provided in this disclosure improves the executability of query statements in natural language query scenarios. Specifically, by constructing pattern enhancement information that includes the target time-series database structure information and real example values, and combining it with the syntax constraint information set for the target database in the query suggestion template, the large language model can simultaneously perceive the data organization structure, actual field value forms, and database execution rules of the target database. This reduces the problems of query failure or empty query results caused by misunderstanding of fields, data format mismatch, or database syntax incompatibility.
[0199] In some implementations, storing domain business experience as executable knowledge entries can improve the reusability of domain knowledge. Specifically, target knowledge entries can associate business description information, target data source association information, and corresponding data acquisition information, enabling business personnel to distill data acquisition methods for specific business phenomena into searchable knowledge. When a user inputs a similar natural language question, the system can provide business semantic information and corresponding data acquisition methods based on the retrieved knowledge entries, thereby assisting the large language model in generating query statements that better meet actual business needs.
[0200] In other implementations, generating query view contexts and data view contexts based on the same target knowledge item can improve the efficiency of knowledge data utilization. The query view context is used in the query generation phase, enabling the large language model to reference data acquisition methods corresponding to existing business scenarios. The data view context, on the other hand, can obtain corresponding reference data based on data acquisition information associated with the target knowledge item and is used in the report generation phase. This ensures that the data content upon which the query analysis report is based is consistent with the actual data in the target database, rather than relying on static text content stored during knowledge storage.
[0201] In some implementations, a two-stage processing mechanism that separates the query generation and report generation stages can balance query accuracy and report expressiveness. In the query generation stage, the generation or output of explicit inference content can be suppressed through model parameter configuration and / or output constraints, and the determinism of the query generation process can be improved by combining single query statement output constraints with target database syntax constraints. In the report generation stage, model configurations suitable for analytical expression can be used, enabling the generated query analysis report to have richer information organization capabilities.
[0202] In some implementations, setting an early rejection mechanism can reduce invalid processing. When the system determines, based on the query generation results, that the current natural language question cannot generate a corresponding query statement based on the current query context, it can directly return the reason for rejection without continuing to execute the database access and query analysis report generation process, thereby reducing unnecessary data processing operations and model call resource consumption.
[0203] Furthermore, by pre-setting query constraints tailored to downstream data processing needs during the query generation phase, the adaptability between query results and subsequent application stages can be improved. For example, in time series data analysis scenarios, query suggestions and constraints can guide the generated query statements to retain the time field and assign appropriate field names to the aggregated results, enabling the query results to be directly used for subsequent time series analysis and visualization without additional data structure transformation. Simultaneously, including knowledge source identification information in the query analysis report allows for the association of report content with relevant knowledge entries, improving the traceability of analysis results.
[0204] In this disclosure, a time-series data natural language query apparatus is also provided. For example... Figure 5 As shown, the time-series data natural language query device 500 can be deployed in a server, computing device or other electronic device capable of performing data processing tasks. It is used to obtain corresponding query results from the target time-series database based on the natural language question input by the user and generate a corresponding query analysis report.
[0205] like Figure 5 As shown, the time-series data natural language query device 500 includes: The receiving module 510 is used to receive natural language questions input by the user for the target time series database.
[0206] The acquisition module 520 is used to acquire the pattern enhancement information corresponding to the target time series database. The pattern enhancement information includes the structural information of the target time series database.
[0207] The retrieval module 530 is used to retrieve target knowledge entries that match the natural language question from the knowledge base. The target knowledge entries include business description information and data acquisition information associated with the business description information.
[0208] The query statement generation module 540 is used to generate query statements for accessing the target time series database based on natural language questions, pattern enhancement information, and target knowledge entries.
[0209] The query module 550 is used to execute query statements and obtain query results.
[0210] The receiving module 510, the obtaining module 520, the retrieval module 530, the query statement generation module 540, and the query module 550 respectively correspond to the implementation process of steps 110 to 150 in the aforementioned method embodiments. Their functions, processing flow, and application scenarios can be found in the corresponding method embodiments, and will not be repeated here.
[0211] In one implementation, such as Figure 6 As shown, the time-series data natural language query device 500 also includes: The report generation module 560 is used to generate query analysis reports based on natural language questions and query results.
[0212] Specifically, the report generation module 560 can be used to obtain corresponding reference data based on the data acquisition information in the target knowledge item, construct a data view context, and generate a query analysis report based on the natural language question, query statement, query results, and data view context.
[0213] In one implementation, the report generation module 560 can also be used for: Access the target time-series database based on the data acquisition information to execute the data acquisition logic bound to the data acquisition information; When the data acquisition logic fails to execute or the corresponding reference data is not obtained, the business description information in the target knowledge item is retained and injected into the data view context, and the corresponding data is replaced with a preset error message or empty table format.
[0214] By using the above methods, even if the data acquisition logic associated with some knowledge items fails to execute, a complete data view context can still be generated based on the business description information, thereby improving the robustness of the query analysis report generation process.
[0215] In one embodiment, the time-series data natural language query device 500 further includes: The query context building module 570 is used to build a query context based on the structural information in the pattern enhancement information and the business description information and data acquisition information in the target knowledge entries.
[0216] Specifically, the query statement generation module 540 can call a large language model based on the natural language question and query context to generate query statements.
[0217] The query context may include: The structural information corresponding to the target time series database; Business description information in the target knowledge entries; Data acquisition information associated with business description information.
[0218] By using the above methods, large language models can simultaneously reference database structure information and business semantic information, thereby improving the matching accuracy between natural language problems and data objects in the target time-series database.
[0219] In one implementation, such as Figure 6 As shown, the time-series data natural language query device 500 also includes: The rejection detection module 580 is used to detect rejection markers in the rejection text output by the large language model.
[0220] Specifically, after the query statement generation module 540 calls the large language model, it can output the query statement or output the rejection text containing the rejection flag.
[0221] When the rejection detection module 580 detects a rejection flag, the query module 550 does not execute the query statement and returns the rejection reason corresponding to the rejection text.
[0222] For example, the rejection detection module 580 can detect whether the output result includes a rejection flag in the form of a preset string. When a rejection flag is detected, the corresponding rejection reason is extracted and fed back to the user.
[0223] In one implementation, such as Figure 6 As shown, the time-series data natural language query device 500 also includes: The dual-view context building module 590 is used to build query view context and data view context respectively based on the target knowledge items.
[0224] Specifically, during the query statement generation stage, the dual-view context construction module 590 can generate a query view context based on the business description information and data acquisition information in the target knowledge item, and use the query view context as a hint constraint for generating the query statement.
[0225] During the query analysis report generation phase, the dual-view context construction module 590 can obtain corresponding data based on data acquisition information and generate a data view context based on business description information and the acquired data, which serves as the data analysis basis for generating the query analysis report.
[0226] Specifically, for the same target knowledge item, the query view context is used to describe the data acquisition logic of the corresponding business data, while the data view context is used to provide the actual data content of the corresponding business data.
[0227] In one embodiment, the acquisition module 520 may further include a pattern enhancement information generation unit. The pattern enhancement information generation unit is used for: Samples are obtained from the target table in the target time series database to obtain real example values; Enhanced information is built based on structural information and real-world example values.
[0228] In one implementation, the pattern enhancement information generation unit can organize structural information and real example values according to a preset structured text format. The preset structured text format may include table identifier information, field name information, field type information, and example value information.
[0229] It should be noted that the above modules can be implemented through software, hardware, or a combination of both. For example, the modules can be implemented by the processor calling program instructions stored in memory, or they can be implemented by dedicated hardware circuits.
[0230] Each of the above modules corresponds to a step in the aforementioned method embodiment. The specific implementation process, technical effects, and application scenarios can be found in the aforementioned method embodiment, and will not be repeated here.
[0231] Those skilled in the art will understand that the various embodiments of this disclosure can be implemented as systems, methods, apparatuses, electronic devices, or computer program products. Therefore, the various modules, units, apparatuses, or platforms in this disclosure can be implemented in a completely hardware manner, a completely software manner (including firmware, executable program instructions stored in memory, microcode, etc.), or a hardware-software co-implementation manner, and used to perform corresponding data processing operations.
[0232] Based on the same inventive concept, this disclosure also provides an electronic device, which includes: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform the method described above by executing the executable instructions. Since the principle by which this electronic device embodiment solves the problem is similar to that of the above method embodiments, the implementation of this electronic device embodiment can refer to the implementation of the above method embodiments, and repeated details will not be described again.
[0233] Based on the same inventive concept, this disclosure also provides an electronic device, which is described below with reference to... Figure 7 To describe an electronic device 700 according to an embodiment of the present disclosure.
[0234] like Figure 7 As shown, the electronic device 700 can be manifested as a general-purpose computing device, including a processing unit 710, a storage unit 720, a bus 730 connecting different system components (including the storage unit 720 and the processing unit 710), and a display unit 740, etc. The storage unit 720 is used to store executable instructions of the processing unit 710, and the processing unit 710 is used to execute the executable instructions to implement the time-series data natural language query method of any of the above embodiments.
[0235] In one embodiment, the electronic device 700 can be a server, terminal device, computing device, or other electronic device with data processing capabilities. The components in the electronic device 700 can be communicatively connected via a bus 730. The electronic device 700 may also include other functional components, such as input / output components, network communication components, etc., which are not limited in this disclosure.
[0236] The storage unit stores program code, which can be executed by the processing unit 710, causing the processing unit 710 to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure. For example, the processing unit 710 can perform the above-described steps. Figure 1 The steps of the method shown.
[0237] Storage unit 720 may include readable media in the form of volatile storage units, such as random access memory (RAM) 721 and / or cache memory 722, and may further include read-only memory (ROM) 723.
[0238] The storage unit 720 may also include a program / utility 724 having a set (at least one) of program modules 725, including but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.
[0239] Bus 730 can represent one or more of several bus structures, including a memory bus or memory controller, peripheral bus, graphics acceleration port, processing unit, or a local bus using any of the various bus structures. Electronic device 700 can also communicate with one or more external devices 770 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable user interaction with electronic device 700, and / or with any device that enables electronic device 700 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed through input / output (I / O) interface 750. Furthermore, electronic device 700 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 760. As shown, network adapter 760 communicates with other modules of electronic device 700 via bus 730. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0240] In some embodiments, this disclosure also provides a computer program product, which includes a computer program that, when executed by a processor, implements the above-described time-series data natural language query method.
[0241] In some embodiments, this disclosure also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described time-series data natural language query method.
[0242] Computer-readable storage media can be readable signal media or readable storage media. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), USB flash drive, portable hard disk, optical storage device, magnetic storage device, or any suitable combination of the foregoing.
[0243] Furthermore, computer-readable storage media may also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof.
[0244] A readable signal medium can be any readable medium other than a readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. Optionally, program code contained on a computer-readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0245] In practical implementation, program code for performing the operations of this disclosure can be written in any combination of one or more programming languages. These programming languages include object-oriented programming languages—such as Java and C++—as well as conventional procedural programming languages—such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device.
[0246] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to embodiments of this disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0247] Furthermore, although the steps of the method in this disclosure are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or a step may be broken down into multiple steps.
[0248] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the appended claims.
Claims
1. A natural language query method for time-series data, characterized in that, include: Receive natural language questions from users targeting a time-series database; Obtain the pattern enhancement information corresponding to the target time series database, wherein the pattern enhancement information includes the structural information of the target time series database; Retrieve target knowledge entries that match the natural language question from the knowledge base, wherein the target knowledge entries include business description information and data acquisition information associated with the business description information; Based on the natural language problem, the pattern enhancement information, and the target knowledge entries, a query statement for accessing the target time series database is generated; Execute the query statement to obtain the query results.
2. The natural language query method for time-series data according to claim 1, characterized in that, The time-series data natural language query method also includes: A query analysis report is generated based on the natural language question and the query results.
3. The natural language query method for time-series data according to claim 2, characterized in that, The process of generating a query analysis report based on the natural language question and the query results includes: Based on the data acquisition information in the target knowledge entry, obtain the corresponding reference data and construct a data view context; The query analysis report is generated based on the natural language question, the query statement, the query results, and the data view context.
4. The natural language query method for time-series data according to claim 3, characterized in that, The process of generating a query analysis report based on the natural language question and the query results also includes: Access the target time-series database based on the data acquisition information to execute the data acquisition logic bound to the data acquisition information; When the data acquisition logic fails to execute or the corresponding reference data is not acquired, the business description information of the target knowledge item is retained and injected into the data view context, and the corresponding data is replaced with a preset error message or empty table format.
5. The natural language query method for time-series data according to claim 3, characterized in that, When generating the query statement, a query view context is generated based on the business description information and the data acquisition information in the target knowledge entry; When generating the query analysis report, corresponding reference data is obtained based on the data acquisition information, and a data view context is generated based on the corresponding reference data.
6. The natural language query method for time-series data according to claim 1, characterized in that, The step of generating a query statement for retrieving query data from the target time-series database based on the natural language problem, the pattern enhancement information, and the target knowledge entries includes: Based on the structural information in the pattern enhancement information and the business description information and data acquisition information in the target knowledge entries, a query context is constructed. The query statement is generated by invoking a large language model based on the natural language problem and the query context.
7. The natural language query method for time-series data according to claim 6, characterized in that, The step of generating the query statement by invoking a large language model based on the natural language problem and the query context further includes: The large language model is invoked to generate the query statement based on the natural language question and the query context, or to generate a rejection text containing a rejection identifier.
8. The natural language query method for time-series data according to claim 7, characterized in that, The time-series data natural language query method also includes: Detect the rejection identifier in the rejection text output by the large language model; If the rejection flag is detected, the query statement is not executed, and the rejection reason corresponding to the rejection text is returned.
9. The natural language query method for time-series data according to claim 1, characterized in that, The step of obtaining the pattern enhancement information corresponding to the target time series database includes: Based on the target table in the target time series database, sample values are obtained to obtain real example values; The pattern enhancement information is constructed based on the structural information and the real example values.
10. The natural language query method for time-series data according to claim 1, characterized in that, The target knowledge entries also include target data source association information; There is a correspondence between the business description information, the target data source association information, and the data acquisition information in the target knowledge entry.
11. A time-series data natural language query device, characterized in that, include: The receiving module receives natural language questions input by the user for the target time series database; The acquisition module acquires the pattern enhancement information corresponding to the target time series database, wherein the pattern enhancement information includes the structural information of the target time series database; The retrieval module retrieves target knowledge entries that match the natural language question from the knowledge base, wherein the target knowledge entries include business description information and data acquisition information associated with the business description information; The query statement generation module generates a query statement for accessing the target time series database based on the natural language question, the pattern enhancement information, and the target knowledge item. The query module executes the query statement and obtains the query results.
12. An electronic device, characterized in that, include: processor; as well as A memory in which executable instructions of the processor are stored; The processor is configured to execute the time-series data natural language query method according to any one of claims 1 to 10 by executing the executable instructions.
13. A computer-readable storage medium for storing a program, characterized in that, When the program is executed, it implements the time-series data natural language query method according to any one of claims 1 to 10.
14. A computer program product having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the time-series data natural language query method according to any one of claims 1 to 10.