A natural language-based data query and visualization method and device

CN123012130APending Publication Date: 2026-10-30ZHITANG TECH (BEIJING) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202611499066.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-24
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0006]为此,本发明提供一种基于自然语言的数据查询与可视化方法及装置,用以克服现有技术中由于依赖向量语义相似度打分与阈值参数选取指标集,导致匹配过程不可解释,且无法确定查询口径的问题

Benefits of technology

[0017]与现有技术相比,本发明的有益效果在于,本发明所述方法通过将查询要素集与预定义指标集进行确定性结构对齐,所述结构对齐包括词典命中判定、维度逐项对应及粒度一致性判定、数据源映射可用性判定,由于采用词典与结构规则的确定性判定替代相似度打分与阈值判定,以查询要素集与指标-维度-数据源结构之间的确定性关系限定了大模型可生成的查询空间,实现了自然语言查询意图与数据指标口径的精确对齐,提高了复杂查询场景下的鲁棒性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123012130A_ABST
    Figure CN123012130A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of data query and visualization, and particularly relates to a data query and visualization method and device based on natural language, which comprises the following steps: receiving a question proposed by a user in natural language, performing semantic analysis, and extracting a set of structured query elements; the set of query elements comprises an intent type, an index word, a dimension word and a hierarchy, a time constraint and granularity, and a filtering condition; performing structural alignment of the set of query elements and a pre-defined index set, the index set comprising an index, an associated dimension list, and data source mapping information; the structural alignment comprises a dictionary hit, a dimension item-by-item correspondence and granularity consistency, and a data source availability determination; when the dimensions are not all corresponding, a completion interaction process is triggered, and when all the dimensions are corresponding, a matched index set is determined. The present application improves robustness in a complex query scenario.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data query and visualization technology, specifically to a data query and visualization method and apparatus based on natural language. Background Technology

[0002] With the rapid development of big data technology, enterprises and institutions have accumulated massive amounts of structured and semi-structured data resources in their daily operations. This data is typically stored in various data sources, including relational databases, non-relational databases, and various API data interfaces. Efficiently extracting valuable information from this data and visualizing it has become a core requirement for data-driven decision-making.

[0003] However, current data query and visualization processes still face many technical challenges. Traditional data query methods require users to have professional SQL programming skills or be familiar with the operation logic of specific data query tools, which is a high barrier to entry for business personnel without a technical background. Converting query results into intuitive visualization charts usually requires a series of tedious operations such as manually selecting chart types, configuring chart parameters, and adjusting data formats. At the same time, existing natural language query systems mostly remain at the natural language to SQL stage, lacking end-to-end automation capabilities from query to visualization charts, and users still need to manually complete the subsequent visualization configuration work.

[0004] In summary, existing technologies for natural language-based data querying and visualization suffer from the following main problems: First, the alignment of natural language query intent with the data indicator system relies on similarity scoring and threshold determination, resulting in uncertain and uninterpretable matching results. Second, the generated query statements lack result-level verification, making it impossible to promptly detect and correct when query results deviate from the semantic constraints of the user's query. Third, chart types are statically bound to data forms, and chart encoding cannot adaptively adjust to the actual characteristics of the result data. Therefore, there is an urgent need to provide a natural language data querying and visualization method and apparatus that can achieve deterministic alignment of query intent, verifiable query results, and adaptive chart adaptation.

[0005] Chinese Patent Publication No. CN122346536A discloses a massive index matching method based on vector semantics and a large model, comprising: receiving a natural language query question input by a user; extracting a set of query elements from the natural language query question using a large model; searching a pre-constructed index library based on the set of query elements to obtain a set of candidate dimensions and a set of candidate indicators; and determining a target indicator using the large model based on the set of query elements, the set of candidate dimensions, and the set of candidate indicators. It is evident that this massive index matching method based on vector semantics and a large model suffers from problems due to its reliance on vector semantic similarity scoring and threshold parameters for selecting the index set, leading to an uninterpretable matching process and an inability to determine the query scope. Summary of the Invention

[0006] To address this, the present invention provides a data query and visualization method and apparatus based on natural language, which overcomes the problems in the prior art where the matching process is uninterpretable and the query scope cannot be determined due to reliance on vector semantic similarity scoring and threshold parameter selection index sets.

[0007] To achieve the above objectives, in one aspect, the present invention provides a data query and visualization method based on natural language, comprising: Semantic parsing is performed on questions posed by users in natural language, and a structured query element set is extracted. The query element set includes intent type, indicator words, dimension words and levels, time constraints and granularity, and filtering conditions. The query element set is structurally aligned with the predefined indicator set. When the structural dimensions do not all correspond, the completion interaction process is triggered. When the structural dimensions all correspond, the matching indicator set is determined. The metadata of the matching indicator set and the query feature set are input into the large model to generate DSL statements. Syntax and semantic checks are performed. When the checks fail, the error type is fed back to the large model for regeneration. The validated DSL statement is mapped to a data query statement and executed. The execution result is compared with the time constraints and dimensional constraints in the query element set item by item. When the comparison result is empty or does not match the time constraint and the dimension constraint, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. The chart base class is determined based on the intent type, the chart encoding configuration is adjusted based on the data characteristics of the execution result, and a visual chart is rendered. The system receives user interaction with the visualization chart, transforms the interaction into incremental query elements for the next round, and feeds them back to the structure alignment and DSL generation.

