Data analysis method and device based on natural language dialogue mode and electronic equipment

By using natural language conversational data analysis methods and automatically generating SQL statements using BGE models and large language models, the problem of long development cycles and high barriers to entry for business personnel's ad-hoc analysis needs has been solved, enabling fast and accurate data analysis.

CN121901256APending Publication Date: 2026-04-21TRAVELSKY TECHNOLOGY LIMITED
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TRAVELSKY TECHNOLOGY LIMITED
Filing Date
2025-12-31
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

In existing technologies, business personnel's ad-hoc analysis needs require developers to develop, test, and deploy reports, which has a high development cycle and high barrier to entry, making it difficult to respond quickly.

Method used

By employing a natural language-based conversational data analysis method, and utilizing BGE and large language models to generate SQL statements, combined with vector retrieval enhancement, semantic matching of user intent and query parameters is achieved, prompt words are generated, and query statements are automatically generated, thus lowering the threshold for data analysis.

Benefits of technology

Business personnel can perform data analysis simply by inputting natural language, which lowers the threshold and development cycle of data analysis and improves response speed and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121901256A_ABST
    Figure CN121901256A_ABST
Patent Text Reader

Abstract

The invention provides a data analysis method and device based on a natural language dialogue mode and electronic equipment, and the method comprises the steps: receiving a user dialogue request for authentication and preprocessing, and obtaining user input data; performing semantic analysis on the user input data to obtain a user intention, and extracting a query parameter from the user input data to obtain a first query parameter; querying a domain data table structure having the maximum semantic similarity with the user intention and the first query parameter, and a historical query case having the semantic similarity greater than a first threshold value; generating cue words according to the user output data, the domain data table structure and the historical query case, and generating an SQL statement according to the cue words to obtain a first target statement; and executing the first target statement to obtain a query result. The method solves the problems that in the prior art, a developer needs to carry out report development, test and online when business personnel suddenly analyze requirements, the development period and threshold are high, and the analysis requirements are difficult to respond quickly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and more specifically, to a data analysis method, apparatus, computer-readable storage medium, and electronic device based on natural language conversation. Background Technology

[0002] The company's operational analysis primarily relies on fixed reporting platforms and manually configured query interfaces. While these systems perform well in terms of data consistency and stability, they suffer from inherent bottlenecks in usability, flexibility, and timeliness. Due to the numerous report parameters and complex configurations, business personnel need to understand the meaning of fields, filtering logic, aggregation rules, and data definitions, resulting in a high learning curve. For non-technical personnel unfamiliar with SQL or reporting tools, it is difficult to independently complete data analysis tasks. Secondly, fixed reports can only be queried according to preset dimensions and indicators, failing to support multi-dimensional combinations and ad-hoc analysis. In mobile work or impromptu decision-making scenarios, business personnel need to navigate through multiple pages and filter layer by layer, a cumbersome and inefficient process. Furthermore, new analytical requirements often require IT intervention for report development, testing, and deployment, with cycles ranging from several days to several weeks. Temporary and exploratory data analysis needs are difficult to respond to quickly.

[0003] In summary, existing data analysis methods are unable to respond promptly to the ad-hoc analysis needs of business personnel due to the high difficulty and long development cycle of new platforms and interfaces. Summary of the Invention

[0004] The main objective of this application is to provide a data analysis method, apparatus, computer-readable storage medium, and electronic device based on natural language conversation, so as to at least solve the problem in the prior art that business personnel's sudden analysis needs require developers to develop, test, and launch reports, which has a high development cycle and threshold, making it difficult to respond quickly to analysis needs.

[0005] To achieve the above objectives, according to one aspect of this application, a natural language conversational data analysis method is provided, comprising: receiving a user dialogue request through a dialogue interface; performing authentication and preprocessing based on the dialogue request to obtain user input data, wherein the preprocessing includes security detection and preset question-and-answer matching; performing semantic analysis on the user input data to obtain user intent; extracting query parameters from the user input data using a preset parameter template to obtain a first query parameter; using a BGE model to query a domain data table structure with the highest semantic similarity to the user intent and the first query parameter; using the BGE model to query historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameter; generating prompt words based on the user output data, the domain data table structure, and the historical query cases; generating an SQL statement based on the prompt words using a large language model to obtain a first target statement; executing the first target statement to obtain query results; and sending the query results back to the user terminal via an event stream.

[0006] Optionally, authentication and preprocessing are performed based on the dialogue request to obtain user input data, including: extracting a session token from the dialogue request; verifying the identity of the user by comparing the session token with the user registration information stored in the database; if the identity verification is successful, checking the request frequency and memory length of the dialogue request; if the check is successful, matching the dialogue request with preset questions and answers; if a match is found, sending the answer corresponding to the preset questions and answers back to the user terminal via an event stream; if a match is not found, filtering the dialogue request for sensitive words, abnormal instructions, and prompt words to obtain the user input data.

[0007] Optionally, a first query parameter is obtained by extracting query parameters from the user input data using a preset parameter template, including: extracting a preset field from the preset parameter template, and determining the parameter value corresponding to the matched field based on the preset field matching the user input data, thereby obtaining a second query parameter; if the preset field does not match, engaging in a question-and-answer session with the user on the dialog interface based on the preset field to obtain the parameter value corresponding to the preset field, thereby obtaining a third query parameter; and determining the first query parameter based on the second query parameter and the third query parameter.

