A large model-based data intelligent question answering ChatBI method and device

By constructing a database knowledge vector library and a large language model, the system automatically processes natural language problems to generate visual charts, solving the problems of manual dependence and insufficient intelligence in existing technologies, and achieving efficient and personalized data visualization.

CN120804144BActive Publication Date: 2025-11-21SHENZHEN AIMALL TECHNOLOGY CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202511294096.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-11
Publication Date
2025-11-21
Estimated Expiration
2045-09-11

AI Technical Summary

Technical Problem

Existing data visualization technologies rely on manual analysis, lack automated support, struggle to handle large-scale, multidimensional data, and lack natural language processing capabilities, resulting in insufficient intelligence.

Method used

We construct a database knowledge vector library, transform natural language problems into structured descriptions through a large language model, generate executable SQL statements, and automatically decide the chart type by combining a visualization rule base, thus achieving end-to-end automation from natural language to visualization.

Benefits of technology

It enables automatic visualization of large-scale, multi-dimensional data, improves the efficiency of data analysis and presentation, reduces the learning cost for users, and provides personalized data display solutions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120804144B_ABST
    Figure CN120804144B_ABST
Patent Text Reader

Abstract

The application provides a large model-based data intelligent question and answer ChatBI method and device, comprising the following steps: step one, constructing a database knowledge vector library; step two, question semantic transcription and retrieval. According to the problem transcription and data retrieval supplement, the large language model is used to generate corresponding visual charts according to the characteristics of the data and the question. This way not only realizes the automatic visualization of any data, but also provides a more detailed and clearer expression method in the form of dialogue, realizes the flexible, intelligent and automated process, and gives the customer a more intuitive display of the trend and relationship of the data. By combining the large language model and data visualization technology, the appropriate visual chart is automatically generated according to the natural language prompt word and the data, thereby greatly improving the efficiency of data analysis and presentation, reducing the learning cost of the user, and providing personalized data display solutions for users in different fields.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence and data science, in particular to a data intelligent question and answer ChatBI method and device based on a large model. BACKGROUND

[0002] With the rapid development of big data and artificial intelligence technology, data acquisition, processing and analysis are increasingly applied in various industries. In order to better understand data and make decisions, data visualization technology has become an indispensable tool. Data visualization converts complex data into graphical representations (such as charts, graphs, heat maps, etc.), allowing users to visually identify patterns, trends and relationships in the data.

[0003] However, current most data visualization technologies still have certain limitations. For example, traditional data visualization methods often rely on manual analysis and manual selection of appropriate visualization forms, lacking automated support for large-scale, multi-dimensional data. In addition, with the diversification of data sources and the vast amount of data, manually drawing and selecting appropriate chart forms becomes more complex and time-consuming.

[0004] Currently, there are some data visualization tools and technologies on the market, such as Tableau, PowerBI, Matplotlib, etc., which can help users generate a variety of common visualization charts (such as bar charts, line charts, scatter plots, heat maps, etc.). These tools usually generate charts based on user pre-set templates and options. However, their limitations are also obvious, mainly in the following aspects: dependence on human intervention, low automation level, lack of natural language processing capability, and insufficient intelligence.

[0005] For example, the known patent CN118916419A discloses a table-type data visualization method and device, which includes obtaining table-type data; determining the probability of the column data belonging to different data types according to the data fields and the data content; performing data feature mining on the table-type data based on the probability of the column data belonging to different data types to obtain a data feature mining result; and matching the table-type data with a pre-set visualization component based on the probability of the column data belonging to different types and the data feature mining result to generate a visualization image of the table-type data. This method can automatically generate a visualization view of the full amount of table-type data. However, this method outputs mostly basic charts, and complex charts still need to be manually integrated, relying heavily on human intervention, lacking natural language processing capability, requiring input of specified table forms, and lacking intelligence.

[0006] Therefore, a data intelligent question and answer ChatBI method and device based on a large model are proposed. SUMMARY

[0007] Therefore, the application provides a ChatBI method and device based on a large model to solve or alleviate one of the technical problems in the prior art, at least providing an advantageous option.

[0008] The technical scheme of the embodiment of the application is implemented as follows: a ChatBI method based on a large model, comprising the following steps:

[0009] Step one, constructing a database knowledge vector library: block processing is performed on the table creation statements of a target database, and vectors are generated and stored based on an embedding model;

[0010] First, the table creation statements are divided according to table names, field definitions and constraint conditions, and the business descriptions are divided according to field annotations and scene descriptions; second, the embedding model is used to convert the text blocks into vectors and store them; and finally, the cosine similarity algorithm is used to calculate the correlation between the text blocks, and blocks with a correlation higher than a threshold are merged to eliminate redundancy;

[0011] Step two, question semantic transcription and retrieval: a preset prompt word template is used to convert a user's natural language question into a structured description containing explicit data requirements, and vector retrieval is performed in the database knowledge vector library based on the structured description to obtain matched database table structures and field business information;

[0012] First, a preset prompt word template is used to guide a large language model to translate a user's natural language question into a structured description containing query intent, business entity, key indicators, limiting conditions and other elements; then, the structured description is converted into an embedding vector through a text embedding model, and based on the cosine similarity, efficient retrieval is performed in the pre-constructed database metadata (table name, field name, business description, etc.) vector library, and the Top-K database table structures and field business information blocks with the most matched semantics are returned;

[0013] Step three, SQL generation and execution: based on the structured description and the retrieval result, a large language model is used to generate an executable SQL statement, and the SQL statement is executed in the target database to obtain original result data;

