Industrial index intelligent query method and system based on multi-level semantic retrieval and adaptive sampling calibration
Patent Information
- Application Number
- CN202611069843.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-17
- Publication Date
- 2026-10-20
AI Technical Summary
当前,一线生产管理者和分析师普遍通过人工编写SQL语句或在BI界面进行多级筛选来获取所需数据,这种方式存在诸多不便
[0025]从以上技术方案可以看出,本申请具有以下优点:通过先采样、后决策的自适应校准机制,利用大语言模型对真实数据样本进行分析,使SQL生成不再依赖静态Schema的推测,而是建立在实际数据规律的基础之上,解决了大模型在时间格式识别和维度值匹配中的幻觉问题。用户仅需以自然语言提出查询请求,系统自动完成指标定位、采样校准、SQL生成和数据返回的全流程,无需掌握SQL语法,大幅降低了工业数据分析的使用门槛。AI服务器无需直接连接数据库,通过标准化的MCP协议进行跨安全域通信,降低了安全风险,同时增强了系统的可维护性和异构数据库适配能力。
Smart Images

Figure FT_1 
Figure FT_2
Abstract
Description
Technical Field
[0001] This application relates to the fields of artificial intelligence and big data processing, specifically to an intelligent query method and system for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration. Background Technology
[0002] During the digital transformation of industry, production data centers have accumulated massive amounts of business metrics. Currently, frontline production managers and analysts generally obtain the required data by manually writing SQL statements or performing multi-level filtering in BI interfaces, which presents many inconveniences.
[0003] Industrial databases often feature complex table structures, with field names frequently employing abbreviations or codes, lacking intuitive business semantics. This makes it difficult for business users to understand the meaning of these fields, let alone independently write correct SQL queries. While some existing natural language to SQL (NLP) solutions based on large language models have made some progress in handling simple database queries, in industrial metric query scenarios, due to the large database size, non-standard field naming, and complex table relationships, LLMs often fail to accurately identify the physical table corresponding to the target metric when parsing user queries. This results in generated SQL statements that do not match actual requirements or are unexecutable.
[0004] Furthermore, industrial data itself suffers from issues such as inconsistent storage formats and non-standardized values. On one hand, time fields in different business systems are stored in varying formats, and large language models, relying solely on the database schema, cannot perceive the actual storage format, easily generating format-mismatched filter conditions and resulting in empty query results. On the other hand, users' colloquial descriptions of dimension values often differ significantly from the actual stored values in the database, making it difficult for large models to ascertain the true distribution of dimension values through static schemas, thus hindering the generation of effective filter conditions.
[0005] In summary, existing technologies have significant shortcomings in terms of accuracy, robustness, and security when querying industrial indicators. Summary of the Invention
[0006] To address the aforementioned issues, this invention provides an intelligent query method and system for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration.
[0007] In a first aspect, the technical solution of the present invention provides an intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, including: S1. Receive a user's natural language query request, and determine the target indicator and its associated physical table path from the pre-built indicator library through joint verification of vector space retrieval and large language model; the physical table path at least includes a fully qualified access identifier at the database level. S2. Perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate the time filtering conditions that match the user's time description based on the identified format; at the same time, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching and calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions; S3. Combine target indicators, time filtering conditions, and dimension filtering conditions to generate executable SQL statements; S4. Encapsulate the SQL statement into a standardized request using the model context protocol, send it to the data service gateway to execute the query and return the result.
[0008] As a preferred embodiment of the technical solution of the present invention, in S1, the step of determining the target indicator and its associated physical table path from the pre-built indicator library through joint verification of vector space retrieval and large language model includes: The natural language query request is analyzed for intent and expanded with synonyms using a large language model to generate enhanced search statements; Based on the enhanced search statement, vector similarity retrieval is performed in the pre-built indicator vector database to recall the Top-N candidate indicators; the indicator vector database is constructed based on indicator name, indicator code, business description and metadata of the system to which it belongs. The names, business definitions, and metadata of the Top-N candidate metrics are input into the big language model. The big language model then performs semantic ranking and confidence assessment based on the context of the natural language query request, and outputs the metric with the highest confidence as the target metric. Parse the access path of the target metric, extract the underlying physical table name, metric filter field name and its corresponding code value associated with the target metric, and dynamically inject the physical table name, the filter field name and the code value into a temporary database to generate the physical table path.
[0009] Employing a dual verification approach of initial vector space screening and LLM semantic ranking, and through synonym expansion and contextual semantic understanding, it maps user-generated colloquial metric descriptions into unique target metrics, effectively overcoming the limitations of simple vector retrieval or pure rule matching. It transforms unstructured business intent into executable physical table paths and filter field information, providing a precise data location foundation for subsequent sampling and SQL generation.
[0010] As a preferred embodiment of the technical solution of the present invention, S1 further includes: When the large language model evaluates that there are at least two candidate indicators whose confidence scores are both greater than the preset threshold, and the confidence score difference between the candidate indicators is less than the preset difference, it is determined to be an ambiguous intent state. Based on the ambiguous state of intent, a clarifying question containing the business differences of each candidate indicator is automatically generated and fed back to the user terminal; Receive user feedback on the clarification issue, and perform semantic ranking again based on the feedback to finally determine the target indicator.
[0011] When LLM identifies multiple candidate metrics with similar confidence levels, the system proactively initiates an interaction for clarification. By generating clarification questions that include key differences, the system guides the user to confirm their intent, effectively avoiding query failures caused by incorrect metric selection and improving the system's intelligence level in ambiguous scenarios.
[0012] As a preferred embodiment of the technical solution of the present invention, in S2, exploratory random sampling is performed on the physical table pointed to by the physical table path, specifically including: Based on the physical table path, determine the target physical table that the physical table path points to; An exploratory SQL statement is constructed based on the table identifier of the target physical table. The exploratory SQL statement includes a random sort clause and a preset row count limit. Execute the exploratory SQL statement to filter data from the target physical table according to the indicator filtering conditions and randomly extract a preset number of sample records to obtain real data samples containing the actual values of the time field and dimension field.
[0013] By including a random sorting clause and a preset row count limit in the sampling SQL, and randomly sampling data after filtering according to the indicator filtering conditions, the obtained samples are ensured to cover the typical value patterns of the time field and dimension field.
[0014] As a preferred embodiment of the technical solution of the present invention, in S2, the calculation of time filtering conditions that match the user time description based on the identified storage format specifically includes: By using a large language model to analyze the actual values of the time field in the real data sample, the storage format type of the time field can be automatically inferred. The colloquial time description in the natural language query request is semantically parsed using a large language model, and the target time range corresponding to the colloquial time description is determined by combining it with the current system time. According to the storage format type, the start and end times of the target time range are converted into strings that conform to the storage format type, and time range filtering conditions are generated.
[0015] By analyzing the actual values of the time field in the sample using LLM analysis rather than relying on schema definitions, the storage format is automatically identified and filter conditions with consistent format are generated accordingly, eliminating query failures caused by inconsistent time formats.
[0016] As a preferred embodiment of the technical solution of the present invention, in S2, semantic matching and calibration are performed between the dimension information in the user description and the valid values to generate accurate dimension filtering conditions, specifically including: The large language model is used to identify dimensional fields with filtering significance from the real data samples; Based on the dimension field, a DISTINCT query request is sent to the database to obtain a list of unique values of the dimension field in recent data; Using a large language model, the dimensional information in the natural language query request is semantically matched with each value in the unique value list, and the unique value with the highest matching degree is selected as the precise filter value. When the matching degree of the unique value with the highest matching degree is lower than a preset threshold, a prompt message indicating that the dimension matching has failed is generated; Dimensional filtering conditions are generated based on the precise filter values.
[0017] By querying the list of unique DISTINCT values for dimension fields in recent data, the LLM can determine the actual distribution of dimension values stored in the database. This allows for precise matching of vague user descriptions to actual database values, resolving the long-standing industry pain point in NL2SQL where colloquial dimension values cannot be mapped to stored database values. The output message when a match fails further enhances system availability.
[0018] As a preferred embodiment of the technical solution of this invention, in S3, an executable SQL statement is generated by comprehensively considering the target indicator, time filtering conditions, and dimension filtering conditions, specifically including: The corresponding aggregation function is determined according to the type of the target indicator. The aggregation function includes at least one of summation, counting, average, maximum and minimum values. Based on the physical table path, determine the table reference in the FROM clause; The basic query framework for SQL statements is constructed based on the target metrics, the aggregation functions, and the physical table paths. The time filtering condition and the dimension filtering condition are used as components of the WHERE clause and concatenated into the basic query framework according to preset syntax rules. When both the time filtering condition and the dimension filtering condition exist, a logical operator is added between them to connect them, generating an SQL statement containing complete filtering conditions. Perform syntax validation on the generated SQL statements, including at least one of the following: table name and field name existence validation, data type matching validation, and consistency validation between aggregate functions and grouping clauses. When the verification passes, the current SQL statement will be output as the executable SQL statement. When the verification fails, the SQL statement is automatically corrected according to the verification failure type and then re-verified until the verification passes or the preset number of retries is reached.
[0019] Through automated syntax verification and intelligent correction mechanisms, the system automatically corrects and re-verifies based on the failure type when verification fails, significantly reducing execution failures caused by syntax issues and improving the system's automation level and query success rate.
[0020] As a preferred embodiment of the technical solution of the present invention, after generating the executable SQL statement in S3 and before S4, the method further includes: Submit the generated executable SQL statement to the database's execution plan analysis interface to obtain estimated resource consumption metrics; When the estimated resource consumption index exceeds the preset safety threshold, resource limit parameters are automatically injected into the executable SQL statement, or the executable SQL statement is intercepted and a performance warning message is generated.
[0021] By analyzing the estimated resource consumption of SQL before execution and performing security interception or resource limitation, the risk of database resource exhaustion caused by complex queries is effectively prevented, thus improving the stability and security of industrial-grade systems.
[0022] As a preferred embodiment of the technical solution of the present invention, in step S4, after sending the data to the data service gateway to execute the query and return the result, the method further includes: The natural language query request, the generated executable SQL statement, and the raw result data returned by the query are all input into the large language model; Generate a natural language summary that summarizes the core findings or data trends of a query using a large language model; The natural language summary and the original result data are combined and returned to the user terminal through the model context protocol.
[0023] LLM is used to generate natural language summaries, transforming raw data into highly readable analytical conclusions. This helps business personnel quickly understand the core findings and trends behind the data, further improving the decision-making efficiency of intelligent industrial analysis.
[0024] Secondly, the technical solution of the present invention also provides an intelligent query system for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, comprising: The indicator localization module is configured to receive user natural language query requests and determine the target indicator and its associated physical table path from a pre-built indicator library through joint verification of vector space retrieval and large language model; the physical table path at least includes a fully qualified access identifier at the database level. The adaptive sampling calibration module is configured to perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate time filtering conditions that match the user's time description based on the identified format; at the same time, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions; The SQL generation module can be configured with comprehensive target indicators, time filtering conditions, and dimension filtering conditions to generate executable SQL statements. The MCP standardized execution module is configured to encapsulate the SQL statement into a standardized request through the model context protocol, send it to the data service gateway to execute the query and return the result.
[0025] As can be seen from the above technical solutions, this application has the following advantages: Through an adaptive calibration mechanism of sampling before decision-making, it utilizes a large language model to analyze real data samples, ensuring that SQL generation no longer relies on static schema speculation but is based on actual data patterns, thus solving the illusion problem of large models in time format recognition and dimensional value matching. Users only need to submit query requests in natural language, and the system automatically completes the entire process of indicator positioning, sampling calibration, SQL generation, and data return, without requiring mastery of SQL syntax, significantly lowering the barrier to entry for industrial data analysis. The AI server does not need to directly connect to the database; it communicates across security domains through the standardized MCP protocol, reducing security risks while enhancing system maintainability and heterogeneous database adaptability. Attached Figure Description
[0026] To more clearly illustrate the technical solution of this application, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0027] Figure 1 This is a flowchart illustrating the method provided in an embodiment of the present invention.
[0028] Figure 2 A block diagram of a system provided in an embodiment of the present invention. Detailed Implementation
[0029] To make the purpose, features, and advantages of this application more apparent and understandable, specific embodiments and accompanying drawings will be used to clearly and completely describe the technical solution protected by this application. Obviously, the embodiments described below are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0030] Unless otherwise defined, all technical and scientific terms used in this application have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used in this application and in the specification of this invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0031] The key terms used in this invention will be explained below.
[0032] Vector space retrieval refers to the technique of converting text into vector representation, calculating similarity in a high-dimensional vector space, and retrieving the most similar results.
[0033] Large Language Models (LLMs) are deep learning language models with a large number of parameters, pre-trained on large-scale corpora, and capable of understanding, reasoning, and generating natural language and code.
[0034] The physical table path refers to the complete location identifier of a physical table in the database, which includes hierarchical information such as catalog, database, and table name.
[0035] Exploratory random sampling refers to the operation of randomly selecting a portion of records from a data table in order to understand the distribution patterns of the data.
[0036] The DISTINCT query is an SQL operation used to retrieve a list of duplicate values for a field.
[0037] Model Context Protocol (MCP) is a standardized protocol for AI models to interact with data sources, supporting request encapsulation and cross-service calls via JSON-RPC format.
[0038] A fully qualified access identifier is a database object identifier that contains complete hierarchical information and can uniquely identify a target object in cross-database and cross-cluster environments.
[0039] This invention provides an intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, which is applied to a query system. The system includes: a user terminal, an AI server, an indicator vector database, an MCP data service gateway, and a target database.
[0040] The user terminal receives natural language query requests input by the user and sends these requests to the AI server via a network. The user terminal can be a personal computer, tablet, smartphone, wearable device, or other terminal device with data input and display capabilities. The AI server is a computing device deployed with a large language model (LLM) to execute core logic such as indicator localization, sampling calibration, and SQL generation. The indicator vector database is a pre-built vector index library, constructed based on indicator names, indicator codes, business descriptions, and metadata of the system to which they belong, to support efficient vector similarity retrieval. The MCP data service gateway is an independently deployed data service middleware layer that follows the model context protocol. It receives standardized requests from the AI server and converts them into query operations on the underlying target database. The target database is a production database in an industrial scenario.
[0041] The AI server and the MCP data service gateway communicate via a standardized JSON-RPC interface, and both can be deployed in different physical security domains. The AI server does not need to directly connect to the target database, thus reducing security risks and achieving decoupling and isolation between the AI logic layer and the database physical layer. Please refer to [link / reference]. Figure 1 The method includes: S1. Receive a user's natural language query request, and determine the target indicator and its associated physical table path from a pre-built indicator library through joint verification of vector space retrieval and a large language model; the physical table path at least contains a fully qualified access identifier at the database level; this step includes the following steps: S11. Use a large language model to perform intent parsing and synonym expansion on the natural language query request to generate an enhanced search statement; The AI server receives natural language query requests input by users through their terminals. These queries include information such as the business metrics, time range, and dimensional conditions the user wishes to query.
[0042] The AI server inputs the natural language query request into a large language model (LLM). This LLM can be a pre-trained and fine-tuned general-purpose large language model, such as the LLaMA series or the Qwen series. The LLM performs deep intent parsing and synonym expansion on the query request. LLM identifies the core intent of user queries and extracts key information. LLM combines this with the industrial business context to perform synonym expansion and implicit semantic inference on the extracted keywords.
[0043] After the above processing, LLM generates a semantically enhanced search query, which not only contains the explicit keywords entered by the user, but also includes expanded implicit semantic information, thus more comprehensively expressing the user's query intent.
[0044] S12. Based on the enhanced search statement, perform vector similarity search in the pre-built indicator vector database to recall the Top-N candidate indicators; the indicator vector database is constructed based on indicator name, indicator code, business description and system metadata. The AI server encodes the semantically enhanced search query into a query vector. The encoding method can use a pre-trained text embedding model, such as BERT or Sentence-BERT, to convert the text into a fixed-length vector representation.
[0045] The AI server performs an approximate nearest neighbor (ANN) search in a pre-built indicator vector database. This indicator vector database is pre-established during the system construction phase, and its construction includes: collecting metadata for all business indicators in the industrial scenario, including indicator name, indicator code, business description, system to which it belongs, and related table information; encoding the metadata into vectors using the same embedding model as the query encoding; establishing an index relationship between the indicator metadata and the corresponding vectors, and storing them in the vector database.
[0046] ANN retrieval uses vector retrieval tools such as FAISS and Milvus to return the Top-N candidate metrics with the highest semantic similarity to the query vector. Similarity can be calculated using cosine similarity or inner product distance.
[0047] S13. Input the names, business definitions and metadata of the Top-N candidate indicators into the big language model. The big language model performs semantic ranking and confidence evaluation in combination with the context of the natural language query request, and outputs the indicator with the highest confidence as the target indicator. The AI server inputs the complete metadata (including indicator name, indicator code, business definition, system, and related table information) of the Top-N candidate indicators into the LLM. The LLM then performs semantic ranking and confidence assessment on the Top-N candidate indicators based on the context of the user's original query request.
[0048] Specifically, LLM performs semantic relevance assessment on each candidate metric, evaluates its matching degree with the user's query intent, and assigns a confidence score to each candidate metric. LLM can also utilize the thought chain reasoning method to compare the business definition of candidate metrics with the user's query requirements item by item, thereby eliminating candidate metrics with semantic biases.
[0049] Ultimately, the LLM output with the highest confidence level is used as the target indicator.
[0050] S14. Parse the access path of the target indicator, extract the underlying physical table name, indicator filter field name and its corresponding code value associated with the target indicator, and dynamically inject the physical table name, the filter field name and the code value into the temporary database to generate the physical table path.
[0051] After identifying the target metric, the AI server parses the access path for that metric. This access path is pre-configured in the metric metadata and includes the underlying physical table name associated with the target metric, the metric filter field name, and its corresponding code value. The AI server dynamically injects the extracted physical table name, filter field name, and code value into a temporary database schema. This temporary database schema is a virtual schema structure maintained by the AI server during the execution of the current query task, used to enable the subsequent SQL generation module to recognize the existence of this logical metric and its physical mapping relationship.
[0052] After processing by S14, the system generates a physical table path. The physical table path contains at least a fully qualified access identifier at the database level, in the format: Catalog name.database name.table name, ensuring that the target physical table can be located unambiguously in complex industrial data environments that span multiple databases and clusters.
[0053] In some embodiments, in S13, when the large language model evaluates that there are at least two candidate indicators whose confidence levels are both greater than a preset threshold, and the confidence level difference between each candidate indicator is less than a preset difference, the system determines that the current query is in an ambiguous state of intent.
[0054] For example, when a user queries production output, it may match two indicators simultaneously: daily output of electrolytic aluminum and daily output of alumina. The confidence levels of the two indicators are 0.72 and 0.68, respectively, with a difference of less than 0.1. The system determines that the intent is ambiguous.
[0055] After determining that the intent is ambiguous, the system automatically invokes the LLM (Local Management Model) to generate clarification questions. These clarification questions contain the key differences in the business aspects of each candidate metric. The system sends these clarification questions to the user via their terminal and awaits feedback. The user selects one of the metrices through their terminal. After receiving the user's feedback, the system uses the user-confirmed metric as the sole target metric and re-performs subsequent semantic ranking and schema injection.
[0056] S2. Perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate time filtering conditions that match the user's time description based on the identified format; simultaneously, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching and calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions; this step specifically includes: S21. Based on the physical table path, determine the target physical table pointed to by the physical table path; construct an exploratory SQL statement based on the table identifier of the target physical table, the exploratory SQL statement includes a random sort clause and a preset row number limit; execute the exploratory SQL statement to randomly extract a preset number of sample records from the target physical table after filtering data according to the indicator filtering conditions, and obtain real data samples containing the actual values of the time field and dimension field.
[0057] Based on the physical table path determined in S1, the AI server determines the target physical table pointed to by the physical table path. Specifically, the AI server parses each level of the physical table path to locate the actual storage location of the target physical table.
[0058] After identifying the target physical table, the AI server first obtains the table structure metadata, including column names, data types, and comments, by querying the database's information schema. Based on this table structure metadata, a two-way mapping relationship is established between physical field names and business aliases to improve the readability and correctness of subsequent SQL generation.
[0059] Subsequently, the AI server constructs exploratory SQL statements. A typical form of these exploratory SQL statements is: SELECT FROM dwarehouse.industry.al_production_daily WHERE metric_code = 'AL_OUTPUT_001' ORDER BY RAND() LIMIT 20 Where: SELECT This selects all fields, ensuring that the collected samples include both the time and dimension fields. The FROM clause specifies the path to the target physical table; WHERE metric_code = 'XXX' ensures that the collected data is consistent with the business definition of the target metric; ORDER BY RAND() performs random sorting to ensure the representativeness of the sampling results; LIMIT 20 is a preset limit on the number of sample rows. The preset number of rows can be adjusted according to actual needs to ensure that the sample size is appropriate, which can reflect the data distribution pattern without putting too much query pressure on the database.
[0060] The AI server executes the exploratory SQL statement through the MCP data service gateway to obtain real data samples from the target physical table. The real data samples contain the actual values of the time and dimension fields.
[0061] S22. Analyze the actual values of the time field in the real data sample using a large language model, and automatically infer the storage format type of the time field; use the large language model to perform semantic parsing on the colloquial time description in the natural language query request, and determine the target time range corresponding to the colloquial time description in combination with the current system time; according to the storage format type, convert the start and end times of the target time range into strings that conform to the storage format type, and generate time range filtering conditions.
[0062] The AI server inputs the real data samples into the large language model and uses LLM to analyze the actual value patterns of the time field in the samples.
[0063] For example, if the time field in the sample has values of "20260123", "20260122", and "20260121", LLM will automatically infer that the storage format of the time field is "YYYYMMDD" based on the value pattern; if the sample has values of "2026-01-23" and "2026-01-22", then the inferred format is "YYYY-MM-DD".
[0064] LLM also parses colloquial time descriptions in users' natural language query requests. For example, if a user's query mentions last week, LLM combines this with the current system time to calculate the target time range corresponding to last week.
[0065] Finally, the LLM converts the start and end times of the target time range into strings that conform to the storage format type identified in step S22.
[0066] Based on the above conversion results, a time range filter condition is generated. The time format of this filter condition is consistent with the actual storage format of the time field in the target table, thereby ensuring that the SQL statement will not fail to execute due to format mismatch.
[0067] S23. Identify dimension fields with filtering significance from the real data samples using a large language model; based on the dimension fields, send a DISTINCT query request to the database to obtain a list of unique values for the dimension fields in recent data; use the large language model to semantically match the dimension information in the natural language query request with each value in the list of unique values, and select the unique value with the highest matching degree as the precise filtering value; when the matching degree of the unique value with the highest matching degree is lower than a preset threshold, generate a prompt message indicating that the dimension matching has failed; generate dimension filtering conditions based on the precise filtering value.
[0068] The AI server first uses a large language model to identify dimension fields with filtering significance from the real data samples. LLM analysis of the actual values of each field in the samples determines which fields are used for business dimension filtering. After identifying the dimension fields, the AI server sends a DISTINCT query request to the target database based on these dimension fields to obtain a list of unique values for each dimension field in recent data.
[0069] The purpose of limiting data to recent times (generally the last 30 days) is to obtain currently valid dimension values, exclude historical obsolete values, and reduce query overhead.
[0070] Assume the list of unique values obtained is: [Electrolysis Plant 1 (North Area), Electrolysis Plant 2, Electrolysis Plant 3 (South Area)].
[0071] Subsequently, the AI server uses a large language model to semantically match the dimensional information in the user's natural language query request with each value in the unique value list. LLM calculates the semantic similarity between "Factory One" and each value, and selects the unique value with the highest matching degree as the precise filter value.
[0072] In this example, "Factory No. 1" and "Electrolysis Factory No. 1 (North District)" have the highest semantic similarity, so "Electrolysis Factory No. 1 (North District)" is used as the exact filter value.
[0073] When the matching degree of the unique value with the highest matching degree is lower than the preset threshold, the system determines that there is no valid matching dimension value, generates a prompt message such as "The selected dimension does not exist, please confirm the name", and sends it back to the user terminal to avoid empty query results due to the absence of dimension value.
[0074] Dimensional filtering conditions are generated based on the precise filter values.
[0075] S3, combining target metrics, time filtering conditions, and dimension filtering conditions, generates executable SQL statements; specifically including: S31. Determine the corresponding aggregation function based on the indicator type of the target indicator. The aggregation function includes at least one of summation, counting, average, maximum, and minimum values. Determine the table reference in the FROM clause based on the physical table path. Construct the basic query framework of the SQL statement based on the target indicator, the aggregation function, and the physical table path. The AI server first determines the corresponding aggregation function based on the target metric's metric type. The mapping relationship between metric types and aggregation functions is pre-configured in the metric metadata. For example, daily electrolytic aluminum production is a numerical cumulative metric, and the corresponding aggregation function is summation (SUM); the number of factories is a count metric, and the corresponding aggregation function is counting (COUNT).
[0076] Aggregate functions include, but are not limited to, at least one of the following: summation (SUM), count (COUNT), average (AVG), maximum (MAX), and minimum (MIN).
[0077] The AI server determines the table reference in the FROM clause based on the physical table path determined in S1.
[0078] The AI server constructs a basic query framework for SQL statements based on the target metrics, the aggregation functions, and the physical table paths.
[0079] S32. The time filtering condition and the dimension filtering condition are used as components of the WHERE clause and concatenated into the basic query framework according to preset syntax rules; when both the time filtering condition and the dimension filtering condition exist, logical operators are added between them to connect them and generate an SQL statement containing complete filtering conditions. The AI server uses the time and dimension filtering conditions generated in S2 as components of the WHERE clause and concatenates them into the basic query framework according to preset syntax rules.
[0080] The default syntax rules include: the filter field name must be consistent with the table field name; the time field uses comparison operators; and the dimension field uses the equality operator (=) or the IN operator.
[0081] When both time-based and dimension-based filtering conditions exist, add the logical operator "AND" between them to connect them.
[0082] S33. Perform syntax validation on the generated SQL statement, the validation including at least one of table name and field name existence validation, data type matching validation, and consistency validation between aggregate functions and grouping clauses; When the verification passes, the current SQL statement will be output as the executable SQL statement. When the verification fails, the SQL statement is automatically corrected according to the verification failure type and then re-verified until the verification passes or the preset number of retries is reached.
[0083] The AI server performs syntax validation on the generated SQL statements, including: Table name and field name existence check: Check whether the table name and field name referenced in the SQL statement exist in the database schema to prevent execution failure due to misspelled field names or table name changes; Data type matching validation: Checks whether the value type in the filter conditions matches the data type defined in the field. For example, a time field cannot be compared with a value that is incompatible with a string type. Aggregate function and grouping clause consistency check: Check whether non-aggregate fields in the SELECT clause appear in the GROUP BY clause to prevent SQL execution engine errors.
[0084] When the verification passes, the AI server outputs the current SQL statement as the executable SQL statement.
[0085] When the validation fails, the AI server automatically corrects the SQL statement based on the validation failure type. For example, if the validation failure type is "field name does not exist," the AI server performs a similarity match between the erroneous field and the actual field list of the target table, selecting the correct field with the highest similarity to replace it. If the validation failure type is due to inconsistency between aggregate function and grouping, the AI server automatically adds the missing non-aggregate field to the GROUP BY clause.
[0086] After correction, the system will re-verify until the verification passes or the preset number of retries is reached. If the verification still fails after the preset number of retries is reached, the system will generate an error report and notify the user.
[0087] S4. Encapsulate the SQL statement into a standardized request using the model context protocol, send it to the data service gateway to execute the query and return the result.
[0088] In some embodiments, after S3 generates the executable SQL statement and before S4, the process further includes: Submit the generated executable SQL statement to the database's execution plan analysis interface to obtain estimated resource consumption metrics; When the estimated resource consumption exceeds a preset safety threshold, resource limitation parameters are automatically injected into the executable SQL statement, or the executable SQL statement is intercepted and a performance warning message is generated. This is used to prevent complex queries from causing resource impact on the production database.
[0089] The AI server submits the generated executable SQL statements to the execution plan analysis interface of the target database to obtain estimated resource consumption metrics. These estimated resource consumption metrics include, but are not limited to: estimated number of rows scanned, estimated execution time, and whether a full table scan is triggered.
[0090] When the estimated resource consumption index exceeds the preset safety threshold, the AI server automatically injects resource limit parameters into the executable SQL statement, or intercepts the executable SQL statement and generates a performance warning message to be fed back to the user terminal, which is then confirmed by the user before execution.
[0091] In some embodiments, step S4 includes: The AI server encapsulates the generated SQL statements and target database identifiers into JSON-RPC requests conforming to the Model Context Protocol (MCP) format. The AI server and the MCP data service gateway can operate in different security domains. The AI server does not need to directly connect to the target database; it communicates only through a standardized interface, significantly reducing the risk of database credential leakage and security attacks.
[0092] After receiving a request, the MCP data service gateway parses the SQL statement and database identifier, establishes a connection with the target database, executes the SQL statement, and obtains the query results.
[0093] The AI server sends the JSON-RPC request to the independently deployed MCP data service gateway via HTTP or gRPC protocol. The AI server and the MCP data service gateway can operate in different security domains. The AI server does not need to directly connect to the target database, but communicates only through a standardized interface, which greatly reduces the risk of database credential leakage and security attacks.
[0094] After receiving a request, the MCP data service gateway parses the SQL statement and database identifier, establishes a connection with the target database, executes the SQL statement, and obtains the query results.
[0095] The MCP data service gateway converts the query results into a standardized JSON format and returns them to the AI server. For high-precision numerical types commonly found in industrial data, the data retrieval module automatically identifies and correctly parses them when converting them to DataFrame or JSON, preventing precision loss or type errors during JSON serialization or front-end display.
[0096] When the MCP server returns a network error or execution exception, the system has automatic retry capabilities. The retry mechanism includes: determining whether the error type is retryable; if so, automatically retrying according to a preset retry strategy, up to a maximum of 3 retries. If the retry still fails, the system converts the underlying database error information into semantic prompts that the user can understand and feeds them back to the user terminal, improving the user experience.
[0097] After S4 returns the query results, the system can also input the natural language query request, the generated executable SQL statement, and the original result data returned by the query into the large language model, and use the large language model to generate a natural language summary that summarizes the core findings or data trends of the query.
[0098] The system combines the natural language summary with the original result data and returns them to the user terminal via the MCP protocol, helping business personnel quickly understand the core findings and trends behind the data.
[0099] This invention provides an intelligent query system for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, such as... Figure 2 As shown, the AI server includes: The indicator localization module is configured to receive user natural language query requests and determine the target indicator and its associated physical table path from a pre-built indicator library through joint verification of vector space retrieval and large language model; the physical table path at least includes a fully qualified access identifier at the database level. The adaptive sampling calibration module is configured to perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate time filtering conditions that match the user's time description based on the identified format; at the same time, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions; The SQL generation module can be configured with comprehensive target indicators, time filtering conditions, and dimension filtering conditions to generate executable SQL statements. The MCP standardized execution module is configured to encapsulate the SQL statement into a standardized request through the model context protocol, send it to the data service gateway to execute the query and return the result.
[0100] The intelligent industrial indicator query system based on multi-level semantic retrieval and adaptive sampling calibration provided by this invention includes three stages: The first stage is the precise indicator positioning stage. The system first receives the user's natural language query, and performs intent understanding and synonym expansion by semantic enhancement inference. Then, based on the enhanced query, it searches the indicator vector database to recall candidate indicators. Subsequently, it uses a large language model to perform semantic fine ranking of candidate indicators and outputs the target indicator with the highest confidence.
[0101] The second stage is the adaptive SQL generation stage. The system first obtains the table structure metadata of the target physical table; then it performs exploratory random sampling to obtain real data samples; then it uses a large language model to analyze the actual values of the time field in the samples, automatically identifies the storage format, and generates time filtering conditions in combination with the user's time description; at the same time, it queries the list of unique values of the dimension fields and performs semantic matching to generate accurate dimension filtering conditions; finally, it integrates the above information to construct a complete executable SQL statement.
[0102] The third stage is the standardized and secure execution stage. The system encapsulates the generated SQL statements into standardized requests using the MCP protocol, sends them to the independently deployed MCP data service gateway to execute the query, and then presents the returned results to the user after data type adaptation processing.
[0103] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for intelligent querying industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, characterized in that, include: S1. Receive a user's natural language query request, and determine the target indicator and its associated physical table path from the pre-built indicator library through joint verification of vector space retrieval and large language model; the physical table path at least includes a fully qualified access identifier at the database level. S2. Perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate the time filtering conditions that match the user's time description based on the identified format; at the same time, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching and calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions. S3. Combine target indicators, time filtering conditions, and dimension filtering conditions to generate executable SQL statements; S4. Encapsulate the SQL statement into a standardized request using the model context protocol, send it to the data service gateway to execute the query and return the result.
2. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 1, characterized in that, In S1, the steps for determining the target index and its associated physical table path from the pre-built index library through joint verification of vector space retrieval and large language model include: The natural language query request is analyzed for intent and expanded with synonyms using a large language model to generate enhanced search statements; Based on the enhanced search statement, vector similarity retrieval is performed in the pre-built indicator vector database to recall the Top-N candidate indicators; the indicator vector database is constructed based on indicator name, indicator code, business description and metadata of the system to which it belongs. The names, business definitions, and metadata of the Top-N candidate metrics are input into the big language model. The big language model then performs semantic ranking and confidence assessment based on the context of the natural language query request, and outputs the metric with the highest confidence as the target metric. Parse the access path of the target metric, extract the underlying physical table name, metric filter field name and its corresponding code value associated with the target metric, and dynamically inject the physical table name, the filter field name and the code value into a temporary database to generate the physical table path.
3. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 2, characterized in that, S1 also includes: When the large language model evaluates that there are at least two candidate indicators whose confidence scores are both greater than the preset threshold, and the confidence score difference between the candidate indicators is less than the preset difference, it is determined to be an ambiguous intent state. Based on the ambiguous state of intent, a clarifying question containing the business differences of each candidate indicator is automatically generated and fed back to the user terminal; Receive user feedback on the clarification issue, and perform semantic ranking again based on the feedback to finally determine the target indicator.
4. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 2, characterized in that, In S2, exploratory random sampling is performed on the physical table pointed to by the physical table path, specifically including: Based on the physical table path, determine the target physical table that the physical table path points to; An exploratory SQL statement is constructed based on the table identifier of the target physical table. The exploratory SQL statement includes a random sort clause and a preset row count limit. Execute the exploratory SQL statement to filter data from the target physical table according to the indicator filtering conditions and randomly extract a preset number of sample records to obtain real data samples containing the actual values of the time field and dimension field.
5. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 4, characterized in that, In S2, time filtering conditions that match the user's time description are calculated based on the identified storage format, specifically including: By using a large language model to analyze the actual values of the time field in real data samples, the storage format type of the time field can be automatically inferred. The colloquial time description in the natural language query request is semantically parsed using a large language model, and the target time range corresponding to the colloquial time description is determined by combining it with the current system time. According to the storage format type, the start and end times of the target time range are converted into strings that conform to the storage format type, and time range filtering conditions are generated.
6. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 4, characterized in that, In S2, the dimension information in the user description is semantically matched and calibrated with the valid values to generate accurate dimension filtering conditions, specifically including: The large language model is used to identify dimensional fields with filtering significance from the real data samples; Based on the dimension field, a DISTINCT query request is sent to the database to obtain a list of unique values of the dimension field in recent data; Using a large language model, the dimensional information in the natural language query request is semantically matched with each value in the unique value list, and the unique value with the highest matching degree is selected as the precise filter value. When the matching degree of the unique value with the highest matching degree is lower than a preset threshold, a prompt message indicating that the dimension matching has failed is generated; Dimensional filtering conditions are generated based on the precise filter values.
7. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 1, characterized in that, In S3, executable SQL statements are generated by combining target metrics, time filtering conditions, and dimension filtering conditions, specifically including: The corresponding aggregation function is determined according to the type of the target indicator. The aggregation function includes at least one of summation, counting, average, maximum and minimum values. Based on the physical table path, determine the table reference in the FROM clause; The basic query framework for SQL statements is constructed based on the target metrics, the aggregation functions, and the physical table paths. The time filtering condition and the dimension filtering condition are used as components of the WHERE clause and concatenated into the basic query framework according to preset syntax rules. When both the time filtering condition and the dimension filtering condition exist, a logical operator is added between them to connect them, generating an SQL statement containing complete filtering conditions. Perform syntax validation on the generated SQL statements, including at least one of the following: table name and field name existence validation, data type matching validation, and consistency validation between aggregate functions and grouping clauses. When the verification passes, the current SQL statement will be output as the executable SQL statement. When the verification fails, the SQL statement is automatically corrected according to the verification failure type and then re-verified until the verification passes or the preset number of retries is reached.
8. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 1, characterized in that, After S3 generates the executable SQL statement and before S4, it also includes: Submit the generated executable SQL statement to the database's execution plan analysis interface to obtain estimated resource consumption metrics; When the estimated resource consumption index exceeds the preset safety threshold, resource limit parameters are automatically injected into the executable SQL statement, or the executable SQL statement is intercepted and a performance warning message is generated.
9. The intelligent query method for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration according to claim 1, characterized in that, In S4, after the query is sent to the data service gateway to execute and return the result, it also includes: The natural language query request, the generated executable SQL statement, and the raw result data returned by the query are all input into the large language model; Generate a natural language summary that summarizes the core findings or data trends of a query using a large language model; The natural language summary and the original result data are combined and returned to the user terminal through the model context protocol.
10. An intelligent query system for industrial indicators based on multi-level semantic retrieval and adaptive sampling calibration, characterized in that, include: The indicator localization module is configured to receive user natural language query requests and determine the target indicator and its associated physical table path from a pre-built indicator library through joint verification of vector space retrieval and large language model; the physical table path at least includes a fully qualified access identifier at the database level. The adaptive sampling calibration module is configured to perform exploratory random sampling on the physical table pointed to by the physical table path to obtain real data samples; use a large language model to analyze the actual values of the time field in the samples to automatically identify its storage format, and calculate time filtering conditions that match the user's time description based on the identified format; at the same time, use a large language model to identify the effective value distribution of the dimension field from the samples, and perform semantic matching calibration between the dimension information in the user description and the effective values to generate accurate dimension filtering conditions; The SQL generation module can be configured with comprehensive target indicators, time filtering conditions, and dimension filtering conditions to generate executable SQL statements. The MCP standardized execution module is configured to encapsulate the SQL statement into a standardized request through the model context protocol, send it to the data service gateway to execute the query and return the result.