[0008] Optionally, querying the domain data table structure with the highest semantic similarity to the user intent and the first query parameter using the BGE model includes: calculating the semantic similarity between the user intent and each of the domain data table structures in the database using the BGE model to obtain multiple first similarities; calculating the semantic similarity between the first query parameter and each of the domain data table structures in the database using the BGE model to obtain multiple second similarities; performing a weighted summation of each first similarity and its corresponding second similarity to obtain multiple third similarities; obtaining the domain data table structure corresponding to the maximum value of the third similarity; and determining that the query is complete and outputting the domain data table structure if the third similarity corresponding to the domain data table structure is greater than or equal to a second threshold.

[0009] Optionally, querying historical query cases with a semantic similarity greater than a first threshold between the user intent and the first query parameter using the BGE model includes: calculating the similarity between the user intent and each of the historical query cases in the database using the BGE model to obtain multiple fourth similarities; calculating the similarity between the first query parameter and each of the historical query cases in the database using the BGE model to obtain multiple fifth similarities; performing a weighted summation of each of the fourth similarities and the corresponding fifth similarities to obtain multiple sixth similarities; obtaining the historical query cases with a sixth similarity greater than the first threshold, sorting the historical query cases according to the sixth similarity from largest to smallest to obtain a target sequence, and truncating the target sequence from front to back with a preset step size to obtain multiple historical query cases.

[0010] Optionally, after generating an SQL statement based on the prompt words using a large language model to obtain the first target statement, the method further includes: performing a risk assessment on each of the first target statements using a pre-stored risk assessment model in the database to obtain a risk coefficient; and intercepting the first target statement if the risk coefficient is greater than or equal to a third threshold.

[0011] Optionally, executing the first target statement to obtain query results includes: executing the first target statement; if the execution is successful, obtaining the query results; if the execution fails, obtaining database error information; inputting the database error information and the first target statement into the large language model to regenerate an SQL statement to obtain a second target statement, and executing the second target statement to obtain the query results, wherein the number of consecutive generation times of the second target statement is less than or equal to a fourth threshold.

[0012] According to another aspect of this application, a data analysis device based on natural language conversation is provided. The device includes: an acquisition unit, configured to receive user conversation requests through a conversational interface, perform authentication and preprocessing based on the conversation requests to obtain user input data, wherein the preprocessing includes security detection and preset question-and-answer matching; a first processing unit, configured to perform semantic analysis on the user input data to obtain user intent, and extract query parameters from the user input data using a preset parameter template to obtain a first query parameter; a query unit, configured to use a BGE model to query a domain data table structure with the highest semantic similarity to the user intent and the first query parameter, and use the BGE model to query historical query cases with a semantic similarity greater than a first threshold to the user intent and the first query parameter; a generation unit, configured to generate prompt words based on the user output data, the domain data table structure, and the historical query cases, and generate an SQL statement based on the prompt words using a large language model to obtain a first target statement; and an execution unit, configured to execute the first target statement to obtain query results, and send the query results back to the user terminal via an event stream.

[0013] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform any of the methods described.

[0014] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for performing any one of the methods described.

[0015] Applying the technical solution of this application, in the aforementioned data analysis method based on natural language dialogue, firstly, a user dialogue request is received through a dialogue interface. Authentication and preprocessing are performed based on the dialogue request to obtain user input data. Preprocessing includes security detection and preset question-and-answer matching. Then, semantic analysis is performed on the user input data to obtain the user intent. Query parameters are extracted from the user input data using a preset parameter template to obtain the first query parameter. Next, a domain data table structure with the highest semantic similarity to the user intent and the first query parameter is queried using a BGE model. Historical query cases with a semantic similarity greater than a first threshold to the user intent and the first query parameter are also queried using the BGE model. Then, prompt words are generated based on the user output data, the domain data table structure, and the historical query cases. An SQL statement is generated based on the prompt words using a large language model to obtain the first target statement. Finally, the first target statement is executed to obtain the query result, and the query result is returned to the user terminal via an event stream. This application enhances data retrieval by introducing vector retrieval. Based on user input, it queries the vectorized representation of the domain data table structure and historical success cases. Combined with the query results, it generates suggestive words to guide a large language model in automatically generating query statements. This allows business personnel to perform data analysis simply by inputting their needs in natural language, lowering the barrier to entry and reducing the development cycle. It solves the problem in existing technologies where sudden analytical needs from business personnel require developers to create, test, and deploy reports, resulting in high development cycles and barriers to entry, hindering rapid response to analytical demands. Attached Figure Description

[0016] Figure 1 A hardware structure block diagram of a mobile terminal based on a natural language conversational data analysis method provided in an embodiment of this application is shown.

[0017] Figure 2 A flowchart illustrating a natural language-based conversational data analysis method according to an embodiment of this application is shown.

[0018] Figure 3 A structural block diagram of a natural language-based conversational data analysis device provided according to an embodiment of this application is shown. Detailed Implementation

[0019] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0020] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0021] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0022] As described in the background section, existing data analysis methods are unable to respond promptly to the ad-hoc analysis needs of business personnel due to the high difficulty and long development cycle of new platforms and interfaces. To address the problem that existing technologies require developers to develop, test, and deploy reports for sudden analysis needs of business personnel, which has a high development cycle and threshold, making it difficult to respond quickly to analysis needs, embodiments of this application provide a data analysis method, apparatus, computer-readable storage medium, and electronic device based on natural language conversational interaction.

[0023] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0024] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal based on a natural language conversational data analysis method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0025] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the natural language-based conversational data analysis method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0026] This embodiment provides a natural language conversational data analysis method that runs on a mobile terminal, computer terminal, or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0027] Figure 2 This is a flowchart of a natural language conversational data analysis method according to an embodiment of this application. Figure 2 As shown, the method includes the following steps:

[0028] Step S201: Receive user dialogue request through dialogue interface, perform authentication and preprocessing based on dialogue request, and obtain user input data. Preprocessing includes security detection and preset question-and-answer matching.

[0029] In its implementation, the access and authentication module serves as the portal to the ChatBI system (hereinafter referred to as the system), receiving natural language query requests from users via the front-end interface. The request carries a user session token for authentication. During the preprocessing stage, the system performs security checks on user input to prevent risks such as SQL injection and malicious operations. Furthermore, the system uses a pre-defined question-and-answer database to match user queries, providing fixed answers directly to simple, predefined questions, thereby enabling rapid response and reducing the inference pressure on large models.

[0030] Step S202: Perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameters;

[0031] In practical implementation, a language processing agent identifies the semantic intent of the user's input, such as query time range, flight segment information, and query metrics. A parameter collection agent extracts query parameters from the user input based on a pre-set parameter template. The template includes necessary fields such as date range, flight segment code, and query metrics, and supports intelligent date inference and multiple rounds of follow-up questions to ensure the completeness and accuracy of the aforementioned first query parameters.

[0032] Step S203: Use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameters that is greater than the first threshold.

[0033] In practice, the BGE model is used to vectorize the schema description (domain data table structure) and user questions, storing them in a vector database. When a user inputs data, the system vectorizes the query metrics and calculates their similarity with the schema vectors in the database to find the best-matching domain data table structure. Similarly, the system also retrieves historical query cases that are semantically similar to the current user's intent and query parameters, providing contextual examples and business guidelines for generating SQL using the large language model.

[0034] Step S204: Generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0035] In practice, the large language model generates SQL statements based on the injected prompts, and the output is in JSON format for easy program parsing.

[0036] Step S205: Execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0037] In practice, the results processing agent performs format validation and normalization on the query results, generating structured analysis reports that include data overviews, in-depth analysis, and business recommendations. Through Server-Side Event Streaming (SSE) technology, the system streams intermediate results and final conclusions from the analysis process back to the user, optimizing the user experience and reducing waiting anxiety.

[0038] In this embodiment, firstly, a user dialogue request is received through a dialogue interface. Authentication and preprocessing are performed based on the dialogue request to obtain user input data. Preprocessing includes security detection and preset question-and-answer matching. Then, semantic analysis is performed on the user input data to obtain the user intent. Query parameters are extracted from the user input data using a preset parameter template to obtain the first query parameter. Next, a domain data table structure with the highest semantic similarity to the user intent and the first query parameter is queried using a BGE model. Historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameter are also queried using the BGE model. Then, prompt words are generated based on the user output data, the domain data table structure, and the historical query cases. An SQL statement is generated based on the prompt words using a large language model to obtain the first target statement. Finally, the first target statement is executed to obtain the query result, and the query result is sent back to the user terminal via an event stream. This application enhances data retrieval by introducing vector retrieval. Based on user input, it queries the vectorized representation of the domain data table structure and historical success cases. Combined with the query results, it generates suggestive words to guide a large language model in automatically generating query statements. This allows business personnel to perform data analysis simply by inputting their needs in natural language, lowering the barrier to entry and reducing the development cycle. It solves the problem in existing technologies where sudden analytical needs from business personnel require developers to create, test, and deploy reports, resulting in high development cycles and barriers to entry, hindering rapid response to analytical demands.

[0039] To ensure the security and accuracy of the input data, in one optional implementation, step S201 includes:

[0040] Step S2011: Extract the session token from the dialogue request, and verify the user's identity based on the session token and the user registration information stored in the database;

[0041] In practice, the access and authentication module extracts a session token from the dialogue request to verify the user's identity and ensure that only authorized users can use the system for data analysis. Specifically, the session token is used to retrieve the corresponding user registration information from the backend database for identity verification. Through these operations, unauthorized access is prevented, protecting data security.

[0042] Step S2012: If the identity verification is successful, check the request frequency and memory length of the dialogue request.

[0043] In practice, the system performs further preprocessing on authenticated dialogue requests, checking the request frequency to prevent excessive server load caused by a large number of requests in a short period. Simultaneously, the system checks the memory length of the requests to ensure that the request content does not exceed the preset length limit, preventing malicious users from submitting excessively large requests and wasting resources.

[0044] Step S2013: If the check passes, match the dialogue request with the preset questions and answers. If a match is found, send the answer corresponding to the preset questions and answers back to the user terminal via an event stream.

[0045] In practical implementation, to quickly respond to common and simple user queries, the system has a built-in pre-set question-and-answer database, which contains typical questions and their corresponding standard answers. When the data entered by the user matches a question in the database, the system can directly retrieve the answer from the database without requiring complex semantic analysis and SQL generation by an intelligent agent, thereby speeding up the response and reducing the burden of subsequent processing.

[0046] In step S2014, if no match is found, the dialogue request is filtered for sensitive words, abnormal instructions, and prompt words to obtain user input data.

[0047] In practice, when a user request does not match the preset question-and-answer database, the system needs to perform more in-depth preprocessing of the request content, including sensitive word filtering, abnormal command detection, and prompt word injection detection. Sensitive word filtering prevents the system from accessing information it shouldn't process, such as personal privacy information or sensitive terms. Abnormal command detection prevents security threats like SQL injection, ensuring that requests received by the system do not damage the database or leak sensitive information. Prompt word injection detection prevents the agent from being misled into generating incorrect SQL statements at the semantic level.

