Data intelligent question and answer ChatBI method and device based on large model
By building a database knowledge vector library and a large language model, the system automatically processes user natural language questions to generate suitable visualization charts, solving the problems of existing technologies such as reliance on manual intervention and low automation levels, and achieving efficient data visualization and personalized display.
Patent Information
- Application Number
- CN202511294096.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-09-11
AI Technical Summary
Existing data visualization technologies rely on manual intervention, have low levels of automation, and lack natural language processing capabilities, making it difficult to efficiently generate suitable visualization charts for large-scale multidimensional data.
Build a database knowledge vector library, convert user natural language questions into structured descriptions through a large language model, generate SQL statements and automatically generate visual configuration prompts, and finally output interactive charts.
It realizes an end-to-end automated process from natural language questions to visual charts, improves the efficiency of data analysis and presentation, reduces user learning costs, and provides personalized data display solutions.
Smart Images

Figure CN120804144A_ABST
Abstract
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: 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; First, the table creation statements are segmented according to table names, field definitions, and constraint conditions, and the business descriptions are segmented according to field annotations and scene descriptions; second, the text blocks are converted into vectors and stored by using an embedding model; and finally, the correlation between the text blocks is calculated by using a cosine similarity algorithm, and blocks with a correlation higher than a threshold are merged to eliminate redundancy; Step two, question semantic transcription and retrieval: a user's natural language question is converted into a structured description containing explicit data requirements by using 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 structures and field business information; First, a large language model is used to translate a user's natural language question into a structured description containing query intent, business entity, key indicators, and limiting conditions by using a preset prompt word template; then, the structured description is converted into an embedding vector by using a text embedding model, and efficient retrieval is performed in a pre-constructed database metadata (table name, field name, business description, etc.) vector library based on cosine similarity, and the Top-K database table structures and field business information blocks with the most matched semantics are returned; Step three, SQL generation and execution: a large language model is used to generate an executable SQL statement based on the structured description and the retrieval result, and the SQL statement is executed in a target database to obtain original result data; A large language model is used to take the structured description clearly expressing a user's data requirements and the Top-K related database metadata obtained by vector retrieval as input, and a preset prompt engineering is used to automatically generate an executable SQL statement conforming to the syntax of a target database; then, the system safely executes the SQL in the target database and obtains original result data; Step four, visual prompt transcription: according to the original user question and the original result data, a visual configuration prompt word containing chart type selection logic is generated by combining a pre-defined visual rule library; The visualization prompt word transcription link returns the original result data according to the original user question and the SQL query, and combines the pre-defined visualization rule library (including data type-chart mapping, multi-field association, dynamic complexity control, etc. rules) to automatically analyze and decide the most suitable visualization expression mode, and finally generate structured visualization configuration prompt words (such as JSON) to clearly specify chart type, data field mapping relationship, visual encoding, aggregation method, interactive function and complexity control measures. Step five, chart generation and output: input the generated visualization configuration prompt word 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.
[0009] Through the large language model, the structured visualization configuration prompt word is automatically translated into front-end JSON configuration or Python Figure serialization data that can be directly rendered, the former includes data sequence, coordinate axis, legend, etc. front-end elements, and the latter includes drawing instructions and style parameters, and the generated code is rendered into an interactive chart in real time in the user interface; Further preferably: in step one, the construction of the database knowledge vector library includes: The table creation statement is divided into independent text blocks according to the table name, field definition and constraint condition; The business description text is divided into independent text blocks according to the field annotation and business scenario description; 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.
[0010] Further preferably: in step two, the specific process of vector retrieval is: Calculate the embedding vector of the structured description of the user question; Retrieve the Top-K text blocks with the smallest cosine distance from the vector library; According to the source type classification, the retrieval results are integrated.
[0011] Further preferably: in step four, the visualization rule library includes: data type-chart type mapping rules, multi-field association rules and dynamic complexity control rules.
[0012] Further preferably: in step five, the generated chart code is a JSON structure or Python-based Figure object serialization data that supports front-end rendering.
[0013] Further preferably: the JSON structure includes data sequence, coordinate axis configuration, and legend information, and the Figure object serialization data includes drawing instructions and style parameters.
[0014] A data visualization answering device based on a large language model is applied to a large model-based data intelligent question answering ChatBI method, comprising: A vector construction module: performing table building statements and business text blocking, vectorization and storage; A semantic transcription module: generating structured problem descriptions through prompt word engineering to drive RAG retrieval; An SQL engine module: calling a large language model to generate and verify SQL and execute data queries; A visualization decision module: transcribing visualization prompt words according to a rule base to generate chart configurations; A rendering output module: converting chart code into front-end renderable visual elements.
[0015] Further preferably, the data visualization answering device based on a large language model further comprises: A cross-database adaptation module: an automatic conversion layer that identifies MySQL / Oracle syntax differences.
[0016] An electronic device, comprising at least one processor, and a memory connected in communication with the at least one processor; 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 large model-based data intelligent question answering ChatBI method.
[0017] A computer-readable storage medium storing computer instructions for causing a computer to execute a large model-based data intelligent question answering ChatBI method.
[0018] The embodiments of the present application have the following advantages due to the use of the above technical solutions: 1. According to the problem transcription and data retrieval supplement, the large model generates corresponding visual charts according to the characteristics of the data and the problem. This way not only realizes the automatic visualization of any data, but also provides a more detailed and clear expression 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.
[0019] 2. The present application combines large language models and data visualization technology to automatically generate appropriate visual charts according to natural language prompts and data, thereby greatly improving the efficiency of data analysis and presentation, reducing the learning cost of users, and providing personalized data display solutions for users in different fields.
[0020] The above summary is intended to illustrate only and is not intended to be limiting in any way. Further aspects, embodiments and features of the present application will become apparent from the following detailed description, taken in conjunction with the accompanying drawings and the description of the embodiments described above. BRIEF DESCRIPTION OF DRAWINGS
[0021] In order to more clearly illustrate the technical solutions of the embodiments of the present application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are only some of the embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0022] Figure 1 Flowchart of the present application; Figure 2 Structure diagram of the visual answering device of the present application. DETAILED DESCRIPTION
[0023] The embodiments of the present disclosure will be described in detail below with reference to the drawings.
[0024] It should be apparent that the following describes the embodiments of the present disclosure through specific concrete 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 of the embodiments of the present disclosure, not all. The present disclosure can also be implemented or applied by other different specific embodiments, and each detail 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.
[0025] It should be noted that the following describes various aspects of the embodiments within the scope of the appended claims. It should be apparent that the aspects described herein can be embodied in a wide variety of forms and that any particular structure and / or function described herein is merely illustrative. Based on the disclosure, those skilled in the art should understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, the devices and / or methods can be implemented using any number of the aspects set forth herein. In addition, this device and / or method can be implemented using other structures and / or functionality in addition to or instead of one or more of the aspects set forth herein.
[0026] It is also necessary to note that the drawings provided in the following embodiments only illustrate the basic concept of the present disclosure in a schematic manner, and only show the components related to the present disclosure in the drawings, not the number, shape and size of the components when actually implemented. The actual implementation of each component may be a random change in type, number and proportion, and the component layout pattern may be more complex.
[0027] In addition, in the following description, specific details are provided in order to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that the aspects described can be practiced without these specific details.
[0028] Embodiment 1 As Figure 1 shown, the embodiment of the present application provides a data intelligent question and answer ChatBI method based on a large model, including the following steps: Step one, build a database knowledge vector library: block the table creation statement of the target database, generate vectors based on the embedding model and store them, the construction of the database knowledge vector library includes: Split the table creation statement into independent text blocks according to the table name, field definition and constraint condition; Split the business description text into independent text blocks according to the field annotation and business scenario description; Use the cosine similarity algorithm to calculate the correlation between text blocks, and merge text blocks with a correlation higher than the threshold; First, split the table creation statement according to the table name, field definition and constraint condition, and split the business description according to the field annotation and scenario description; second, use the embedding model to convert the text blocks into vectors and store them; finally, calculate the correlation between the text blocks by the cosine similarity algorithm, and merge the blocks with a correlation higher than the threshold to eliminate redundancy, realize the semantic integration of the database structure and business knowledge, support efficient retrieval and intelligent analysis, and provide a foundation for data management and large language model application.
[0029] Step two, question semantic transcription and retrieval: convert the user's natural language question into a structured description containing explicit data requirements through a preset prompt word template, perform vector retrieval in the database knowledge vector library based on the structured description, and obtain the matched database table structure and field business information. The specific process of vector retrieval is: Calculate the embedding vector of the user's question structured description; Retrieve the Top-K text blocks with the smallest cosine distance from the vector library; 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 clear query intent, business entity, key indicator, and limiting condition; then, the structured description is converted into an embedding vector through a text embedding model, and based on the cosine similarity, an efficient search is performed in the pre-constructed database metadata (table name, field name, business description, etc.) vector library, and the Top-K database table structure and field business information block with the most matched semantics are returned. 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 user questions, and improving the efficiency and ease of use of data retrieval; Step three, SQL generation and execution: based on the structured description and retrieval result, input the large language model to generate an executable SQL statement, execute the SQL statement in the target database, and obtain the original result data; Using a large language model, 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, and through a preset prompt engineering, an executable SQL statement conforming to the syntax of the target database is automatically generated. Then, the system safely executes the SQL in the target database and obtains the original result data. Automated SQL writing reduces the data acquisition threshold for non-technical users, and based on accurate context input, improves the semantic accuracy of generated SQL, which can effectively handle common complex queries including multi-table joins and aggregation calculations, thereby improving the efficiency of data query and exploration; 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 prompts 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; The visualization prompt transcription link automatically analyzes and decides the most suitable visualization expression based on 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 prompts (such as JSON), which clearly specify chart types, data field mapping relationships, visual encoding, aggregation methods, interactive functions, and complexity control measures. Automatic and intelligent chart recommendation and configuration improve 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 obtaining data insights.
[0030] Step five, chart generation and output: input the generated visual configuration prompt word into the large language model, generate chart code that meets the front-end rendering standard, and output the visual chart to the user interaction interface. 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 sequences, coordinate axis configurations, and legend information. The Figure object serialization data includes drawing instructions and style parameters. By automatically translating structured visual configuration prompts into directly renderable front-end JSON configurations or Python Figure serialization data through a large language model, the former includes data sequences, coordinate axes, legends, and other front-end elements, and the latter includes drawing instructions and style parameters. The generated code is rendered into interactive charts in real-time in the user interface, enabling end-to-end automation from data to insights, eliminating the need for manual chart code writing, ensuring consistency in visual effects and business rules, and supporting dynamic interaction and multi-environment deployment.
[0031] Embodiment 2 As shown in Figure 1 , the present application provides a data intelligent question and answer ChatBI method based on a large model, including the following steps: Step one, build a database knowledge vector library: block process the table creation statements of the target database, generate vectors based on the embedding model, and store them. The construction of the database knowledge vector library includes: Split the table creation statements into independent text blocks according to table names, field definitions, and constraint conditions. Split the business description text into independent text blocks according to field annotations and business scenario descriptions. Use the cosine similarity algorithm to calculate the correlation between text blocks and merge text blocks with a correlation higher than the threshold. First, split the table creation statements according to table names, field definitions, and constraint conditions, and split the business description according to field annotations and scenario descriptions. Second, use the embedding model to convert the text blocks into vectors and store them. Finally, use the cosine similarity algorithm to calculate the correlation between text blocks and merge blocks with a correlation higher than the threshold to eliminate redundancy, realize the semantic integration of database structure and business knowledge, and support efficient retrieval and intelligent analysis to provide a foundation for data management and large language model applications.
[0032] 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 machine-understandable knowledge system. For database table creation statements, use syntax parsing technology to atomize and split according to table names, field definitions, and constraint conditions. This syntax tree-based splitting method ensures that each text block carries a single technical concept and avoids information coupling.
[0033] For unstructured business description documents, a scenario-driven chunking strategy is implemented: field annotations are independently chunked by field dimension; business scenario descriptions are cut according to business process boundaries, while cross-reference relationships need to be handled.
[0034] After chunking, 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.
[0035] The redundancy elimination optimization step first calculates the cosine similarity matrix of all text block vectors. This mathematical measure accurately quantifies the semantic relevance between texts through the ratio of vector dot product and modulus product. When the similarity between technical definition blocks and business description blocks exceeds the preset threshold (empirical value 0.85), the dynamic merging mechanism is triggered.
[0036] The merging process follows three principles: first, information lossless, preserving all unique semantic elements; second, context inheritance, ensuring that business constraints are bound to technical definitions; third, vector update, generating an embedding vector for the merged text.
[0037] Step 2: 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. 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: Calculate the embedding vector of the user's structured description; Retrieve the Top-K text blocks with the smallest cosine distance from the vector library; First, use a preset prompt word template to guide a large language model to translate the user's natural language question into a structured description containing explicit query intent, business entities, 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, 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 matching 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 user questions, and improving the efficiency and ease of use of data retrieval; The core function of this module is to convert ambiguous natural language queries into executable database search instructions. This is achieved through the precise guidance of pre-set prompt word templates. The template design utilizes a structured placeholder strategy, encompassing four mandatory elements: query intent, business entities, key indicators, and qualifying conditions. By constraining the LLM output format, it eliminates ambiguity in natural language and ensures that spoken expressions accurately correspond to database terminology.
[0038] The structured description then enters the vector retrieval stage, where it is converted into a 768-dimensional semantic vector using an embedding model derived from the vector library. This vector contains the deep features of the user's needs. This vector is input into the vector database as a retrieval anchor point, and a nearest neighbor search is performed using the optimized HNSW index. Its cosine similarity with all metadata vectors in the library is calculated. The algorithm quantifies semantic relevance by the ratio of the vector dot product to the module-length product, ensuring that technical definitions and spoken expressions can still be efficiently matched.
[0039] 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, a three-step optimization mechanism is implemented: first, a similarity threshold of 0.7 is set to filter out low-quality matches; second, related text blocks are dynamically spliced; and third, composite blocks with business annotations are returned first.
[0040] At the cognitive level, template-guided semantic transcription improves the accuracy of natural language understanding and effectively bridges terminology differences; at the efficiency level, vector retrieval based on cosine similarity can complete the scanning of tens of millions of metadata in a short period of time, which is 15 times faster than traditional keyword retrieval; at the knowledge fusion level, the returned Top-K text blocks form a self-explanatory knowledge network, providing a panoramic context for subsequent SQL generation, and bridging the gap between human language and machine cognition. It is the core interaction engine of the intelligent data system.
[0041] Step 3: SQL generation and execution: Generate executable SQL statements based on the structured description and search results input into the large language model, execute the SQL statements in the target database, and obtain the original result data; Leveraging a large language model, the system takes as input a structured description that clearly expresses the user's data needs and the metadata of the top-K relevant databases obtained through vector retrieval. Through pre-set prompt engineering, it automatically generates executable SQL statements that conform to the syntax of the target database. The system then securely executes the SQL statements in the target database and retrieves the original result data. Automated SQL writing lowers the data acquisition threshold for non-technical users and improves the semantic accuracy of generated SQL based on precise contextual input. It can effectively handle common and complex queries, including multi-table joins and aggregate calculations, thereby improving the efficiency of data query and exploration. The core function of this module is to convert semantic understanding into executable data operations. Its implementation begins with the fusion of two sources at the input layer: structured descriptions precisely encapsulate 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 pre-set prompt templates, forming the driving instructions for LLMs. The template design adopts a three-part structure: the first part explicitly requires the generation of a specific dialect of 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.
[0042] 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.
[0043] SQL execution is implemented with a two-stage verification: the syntax layer calls an open-source parser to check compliance (such as verifying the use of MySQL keywords), and the semantic layer conducts a logical review through a small LLM (detecting unassociated tables or missing GROUP BY). Statements that pass verification are executed via an isolated connection pool, which is pre-set with read-only permissions and a 30-second timeout fuse, effectively preventing resource overload. The execution results are returned in a standardized JSON format, including data matrices (row and column values) and meta-information (field types, row counts). For result sets above 100,000, an automatic paging mechanism is triggered, returning only 100 rows of preview data on the first screen.
[0044] 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, permission isolation and SQL pre-check eliminate 99% of data operation risks; in terms of efficiency, the average response time is significantly reduced. Most importantly, 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, demonstrating its practicality in real business scenarios.
[0045] Step four, visual prompt transcription: based on the original user question and the original result data, combined with a pre-defined visual rule library, generate visual configuration prompts containing chart type selection logic. The visual rule library includes: mapping rules between data types and chart types, multi-field association rules, and dynamic complexity control rules; The visualization prompt word transcription link returns the original result data according to the original user question and SQL query, and combines the pre-defined visualization rule library (including data type-chart mapping, multi-field association, dynamic complexity control, etc. rules) to automatically analyze and decide the most suitable visualization expression mode, and finally generate structured visualization configuration prompt words (such as JSON), which clearly specify the chart type, data field mapping relationship, visual encoding, aggregation method, interaction function and complexity control measures, automatically and intelligently complete chart recommendation and configuration, improve the accuracy, effectiveness and consistency of visualization expression, and dynamically optimize readability according to the data size, thereby reducing the threshold and operation cost of users to obtain data insights.
[0046] The core function of the module is to transform raw data into intuitive business insights, and its implementation starts with comprehensive analysis of multi-source input. The original user question provides an intention anchor point, such as analyzing the sales trend in a certain region, where keywords such as "comparison" and "trend" trigger multi-sequence time series analysis requirements; the original result data returned by SQL provides the data structure basis. Both of them work together with the pre-defined visualization rule library to form a decision-making closed loop. The rule library adopts a three-layer architecture: the data type mapping rules in the basic layer classify fields according to 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" to generate a multi-line chart, and "2 numerical fields" to trigger scatter plot analysis; the dynamic complexity control rules in the top layer introduce a real-time calculation module to quantitatively evaluate data row number, unique value number, and value range distribution.
[0047] When processing a user query, 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 value: 15); the second step matches the rule library, the basic layer maps the time field to the X-axis and the numerical field to the Y-axis, and the multi-field association layer triggers the "double-grouped line chart" rule due to the presence of "region" and "category" double-grouped fields; the third step detects complexity, and the calculation finds that the "category" unique value is 15, which is lower than the threshold (threshold 50) of the column chart, but "region" contains only a single value, which is automatically downgraded to single-grouped mode; the fourth step generates configuration prompt words, and the core parameters include: chart type (line chart), field mapping (X-axis: month, Y-axis: sales, color grouping: category), aggregation rule (sum of category sales in the same month), visual encoding (line width 2px, data point marker radius 5).
[0048] Dynamic optimization for big data scenarios is particularly critical. When the number of data rows exceeds 5000, the complexity control rule is automatically started: weekly aggregation is enabled for time series data, and high cardinality classification fields (such as unique user ID exceeding 1000) are forced to switch to box plot display distribution characteristics. In a real case, the user query "100,000 order amount distribution" identifies that the "order_amount" field value range is large (1-50,000 yuan), and automatically triggers the binning rule: generates an order amount interval with a width of 1000, outputs the histogram configuration (bin number: 50, Y axis: order count), and avoids front-end rendering lag.
[0049] 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 superposition 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 visualization configuration prompt word adopts a standardized JSON structure, including a chart_type field to define the main chart type, an encoding object to describe the field mapping logic, a config object to set style details (such as color theme, coordinate axis label rotation angle), and an interaction object to declare interaction behavior (such as clicking the legend to filter categories, and displaying detailed values on mouseover).
[0050] In terms of decision accuracy, the rule base constraint improves the accuracy of chart matching business scenarios, 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, automated 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 analyzes "store efficiency comparison during promotion", and the system automatically identifies "store area", "sales", and "promotion week" fields, generates a double-Y-axis combination chart, and adds a promotion week background color label.
[0051] 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 a Python-based 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. The structured visualization configuration prompt words are automatically translated into directly renderable front-end JSON configurations or Python Figure serialized data by a large language model. The former includes data sequences, coordinate axes, legends, and other front-end elements, while 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 insight, 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.
[0052] The core function of this module is the deep analysis of visualization configuration prompts. When receiving structured configuration instructions (such as JSON format chart definitions), the system starts a double-path translation engine: for web front-end scenarios, it calls a large language model 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).
[0053] In specific implementation, when the input configuration prompt requires generating a "2024 regional sales trend line chart", the large language model first analyzes 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 legend click event handling function is bound in the event listening module to realize data sequence display control when the legendselectchanged event is triggered.
[0054] To ensure output quality, a three-layer verification mechanism is implemented: the syntax verification layer verifies configuration integrity through JSON Schema, the visual compliance layer checks whether the color contrast meets the WCAG 2.0 accessibility standards, and the performance optimization layer automatically enables sampling strategy for over ten thousand data points. When the configuration requires generating a Python environment map heat map, the model constructs a Plotly Choropleth track object, binds city codes and 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.
[0055] 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 network-transmissible pickle byte stream. In the deployment stage, containerized microservices architecture is used to make the same configuration prompt word 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.
[0056] In thousands of task tests, the average code generation takes less time and improves efficiency compared to manual development. The output configuration passes the ECharts official validator detection with 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-based customer flow comparison" requirement: the main view is a 24-hour line chart, and the auxiliary view uses a calendar heat map to display weekly patterns. Clicking on the time interval automatically refreshes the detail table. This deep interaction is achieved with only a single configuration prompt word input, which would take multiple person-days of work in traditional development.
[0057] Embodiment 3 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: A vector construction module: performing table building statements, block, vectorization and storage of business text; A semantic transcription module: generating structured problem descriptions through prompt word engineering to drive RAG retrieval; An SQL engine module: calling a large language model to generate and verify SQL, and executing data queries; A visualization decision module: transcribing visualization prompt words according to a rule base to generate chart configurations; A rendering output module: converting chart code into front-end renderable visual elements.
[0058] Through the prompt word engineering of the semantic transcription module and the accurate analysis of user intent by RAG retrieval, the SQL engine module generates safe and executable queries to obtain data. Based on the rule base of the visualization decision module, chart configurations are automatically generated. Finally, the rendering output module converts ECharts JSON or Plotly objects to output interactive visualization charts.
[0059] The device builds an end-to-end intelligent channel from natural language to visualized insights. The vector construction module first deeply integrates database technical metadata with 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, and the business document is blocked according to field annotation and scenario description; 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 vector is dynamically merged into a composite block "field customer number: type integer, business meaning customer unique identifier" and updated, and finally stored in the vector database to form a knowledge base integrating business and technical semantics. This process reduces the metadata volume by 40% and improves the retrieval accuracy by 35%.
[0060] The semantic transcription module drives intent analysis through a four-element structured template: the user query "the top three products with the highest sales last year" is transcribed into a machine-readable JSON description by a large language model. After vectorization by a homologous embedding model, the description is executed in the vector library for millisecond-level RAG retrieval: based on HNSW index calculation of cosine similarity, 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%.
[0061] The SQL engine module adopts 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 specification). 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 joining the product table with the order table by sales in descending order to get the top three). Before execution, a dual-protection mechanism is started: an open-source parser checks the syntax integrity, and a small review model detects logical vulnerabilities; the verified SQL is executed via a read-only connection pool, and the timeout fuse mechanism intercepts long-time-consuming queries, and the returned results are automatically paginated and annotated with field types.
[0062] The visualized decision module combines the original problem keywords with the result data structure to start rule reasoning: the "trend" in the user's question triggers the time series analysis requirement, 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 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.
[0063] 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; and for Python environments, a serialized Figure object of Plotly is output. During deployment, multiple-end outputs are synchronously generated through containerized microservices, such as a store heat map demand that returns GeoJSON data of a Leaflet map and an interactive three-dimensional object of Jupyter. The quality assurance system includes syntax verification (JSONSchema detection), accessibility color gamut checking (WCAG2.0 standard), and big data sampling strategies (1 / 10,000 samples that retain distribution characteristics).
[0064] Embodiment 4 A data visualization answering apparatus based on a large language model is applied to a ChatBI method based on a large model, and further includes: A cross-database adaptation module: a conversion layer that automatically identifies and converts the syntax differences between MySQL and Oracle. The difference between this embodiment and Embodiment 2 is that the cross-database adaptation module automatically bridges the syntax differences between MySQL, Oracle, and other databases, so that the same SQL with the same semantics can be executed losslessly in heterogeneous data sources, thereby enhancing the application scenarios of the data visualization answering apparatus based on a large language model.
[0065] This module realizes 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 a 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 into a combination of SEQUENCE+TRIGGER of Oracle, while automatically adding comments to explain the conversion logic.
[0066] Dual safeguards are implemented in the execution phase: the converted SQL is verified for compliance by a syntax parser, and the metadata perception module checks field type compatibility. For distributed database scenarios, performance optimization instructions are automatically injected. The conversion rules support more than 200 rules, reducing the execution result difference between MySQL and Oracle to less than 1%, and reducing the deployment cost in a hybrid cloud environment.
[0067] Embodiment 5 An electronic device includes at least one processor and a memory connected in communication with the at least one processor. 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.
[0068] For example, the computer program can be divided 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 is used to describe the execution process of the computer program in the computer device.
[0069] 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 gates 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.
[0070] 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.
[0071] Embodiment 6 A computer readable storage medium stores computer instructions for causing a computer to perform a ChatBI method based on a large model.
[0072] The computer program can be stored in a computer readable storage medium, and when the computer program is executed by the processor, the steps of each method embodiment described above can be implemented. The computer program includes computer program code, which can be in the form of source code, object code, executable files or some intermediate forms, etc. The computer readable medium can include any entity or device capable of carrying 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.
[0073] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described or recorded in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0074] The steps in the method of the embodiments of the present application can be adjusted in sequence, combined and deleted according to actual needs.
[0075] Those skilled in the art can understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized in electronic preset hardware or a combination of computer software and electronic preset hardware. Whether the functions are realized in preset hardware or software manner 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.
[0076] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any person skilled 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 ChatBI method for intelligent data question answering based on a large model, characterized in that: The following steps are involved: Step 1: Build a database knowledge vector library: Block the table creation statements of the target database, generate vectors based on the embedding model, and store them; Step 2: Question Semantic Transcription and Retrieval: The user's natural language question is converted into a structured description containing clear data requirements using a preset prompt word template. Based on the structured description, a vector search is performed in the database knowledge vector library to obtain matching database table structures and field business information. Step 3: SQL generation and execution: Generate executable SQL statements based on the structured description and search results input into the large language model, execute the SQL statements in the target database, and obtain the original result data; Step 4: Visual prompt word transcription: Based on the original user question and original result data, combined with the predefined visualization rule library, generate visualization configuration prompt words that include chart type selection logic; Step 5. Chart generation and output: Input the generated visualization configuration prompt words into the large language model, generate chart code that meets the front-end rendering standards, and output the visualization chart to the user interaction interface.
2. A ChatBI method for data intelligent question answering based on a large model according to claim 1, characterized in that: In step 1, the construction of the database knowledge vector library includes: Split table creation statements into independent text blocks based on table name, field definition, and constraint conditions; Divide the business description text into independent text blocks according to field annotations and business scenario descriptions; 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.
3. A ChatBI method for data intelligent question answering based on a large model according to claim 1, characterized in that: In step 2, the specific process of vector retrieval is as follows: Calculate the embedding vector of the structured description of the user question; Retrieve the top-K text blocks with the smallest cosine distance to the vector in the vector library; The search results are classified and integrated according to the source type of the text block.
4. A ChatBI method for data intelligent question answering based on a large model according to claim 1, characterized in that: In step 4, the visualization rule base includes: mapping rules between data types and chart types, multi-field association rules, and dynamic complexity control rules.
5. The ChatBI method based on large-scale data model according to claim 1, characterized in that: In step 5, the generated chart code is a JSON structure that supports front-end rendering or Python-based Figure object serialized data.
6. A ChatBI method for data intelligent question answering based on a large model according to claim 5, characterized in that: The JSON structure includes data sequence, coordinate axis configuration, and legend information, and the Figure object serialized data includes drawing instructions and style parameters.
7. 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 as described in claims 1-6, characterized in that: include: Vector construction module: executes the block division, 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: calls the large language model to generate and verify SQL and execute data queries; Visual decision module: transcribes visual prompt words according to the rule base and generates chart configuration; Rendering output module: converts chart code into visual elements that can be rendered by the front end.
8. The data visualization answering device based on a large language model according to claim 7, characterized in that: The data visualization answering device based on the large language model also includes: Cross-database adaptation module: a conversion layer that automatically identifies syntax differences between MySQL and Oracle.
9. 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; In which, the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the ChatBI method based on large model data intelligent question answering according to any one of claims 1-6.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, which are used to enable a computer to execute a data intelligent question-answering ChatBI method based on a large model as described in any one of claims 1-6.
Citation Information
Patent Citations
Method and device for visualizing table type data
CN118916419A
Data query analysis method and system based on LLM and semantic model
CN120030045A
Logic decomposition SQL (Structured Query Language) generation visualization system and method based on large language model
CN120596577A
Systems and methods for facilitating database queries
US20240394251A1
Incorporating large language model prompts in graph query language
US20240419835A1
Cited By
Answer data visualization method and device and storage medium
CN121092150A
Answer data visualization method, device, and storage medium
CN121092150B
Dynamic multimode SQL generation method and system based on four-quadrant strategy
CN121117014A
Method, device, medium and program product for generating analysis model Schema based on natural language input
CN121502405A