[0008] Furthermore, the semantic parsing and extraction of the structured query element set includes: Preprocessing is performed on natural language problems to remove irrelevant punctuation, filter stop words, and perform semantic error correction; The preprocessed text is segmented using a word segmentation algorithm to obtain a word sequence; Semantic role labeling and intent recognition are performed on the word sequence, the core intent is mapped to a predefined intent type, and the word is mapped to four types of elements: indicator words, dimension words and levels, time constraints and granularity, and filtering conditions, forming a structured query element set.

[0009] Furthermore, the structural alignment includes dictionary hit, dimension-by-dimensional correspondence, granularity consistency, and data source availability determination. The dictionary hit determination includes: A pre-defined indicator dictionary includes several candidate indicators and their corresponding associated indicator information, including indicator name, business alias, and definition keywords; The indicator information is compared item by item with the indicator terms and the candidate indicators in the structured query element set; When at least one indicator information matches between the indicator term in the structured query element set and the candidate indicator, it is determined that the current indicator term matches the candidate indicator. When the indicator words in the structured query element set do not match any of the candidate indicators, the current indicator word is expanded by synonyms to obtain an expanded set, and the expanded set is compared with the indicator dictionary. If the extended set does not match the candidate index, then the current index term is determined to be a missing index term.

[0010] Furthermore, the granularity consistency determination includes: Analyze the granularity of time constraints and the level of dimension terms in the query elements; The granularity is determined to be consistent when the query time granularity is the same as the time granularity of the associated dimension of the indicator set or when there is a corresponding relationship between the query dimension level and the dimension level of the indicator set. When the granularity is inconsistent, the time granularity or dimension level of the query element is rolled up or drilled down to the granularity supported by the indicator set and then re-evaluated.

[0011] Further, determining the matching index set includes: The matching indicator set can be determined by a combination of three criteria: keyword hit, dimension alignment, and data source mapping. The matching indicator set is determined when all three criteria are met. When multiple indicator sets meet the judgment conditions at the same time, the determination is made according to the definition level and coverage of the indicator set, or the query is split into multiple DSLs corresponding to each indicator set respectively. When not all dimension terms match, generate and present a list of missing dimension candidates, and after receiving confirmation, update the query element set and re-execute the structure alignment. Perform a small-scale pre-query on representative dimension values, and then perform a full query after verifying that the structure of the pre-query results is consistent with the query elements.

[0012] Furthermore, the syntax verification and semantic verification include: Syntax validation checks the structural integrity of DSL statements, the validity of keywords, and the correctness of parameter types; Semantic validation checks the effectiveness of the combination of indicators and dimensions, the completeness of time constraints, and the consistency of filtering conditions. When a validation fails, the specific error type and location are fed back to the larger model. After the error is corrected, the DSL is regenerated.

[0013] Furthermore, the execution result is compared with each constraint, including: Check whether the time range of the execution results falls within the query time constraint, whether the dimension values ​​match the query dimension constraints, and whether the result set is empty; If the result is empty, confirm with the user whether to relax the time constraints or filtering conditions before regenerating; When the results do not match the constraints, the query elements are corrected according to the time range or dimension value of the deviation, and the DSL is regenerated.

[0014] Furthermore, adjusting the chart encoding configuration based on the data characteristics of the execution results includes: When the cardinality of the resulting data exceeds the preset carrying capacity, dimensional aggregation or sampling is triggered, or the chart base class is switched to a heatmap or scatter plot. When the result data contains time series fields, map the time series fields to the time axis; When the result data is distributed, it is mapped to a distribution class code; the adjusted chart code configuration is entered into the chart component along with the rendering parameters.

[0015] Furthermore, the interactive operation conversion includes: Transform user chart switching operations into chart base class adjustment requests, drill-down operations into dimension level drill-down elements, zoom operations into time range narrowing elements, and follow-up question operations into adding new indicators or dimension elements. The above elements are merged into the next round of query element set as element increments and written to the incremental cache, triggering the indicator dictionary synchronization update task. The backend synchronization task completes the persistent update of aliases and associations.

[0016] On the other hand, the present invention provides a data query and visualization device based on natural language, comprising: The natural language parsing module is used to perform semantic parsing on questions posed by users in natural language and extract a set of structured query elements. The indicator structure alignment module is used to align the query element set with the predefined indicator set. When the structure dimensions do not all correspond, the completion interaction process is triggered. When the structure dimensions all correspond, the matching indicator set is determined. The DSL generation and verification module is used to input the matching index set metadata and query element set into the large model to generate DSL statements, perform syntax verification and semantic verification, and return the error type when the verification fails and regenerate. The query result verification module is used to map the verified DSL to a data query statement and execute it. The execution result is compared with the time constraints and dimensional constraints in the query element set item by item. If the result is empty or inconsistent, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. The visualization adaptation module is used to determine the chart base class based on the intent type, adjust the chart encoding configuration based on the data characteristics of the execution result, and render and present the visualization chart. The interactive feedback module receives user interactions with the visualization charts, converts them into incremental query elements, and feeds them back to the structure alignment and DSL generation.