[0048] Through the authentication and preprocessing technologies detailed in the above embodiments, the solution of this application achieves efficient, secure, and compliant processing of user data analysis requests. Specifically, it not only ensures that only authenticated and legitimate users can use the system, but also improves the system's response speed and security through a series of preprocessing measures, such as request frequency control, memory length checking, preset question-and-answer matching, and filtering of sensitive words, abnormal commands, and prompts. This provides business personnel with reliable boundary data analysis tools.

[0049] In order to extract key features from user input data, in one optional implementation, step S202 above includes:

[0050] Step S2021: Extract preset fields from the preset parameter template, and determine the parameter values ​​corresponding to the matched fields based on the matching of the preset fields with the user input data to obtain the second query parameters;

[0051] In practice, the parameter collection agent invokes a pre-defined parameter template. This template contains the basic fields required for data analysis, such as query time, flight segment, and data indicators. The pre-defined fields in the template guide the system to automatically identify and extract the values ​​of these fields from the user-input data, thereby generating an initial set of query parameters. Based on the above operations, the system further refines the parameter extraction process, converting the field values ​​directly matched from the user input into a system-understandable format to obtain the second set of query parameters.

[0052] Step S2022: If the preset field does not match, ask and answer questions with the user in the dialog interface based on the preset field to obtain the parameter value corresponding to the preset field and obtain the third query parameter.

[0053] In practice, if all fields in the preset template cannot be directly identified from the user input, the parameter collection intelligence will engage in multiple rounds of interaction with the user to supplement the missing parameter information and obtain the aforementioned third query parameters. It is understood that the above interactive question-and-answer mechanism is based on contextual understanding and can dynamically adjust the questions until complete parameters are obtained.

[0054] Step S2023: Determine the first query parameter based on the second query parameter and the third query parameter.

[0055] In practice, after collecting the second query parameters (parameters directly matched) and the third query parameters (parameters obtained through interaction), these two sets of parameters are integrated to obtain the first query parameters, which is the complete parameter set ultimately used for SQL generation. During the integration process, the system performs parameter validation to ensure the validity of the parameters, such as whether the date range is reasonable and whether the flight segment code exists.

[0056] Through the above embodiments, the solution of this application achieves the goal of accurately and completely extracting query parameters from user natural language input, thus obtaining the basis for generating SQL statements. Specifically, the above solution combines automatic recognition and user interactive question answering, which can quickly process explicit user input and dynamically complete information through questioning, ensuring the comprehensiveness and accuracy of parameters. In addition, parameter formatting and validation further improve the reliability of SQL generation and avoid query failures caused by parameter errors.

[0057] To obtain the aforementioned domain data table structure, in one optional implementation, step S203 includes:

[0058] Step S2031: Calculate the semantic similarity between user intent and the data table structure of each domain in the database using the BGE model to obtain multiple first similarity scores;

[0059] In practice, the system transforms user intent (such as "query sales information") into a vector using a Bi-Encoder for General Embedding (BGE) model. This vector is then compared to the structure description vectors of all data tables stored in the database to calculate a series of first-order similarity scores. BGE is a deep learning-based text vector embedding model that converts text into high-dimensional vector representations, facilitating semantic similarity calculation. Similarity calculations typically use cosine similarity or dot product to measure the proximity of two vector directions, thus reflecting the semantic matching degree of the text.

[0060] Step S2032: Calculate the semantic similarity between the first query parameter and the data table structure of each domain in the database using the BGE model to obtain multiple second similarities;

[0061] In practical implementation, the system similarly transforms the first query parameters (such as ISS_DATE, SEGMENT, QUERY_METRIC) into vectors using the BGE model. These vectors represent the specific conditions and requirements of the user's query. The semantic similarity between these parameter vectors and the structural description vectors of each domain data table in the database is then calculated to obtain a series of second similarity scores.

[0062] Step S2034: Weighted summation of each first similarity score with its corresponding second similarity score to obtain multiple third similarity scores;

[0063] In practice, a weighted summation method is used to add the first and second similarities with certain weights to obtain the third similarity, which comprehensively considers the matching degree between user intent and query parameters. The selection of these weights depends on the application scenario; for example, if the system places greater emphasis on matching user intent, the first similarity of user intent is given a higher weight.

[0064] Step S2034: Obtain the domain data table structure corresponding to the maximum third similarity value. If the third similarity of the domain data table structure is greater than or equal to the second threshold, determine that the query is complete and output the domain data table structure.

[0065] In practice, the system selects the data table structure with the highest third similarity as the output and checks whether this highest third similarity exceeds a preset second threshold. This second threshold is used to prevent mismatches with table structures of lower similarity, ensuring a high degree of consistency between the selected table structure and the user's intent.

[0066] Through the above embodiments, the semantic similarity between user intent and query parameters and the domain data table structure is calculated using the BGE model. A weighted summation and threshold checking mechanism is then employed to accurately select the data table structure most relevant and consistent with the user query. This improves the accuracy of SQL generation and the consistency of business definitions, reduces the probability of incorrect table or field names due to insufficient domain knowledge, and ensures that the generated SQL statements accurately reflect the user's actual needs. Simultaneously, this method demonstrates a deep understanding of user intent, automatically correcting minor errors or ambiguities in user input to a certain extent, and providing a more user-friendly interactive experience.

[0067] In order to obtain historical success stories, in an optional implementation, step S203 above further includes:

[0068] Step S2035: Calculate the similarity between the user intent and each historical query case in the database using the BGE model to obtain multiple fourth similarities;