[0014] The structured description clearly expressing the user's data requirements and the Top-K related database metadata obtained through vector retrieval are used as inputs to a large language model, and a preset prompt engineering is used to automatically generate an executable SQL statement that conforms to the syntax of the target database; then, the system safely executes the SQL in the target database and obtains the original result data;

[0015] Step four, visual prompt transcription: according to the original user question and the original result data, combined with the pre-defined visualization rule library, the visualization configuration prompt words containing chart type selection logic are generated;

[0016] The visualization prompt transcription link automatically analyzes and decides the most suitable visualization expression mode according to the original user question and the original result data returned by the SQL query, combined with the pre-defined visualization rule library (including data type-chart mapping, multi-field association, dynamic complexity control, etc.), and finally generates structured visualization configuration prompt words (such as JSON), which clearly specifies chart type, data field mapping relationship, visual encoding, aggregation method, interactive function and complexity control measures;

[0017] Step five, chart generation and output: input the generated visualization configuration prompt words into the large language model to generate chart code that meets the front-end rendering standard, and output the visualization chart to the user interaction interface.

[0018] Through the large language model, the structured visualization configuration prompt words are automatically translated into front-end JSON configuration or Python Figure serialized data that can be directly rendered, the former includes data sequence, coordinate axis, legend and other front-end elements, and the latter includes drawing instructions and style parameters. The generated code is rendered into an interactive chart in real time in the user interface;

[0019] Further preferably: in step one, the construction of the database knowledge vector library includes:

[0020] The table creation statement is divided into independent text blocks according to table name, field definition and constraint condition;

[0021] The business description text is divided into independent text blocks according to field annotation and business scenario description;

[0022] The cosine similarity algorithm is used to calculate the correlation between text blocks, and the text blocks with correlation higher than the threshold are merged.

[0023] Further preferably: in step two, the specific process of vector retrieval is:

[0024] The embedding vector of the structured description of the user question is calculated;

[0025] In the vector library, retrieve the Top-K text blocks with the smallest cosine distance from the vector;

[0026] According to the source type of the text block, the retrieval results are classified and integrated.

[0027] Further preferably: in step four, the visualization rule library includes: data type-chart type mapping rule, multi-field association rule and dynamic complexity control rule.

[0028] Further preferably, in step five, the generated chart code is a JSON structure or a Python-based Figure object serialization data supporting front-end rendering.

[0029] Further preferably, the JSON structure includes data sequences, coordinate axis configurations, and legend information, and the Figure object serialization data includes drawing instructions and style parameters.

[0030] A data visualization answering device based on a large language model, applied to a ChatBI method based on a large model, comprising:

[0031] A vector construction module: performing table building statements, block, vectorization and storage of business text;

[0032] A semantic transcription module: generating structured problem descriptions through prompt word engineering and driving RAG retrieval;

[0033] An SQL engine module: calling a large language model to generate and verify SQL and execute data queries;

[0034] A visualization decision module: transcribing visualization prompt words according to a rule base and generating chart configurations;

[0035] A rendering output module: converting chart code into front-end renderable visual elements.

[0036] Further preferably, the data visualization answering device based on a large language model further comprises:

[0037] A cross-database adaptation module: a conversion layer automatically identifying MySQL / Oracle syntax differences.

[0038] An electronic device, comprising at least one processor and a memory connected in communication with the at least one processor;

[0039] Wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform a ChatBI method based on a large model.

[0040] A computer-readable storage medium storing computer instructions for causing a computer to execute a ChatBI method based on a large model.

[0041] The embodiments of the present application have the following advantages due to the use of the above technical solutions:

[0042] 1、The application according to the problem transcription, data retrieval supplement, let the large model according to the characteristics of data and problem, carry out corresponding visualization chart generation, this kind of mode not only realizes the automatic visualization of arbitrary data, simultaneously provides more detailed and more clear expression mode in the form of dialogue, realizes the flexible, intelligent and automatic process, gives the customer more intuitive display data trend and relationship.

[0043] 2、The application combines large language model and data visualization technology, automatically generates appropriate visualization chart according to natural language prompt word and data, thereby greatly improving the efficiency of data analysis and presentation, reducing the learning cost of users, and providing personalized data display solution for users in different fields.

[0044] The above summary is only for the purpose of the description and is not intended to limit in any way. In addition to the illustrative aspects, embodiments and features described above, further aspects, embodiments and features of the present application will be readily apparent to those skilled in the art by reference to the drawings and the following detailed description. BRIEF DESCRIPTION OF DRAWINGS