[0017] Compared with the prior art, the beneficial effects of the present invention are that the method of the present invention performs deterministic structural alignment between the query element set and the predefined indicator set. The structural alignment includes dictionary hit determination, dimension item-by-item correspondence and granularity consistency determination, and data source mapping availability determination. Since the deterministic determination of dictionary and structural rules is used to replace similarity scoring and threshold determination, the deterministic relationship between the query element set and the indicator-dimension-data source structure limits the query space that the large model can generate, realizes the accurate alignment between natural language query intent and data indicator caliber, and improves robustness in complex query scenarios.

[0018] Furthermore, this invention compares the execution result with the time constraints and dimensional constraints in the query element set item by item. When the result is empty or does not match the constraints, it corrects the result according to the deviation type and regenerates the result. Since the result deviation is repositioned to the specific query element, the correction occurs at the query semantic structure layer rather than the SQL text layer. This achieves consistency verification between the query result and the user's query semantic constraints, prevents queries that seem semantically correct but do not match the user's intent from being directly presented, and further improves the robustness in complex query scenarios.

[0019] Furthermore, this invention adjusts the chart encoding configuration based on the data characteristics of the execution results. Since the chart encoding is dynamically adjusted based on observable data characteristics such as dimensional cardinality, time series fields, and distribution patterns, adaptive matching between chart type and data form is achieved. This avoids misinterpretation caused by chart and data mismatch under static rules and further improves robustness in complex query scenarios.

[0020] Furthermore, by transforming user interactions with the chart into incremental query elements for the next round and re-injecting them into the structural alignment process, the present invention forms a cross-round closed-loop iteration, and the system continuously converges the query scope and chart adaptation as it is used, thereby further improving the robustness of complex query scenarios. Attached Figure Description

[0021] Figure 1 This is an overall flowchart of the natural language-based data query and visualization method according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating the process of determining the matching index set in the natural language-based data query and visualization method of this invention. Figure 3 This is a flowchart illustrating the syntax and semantic validation process of the natural language-based data query and visualization method according to an embodiment of the present invention. Figure 4 This is a block diagram of the overall structure of the data query and visualization device based on natural language according to an embodiment of the present invention. Detailed Implementation

[0022] To make the objectives and advantages of the present invention clearer, the present invention will be further described below with reference to embodiments; it should be understood that the specific embodiments described herein are merely for explaining the present invention and are not intended to limit the present invention.

[0023] Preferred embodiments of the present invention will now be described with reference to the accompanying drawings. Those skilled in the art should understand that these embodiments are merely illustrative of the technical principles of the present invention and are not intended to limit the scope of protection of the present invention.

[0024] Please see Figure 1 The diagram shown is an overall flowchart of the natural language-based data query and visualization method according to an embodiment of the present invention. The method described in this embodiment includes: Step S1: Semantic parsing of the questions raised by the user in natural language and extraction of a structured query element set, wherein the query element set includes intent type, indicator words, dimension words and levels, time constraints and granularity, and filtering conditions. Step S2: Align the query element set with the predefined indicator set. If the structural dimensions do not all correspond, trigger the completion interaction process. If the structural dimensions all correspond, determine the matching indicator set. Step S3: Input the metadata of the matching indicator set and the query feature set into the large model to generate DSL statements, perform syntax and semantic checks, and if the checks fail, return the error type to the large model for regeneration. Step S4: Map the verified DSL statement to a data query statement and execute it; compare the execution result with the time constraints and dimensional constraints in the query element set item by item. Step S5: When the comparison result is empty or does not match the time constraint and the dimension constraint, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. Step S6: Determine the chart base class according to the intent type, adjust the chart encoding configuration according to the data characteristics of the execution result, and render and present the visual chart; Step S7: Receive user interaction with the visualization chart, convert the interaction into incremental query elements for the next round, and feed it back to the structure alignment and DSL generation.

[0025] Specifically, the query element set is a collection of structured query elements extracted after semantic parsing of the natural language problem. The query element set includes intent type, indicator words, dimension words and levels, time constraints and granularity, and filtering conditions.

[0026] Specifically, the query elements have predefined element relationships, which are used to represent the correspondence between indicators and dimensions, dimensions and dimension levels, dimensions and filter values, and time constraints and time granularity. The correspondence between indicators and dimensions is used to determine the analytical dimensions supported by the indicators, and the correspondence between dimensions and dimension levels is used to determine the roll-up or drill-down path of the dimensions.

[0027] Specifically, the large model is a model with instruction following and structured text generation capabilities. It can be at least one of the Qwen model, DeepSeek model, and GLM model, with the preferred embodiment being the DeepSeek model.

[0028] Specifically, the intent type is a predefined query intent category corresponding to the core intent of the natural language question. The predefined query intent categories include trend type, comparison type, proportion type, ranking type, and detail type.

[0029] Specifically, the indicator term is a word used to indicate the business metric to be queried; the dimension term is a word used to indicate the classification perspective of the indicator; and the dimension term and level are a combination of the dimension term and its hierarchical relationship.

[0030] Specifically, time constraints and granularity are query elements used to indicate the time range and statistical granularity of the query; the filtering conditions are query elements used to indicate additional limiting conditions for the query.