[0069] In practice, the BGE model is used to calculate the semantic similarity between the user's current intent and various historical query cases stored in the database, resulting in multiple fourth similarities. These historical query cases include the user's natural language queries and their corresponding SQL query pairs, which are also converted into vectors by the BGE model for display. The aforementioned fourth similarities reflect the degree of semantic association between the historical query cases and the current intent.

[0070] Step S2036: Calculate the similarity between the first query parameter and each historical query case in the database using the BGE model to obtain multiple fifth similarities;

[0071] In practice, the system similarly transforms the first query parameters (such as ISS_DATE, SEGMENT, QUERY_METRIC) into vectors using the BGE model. These vectors represent the specific conditions and requirements of the user's query. The similarity between these parameter vectors and historical query cases in the database is then calculated again to obtain multiple fifth similarity scores.

[0072] Step S2037: Weighted summation of each fourth similarity score with the corresponding fifth similarity score to obtain multiple sixth similarity scores;

[0073] In practice, the system weights and sums the fourth similarity (similarity between user intent and historical cases) and the fifth similarity (similarity between query parameters and historical cases) according to predetermined weights to obtain the sixth similarity. The sixth similarity represents the degree of matching between the case as a whole and the current query. The weight allocation is based on the system's consideration of the importance of different matching dimensions.

[0074] Step S2038: Obtain historical query cases with a sixth similarity greater than the first threshold, sort the historical query cases from largest to smallest according to the sixth similarity to obtain the target sequence, and truncate the target sequence from front to back with a preset step size to obtain multiple historical query cases.

[0075] In practice, the system selects historical query cases with a sixth similarity greater than a preset first threshold to ensure that the selected cases are sufficiently relevant to the current query. This first threshold ensures that only sufficiently similar historical query cases are included in the reference range, avoiding interference from irrelevant cases in SQL generation. Furthermore, the selected cases are sorted from highest to lowest sixth similarity to form a target sequence. By truncating the target sequence with a preset step size, the system obtains a finite set of the most similar cases, which serves as a reference for generating SQL.

[0076] Through the above embodiments, the ChatBI system can accurately filter out cases highly relevant to the current user's intent and query parameters from a large number of historical query cases, providing contextual examples for generating SQL statements for the general language model. This process improves the accuracy and efficiency of Text2SQL conversion and reduces errors caused by the lack of domain knowledge in the general language model. Furthermore, because the selection of cases is based on both user intent and specific query parameters, the generated SQL not only expresses the user's actual needs but also maintains consistency in business terminology, further enhancing the credibility and usability of the query results.

[0077] To ensure the security of the data analysis process, in one optional implementation, after generating the SQL statement based on prompt words using a large language model to obtain the first target statement, the above method further includes:

[0078] Step S301: Use the pre-stored risk assessment model in the database to assess the risk of each first target statement and obtain the risk coefficient;

[0079] In practice, after the SQL generation stage, the system uses a pre-trained risk assessment model to review each primary target SQL statement and evaluate its potential security risks. This risk assessment model is typically based on a machine learning classifier, capable of identifying risk characteristics such as SQL injection, data leakage, and full table scans. Understandably, this risk assessment model is trained using a large number of secure and insecure SQL statement samples through deep learning algorithms. This model can predict the risk level of new statements, i.e., the aforementioned risk coefficient.

[0080] Step S302: If the risk coefficient is greater than or equal to the third threshold, intercept the first target statement.

[0081] In practice, the aforementioned third threshold is a pre-set critical value used to determine whether the generated SQL statement poses a risk and the magnitude of that risk. If the risk is low, execution is allowed; if the risk is high, it needs to be blocked to prevent impact on the system. The setting of this third threshold is based on a balance between business requirements and Xiong Security Quality Inspection, ensuring that legitimate queries are not misjudged, nor are high-risk queries allowed to proceed.

[0082] Through the above embodiments, automatic security review of generated SQL statements is achieved, ensuring that only safe and compliant statements can be executed. Specifically, the above operation combines the SQL generated by the large language model with the risk assessment of the machine learning model, leveraging both the intelligent generation capability of the large language model and the accurate identification capability of the risk assessment model, effectively balancing the convenience of data analysis with the rigor of data security.

[0083] To achieve automated data querying, in one optional implementation, step S205 includes:

[0084] Step S2051: Execute the first target statement. If the execution is successful, obtain the query results.

[0085] In practice, after the SQL generation phase, the system submits the first target statement to the backend database for execution to obtain the data query results required by the user. The database execution engine is responsible for parsing and executing the SQL statement, returning query results or execution error information.

[0086] Step S2052: If the execution fails, obtain the database error information;

[0087] In practice, when SQL execution fails, the system extracts the specific reason for the failure from the error code and error message returned by the database. The error message may indicate SQL syntax errors, missing fields, insufficient permissions, or other issues, guiding the repair of the SQL.

[0088] Step S2053: Input the database error information and the first target statement into the large language model to regenerate the SQL statement, obtain the second target statement, and execute the second target statement to obtain the query results. The number of consecutive generation of the second target statement is less than or equal to the fourth threshold.

[0089] In practice, the system uses a large language model to analyze error messages and the original SQL statement, intelligently generating a corrected second target statement. This generated second target statement is then submitted to the database for execution until a query result is successfully obtained or the maximum number of retries is reached. To avoid getting stuck in an infinite loop of SQL generation and execution, the system sets a limit on the number of times the second target statement can be generated consecutively, which is the fourth threshold and usually does not exceed 3 times. Once the limit is exceeded, the system will no longer attempt to generate new SQL statements, but will instead take degraded measures, such as providing user-friendly error messages, to avoid continuous resource consumption.