[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without creative labor.

[0046] Figure 1 Flowchart of the present application;

[0047] Figure 2 Structure diagram of the visualization answering device of the present application. DETAILED DESCRIPTION

[0048] The embodiments of the present disclosure will be described in detail below with reference to the drawings.

[0049] It should be clear that the embodiments of the present disclosure are described below by specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the disclosure. Obviously, the described embodiments are only some embodiments of the present disclosure, not all. The present disclosure can also be implemented or applied by other different specific embodiments, and the details in the specification can be modified or changed based on different views and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present disclosure.

[0050] It is noted that various aspects of the embodiments within the scope of the appended claims are described herein. It is to be understood that the aspects described herein can be implemented in widely varying forms and that any specific structure and / or function described herein is merely illustrative. Based on the disclosure provided, one skilled in the art should appreciate that an aspect described herein can be implemented, independently of any other aspects and that two or more of these aspects can be combined in various ways. For example, an apparatus can be implemented and / or a method can be practiced using any number of the aspects set forth herein. In addition, such an apparatus can be implemented and / or such a method can be practiced using other structure and / or functionality in addition to or other than one or more of the aspects set forth herein.

[0051] It is also noted that the illustrative figures provided in the following embodiments merely show the basic idea of the present disclosure, and only show the components related to the present disclosure in the figures, not drawn according to the number, shape and size of the components in actual implementation, the shape, number and proportion of each component in actual implementation can be a kind of arbitrary change, and the layout pattern of its components can be more complex.

[0052] In addition, in the following description, specific details are provided in order to facilitate a thorough understanding of the examples. However, one skilled in the art will understand that the aspects described can be practiced without these specific details.

[0053] Embodiment 1

[0054] As Figure 1 shown, the embodiment of the present application provides a data intelligent question and answer ChatBI method based on a large model, which includes the following steps:

[0055] Step 1, constructing a database knowledge vector library: the table creation statements of the target database are processed in blocks, vectors are generated based on the embedding model and stored, and the construction of the database knowledge vector library includes:

[0056] The table creation statements are divided into independent text blocks according to table name, field definition and constraint condition;

[0057] The business description text is divided into independent text blocks according to field annotation and business scenario description;

[0058] The cosine similarity algorithm is used to calculate the correlation between text blocks, and the text blocks with correlation higher than the threshold are merged;

[0059] Firstly, the table creation statement is divided by table name, field definition and constraint condition, and the business description is divided by field annotation and scene description; secondly, the text block is converted into a vector and stored by using an embedding model; finally, the correlation between text blocks is calculated by a cosine similarity algorithm, and blocks with a correlation higher than a threshold are merged to eliminate redundancy, realizing the semantic integration of database structure and business knowledge, supporting efficient retrieval and intelligent analysis, and providing a basic support for data management and large language model application.

[0060] Step two, problem semantic transcription and retrieval: the user's natural language question is converted into a structured description containing explicit data requirements through a preset prompt word template, and vector retrieval is performed in the database knowledge vector library based on the structured description to obtain matched database table structure and field business information. The specific process of vector retrieval is:

[0061] Calculate the embedding vector of the structured description of the user's question;

[0062] Retrieve the Top-K text blocks with the smallest cosine distance from the vector library;

[0063] First, the natural language question of the user is translated into a structured description containing query intent, business entity, key indicator, and limiting condition, etc. by using a large language model guided by a preset prompt word template; then, the structured description is converted into an embedding vector by a text embedding model, and efficient retrieval is performed in the pre-constructed database metadata (table name, field name, business description, etc.) vector library based on cosine similarity, returning the Top-K database table structure and field business information blocks with the most matched semantics. The accuracy of natural language understanding and the relevance of semantic retrieval are improved, effectively overcoming the differences between user expression and database terminology, quickly locking the core data structure supporting the user's question, and improving the efficiency and ease of use of data retrieval;

[0064] Step three, SQL generation and execution: input the structured description and retrieval results into a large language model to generate an executable SQL statement, and execute the SQL statement in the target database to obtain the original result data;

[0065] The structured description clearly expressing the user's data requirements and the Top-K related database metadata obtained by vector retrieval are used as input by using a large language model, and a preset prompt engineering is used to automatically generate an executable SQL statement that meets the syntax of the target database; then, the system safely executes the SQL in the target database and obtains the original result data. Automatic SQL writing reduces the data acquisition threshold for non-technical users, and improves the semantic accuracy of generated SQL based on precise context input, which can effectively handle common complex queries including multi-table join and aggregation calculation, thereby improving the efficiency of data query and exploration;

[0066] Step four, visual prompt transcription: according to the original user question and the original result data, combined with the pre-defined visualization rule library, the visualization configuration prompt words containing chart type selection logic are generated, and the visualization rule library includes: data type and chart type mapping rule, multi-field association rule and dynamic complexity control rule;

[0067] The visualization prompt transcription link automatically analyzes and decides the most suitable visualization expression mode according to the original user question and the original result data returned by the SQL query, combined with the pre-defined visualization rule library (including data type-chart mapping, multi-field association, dynamic complexity control, etc.), and finally generates structured visualization configuration prompt words (such as JSON), which clearly specifies chart type, data field mapping relationship, visual encoding, aggregation method, interactive function and complexity control measures, automatically and intelligently completes chart recommendation and configuration, improves the accuracy, effectiveness and consistency of visualization expression, and can dynamically optimize readability according to data size, reducing the threshold and operation cost of users to obtain data insights.

[0068] Step five, chart generation and output: input the generated visualization configuration prompt words into the large language model to generate chart code that meets the front-end rendering standard, output the visualization chart to the user interaction interface, and the generated chart code is a JSON structure or Python-based Figure object serialization data that supports front-end rendering, the JSON structure includes data sequence, coordinate axis configuration, legend information, and the Figure object serialization data includes drawing instructions and style parameters;

[0069] The structured visualization configuration prompt words are automatically translated into front-end JSON configuration or Python Figure serialization data that can be directly rendered by the large language model, the former includes data sequence, coordinate axis, legend, etc. The latter includes drawing instructions and style parameters. The generated code is rendered into an interactive chart in real time in the user interface, realizing end-to-end automation from data to insight, eliminating the cost of manually writing chart code, ensuring the consistency of visualization effect and business rules, and supporting dynamic interaction and multi-environment deployment.

[0070] Embodiment 2

[0071] As shown in the Figure 1 , the embodiment of the application provides a data intelligent question and answer ChatBI method based on a large model, including the following steps:

[0072] Step one, constructing a database knowledge vector library: block processing is performed on the table building statements of the target database, and vectors are generated and stored based on an embedding model, and the construction of the database knowledge vector library includes:

[0073] The table building statement is divided into independent text blocks according to the table name, field definition and constraint condition;

[0074] The business description text is divided into independent text blocks according to field annotations and business scenario descriptions;

[0075] The cosine similarity algorithm is used to calculate the correlation between text blocks, and the text blocks with a correlation higher than a threshold are merged;

[0076] Firstly, the table building statement is divided into independent text blocks according to the table name, field definition and constraint condition, and the business description is divided into blocks according to field annotations and scenario descriptions. Secondly, the text blocks are converted into vectors using an embedding model and stored. Finally, the correlation between text blocks is calculated using the cosine similarity algorithm, and blocks with a correlation higher than a threshold are merged to eliminate redundancy, realizing the semantic integration of database structure and business knowledge, supporting efficient retrieval and intelligent analysis, and providing a foundation for data management and large language model application.

[0077] The core goal of building a database knowledge vector library is to deeply integrate scattered structured technical definitions and business semantics to form a unified knowledge system that machines can understand. For database table building statements, syntax parsing technology is used to atomize the division according to the three elements of table name, field definition and constraint condition. This division method based on syntax tree ensures that each text block carries a single technical concept and avoids information coupling.

[0078] For unstructured business description documents, a scenario-driven blocking strategy is implemented: field annotations are independently blocked according to field dimensions; business scenario descriptions are cut according to business process boundaries, and cross-reference relationships need to be handled.

[0079] After blocking, the vectorization phase is entered, and a pre-trained text embedding model is used for semantic encoding. Each text block is converted into a 768-dimensional dense vector, and the numerical distribution captures the deep semantic features of the text. For example, synonyms such as "primary key" and "unique identifier" are significantly close in vector space, while "order table" and "inventory table" are clearly distinguished. The mapping relationship between all vectors and the original text is stored in a dedicated vector database, and a hierarchical index structure (such as the HNSW algorithm) is used to support subsequent efficient retrieval.

[0080] The redundancy elimination optimization first calculates the cosine similarity matrix of all text block vectors. This mathematical measure accurately quantifies the semantic correlation between texts through the ratio of vector dot product and modulus product. When the similarity between a technical definition block and a business description block exceeds a preset threshold (empirical value 0.85), a dynamic merging mechanism is triggered.

[0081] The merging process follows three principles: first, information lossless, preserving all unique semantic elements; second, context inheritance, ensuring that business constraints are bound with technical definitions; third, vector update, generating an embedding vector for the merged text.

[0082] Step two, question semantic transcription and retrieval: The user's natural language question is converted into a structured description containing explicit data requirements through a preset prompt word template. Based on the structured description, vector retrieval is performed in the database knowledge vector library to obtain matching database table structures and field business information. The specific process of vector retrieval is as follows:

[0083] Calculate the embedding vector of the structured description of the user's question;

[0084] Retrieve the Top-K text blocks with the smallest cosine distance in the vector library;

[0085] First, the preset prompt word template is used to guide the large language model to translate the user's natural language question into a structured description containing query intent, business entity, key indicators, and limiting conditions. Then, the structured description is converted into an embedding vector through a text embedding model, and based on the cosine similarity, an efficient retrieval is performed in the pre-constructed database metadata (table name, field name, business description, etc.) vector library, returning the Top-K database table structures and field business information blocks with the most matched semantics. This improves the accuracy of natural language understanding and the relevance of semantic retrieval, effectively overcoming the differences between user expressions and database terminology, quickly locking the core data structure supporting the user's question, and improving the efficiency and ease of use of data retrieval.

[0086] The core function of this module is to convert the user's fuzzy natural language query into executable database retrieval instructions. The implementation starts with the precise guidance of the preset prompt word template. The template design uses a structured placeholder strategy, including four types of mandatory elements: query intent, business entity, key indicators, and limiting conditions. By constraining the LLM output format, the ambiguity of natural language is forced to be eliminated, and the spoken language expression is accurately matched with the database terminology.

[0087] The structured description then enters the vector retrieval stage, and a 768-dimensional semantic vector is generated using an embedding model that is homologous to the vector library. This vector contains the depth features of the user's requirements, and it is used as an anchor point for vector database retrieval. The HNSW index is used for nearest neighbor search, and the cosine similarity between the vector and all metadata vectors in the library is calculated. This algorithm quantifies semantic relevance through the ratio of vector dot product to modulus product, ensuring that technical definitions and spoken language expressions can still be efficiently matched.

[0088] The retrieval process performs Top-K result screening and returns the set of metadata text blocks with the highest similarity. To improve the usability of the results, three optimization mechanisms are implemented: first, a similarity threshold of 0.7 is set to filter low-quality matches; second, the associated text blocks are dynamically spliced; and third, the composite blocks with business annotations are prioritized for return.

[0089] At the cognitive level, template-guided semantic transcription improves natural language understanding accuracy and effectively bridges the gap between terminology. At the efficiency level, vector retrieval based on cosine similarity can complete metadata scanning of millions of levels in a short time, which is 15 times faster than traditional keyword retrieval. At the knowledge fusion level, the returned Top-K text blocks form a self-explaining knowledge network, providing panoramic context for subsequent SQL generation. The bridge architecture that converts human language into machine cognition is the core interactive engine of intelligent data systems.

[0090] Step three, SQL generation and execution: inputting the structured description and retrieval results into a large language model to generate executable SQL statements, executing the SQL statements in the target database to obtain raw result data;

[0091] Using a large language model, the structured description clearly expressing user data requirements and the Top-K relevant database metadata obtained by vector retrieval are used as input. Through the preset prompt engineering, executable SQL statements that meet the syntax of the target database are automatically generated. Then, the system safely executes the SQL in the target database and obtains the raw result data. Automated SQL writing reduces the data acquisition threshold for non-technical users and improves the semantic accuracy of generated SQL based on precise context input, effectively handling common complex queries including multi-table joins and aggregate calculations, thereby improving data query and exploration efficiency;

[0092] The core function of this module is to convert semantic understanding into executable data operations. Its implementation begins with the dual-source fusion at the input layer: structured description accurately encapsulates user requirements, while the Top-5 metadata text blocks returned by vector retrieval provide database context. These two types of information are systematically injected into the preset prompt word template, forming the driving instructions for LLM. The template design adopts a three-part structure: the first part clearly requires the generation of a specific dialect SQL (such as MySQL 8.0), the second part inserts dynamically spliced technical context (including table structure, field constraints, and association rules), and the third part embeds the structured description of user requirements and adds security specifications.

[0093] This process achieves four key controls through constraint prompts: field references are strictly limited to the metadata range returned by retrieval, association paths must be based on foreign key description blocks, aggregate functions must match the characteristics of the indicators (such as using SUM for sales instead of AVG), and conditional expressions must conform to field types.

[0094] SQL execution before the implementation of two-stage verification: syntax layer call open source parser to check compliance (such as verifying the use of MySQL keywords), semantic layer through small LLM logic review (detect unassociated tables or missing GROUP BY). The statement is verified via an isolated connection pool, which is pre-set to read-only and has a 30-second timeout fuse, effectively preventing resource overload. The execution result is returned in a standardized JSON format, including data matrix (row and column values) and meta information (field type, row count). For more than 100,000-level result sets, an automatic paging mechanism is triggered, returning only 100 rows of preview data on the first screen.

[0095] In terms of accuracy, the fusion of business semantics and technical metadata improves the correctness of multi-table join SQL generation compared to pure natural language conversion; in terms of security, through permission isolation and SQL pre-check, 99% of data misuse risks are eliminated; in terms of efficiency, the average response time is greatly shortened. What is particularly key is that when dealing with complex requirements, the system can automatically combine fields, indicators, and table data to generate SQL containing three-table joins and complex calculations, proving its practicality in real business scenarios.

[0096] Step four, visual prompt transcription: According to the original user question and the original result data, combined with the pre-defined visualization rule library, generate visualization configuration prompt words containing chart type selection logic. The visualization rule library includes: data type and chart type mapping rules, multi-field association rules, and dynamic complexity control rules;

[0097] The visualization prompt transcription link automatically analyzes and decides the most suitable visualization expression method according to the original user question and the original result data returned by the SQL query, combined with the pre-defined visualization rule library (including data type-chart mapping, multi-field association, dynamic complexity control, etc.), and finally generates structured visualization configuration prompt words (such as JSON), which clearly specify chart type, data field mapping relationship, visual encoding, aggregation method, interactive function, and complexity control measures. The chart recommendation and configuration are automatically and intelligently completed, improving the accuracy, effectiveness, and consistency of visualization expression, and dynamically optimizing readability according to data size, reducing the threshold and operation cost of users obtaining data insights.

[0098] The core function of this module is to transform raw data into intuitive business insights, which is implemented by comprehensive analysis of multi-source inputs. Raw user questions provide intention anchors, such as analyzing regional sales trends, where keywords like "compare" and "trend" trigger multi-sequence time series analysis requirements; and raw result data returned by SQL provides the basis for data structure. Both work together with a pre-defined visualization rule library to form a decision-making loop. The rule library adopts a three-layer architecture: the data type mapping rules in the base layer classify fields by technical characteristics, such as automatically marking time fields as X-axis candidates, defaulting numerical fields as Y-axis measures, and classifying text fields as grouping dimensions; the multi-field association rules in the middle layer define combination logic, such as "1 time field + N numerical fields" generating a multi-line chart, and "2 numerical fields" triggering scatter plot analysis; and the dynamic complexity control rules in the top layer introduce real-time calculation modules to quantify and evaluate features such as data row count, unique value count, and value range distribution.

[0099] When processing user queries, the system performs a four-step transcription process: the first step analyzes the result data structure and identifies "month" as a time type, "sales" as a floating-point numerical value, and "category" as an enumerated text (unique values: 15); the second step matches the rule library, with the base layer mapping time fields to the X-axis and numerical fields to the Y-axis, and the multi-field association layer triggering the "double-grouped line chart" rule due to the presence of "region" and "category" double-grouping fields; the third step detects complexity, with the calculation finding that the "category" unique value of 15 is below the bar chart threshold (threshold 50), but "region" contains only a single value, automatically downgrading to single-group mode; and the fourth step generates configuration prompt words, with core parameters including: chart type (line chart), field mapping (X-axis: month, Y-axis: sales, color grouping: category), aggregation rule (sum of category sales for the same month), and visual encoding (line width 2px, data point marker radius 5).

[0100] Dynamic optimization for big data scenarios is particularly critical. When detecting that the data row count exceeds 5000 rows, the complexity control rule automatically starts: enabling weekly aggregation for time series data, and forcibly switching to box plot display for high-base classification fields (such as unique user IDs exceeding 1000). In a real case, the user queries "100,000 order amount distribution", the system identifies that the "order_amount" field value range is large (1-50,000 yuan), and automatically triggers the binning rule: generates 1000-width amount intervals, outputs histogram configuration (bin number: 50, Y-axis: order count), and avoids front-end rendering lag.

[0101] The intelligence of the rule base is reflected in the triple adaptive mechanism: the business semantic enhancement module parses the "proportion" and "ranking" in the user's question and automatically adds pie chart or bar chart suggestions; the associated field reasoning module discovers that "sales" and "profit" fields coexist, and adds secondary Y-axis configuration to realize double-metric superimposed analysis; the historical behavior learning module records the user's correction operation (such as changing the column chart to the stacking mode) on the automatically generated chart, and gradually optimizes the rule weight. The final output of the visualization configuration prompt word uses a standardized JSON structure, including the chart_type field to define the main chart type, the encoding object to describe the field mapping logic, the config object to set the style details (such as color theme, coordinate axis label rotation angle), and the interaction object to declare the interaction behavior (such as clicking the legend to filter categories, and displaying detailed values on mouseover).

[0102] In terms of decision accuracy, the accuracy of chart matching business scenarios is improved through rule base constraints, avoiding common mistakes such as "using a pie chart to display 30 categories"; in terms of system robustness, dynamic complexity control compresses the rendering preparation time of a million-level data set to within 3 seconds, which is 8 times faster than traditional BI tools; in terms of user experience, automatic configuration saves an average of 7 minutes of manual operation for each chart, especially enabling non-technical users to independently complete the entire process from asking questions to gaining insights. In a typical case, a retail enterprise analyzed "store square efficiency comparison during promotion period", the system automatically identified the "store area", "sales", and "promotion week" fields, generated a double-Y-axis combination chart, and added a promotion week background color with markers.

[0103] Step five, chart generation and output: input the generated visualization configuration prompt word into a large language model to generate chart code that meets the front-end rendering standards, and output the visualization chart to the user interaction interface. The generated chart code is a JSON structure or Python Figure object serialization data that supports front-end rendering. The JSON structure includes data sequences, coordinate axis configurations, and legend information. The Figure object serialization data includes drawing instructions and style parameters.

[0104] Through a large language model, structured visualization configuration prompt words are automatically translated into directly renderable front-end JSON configurations or Python Figure serialization data. The former includes data sequences, coordinate axes, and legends, and the latter includes drawing instructions and style parameters. The generated code is rendered into interactive charts in real-time in the user interface, realizing end-to-end automation from data to insights, eliminating the cost of manually writing chart code, ensuring the consistency of visualization effects and business rules, and supporting dynamic interaction and multi-environment deployment.

[0105] The core function of this module is to visualize the deep parsing of configuration prompts. When receiving structured configuration instructions (such as chart definitions in JSON format), the system starts a dual-path translation engine: for web front-end scenarios, it calls large language models to generate standard rendering code, and for Python analysis environments, it outputs serialized drawing objects. The front-end path uses a three-level JSON architecture: the data sequence layer encapsulates core numerical values (such as date-sales key-value pairs for time series), the coordinate axis configuration layer defines scale precision, label rotation angle, and double-Y axis linkage rules, and the legend interaction layer implements dynamic filtering and hovering details; the Python path generates Plotly Figure object serialization data, fully preserving graph track types (such as scatter plot bubble size parameters) and style templates (such as enterprise standard color schemes).

[0106] In specific implementations, when the input configuration prompt requires generating a "2024 regional sales trend line chart", the large language model first parses the key parameters: chart type (line chart), field mapping (X-axis: month, Y-axis: sales, color: region), and interaction requirements (click legend to switch regions). Based on this, it generates ECharts standard JSON configuration: data sequence dynamically inserts a two-dimensional array extracted from SQL results, coordinate axis configuration automatically adds quarter division lines, and legend is set to right-side floating positioning. Especially for dynamic interaction requirements, the event listener module binds the legend click event handling function to realize data sequence visibility control when the legendselectchanged event is triggered.

[0107] To ensure output quality, three verification mechanisms are implemented: the syntax verification layer verifies configuration integrity through JSON Schema, the visual compliance layer checks color contrast against WCAG 2.0 accessibility standards, and the performance optimization layer automatically enables sampling strategies for over ten thousand data points. When the configuration requires generating a map heat map in a Python environment, the model constructs a Plotly Choropleth track object, binds city codes with sales values, and generates a responsive SVG vector graph through fig.write_image(), while outputting the serialized JSON required by plotly.js for web embedding.

[0108] Cross-platform adaptation capability is the core breakthrough of this module: the front-end JSON path supports deep compatibility with mainstream rendering libraries, and the Python path supports Matplotlib object serialization in addition to Plotly. The chart topology formed by fig, ax = plt.subplots() is converted into a pickle byte stream that can be transmitted over the network. The deployment stage uses a containerized microservices architecture to allow the same configuration prompt to generate multiple environment outputs in parallel. In a typical scenario, a user queries "store customer flow heat distribution", and the system simultaneously outputs a Leaflet map rendered on the browser and a Plotly three-dimensional heat map in a Jupyter Notebook.

[0109] In thousands of task tests, the average code generation takes less time and is more efficient than manual development. The output configuration passes the ECharts official validator detection 100% and has high visual consistency. The supported interaction types cover 16 common operations (from basic data label display and hiding to advanced cross-chart linkage). In a case of a certain retail enterprise, the system automatically generates a multi-view dashboard with a pager for the "promotion period time period customer flow comparison" requirement: the main view is a 24-hour line chart, the auxiliary view uses a calendar heat map to show weekly patterns, and clicking on the time interval automatically refreshes the detail table. This deep interaction implementation only requires a single configuration prompt input, while traditional development requires multiple person-days of work.

[0110] Embodiment 3

[0111] A data visualization answering device based on a large language model, applied to a data intelligent question-answering ChatBI method based on a large model, comprising:

[0112] A vector construction module: performing table building statements, block, vectorization and storage of business text;

[0113] A semantic transcription module: generating structured problem descriptions through prompt engineering to drive RAG retrieval;

[0114] An SQL engine module: calling a large language model to generate and verify SQL, and executing data queries;

[0115] A visualization decision module: transcribing visualization prompts according to a rule base to generate chart configurations;

[0116] A rendering output module: converting chart code into front-end renderable visual elements.

[0117] The semantic transcription module accurately analyzes user intent through prompt word engineering and RAG retrieval. The SQL engine module generates safe and executable queries to obtain data. The visualization decision module automatically generates chart configurations based on the rule base. Finally, the rendering output module converts the data into ECharts JSON or Plotly objects, outputting interactive visual charts.

[0118] The device builds an end-to-end intelligent channel from natural language to visual insights. The vector construction module first deeply integrates database technical metadata and business knowledge: the table creation statement is disassembled into three types of atomized text blocks: table name, field definition, and constraint condition by the syntax parser. The business document is blocked according to field annotations and scenario descriptions. A 768-dimensional semantic vector is generated for each block using a text embedding model. The relevance of technical definition and business description is identified by cosine similarity calculation, and the blocks are dynamically merged into "field customer number: type integer, business meaning customer unique identifier" and the vector is updated. Finally, the knowledge base is stored in the vector database to form a knowledge base that integrates business and technical semantics. This process reduces the metadata volume by 40% and improves retrieval accuracy by 35%.

[0119] The semantic transcription module analyzes intent through a four-element structured template: the user query "the top three products with the highest sales last year" is converted into a machine-readable JSON description by a large language model. After vectorization by a homologous embedding model, a millisecond-level RAG retrieval is performed in the vector library: based on HNSW index cosine similarity calculation, the Top5 semantic matching block is returned, and the associated foreign key constraint text is automatically attached. This process accurately anchors the fuzzy requirements to the database elements, with a term difference elimination rate of 90%.

[0120] The SQL engine module uses a dual-source input fusion strategy: structured description and retrieved metadata blocks are injected into a three-layer prompt template (dialect declaration, technical context, and security specifications). When processing cross-table queries, the large language model automatically generates JOIN-based syntax-verified SQL based on the metadata "product name in product table, sales in order table" (such as associating the product table with the order table by sales in descending order to get the top three). Before execution, a dual-safeguard mechanism is activated: an open-source parser checks the syntax integrity, and a small review model detects logical vulnerabilities. The verified SQL is executed through a read-only connection pool, and a timeout fuse mechanism intercepts long-time-consuming queries. The returned results are automatically paginated and annotated with field types.

[0121] The visualization decision module combines the original problem keywords and the result data structure to start rule inference: "trend" in the user question triggers the need for time series analysis, and the month field in the result data is mapped to the X axis and the sales field to the Y axis; the rule library detects the coexistence of multiple value fields and starts the line chart combination rule, and automatically aggregates when the unique value exceeds the limit. The final generated visualization configuration prompt word explicitly specifies the chart type as a line chart, the field mapping relationship, the line width style, and the hover interaction, and processes the distribution of 100,000-level data through a dynamic binning mechanism.

[0122] The rendering output module implements cross-environment adaptation: for Web scenarios, the configuration prompt word is input into a large language model to generate ECharts standard JSON; for Python environments, the serialized Figure object of Plotly is output. During deployment, multiple-end outputs are generated synchronously through containerized microservices, such as returning GeoJSON data of Leaflet maps and interactive three-dimensional objects of Jupyter for store heat map requirements. The quality assurance system includes syntax verification (JSONSchema detection), accessibility color gamut inspection (WCAG2.0 standard), and big data sampling strategy (1 / 10,000 sample retaining distribution characteristics).

[0123] Embodiment 4

[0124] A data visualization answering device based on a large language model is applied to a ChatBI method based on a large model, and further comprises:

[0125] The cross-database adaptation module: a conversion layer that automatically identifies the syntax differences between MySQL and Oracle. The difference between this embodiment and embodiment two is that the cross-database adaptation module automatically bridges the syntax differences between MySQL, Oracle, and other databases, so that SQL with the same semantics can be executed losslessly in heterogeneous data sources, thereby enhancing the application scenarios of the data visualization answering device based on a large language model.

[0126] This module achieves seamless adaptation of heterogeneous databases through a three-layer conversion architecture. First, a dialect feature library is established to dynamically identify SQL syntax fingerprints: when the LIMIT clause is detected, it is marked as a MySQL feature, and ROWNUM is classified as an Oracle syntax. The core conversion layer uses abstract syntax tree parsing technology to disassemble the original SQL into atomic operation units. For complex scenarios, a large language model is used to assist in rewriting, such as converting the AUTO_INCREMENT primary key logic of MySQL to the SEQUENCE+TRIGGER combination of Oracle, while automatically adding comments to explain the conversion logic.

[0127] The execution phase implements double protection: the converted SQL is verified for compliance by a syntax parser, and a metadata-aware module checks field type compatibility. For distributed database scenarios, performance optimization instructions are automatically injected. The implementation supports more than 200 conversion rules, reducing the difference between the execution results of the same query in MySQL and Oracle to less than 1%, and reducing the deployment cost in a hybrid cloud environment.

[0128] Embodiment 5

[0129] An electronic device includes at least one processor, and a memory connected to the at least one processor in communication;

[0130] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform a ChatBI method based on a large model.

[0131] By way of example, a computer program can be segmented into one or more modules / units, one or more modules / units are stored in the memory and executed by the processor to complete the present application. One or more modules / units can be a series of computer program instruction segments capable of completing a specific function, which are used to describe the execution process of the computer program in the computer device.

[0132] The processor can be a central processing unit, and can also be other general-purpose processors, digital signal processors, application-specific integrated circuits, field programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete preset hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0133] The memory can be an internal storage unit of the computer device, such as a hard disk or memory of the computer device. The memory can also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card, a secure digital card, a flash memory card, etc. Further, the memory can include both the internal storage unit and the external storage device of the computer device.