[0031] Specifically, the predefined indicator set is a predefined set of data query criteria. The indicator set includes indicators, a list of related dimensions, and data source mapping information. The data source mapping information is used to indicate the data source and query interface corresponding to the indicator.

[0032] Specifically, a DSL includes at least data source declaration, metric selection, dimension definition, time constraints, and filtering conditions; When the query intent includes sorting, quantity limits, or aggregation calculations, it also includes the DSL syntax elements corresponding to the sorting, result quantity limits, or aggregation operations.

[0033] Specifically, structural alignment is the process of determining dictionary match, dimension-by-dimensional correspondence and granularity consistency, and data source mapping availability between the query element set and the predefined indicator set.

[0034] Specifically, a DSL statement is a query description statement that conforms to a predetermined query description syntax. The DSL syntax includes syntax elements such as data source declaration, indicator selection, and dimension constraints. The data source declaration is used to specify the target data source corresponding to the indicator. The indicator selection is used to specify the query indicator. The dimension constraints are used to limit the query dimensions and their values. Dimension nesting expresses hierarchical relationships through multiple DIMENSION BY clauses.

[0035] Specifically, the chart base class is an initial chart type determined according to the intent type. The chart base class includes line charts corresponding to trend intents, bar charts corresponding to comparison intents, pie charts corresponding to percentage intents, bar charts corresponding to ranking intents, and tables corresponding to detail intents. The chart encoding configuration is a visual channel encoding configuration determined according to the data characteristics of the execution result.

[0036] Specifically, the execution results include data values, returned dimensions, time range, and metadata information.

[0037] Specifically, the semantic parsing and extraction of a structured query element set includes: preprocessing natural language problems by removing irrelevant punctuation, filtering stop words, and performing semantic error correction; segmenting the preprocessed text using a word segmentation algorithm to obtain a word sequence; performing semantic role labeling and intent recognition on the word sequence, mapping the core intent to a predefined intent type, and mapping word elements to four types of elements: indicator words, dimension words and levels, time constraints and granularity, and filtering conditions, thus forming a structured query element set.

[0038] In this embodiment, the method performs deterministic structural alignment between the query element set and the predefined indicator set. The structural alignment includes dictionary hit determination, dimension item-by-item correspondence and granularity consistency determination, and data source mapping availability determination. Since the deterministic determination of dictionary and structural rules is used to replace similarity scoring and threshold determination, the deterministic relationship between the query element set and the indicator-dimension-data source structure limits the query space that the large model can generate, achieving accurate alignment between natural language query intent and data indicator caliber, and improving robustness in complex query scenarios.

[0039] Please see Figure 2 As shown, it is a logical flowchart of the process of determining the matching index set in the data query and visualization method based on natural language according to an embodiment of the present invention.

[0040] Specifically, the semantic parsing and extraction of the structured query element set includes: Preprocessing is performed on natural language problems to remove irrelevant punctuation, filter stop words, and perform semantic error correction; The preprocessed text is segmented using a word segmentation algorithm to obtain a word sequence; Semantic role labeling and intent recognition are performed on the word sequence, the core intent is mapped to a predefined intent type, and the word is mapped to four types of elements: indicator words, dimension words and levels, time constraints and granularity, and filtering conditions, forming a structured query element set.

[0041] Specifically, the structure alignment includes dictionary hit, dimension-by-dimensional correspondence, granularity consistency, and data source availability determination. The dictionary hit determination includes: A pre-defined indicator dictionary includes several candidate indicators and their corresponding associated indicator information, including indicator name, business alias, and definition keywords; The indicator information is compared item by item with the indicator terms and the candidate indicators in the structured query element set; When at least one indicator information matches between the indicator term in the structured query element set and the candidate indicator, it is determined that the current indicator term matches the candidate indicator. When the indicator words in the structured query element set do not match any of the candidate indicators, the current indicator word is expanded by synonyms to obtain an expanded set, and the expanded set is compared with the indicator dictionary. If the extended set does not match the candidate index, then the current index term is determined to be a missing index term.

[0042] Specifically, the granularity consistency determination includes: Analyze the granularity of time constraints and the level of dimension terms in the query elements; The granularity is determined to be consistent when the query time granularity is the same as the time granularity of the associated dimension of the indicator set or when there is a corresponding relationship between the query dimension level and the dimension level of the indicator set. When the granularity is inconsistent, the time granularity or dimension level of the query element is rolled up or drilled down to the granularity supported by the indicator set and then re-evaluated.

[0043] Specifically, determining the matching index set includes: The matching indicator set can be determined by a combination of three criteria: keyword hit, dimension alignment, and data source mapping. The matching indicator set is determined when all three criteria are met. When multiple indicator sets meet the judgment conditions at the same time, the determination is made according to the definition level and coverage of the indicator set, or the query is split into multiple DSLs corresponding to each indicator set respectively. When not all dimension terms match, generate and present a list of missing dimension candidates, and after receiving confirmation, update the query element set and re-execute the structure alignment. Perform a small-scale pre-query on representative dimension values, and then perform a full query after verifying that the structure of the pre-query results is consistent with the query elements.