[0090] Through the above embodiments, the natural language conversational data analysis system achieves automatic execution and correction of SQL statements, significantly improving the accuracy of SQL generation and the stability of execution. It can not only quickly respond to user query requests but also automatically and intelligently repair SQL syntax errors or field problems, reducing user waiting time and the frequency of manual intervention, thus improving data analysis efficiency. Simultaneously, by setting a fourth threshold to control the number of retries, the system prevents resource waste and provides clear guidance to users when execution fails, maintaining system stability and user experience.

[0091] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0092] This application also provides a data analysis device based on natural language dialogue. It should be noted that this data analysis device based on natural language dialogue can be used to execute the data analysis method based on natural language dialogue provided in this application. This device is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0093] The following describes the data analysis device based on natural language dialogue provided in the embodiments of this application.

[0094] Figure 3 This is a structural block diagram of a natural language-based conversational data analysis device according to an embodiment of this application. Figure 3 As shown, the device includes:

[0095] The acquisition unit 10 is used to receive user dialogue requests through the dialogue interface, perform authentication and preprocessing based on the dialogue requests, and obtain user input data. The preprocessing includes security detection and preset question-and-answer matching.

[0096] The first processing unit 20 is used to perform semantic analysis on user input data to obtain user intent, and extract query parameters from user input data using a preset parameter template to obtain the first query parameters;

[0097] Query unit 30 is used to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameter using the BGE model, and to query historical query cases with a semantic similarity greater than a first threshold using the BGE model.

[0098] The generation unit 40 is used to generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0099] Execution unit 50 is used to execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0100] In this embodiment, the acquisition unit receives user dialogue requests through a dialogue interface, performs authentication and preprocessing based on the dialogue requests to obtain user input data. The preprocessing includes security detection and preset question-and-answer matching. The first processing unit performs semantic analysis on the user input data to obtain the user intent, and extracts query parameters from the user input data using a preset parameter template to obtain the first query parameter. The query unit uses a BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameter, and uses a BGE model to query historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameter. The generation unit generates prompt words based on the user output data, the domain data table structure, and the historical query cases, and generates an SQL statement based on the prompt words using a large language model to obtain the first target statement. The execution unit executes the first target statement to obtain the query result and sends the query result back to the user terminal via an event stream. This application enhances data retrieval by introducing vector retrieval. Based on user input, it queries the vectorized representation of the domain data table structure and historical success cases. Combined with the query results, it generates suggestive words to guide a large language model in automatically generating query statements. This allows business personnel to perform data analysis simply by inputting their needs in natural language, lowering the barrier to entry and reducing the development cycle. It solves the problem in existing technologies where sudden analytical needs from business personnel require developers to create, test, and deploy reports, resulting in high development cycles and barriers to entry, hindering rapid response to analytical demands.

[0101] To ensure the security and accuracy of the input data, in one optional implementation, the acquisition unit includes:

[0102] The first acquisition module is used to extract the session token from the dialogue request and perform identity verification based on the session token and the user registration information stored in the database.

[0103] The first processing module is used to check the request frequency and memory length of the dialogue request after the identity verification is passed.

[0104] The second processing module is used to match the dialogue request with the preset questions and answers if the check passes, and if the match is successful, to send the answer corresponding to the preset questions and answers back to the user terminal through an event stream.

[0105] The third processing module is used to filter sensitive words, abnormal instructions, and prompt words in the dialogue request when no match is found, so as to obtain user input data.

[0106] In order to extract key features from user input data, in one optional implementation, the first processing unit includes:

[0107] The second acquisition module is used to extract preset fields from the preset parameter template, and determine the parameter values ​​corresponding to the matched fields based on the matching of the preset fields with the user input data, so as to obtain the second query parameters.

[0108] The third acquisition module is used to obtain the parameter values ​​corresponding to the preset fields by engaging in a question-and-answer session with the user based on the preset fields in the dialog interface when no match is found in the preset fields, and thus obtain the third query parameters.

[0109] The first determining module is used to determine the first query parameter based on the second query parameter and the third query parameter.

[0110] To obtain the aforementioned domain data table structure, in one optional implementation, the query unit includes:

[0111] The first calculation module is used to calculate the semantic similarity between user intent and the data table structure of each domain in the database using the BGE model, and obtain multiple first similarities.

[0112] The second calculation module is used to calculate the semantic similarity between the first query parameters and the data table structures of various domains in the database using the BGE model, and obtain multiple second similarities.

[0113] The third calculation module is used to perform a weighted summation of each first similarity and its corresponding second similarity to obtain multiple third similarities;

[0114] The second determining module is used to obtain the domain data table structure corresponding to the maximum third similarity value. If the third similarity of the domain data table structure is greater than or equal to the second threshold, the query is determined to be complete and the domain data table structure is output.

[0115] To obtain historical success cases, in one optional implementation, the query unit further includes:

[0116] The fourth calculation module is used to calculate the similarity between user intent and each historical query case in the database using the BGE model, and obtain multiple fourth similarities;

[0117] The fifth calculation module is used to calculate the similarity between the first query parameter and each historical query case in the database using the BGE model, and obtain multiple fifth similarity scores.

[0118] The sixth calculation module is used to perform a weighted summation of each fourth similarity and its corresponding fifth similarity to obtain multiple sixth similarities;

[0119] The fourth processing module is used to obtain historical query cases with a sixth similarity greater than the first threshold, sort the historical query cases from largest to smallest according to the sixth similarity, obtain the target sequence, and truncate the target sequence from front to back with a preset step size to obtain multiple historical query cases.