[0134] Embodiment 6

[0135] A computer readable storage medium stores computer instructions for causing a computer to perform a ChatBI method based on a large model.

[0136] The computer program can be stored in a computer readable storage medium, and when executed by a processor, the computer program can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable code, or some intermediate form. The computer readable medium can include any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier signal, telecommunication signal, and software distribution medium, etc.

[0137] In the above embodiments, the description of each embodiment has its own focus, and the parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.

[0138] The steps in the method of the embodiments of the present application can be adjusted in sequence, combined and deleted according to actual needs.

[0139] Those skilled in the art can realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized by electronic preset hardware or a combination of computer software and electronic preset hardware. Whether the functions are realized by preset hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0140] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any skilled person in the art can easily think of various changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A data-driven intelligent question-answering (ChatBI) method based on a large model, characterized in that, Includes the following steps: Step 1: Construct a database knowledge vector library: Divide the table creation statements of the target database into blocks, generate vectors based on the embedding model, and store them; In step one, the construction of the database knowledge vector base includes: dividing the table creation statement into independent text blocks according to the table name, field definition, and constraint conditions; dividing the business description text into independent text blocks according to field comments and business scenario descriptions; using the cosine similarity algorithm to calculate the correlation between text blocks and merging text blocks with a correlation higher than the threshold. Step Two, Question Semantic Translation and Retrieval: The user's natural language question is transformed into a structured description containing explicit data requirements using a preset prompt word template. Based on this structured description, a vector retrieval is performed in the database knowledge vector library to obtain the matching database table structure and field business information. The specific process of the vector retrieval in Step Two is as follows: Calculate the embedding vector of the user's structured question description; retrieve the Top-K text blocks with the smallest cosine distance to this vector in the vector library; and classify and integrate the retrieval results according to the source type of the text blocks. Step 3: SQL Generation and Execution: Based on the structured description and retrieval results, the large language model generates an executable SQL statement, executes the SQL statement in the target database, and obtains the raw result data; Step 4: Visual prompt transcription: Based on the original user question and original result data, and combined with a predefined visualization rule base, generate visualization configuration prompts that include chart type selection logic; In step 4, the visualization rule base includes: data type and chart type mapping rules, multi-field association rules, and dynamic complexity control rules; Step 5: Chart Generation and Output: Input the generated visualization configuration prompts into the large language model to generate chart code that conforms to the front-end rendering standard, and output the visualization chart to the user interface.