[0044] Specifically, when the indicator words have been matched but there is at least one dimension word, time granularity or filtering condition that cannot correspond to the matching indicator set, the misaligned element is determined; Based on the list of dimensions associated with the matching index set, the supported time granularity, and the set of dimension values, candidate completion items corresponding to the misaligned elements are generated. The candidate completion items are presented to the user, and the query element set is updated based on the candidate completion items confirmed by the user.

[0045] Specifically, the data source mapping availability determination includes: Determine whether the data source corresponding to the indicator exists, whether the data source has a field mapping relationship with the query indicator and dimension, and whether the query interface corresponding to the data source is accessible.

[0046] Specifically, the structure alignment includes dictionary matching, dimension-by-dimensional correspondence, granularity consistency, and data source availability determination. The dictionary matching determination includes: a pre-set indicator dictionary containing the name, business alias, and definition keywords of each indicator; comparing the indicator words in the query elements with the indicator dictionary item by item, and determining the indicator corresponding to the indicator word if at least one of the name, business alias, or definition keyword is matched; performing synonym expansion queries on indicator words not included in the dictionary, and determining a no-match if no item is matched after expansion.

[0047] Specifically, the granularity consistency determination includes: parsing the granularity of the time constraint in the query element and the level to which the dimension term belongs; determining granularity consistency when the query time granularity is the same as the time granularity of the associated dimension of the indicator set or when there is a corresponding relationship between the query dimension level and the dimension level of the indicator set; when the granularity is inconsistent, rolling up or drilling down the time granularity or dimension level of the query element to the granularity supported by the indicator set and then re-determining.

[0048] In this embodiment, the method determines the matching indicator set through dictionary hit, dimension-by-dimensional correspondence and granularity consistency, and data source availability. Since the matching indicator set is determined by a combination of the three judgment results of indicator word hit, dimension alignment, and data source mapping availability, and the case where not all dimension words are matched is confirmed by the completion interaction process, the deterministic alignment of the matching indicator set is achieved, avoiding the uninterpretable matching results and uncertain query scope caused by similarity scoring and threshold judgment, and further improving the robustness in complex query scenarios.

[0049] Please see Figure 3 As shown, it is a logical flowchart of the syntax and semantic verification process of the data query and visualization method based on natural language in an embodiment of the present invention.

[0050] Specifically, the syntax verification and semantic verification include: Syntax validation checks the structural integrity of DSL statements, the validity of keywords, and the correctness of parameter types; Semantic validation checks the effectiveness of the combination of indicators and dimensions, the completeness of time constraints, and the consistency of filtering conditions. When a validation fails, the specific error type and location are fed back to the larger model. After the error is corrected, the DSL is regenerated.

[0051] Specifically, the execution result is compared with each constraint, including: Check whether the time range of the execution results falls within the query time constraint, whether the dimension values ​​match the query dimension constraints, and whether the result set is empty; If the result is empty, confirm with the user whether to relax the time constraints or filtering conditions before regenerating; When the results do not match the constraints, the query elements are corrected according to the time range or dimension value of the deviation, and the DSL is regenerated.

[0052] Specifically, the DSL statement is parsed to obtain the data source declaration, indicator selection, dimension constraints, time constraints, and filtering conditions; the target data source and corresponding query interface are determined based on the data source mapping information; and the indicators, dimensions, time constraints, and filtering conditions are converted into data query fields and query conditions corresponding to the query interface according to the field mapping relationship, thereby generating the data query statement.

[0053] Specifically, the execution result includes at least the returned data, returned fields, time field and corresponding time value, dimension field and corresponding dimension value; when the query includes aggregated metrics, it also includes the numerical results corresponding to the aggregated metrics.

[0054] Specifically, the corresponding query element is selected as the correction object based on the determined deviation type, and the DSL is regenerated after modifying only the query element.

[0055] Specifically, when the number of corrections reaches the preset maximum number of corrections, or when the query results do not change after two consecutive corrections, the automatic correction process is terminated, and the current query status and unresolved deviation types are output to the user.

[0056] Specifically, the preset maximum number of corrections is the maximum number of automatic correction rounds that the query correction process is allowed to execute continuously. It is determined based on the correction success rate increment and query time corresponding to different correction rounds in historical query tasks. When the correction success rate increment generated by continuing to increase the number of correction rounds is lower than the preset gain threshold, or the cumulative query time reaches the preset time limit, the preset maximum number of corrections will no longer be increased.

[0057] In this embodiment, the method compares the execution result with the time constraints and dimensional constraints in the query element set item by item. When the result is empty or does not match the constraints, it is corrected according to the deviation type and then regenerated. Since the result deviation is repositioned to the specific query element, the correction occurs at the query semantic structure layer rather than the SQL text layer. This achieves consistency verification between the query result and the user's query semantic constraints, prevents queries that seem semantically correct but whose results do not match the user's intent from being directly presented, and further improves the robustness in complex query scenarios.

[0058] Specifically, adjusting the chart encoding configuration based on the data characteristics of the execution results includes: When the cardinality of the resulting data exceeds the preset carrying capacity, dimensional aggregation or sampling is triggered, or the chart base class is switched to a heatmap or scatter plot. When the result data contains time series fields, map the time series fields to the time axis; When the result data is distributed, it is mapped to a distribution class code; the adjusted chart code configuration is entered into the chart component along with the rendering parameters.