[0120] To ensure the security of the data analysis process, in one optional implementation, the above-mentioned mixing method further includes:

[0121] The second processing unit is used to generate SQL statements based on prompt words through a large language model to obtain the first target statement, and then use a risk assessment model pre-stored in the database to assess the risk of each first target statement and obtain the risk coefficient.

[0122] The interception unit is used to intercept the first target statement when the risk coefficient is greater than or equal to the third threshold.

[0123] To achieve automated data querying, in one optional implementation, the execution unit includes:

[0124] The first execution module is used to execute the first target statement and, if the execution is successful, obtain the query results.

[0125] The fourth module is used to obtain database error information in the event of execution failure.

[0126] The second execution module is used to input the database error information and the first target statement into the large language model to regenerate the SQL statement, obtain the second target statement, and execute the second target statement to obtain the query results. The number of consecutive generation of the second target statement is less than or equal to the fourth threshold.

[0127] The aforementioned natural language-based conversational data analysis device includes a processor and a memory. The acquisition unit, first execution unit, query unit, generation unit, and execution unit are all stored as program units in the memory. The processor executes these program units stored in the memory to achieve the corresponding functions. All of the above modules reside in the same processor; alternatively, the modules may be located in different processors in any combination.

[0128] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and the efficiency of data analysis can be improved by adjusting kernel parameters.

[0129] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0130] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device containing the computer-readable storage medium to perform the natural language-based conversational data analysis method.

[0131] Specifically, natural language conversational data analysis methods include:

[0132] Step S201: Receive user dialogue request through dialogue interface, perform authentication and preprocessing based on dialogue request, and obtain user input data. Preprocessing includes security detection and preset question-and-answer matching.

[0133] Step S202: Perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameters;

[0134] Step S203: Use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameters that is greater than the first threshold.

[0135] Step S204: Generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0136] Step S205: Execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0137] This invention provides a processor for running a program, wherein the program executes the aforementioned data analysis method based on natural language conversation.

[0138] Specifically, natural language conversational data analysis methods include:

[0139] Step S201: Receive user dialogue request through dialogue interface, perform authentication and preprocessing based on dialogue request, and obtain user input data. Preprocessing includes security detection and preset question-and-answer matching.

[0140] Step S202: Perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameters;

[0141] Step S203: Use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameters that is greater than the first threshold.

[0142] Step S204: Generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0143] Step S205: Execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0144] This invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:

[0145] Step S201: Receive user dialogue request through dialogue interface, perform authentication and preprocessing based on dialogue request, and obtain user input data. Preprocessing includes security detection and preset question-and-answer matching.

[0146] Step S202: Perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameters;

[0147] Step S203: Use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameters that is greater than the first threshold.

[0148] Step S204: Generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0149] Step S205: Execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0150] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:

[0151] Step S201: Receive user dialogue request through dialogue interface, perform authentication and preprocessing based on dialogue request, and obtain user input data. Preprocessing includes security detection and preset question-and-answer matching.

[0152] Step S202: Perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameters;

[0153] Step S203: Use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameters that is greater than the first threshold.

[0154] Step S204: Generate prompt words based on user output data, domain data table structure and historical query cases, and generate SQL statements based on prompt words through a large language model to obtain the first target statement;

[0155] Step S205: Execute the first target statement, obtain the query results, and send the query results back to the user terminal via an event stream.

[0156] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0157] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0158] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0159] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0160] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0161] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0162] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0163] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0164] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0165] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0166] As can be seen from the above description, the embodiments of this application achieve the following technical effects:

[0167] 1) The data analysis method based on natural language dialogue in this application firstly receives user dialogue requests through a dialogue interface, performs authentication and preprocessing based on the dialogue requests to obtain user input data. The preprocessing includes security detection and preset question-and-answer matching. Then, semantic analysis is performed on the user input data to obtain user intent. Query parameters are extracted from the user input data using preset parameter templates to obtain the first query parameter. Next, the domain data table structure with the highest semantic similarity to the user intent and the first query parameter is queried using a BGE model. Historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameter are also queried using the BGE model. Then, prompt words are generated based on user output data, domain data table structure, and historical query cases. SQL statements are generated based on the prompt words using a large language model to obtain the first target statement. Finally, the first target statement is executed to obtain the query results, and the query results are returned to the user terminal via an event stream. This application enhances data retrieval by introducing vector retrieval. Based on user input, it queries the vectorized representation of the domain data table structure and historical success cases. Combined with the query results, it generates suggestive words to guide a large language model in automatically generating query statements. This allows business personnel to perform data analysis simply by inputting their needs in natural language, lowering the barrier to entry and reducing the development cycle. It solves the problem in existing technologies where sudden analytical needs from business personnel require developers to create, test, and deploy reports, resulting in high development cycles and barriers to entry, hindering rapid response to analytical demands.

[0168] 2) The data analysis device based on natural language dialogue of this application includes: an acquisition unit receiving user dialogue requests through a dialogue interface, performing authentication and preprocessing based on the dialogue requests to obtain user input data, including security detection and preset question-and-answer matching; a first processing unit performing semantic analysis on the user input data to obtain user intent, extracting query parameters from the user input data using preset parameter templates to obtain first query parameters; a query unit using a BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameters, and using a BGE model to query historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameters; a generation unit generating prompt words based on user output data, domain data table structure, and historical query cases, and generating SQL statements based on the prompt words using a large language model to obtain a first target statement; and an execution unit executing the first target statement to obtain query results, and sending the query results back to the user terminal via an event stream. This application enhances data retrieval by introducing vector retrieval. Based on user input, it queries the vectorized representation of the domain data table structure and historical success cases. Combined with the query results, it generates suggestive words to guide a large language model in automatically generating query statements. This allows business personnel to perform data analysis simply by inputting their needs in natural language, lowering the barrier to entry and reducing the development cycle. It solves the problem in existing technologies where sudden analytical needs from business personnel require developers to create, test, and deploy reports, resulting in high development cycles and barriers to entry, hindering rapid response to analytical demands.