2. The ChatBI method based on a large model for intelligent question answering according to claim 1, characterized in that, In step five, the generated chart code is either a JSON structure that supports front-end rendering or serialized data of a Python-based Figure object.

3. The ChatBI method based on a large model for intelligent question answering according to claim 2, characterized in that, The JSON structure includes a data sequence, coordinate axis configuration, and legend information. The serialized data of the Figure object includes drawing instructions and style parameters.

4. A data visualization response device based on a large language model, applied to the ChatBI method for data-driven intelligent question answering based on a large model as described in any one of claims 1-3, characterized in that, include: Vector construction module: performs the segmentation, vectorization, and storage of table creation statements and business text; Semantic transcription module: Generates structured question descriptions through prompt word engineering to drive RAG retrieval; SQL Engine Module: Generates and validates SQL by calling a large language model, and executes data queries; Visualization Decision Module: Transcribes visual prompts based on the rule base and generates chart configurations; Rendering output module: Converts chart code into visual elements that can be rendered on the front end.

5. The data visualization response device based on a large language model according to claim 4, characterized in that, The data visualization response device based on a large language model also includes: Cross-database adaptation module: A conversion layer that automatically identifies syntax differences between MySQL and Oracle.

6. An electronic device, characterized in that, The electronic device includes: at least one processor, and a memory communicatively connected to the at least one processor; The memory stores instructions that can be executed by the at least one processor, which are executed by the at least one processor to enable the at least one processor to execute the ChatBI method based on a large model as described in any one of claims 1-3.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to execute the ChatBI method for data-driven intelligent question answering based on a large model, as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Method and device for visualizing table type data

    CN118916419A

  • Systems and methods for facilitating database queries

    US20240394251A1

  • Incorporating large language model prompts in graph query language

    US20240419835A1