[0059] Specifically, the data characteristics include field type, dimensional cardinality, number of numerical fields, existence of time fields, length of time series, and the dispersion or distribution statistical characteristics of numerical fields.

[0060] Specifically, the category field, numeric field, and time field are determined based on the field type; Determine whether to perform aggregation or sampling based on the cardinality of the dimension; Determine the time visual channel based on the existence of the time field; The visual encoding of the distribution class is determined based on the statistical characteristics of the distribution of the numerical field.

[0061] Specifically, the preset carrying capacity is the maximum data scale that the chart component can maintain a predetermined interactive response performance under a predetermined display terminal, display size and rendering configuration, which is represented by at least one of the following: upper limit of dimension cardinality, upper limit of number of time points or upper limit of number of data records.

[0062] Understandably, under a fixed chart component, display size, and terminal operating environment, test data of different data scales are loaded respectively to obtain the chart's initial rendering time and interaction response time corresponding to each data scale. When the initial rendering time or interaction response time exceeds the preset performance limit, the data scale that exceeds the limit is determined as the candidate boundary, and the data scale that does not exceed the candidate boundary is determined as the preset bearable range.

[0063] Specifically, the interactive operation conversion includes: Transform user chart switching operations into chart base class adjustment requests, drill-down operations into dimension level drill-down elements, zoom operations into time range narrowing elements, and follow-up question operations into adding new indicators or dimension elements. The above elements are merged into the next round of query element set as element increments and written to the incremental cache, triggering the indicator dictionary synchronization update task. The backend synchronization task completes the persistent update of aliases and associations.

[0064] Specifically, the chart base class is used to determine the basic geometric structure and coordinate system of the chart, and the chart coding configuration is used to map the fields in the execution result to the visual channels of the chart base class respectively. The visual channels include at least one of the horizontal axis, vertical axis, color, size, position and time axis.

[0065] Specifically, the query element increment refers to the query elements added, deleted, or modified by the user's current interaction operation relative to the current query element set. The query element increment is then differentially merged with the current query element set, retaining the original query elements that have not been modified by the interaction operation.

[0066] In this embodiment, the method adjusts the chart encoding configuration according to the data characteristics of the execution result. Since the chart encoding is dynamically adjusted based on observable data characteristics such as dimensional cardinality, time series field, and distribution pattern, adaptive matching between chart type and data form is achieved, avoiding misreading caused by chart and data mismatch under static rules. By transforming user interactions with the chart into incremental query elements for the next round and re-injecting them into the structure alignment process, the system continuously converges the query scope and chart adaptation as it is used, thus further improving its robustness in complex query scenarios.

[0067] Please see Figure 4 The diagram shown is an overall structural block diagram of the data query and visualization device based on natural language according to an embodiment of the present invention. The device according to the embodiment of the present invention includes: The natural language parsing module is used to perform semantic parsing on questions posed by users in natural language and extract a set of structured query elements. The indicator structure alignment module, which is connected to the natural language parsing module, is used to align the query element set with the predefined indicator set. When the structural dimensions do not all correspond, the completion interaction process is triggered. When the structural dimensions all correspond, the matching indicator set is determined. The DSL generation and verification module is connected to the indicator structure alignment module. It is used to input the matching indicator set metadata and query element set into the large model to generate DSL statements, perform syntax verification and semantic verification, and when the verification fails, the error type is fed back and regenerated. The query result verification module is connected to the DSL generation and verification module. It is used to map the verified DSL into a data query statement and execute it. The execution result is compared with the time constraints and dimension constraints in the query element set item by item. If the result is empty or inconsistent, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. The visualization adaptation module, which is connected to the query result verification module, is used to determine the chart base class according to the intent type, adjust the chart encoding configuration according to the data characteristics of the execution result, and render and present the visualization chart. The interactive feedback module, which is connected to the natural language parsing module and the visualization adaptation module respectively, is used to receive user interaction operations on the visualization charts, convert them into query element increments, and feed them back to the structure alignment and DSL generation.

[0068] Specifically, the natural language parsing module includes a preprocessing unit, a word segmentation unit, and a semantic role labeling and intent recognition unit. The preprocessing unit is used to perform preprocessing on natural language problems, such as removing irrelevant punctuation, filtering stop words, and semantic error correction. The word segmentation unit is used to segment the preprocessed text using a word segmentation algorithm to obtain a word sequence. The semantic role labeling and intent recognition unit is used to perform semantic role labeling and intent recognition on the word sequence, mapping the core intent to a predefined intent type and mapping the word to four types of elements: indicator words, dimension words and levels, time constraints and granularity, and filtering conditions, forming a structured query element set.

[0069] Specifically, the indicator structure alignment module includes a dictionary hit determination unit, a dimension correspondence determination unit, a granularity consistency determination unit, a data source availability determination unit, and a completion interaction unit, wherein... The dictionary hit determination unit is used to compare the indicator words in the query elements with the preset indicator dictionary item by item. If at least one of the indicator name, business alias or definition keyword is hit, the indicator word is determined to correspond to the indicator word. For indicator words not included in the dictionary, a synonym expansion query is performed. If no item is hit after expansion, it is determined to be a no-hit. The dimension correspondence determination unit is used to match the dimension words and levels in the query elements with the dimension list associated with the indicator set item by item; The granularity consistency determination unit is used to parse the granularity of the time constraint and the level to which the dimension terms belong in the query elements. When the granularity is inconsistent, the time granularity or dimension level of the query elements is rolled up or drilled down to the granularity supported by the indicator set before re-determination. The data source availability determination unit is used to determine whether the data source indicated by the data source mapping information of the indicator set is currently available. The completion interaction unit is used to generate and present a list of missing dimension candidates when not all dimension terms correspond. After receiving confirmation, the query element set is updated and the structure alignment is re-executed.