[0169] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A data analysis method based on natural language conversation, characterized in that, include: The system receives user dialogue requests through a dialogue interface, performs authentication and preprocessing based on the dialogue requests, and obtains user input data. The preprocessing includes security detection and preset question-and-answer matching. Semantic analysis is performed on the user input data to obtain the user intent, and query parameters are extracted from the user input data using a preset parameter template to obtain the first query parameter; The domain data table structure with the highest semantic similarity to the user intent and the first query parameters is queried using the BGE model. Historical query cases with semantic similarity greater than a first threshold to the user intent and the first query parameters are also queried using the BGE model. Based on the user output data, the domain data table structure, and the historical query cases, prompt words are generated, and an SQL statement is generated based on the prompt words using a large language model to obtain the first target statement. The first target statement is executed to obtain the query results, and the query results are sent back to the user terminal via an event stream.

2. The method according to claim 1, characterized in that, Based on the dialogue request, authentication and preprocessing are performed to obtain user input data, including: Extract a session token from the dialogue request, and verify the user's identity by comparing the session token with the user registration information stored in the database; If the identity verification passes, check the request frequency and memory length of the dialogue request; If the check passes, the dialogue request is matched with preset questions and answers. If a match is found, the answer corresponding to the preset questions and answers is sent back to the user terminal via an event stream. If no match is found, the dialogue request is filtered for sensitive words, abnormal instructions, and prompt words to obtain the user input data.

3. The method according to claim 1, characterized in that, The first query parameters are obtained by extracting query parameters from the user input data using a preset parameter template, including: Preset fields are extracted from the preset parameter template, and the parameter values ​​corresponding to the matched fields are determined based on the matching of the preset fields with the user input data to obtain the second query parameters; If the preset field is not matched, the system engages in a question-and-answer session with the user on the dialog interface based on the preset field to obtain the parameter value corresponding to the preset field and thus obtain the third query parameter. The first query parameter is determined based on the second query parameter and the third query parameter.

4. The method according to claim 1, characterized in that, The domain data table structure that has the highest semantic similarity to the user intent and the first query parameters is queried using the BGE model, including: The semantic similarity between the user intent and the structure of each domain data table in the database is calculated using the BGE model to obtain multiple first similarities. The semantic similarity between the first query parameter and the structure of each domain data table in the database is calculated using the BGE model to obtain multiple second similarities. The first similarity scores are weighted and summed with their corresponding second similarity scores to obtain multiple third similarity scores. Obtain the domain data table structure corresponding to the maximum value of the third similarity. If the third similarity corresponding to the domain data table structure is greater than or equal to the second threshold, determine that the query is complete and output the domain data table structure.

5. The method according to claim 1, characterized in that, Using the BGE model to query historical query cases where the semantic similarity between the query and the user intent and the first query parameters is greater than a first threshold includes: The BGE model is used to calculate the similarity between the user intent and each of the historical query cases in the database, resulting in multiple fourth similarities. The similarity between the first query parameter and each of the historical query cases in the database is calculated using the BGE model to obtain multiple fifth similarities. The fourth similarity scores are weighted and summed with the corresponding fifth similarity scores to obtain multiple sixth similarity scores; Obtain the historical query cases whose sixth similarity is greater than the first threshold, sort the historical query cases from largest to smallest according to the sixth similarity to obtain the target sequence, and truncate the target sequence from front to back with a preset step size to obtain multiple historical query cases.

6. The method according to claim 1, characterized in that, After generating an SQL statement based on the prompt words using a large language model to obtain the first target statement, the method further includes: The risk assessment model stored in the database is used to assess the risk of each of the first target statements and obtain the risk coefficient. If the risk coefficient is greater than or equal to the third threshold, the first target statement is intercepted.

7. The method according to claim 1, characterized in that, Executing the first target statement yields the query results, including: Execute the first target statement, and if the execution is successful, obtain the query results; If the execution fails, retrieve the database error information; The database error information and the first target statement are input into the large language model to regenerate the SQL statement, resulting in the second target statement. The second target statement is then executed to obtain the query result, wherein the number of consecutive generation times of the second target statement is less than or equal to the fourth threshold.

8. A data analysis device based on natural language dialogue, characterized in that, The device includes: The acquisition unit is used to receive user dialogue requests through a dialogue interface, perform authentication and preprocessing based on the dialogue requests, and obtain user input data. The preprocessing includes security detection and preset question-and-answer matching. The first processing unit is used to perform semantic analysis on the user input data to obtain the user intent, and extract query parameters from the user input data using a preset parameter template to obtain the first query parameter; The query unit is used to use the BGE model to query the domain data table structure with the highest semantic similarity to the user intent and the first query parameter, and to use the BGE model to query historical query cases with semantic similarity to the user intent and the first query parameter that is greater than a first threshold. The generation unit is used to generate prompt words based on the user output data, the domain data table structure and the historical query cases, and generate an SQL statement based on the prompt words through a large language model to obtain the first target statement; The execution unit is used to execute the first target statement, obtain the query result, and send the query result back to the user terminal via an event stream.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 7.

10. An electronic device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising methods for performing any one of claims 1 to 7.