[0070] Specifically, the DSL generation and verification module includes a DSL generation unit, a syntax verification unit, and a semantic verification unit. The DSL generation unit is used to input the metadata information of the matching indicator set and the query element set as prompt words into the large language model to generate a query description statement that conforms to the DSL syntax. The syntax verification unit is used to check the structural integrity, keyword validity, and parameter type correctness of the DSL statement. The semantic verification unit is used to check the combination validity of indicators and dimensions, the integrity of time constraints, and the self-consistency of filtering conditions. When a verification fails, the specific error type and error location are fed back to the large model, instructing the large model to correct the error and regenerate the DSL.

[0071] Specifically, the query result verification module includes a DSL mapping execution unit and a constraint comparison unit. The DSL mapping execution unit maps each syntactic element in the DSL statement to an SQL query statement or API call statement corresponding to the target data source according to the DSL syntax rules, generates the final data query statement, and executes it. In multi-data source scenarios, the results of each sub-query are merged and concatenated in the DSL mapping execution unit. The constraint comparison unit compares the execution result with the time constraints and dimension constraints in the query element set item by item, including comparing whether the time range of the execution result falls within the query time constraint, whether the dimension value matches the query dimension constraint, and whether the result set is empty. When the result is empty, the user is asked whether to relax the time constraint or filter conditions. When the result does not match the constraint, the query element is corrected according to the time range or dimension value of the deviation, triggering the DSL generation and verification module to regenerate the DSL.

[0072] Specifically, the visualization adaptation module includes a chart base class determination unit, a coding configuration adjustment unit, and a chart rendering unit. The chart base class determination unit determines the chart base class based on the intent type. The coding configuration adjustment unit adjusts the chart coding configuration based on the data characteristics of the execution results. When the dimensionality of the result data exceeds a preset carrying capacity, it triggers dimensional aggregation or sampling, or switches the chart base class to a heatmap or scatter plot. When the result data contains time-series fields, it maps the time-series fields to a time axis. When the result data exhibits a distributed pattern, it maps it to a distribution-type coding. The chart rendering unit inputs the adjusted chart coding configuration along with rendering parameters into the encapsulated chart component, renders the corresponding visualization chart, and presents it to the user.

[0073] Specifically, the interactive feedback module includes an interactive receiving unit, an incremental conversion unit, and a dictionary synchronization triggering unit. The interactive receiving unit receives user interactions with the visualization charts, including chart switching, drill-down, zooming, and follow-up questioning. The incremental conversion unit converts chart switching into chart base class adjustment requests, drill-down into dimension level drill-down elements, zooming into time range narrowing elements, and follow-up questioning into new indicators or dimension elements. These elements are then merged into the next round of query element sets as element increments and written to the incremental cache. The dictionary synchronization triggering unit triggers an indicator dictionary synchronization update task after writing to the incremental cache, with the backend synchronization task performing the persistent update of aliases and relationships.

[0074] The technical solution of the present invention has been described above with reference to the preferred embodiments shown in the accompanying drawings. However, it will be readily understood by those skilled in the art that the scope of protection of the present invention is obviously not limited to these specific embodiments. Without departing from the principles of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will all fall within the scope of protection of the present invention.

Claims

1. A data query and visualization method based on natural language, characterized in that, include: Semantic parsing is performed on questions posed by users in natural language, and a structured query element set is extracted. The query element set includes intent type, indicator words, dimension words and levels, time constraints and granularity, and filtering conditions. The query element set is structurally aligned with the predefined indicator set. When the structural dimensions do not all correspond, the completion interaction process is triggered. When the structural dimensions all correspond, the matching indicator set is determined. The metadata of the matching indicator set and the query feature set are input into the large model to generate DSL statements. Syntax and semantic checks are performed. When the checks fail, the error type is fed back to the large model for regeneration. The validated DSL statement is mapped to a data query statement and executed. The execution result is compared with the time constraints and dimensional constraints in the query element set item by item. When the comparison result is empty or does not match the time constraint and the dimension constraint, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. The chart base class is determined based on the intent type, the chart encoding configuration is adjusted based on the data characteristics of the execution result, and a visual chart is rendered. The system receives user interaction with the visualization chart, transforms the interaction into incremental query elements for the next round, and feeds them back to the structure alignment and DSL generation.

2. The data query and visualization method based on natural language according to claim 1, characterized in that, The semantic parsing and extraction of the structured query element set includes: Preprocessing is performed on natural language problems to remove irrelevant punctuation, filter stop words, and perform semantic error correction; The preprocessed text is segmented using a word segmentation algorithm to obtain a word sequence; Semantic role labeling and intent recognition are performed on the word sequence, the core intent is mapped to a predefined intent type, and the word is mapped to four types of elements: indicator words, dimension words and levels, time constraints and granularity, and filtering conditions, forming a structured query element set.

3. The natural language-based data query and visualization method according to claim 1 or 2, characterized in that, The structure alignment includes dictionary matching, dimension-by-dimensional correspondence, granularity consistency, and data source availability determination. The dictionary matching determination includes: A pre-defined indicator dictionary includes several candidate indicators and their corresponding associated indicator information, including indicator name, business alias, and definition keywords; The indicator information is compared item by item with the indicator terms and the candidate indicators in the structured query element set; When at least one indicator information matches between the indicator term in the structured query element set and the candidate indicator, it is determined that the current indicator term matches the candidate indicator. When the indicator words in the structured query element set do not match any of the candidate indicators, the current indicator word is expanded by synonyms to obtain an expanded set, and the expanded set is compared with the indicator dictionary. If the extended set does not match the candidate index, then the current index term is determined to be a missing index term.

4. The data query and visualization method based on natural language according to claim 3, characterized in that, The particle size consistency determination includes: Analyze the granularity of time constraints and the level of dimension terms in the query elements; The granularity is determined to be consistent when the query time granularity is the same as the time granularity of the associated dimension of the indicator set or when there is a corresponding relationship between the query dimension level and the dimension level of the indicator set. When the granularity is inconsistent, the time granularity or dimension level of the query element is rolled up or drilled down to the granularity supported by the indicator set and then re-evaluated.

5. The natural language-based data query and visualization method according to claim 4, characterized in that, The determination of the matching index set includes: The matching indicator set can be determined by a combination of three criteria: keyword hit, dimension alignment, and data source mapping. The matching indicator set is determined when all three criteria are met. When multiple indicator sets meet the judgment conditions at the same time, the determination is made according to the definition level and coverage of the indicator set, or the query is split into multiple DSLs corresponding to each indicator set respectively. When not all dimension terms match, generate and present a list of missing dimension candidates, and after receiving confirmation, update the query element set and re-execute the structure alignment. Perform a small-scale pre-query on representative dimension values, and then perform a full query after verifying that the structure of the pre-query results is consistent with the query elements.

6. The data query and visualization method based on natural language according to claim 5, characterized in that, The syntax and semantic checks include: Syntax validation checks the structural integrity of DSL statements, the validity of keywords, and the correctness of parameter types; Semantic validation checks the effectiveness of the combination of indicators and dimensions, the completeness of time constraints, and the consistency of filtering conditions. When a validation fails, the specific error type and location are fed back to the larger model. After the error is corrected, the DSL is regenerated.

7. The natural language-based data query and visualization method according to claim 6, characterized in that, The execution results are compared with the constraints item by item, including: Check whether the time range of the execution results falls within the query time constraint, whether the dimension values ​​match the query dimension constraints, and whether the result set is empty; If the result is empty, confirm with the user whether to relax the time constraints or filtering conditions before regenerating; When the results do not match the constraints, the query elements are corrected according to the time range or dimension value of the deviation, and the DSL is regenerated.

8. The data query and visualization method based on natural language according to claim 7, characterized in that, Adjusting the chart encoding configuration based on the data characteristics of the execution results includes: When the cardinality of the resulting data exceeds the preset carrying capacity, dimensional aggregation or sampling is triggered, or the chart base class is switched to a heatmap or scatter plot. When the result data contains time series fields, map the time series fields to the time axis; When the resulting data exhibits a distributed pattern, it is mapped to a distribution class code; The adjusted chart encoding configuration is entered into the chart component along with the rendering parameters.

9. The data query and visualization method based on natural language according to claim 8, characterized in that, The interactive operation conversion includes: Transform user chart switching operations into chart base class adjustment requests, drill-down operations into dimension level drill-down elements, zoom operations into time range narrowing elements, and follow-up question operations into adding new indicators or dimension elements. The above elements are merged into the next round of query element set as element increments and written to the incremental cache, triggering the indicator dictionary synchronization update task. The backend synchronization task completes the persistent update of aliases and associations.

10. A visualization apparatus using the natural language-based data query and visualization method according to any one of claims 1-9, characterized in that, include: The natural language parsing module is used to perform semantic parsing on questions posed by users in natural language and extract a set of structured query elements. The indicator structure alignment module is used to align the query element set with the predefined indicator set. When the structure dimensions do not all correspond, the completion interaction process is triggered. When the structure dimensions all correspond, the matching indicator set is determined. The DSL generation and verification module is used to input the matching index set metadata and query element set into the large model to generate DSL statements, perform syntax verification and semantic verification, and return the error type when the verification fails and regenerate. The query result verification module is used to map the verified DSL to a data query statement and execute it. The execution result is compared with the time constraints and dimensional constraints in the query element set item by item. If the result is empty or inconsistent, the query elements or constraints are corrected according to the deviation type and the DSL is regenerated. The visualization adaptation module is used to determine the chart base class based on the intent type, adjust the chart encoding configuration based on the data characteristics of the execution result, and render and present the visualization chart. The interactive feedback module receives user interactions with the visualization charts, converts them into incremental query elements, and feeds them back to the structure alignment and DSL generation.

Citation Information

Patent Citations

  • Mass index matching method and device based on vector semantics and large model

    CN122346536A