Intelligent report generation method, system and equipment based on NL2SQL (Non-Layer 2Structured Query Language) and medium

By building scenario tables and integrating data with ETL tools, and combining LSTM models and graph databases to generate and review SQL code, we solved the adaptation and optimization issues of NL2SQL technology in enterprise-level applications, and achieved efficient and accurate report generation and user-friendly data analysis.

CN120596499APending Publication Date: 2025-09-05山东浪潮智能生产技术有限公司
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510711079.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-29
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

The existing NL2SQL technology in enterprise-level applications has insufficient adaptability to multi-source heterogeneous data, unstable SQL statement quality, and a lack of business scenario optimization, resulting in low query efficiency and system failures, making it difficult to meet the complex analysis needs of enterprises.

Method used

Build scenario tables and use ETL tools for data integration. Identify query intent through LSTM models. Combine graph databases and scenario SQL template libraries to generate and review SQL code to achieve automatic conversion from natural language to database queries.

Benefits of technology

It improves data integration efficiency and accuracy, reduces labor costs, enhances report generation stability and user experience, and meets the complex analysis needs of enterprises.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596499A_ABST
    Figure CN120596499A_ABST
Patent Text Reader

Abstract

The invention provides an intelligent report generation method, system and device based on NL2SQL and a medium, and belongs to the technical field of data processing and report generation. The method comprises the steps that data of all business systems of an enterprise are obtained, scene tables are constructed according to five dimensions of personnel, equipment, products, quality and production, and the corresponding relation between fields of each scene table and business system fields is determined; regularly extracting data from a business system in an incremental extraction mode, processing the data, and storing the processed data in a corresponding scene table; in response to a natural language query request of a user, identifying a query intention, matching and retrieving a pre-constructed scene SQL template library and a scene prompt word library through the query intention, and determining an associated scene table; and generating an SQL code based on a matching retrieval result, performing auditing, executing the SQL code passing the auditing to the associated scene table to generate a report, and displaying the generated report to the user in a front-end adaptation mode. According to the invention, enterprise data integration and report automatic generation are realized, and efficiency and accuracy are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the technical field of data processing and report generation, and specifically relates to an NL2SQL-based intelligent report generation method, system, device, and medium. Background Art

[0002] With the development of enterprise informatization, the data generated by various business systems (such as ERP, MES, and CRM) has grown exponentially. However, this data is often scattered across different business systems and faces the following conflicts: First, data structure and semantics are inconsistent. Different systems use different data encoding methods, naming conventions, and storage formats. Second, data redundancy and duplication occur. The same information is stored repeatedly in different systems and in different formats. Third, data quality issues exist. There are missing data, outliers, and even incomplete data for some key business data, which affects the accuracy of data analysis. Fourth, report generation is inefficient. Traditional methods require technical personnel to manually write complex SQL query statements, which is labor-intensive, time-consuming, and prone to errors. Business personnel cannot directly access data and are heavily dependent on technical support.

[0003] While the current NL2SQL (Natural Language to SQL) approach can convert users' natural language queries into database query statements, it suffers from the following limitations in enterprise applications: First, existing NL2SQL systems lack adaptability to multi-source, heterogeneous data, making it difficult to effectively handle the complex data structures and semantic differences found in enterprise environments. Second, the quality of generated SQL statements varies, and a lack of validation and review can lead to inefficient queries and even system failures. Finally, they lack optimization for specific business scenarios and are unable to meet the complex analytical needs of enterprises. Summary of the Invention

[0004] In a first aspect, an embodiment of the present application provides an NL2SQL-based intelligent report generation method, comprising the following steps: S1. Obtain data from each business system of the enterprise and construct scenario tables based on personnel, equipment, product, quality, and production dimensions. Determine the correspondence between the fields in each scenario table and the fields in the business system. S2. Use ETL tools to periodically extract data from the business system in an incremental manner, process it, and then save it to the corresponding scenario table; S3. Respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; S4. Generate SQL code based on the matching search results and conduct an audit. Execute the audited SQL code to the associated scenario table to generate a report, and display the generated report to the user through the front-end adaptation method.

[0005] Furthermore, the specific steps of step S1 are as follows: S11. Construct scenario tables based on the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and predefine the logical structure of each scenario table and the relationship between dimension tables; S12. By analyzing the foreign key constraints and semantic relationships of each business system data, determine the mapping relationship between the scenario table and the business system data fields and the associated fields between the dimension tables; S13. Determine the association relationship based on the association fields between dimension tables and use Neo4j to build a graph database.

[0006] Furthermore, the specific steps of step S2 are as follows: S21. Use ETL tools to extract data from each business system based on the set timestamp after the last timestamp extraction; S22. The extracted data is cleaned using the cluster detection algorithm, and after data standardization, it is saved in the corresponding dimension table according to the mapping relationship.

[0007] Furthermore, the specific steps of step S3 are as follows: S31. Build a scenario-wide SQL template for each dimension, and use placeholders to identify variable parameters in the scenario-wide SQL template; S32. Build a scene prompt word library, add thinking chain prompt word templates, instruction fine-tuning prompt word templates, few-shot learning prompt word templates, role prompt prompt templates; S33. Receive a natural language query request input by the user, perform semantic understanding and feature extraction through the LSTM model, and determine the query intent; S34. Match the query intent with the association relationships stored in the graph database, generate a gallery matching result, and determine the relevant scenario; S35. Match the user input with the alias database of the dimension table, identify the keywords using the alias, and convert the corresponding keywords into aliases in the scenario table; S36. Match the query intent with the scenario-wide SQL template. If the match fails, match the query intent with the historical SQL database to obtain the historical SQL with the highest similarity. S37. Filter the business entities and related scenarios involved in the query intent from the scenario table to generate the target table required for SQL; S38. Match the required type of prompt word template from the scene prompt word library according to the relevant scenarios and data characteristics of the query intent; S39. Retrieve the preset data dictionary according to the query intent, search and filter the relevant fields involved, and determine the field information.

[0008] Furthermore, the specific steps of step S36 are as follows: S361. Convert the natural language corresponding to the query intent and the natural language description of the scene SQL target into vectors through the pre-trained model, and calculate the cosine similarity; If the similarity is higher than the threshold, it is determined that the match is successful and the process goes to step S37; If the similarity is less than the threshold, proceed to step S362; S362. Obtain a historical SQL database, and retrieve the top N historical SQLs similar to the query intent from the historical SQL database based on similarity. Associate metadata such as a natural language description, a business scenario label, and usage frequency metadata with each historical SQL; S363. Based on weighted sorting based on similarity and usage frequency, use the historical SQL with the highest overall score; S364. Check whether the tables and fields involved in the historical SQL are consistent with the current database matching results; If not, discard the historical SQL and search again, and return to step S362; If so, go to step S37.

[0009] Furthermore, the specific steps of step S4 are as follows: S41. Determine whether the scenario-wide SQL template is matched; If yes, go to step S42; If not, proceed to step S43; S42. Generate SQL code based on the query intent, the library matching results, the matching field information and the variable parameters of the matching alias replacement placeholders, and proceed to step S44. S43 obtains the matching history SQL, according to the matching prompt word template guide through the large model based on the library matching results, matching field information and matching alias to adapt the historical SQL, generate SQL code; S44. Review the generated SQL code using a large model combined with the SVM algorithm; If the review is successful, proceed to step S45; If the audit fails, return to step S33 or step S41; S45. Connect to the target table, execute the generated SQL code to obtain the query data, and filter it according to business needs; S46. Generate a table for the filtered query data in a format adapted to the front end and return it to the user.

[0010] Furthermore, the specific steps of step S44 are as follows: S441. Perform syntax review of SQL code using an SQL parser; S442. Use support vector machine classifier to judge the logical rationality of SQL; S443. Use the large model to verify the consistency of the generated SQL code with the user's intention; S444. Determine whether the SQL code review is completed; If yes, go to step S45; If not, proceed to step S445; S445. Determine whether the audit process exceeds the preset timeout threshold; If yes, return to step S33 or step S41; If not, wait for the review to be completed and return to step S441.

[0011] In a second aspect, an embodiment of the present application further provides an NL2SQL-based intelligent report generation system, comprising: The scenario table construction module is used to obtain data from various business systems of the enterprise and construct scenario tables according to the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and determine the correspondence between the fields in each scenario table and the fields in the business system; The data extraction module is used to use ETL tools to periodically extract data from the business system in an incremental manner, process it, and then save it to the corresponding scenario table; The intent recognition and matching module is used to respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; The SQL code generation and execution module is used to generate and review SQL code based on matching search results, execute the reviewed SQL code on the associated scene table to generate a report, and display the generated report to the user through front-end adaptation.

[0012] In a third aspect, an embodiment of the present application further provides an electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the NL2SQL-based intelligent report generation method as described in the first aspect are implemented.

[0013] In a fourth aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the NL2SQL-based intelligent report generation method as described in the first aspect are implemented.

[0014] It can be seen from the above technical solutions that this application has the following advantages: The NL2SQL-based intelligent report generation method, system, device, and medium provided in this application construct a scenario table using five dimensions and regularly extract data in an incremental extraction manner using ETL tools. This method can efficiently integrate scattered data from various business systems of an enterprise, solve the problems of inconsistent data structure and semantics, data redundancy, and duplication, and provide a data foundation for subsequent report generation. By combining query intent matching to retrieve a scenario SQL template library and a scenario prompt vocabulary library, and through an audit mechanism, accurate SQL code is generated, effectively avoiding low query efficiency and even system failures caused by SQL statement quality issues, and improving the stability and reliability of report generation. By responding to users' natural language query requests and integrating natural language processing and matching strategies, query intent can be quickly identified and corresponding SQL code can be generated. This eliminates the need for technicians to manually write complex SQL query statements, reduces the workload and time cost of report generation, improves the efficiency of report generation, and enables business personnel to obtain the required data in a timely manner. Reports are presented to users in a front-end adaptation manner, making the report display more intuitive. The entire process is driven by users' natural language queries, lowering the usage threshold of report generation, improving the user experience, and enabling business personnel to conveniently perform data analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0016] Figure 1 The figure is a flow chart of the NL2SQL-based intelligent report generation method of the present invention.

[0017] Figure 2 Schematic diagram of the NL2SQL-based intelligent report generation system of the present invention. DETAILED DESCRIPTION

[0018] The following detailed description of the specific steps of the NL2SQL-based intelligent report generation method will further fully describe various embodiments of the present disclosure. The present disclosure is capable of various embodiments, and modifications and variations therein are possible. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein. Instead, the present disclosure is to be construed as encompassing all modifications, equivalents, and / or alternatives falling within the spirit and scope of the various embodiments of the present disclosure.

[0019] For example, in today's enterprise informatization process, the amount of data generated by various business systems, such as ERP, MES, and CRM, is growing exponentially. However, this massive amount of data is stored disparately across different business systems, presenting a series of urgent problems. First, there are inconsistencies in data structure and semantics. Each system has its own independent approach to data encoding, naming conventions, and storage formats, lacking unified standards. Second, data redundancy and duplication are prominent. The same information is stored multiple times in different systems, and each storage format may vary. Third, data quality varies. Missing data and outliers are common, and some critical business data may even be incomplete. These problems pose a serious threat to the accuracy of data analysis. Finally, traditional report generation methods are inefficient. Currently, report generation relies primarily on technical personnel manually writing complex SQL queries. This method is not only labor-intensive and time-consuming, but also prone to errors. It makes it difficult for business personnel to directly obtain the required data, significantly limiting the improvement of enterprise operational efficiency.

[0020] Although NL2SQL (natural language to SQL) technology can, to a certain extent, convert users' natural language queries into database query statements, it still has many limitations in actual enterprise-level application environments. First, existing NL2SQL systems lack adaptability when faced with complex and ever-changing multi-source heterogeneous data, making it difficult to effectively address the data structure and semantic differences between different systems. Second, after generating SQL statements, the lack of a comprehensive verification and audit process makes the quality of the generated SQL statements unstable, which can lead to inefficient queries and even system failures. Finally, the technology lacks in-depth optimization for specific business scenarios and cannot meet the needs of enterprises for complex business analysis, limiting the further development of enterprises in data-driven decision-making.

[0021] To address the above issues, this embodiment provides an intelligent report generation method based on NL2SQL, which integrates multi-source data, constructs scenario tables and intelligently generates reports, thereby improving efficiency and accuracy and reducing labor costs.

[0022] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0023] See also Figure 1 FIG. 1 is a flow chart of a method for generating an intelligent report based on NL2SQL in a specific embodiment, wherein the method comprises the following steps: S1. Obtain data from each business system of the enterprise and construct scenario tables based on personnel, equipment, product, quality, and production dimensions. Determine the correspondence between the fields in each scenario table and the fields in the business system. It should be noted that by acquiring data from various business systems of an enterprise and constructing scenario tables according to five dimensions, it is possible to integrate and normalize data scattered across different business systems, clarify the correspondence and association relationships between the data, and establish a unified data framework for subsequent data query and report generation. This solves the problems of inconsistent data structure and semantics, data redundancy and duplication, and improves data availability and management efficiency. S2. Use ETL tools to periodically extract data from the business system in an incremental manner, process it, and then save it to the corresponding scenario table; It should be noted that using ETL tools to incrementally extract data from the business system regularly, process it, and then save it to the corresponding scenario table ensures that the data in the scenario table can be updated in a timely manner, maintaining consistency and timeliness with the business system data. The incremental extraction method reduces the amount of data processing and improves the efficiency of data extraction. At the same time, data quality is further improved through data processing processes (such as cleaning and standardization), providing data support for subsequent SQL queries and report generation based on the scenario table. S3. Respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; It should be noted that the system responds to users' natural language query requests, identifies query intent, and determines the associated scenario table by matching and retrieving the scenario SQL template library and scenario prompt vocabulary, thus realizing the automatic conversion from user natural language to database query. Through natural language processing and matching strategies, it can quickly and accurately understand user needs and convert complex natural language queries into a form that the system can understand and process, providing a basis for subsequent SQL code generation, improving the efficiency of report generation, and reducing dependence on technical personnel. S4. Generate SQL code based on the matching search results and review it, execute the approved SQL code to generate a report on the associated scene table, and display the generated report to the user through the front-end adaptation method; It should be noted that generating SQL code based on matching search results and conducting an audit, executing the audited SQL code on the associated scenario table to generate a report, and presenting the report to the user through front-end adaptation are the key execution links in the entire report generation process; by generating and auditing SQL code, the accuracy of the query and the stability of the system are ensured; executing SQL code to generate reports and performing front-end adaptation and display realizes the intuitive presentation of query results to users, completing the conversion from data to reports, and meeting users' needs for report generation.

[0024] This embodiment improves the efficiency and accuracy of report generation from the entire process of data acquisition, scenario table construction, data extraction, user intent identification and matching to SQL code generation, review and report presentation, solves the current problems of difficult data integration, uneven SQL generation quality, and low report generation efficiency, and realizes intelligent report generation.

[0025] Furthermore, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another intelligent report generation method based on NL2SQL is provided, which includes the following steps: S1. Obtain data from each business system of the enterprise and construct a scenario table based on the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension. Determine the correspondence between the fields in each scenario table and the fields in the business system. The specific steps of step S1 are as follows: S11. Construct scenario tables based on the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and predefine the logical structure of each scenario table and the relationship between dimension tables; For example, the personnel dimension scenario table includes fields for employee number, name, and department, and is associated with the equipment operation record table through the employee number; The equipment dimension scenario table includes fields for equipment number, status, and maintenance history, and is associated with the production record table through the equipment number; S12. By analyzing the foreign key constraints and semantic relationships of each business system data, determine the mapping relationship between the scenario table and the business system data fields and the associated fields between the dimension tables; Specifically, the Apriori association rule mining algorithm is used to analyze the frequent item sets of the original business data, and the association fields between the five-dimensional tables are determined accordingly; Take the transaction item set of the original business data (such as {equipment A, product B, fault type C}) as input, output frequent item sets (such as {equipment A, product B} support = 0.85), and use this to determine the product ID field associated with the equipment table and the product table; for example, the parameters can be set to minimum support = 0.7 and minimum confidence = 0.8; S13. Determine the association relationships based on the association fields between dimension tables and build a graph database using Neo4j. For example, Neo4j is used to construct personnel, equipment, and product nodes, and to construct personnel-equipment and equipment-product relationship types; S2. Use ETL tools to periodically extract data from the business system in an incremental manner, process it, and save it to the corresponding scenario table. The specific steps of step S2 are as follows: S21. Use ETL tools to extract data from each business system based on the set timestamp after the last timestamp extraction; S22. The extracted data is cleaned using a cluster detection algorithm, and after data standardization, it is saved in the corresponding dimension table according to the mapping relationship; Specifically, a statistical outlier detection algorithm is used to clean the data, such as the Z-score method; for a set of data ; Calculate its statistical characteristics, such as mean , standard deviation , and then calculate the Z-score value of each data point When Zi exceeds the set threshold, such as 3, the data point is treated as an outlier and processed, such as correction or deletion; The Min-Max normalization algorithm is used to standardize data, unify the data formats, encodings and naming conventions of different systems, and map the data to the [0,1] interval; for the original data x, the standardized value ,in and are the minimum and maximum values ​​of the data set, respectively; S3 responds to the user's natural language query request, identifies the query intent, retrieves the pre-built scene SQL template library and scene prompt vocabulary through query intent matching, and determines the associated scene table; the specific steps of step S3 are as follows: S31. Build a scenario-wide SQL template for each dimension, and use placeholders to identify variable parameters in the scenario-wide SQL template; S32. Build a scene prompt word library, add thinking chain prompt word templates, instruction fine-tuning prompt word templates, few-shot learning prompt word templates, role prompt prompt templates; It should be noted that thought chain prompts guide SQL generation logic by breaking down business problems step by step; instruction fine-tuning prompts can embed business keywords to clarify query requirements; few-shot learning prompts train models based on historical query samples to adapt to specific scenarios; and role prompts set model roles to generate SQL that meets professional standards. S33. Receive a natural language query request input by the user, perform semantic understanding and feature extraction through the LSTM model, and determine the query intent; S34. Match the query intent with the association relationships stored in the graph database, generate a gallery matching result, and determine the relevant scenario; S35. Match the user input with the alias database of the dimension table, identify the keywords using the alias, and convert the corresponding keywords into aliases in the scenario table; S36. Match the query intent with the scenario-wide SQL template. If the match fails, match the query intent with the historical SQL database to obtain the historical SQL with the highest similarity. The specific steps of step S36 are as follows: S361. Convert the natural language corresponding to the query intent and the natural language description of the scene SQL target into vectors through the pre-trained model, and calculate the cosine similarity; If the similarity is higher than the threshold, it is determined that the match is successful and the process goes to step S37; If the similarity is less than the threshold, proceed to step S362; S362. Obtain a historical SQL database, and retrieve the top N historical SQLs similar to the query intent from the historical SQL database based on similarity. Associate metadata such as a natural language description, a business scenario label, and usage frequency metadata with each historical SQL; S363. Based on weighted sorting based on similarity and usage frequency, use the historical SQL with the highest overall score; S364. Check whether the tables and fields involved in the historical SQL are consistent with the current database matching results; If not, discard the historical SQL and search again, and return to step S362; If yes, go to step S37; S37. Filter the business entities and related scenarios involved in the query intent from the scenario table to generate the target table required for SQL; S38. Match the required type of prompt word template from the scene prompt word library according to the relevant scenarios and data characteristics of the query intent; S39. Retrieve the preset data dictionary according to the query intent, search and filter the relevant fields involved, and determine the field information; S4. Generate SQL code based on the matching search results and conduct an audit. Execute the audited SQL code to generate a report for the associated scene table, and display the generated report to the user through the front-end adaptation method. The specific steps of step S4 are as follows: S41. Determine whether the scenario-wide SQL template is matched; If yes, go to step S42; If not, proceed to step S43; S42. Generate SQL code based on the query intent, the library matching results, the matching field information and the variable parameters of the matching alias replacement placeholders, and proceed to step S44. S43 obtains the matching history SQL, according to the matching prompt word template guide through the large model based on the library matching results, matching field information and matching alias to adapt the historical SQL, generate SQL code; S44. Review the generated SQL code using a large model combined with the SVM algorithm; If the review is successful, proceed to step S45; If the audit fails, return to step S33 or step S41; The specific steps of step S44 are as follows: S441. Perform syntax review of SQL code using an SQL parser; Specifically, syntax review includes checking the correct spelling of keywords (such as SELECT instead of SELEC), checking whether the table name and field name exist, and checking whether the JOIN conditions are complete; S442. Use support vector machine classifier to judge the logical rationality of SQL; Specifically, the SQL structure (such as the subquery nesting depth), query condition combination (such as whether the time range is reasonable), and table association relationship (such as whether the foreign key constraint matches) are input into the support vector machine classifier; it is determined whether the confidence level of the support vector machine output is greater than the threshold. If so, it is determined to be logically legal; S443. Use the large model to verify the consistency of the generated SQL code with the user's intention; S444. Determine whether the SQL code review is completed; If yes, go to step S45; If not, proceed to step S445; S445. Determine whether the audit process exceeds the preset timeout threshold; If yes, return to step S33 or step S41; If not, wait for the review to be completed and return to step S441; S45. Connect to the target table, execute the generated SQL code to obtain the query data, and filter it according to business needs; S46. Generate a table for the filtered query data in a format adapted to the front end and return it to the user.

[0026] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0027] like Figure 2 As shown, the following is an embodiment of the NL2SQL-based intelligent report generation system provided by the embodiment of the present disclosure. The system and the NL2SQL-based intelligent report generation method of the above-mentioned embodiments belong to the same inventive concept. For details not fully described in the embodiment of the NL2SQL-based intelligent report generation system, please refer to the embodiment of the above-mentioned NL2SQL-based intelligent report generation method.

[0028] The system includes: The scenario table construction module is used to obtain data from various business systems of the enterprise and construct scenario tables according to the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and determine the correspondence between the fields in each scenario table and the fields in the business system; The data extraction module is used to use ETL tools to periodically extract data from the business system in an incremental manner, process it, and then save it to the corresponding scenario table; The intent recognition and matching module is used to respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; The SQL code generation and execution module is used to generate and review SQL code based on matching search results, execute the reviewed SQL code on the associated scene table to generate a report, and display the generated report to the user through front-end adaptation.

[0029] This embodiment integrates multi-source data, constructs scenario tables, and intelligently generates reports through the interactive collaboration of the scenario table construction module, data extraction module, intent recognition and matching module, and SQL code generation and execution module, thereby improving efficiency and accuracy and reducing labor costs.

[0030] The NL2SQL-based intelligent report generation method provided in the embodiments of the present application can be applied to electronic devices. Those skilled in the art will understand that the electronic device structure involved in the embodiments of the present invention does not constitute a limitation on the electronic device, and the electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. In the embodiments of the present invention, the electronic device includes but is not limited to a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.

[0031] The electronic device may include a processor, an external memory interface, an internal memory, a universal serial bus (USB) interface, a charging management module, a power management module, a battery, a wireless communication module, an audio module, a speaker, a microphone, a sensor module, a button, a camera, a display, and a SIM card interface, etc.

[0032] It is understood that the structures illustrated in the embodiments of the present application do not constitute specific limitations on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown, or combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0033] A processor may include one or more processing units, such as a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0034] The processor can be the nerve center and command center of the electronic device. The controller can generate operation control signals based on the instruction opcode and timing signal to complete the control of instruction fetching and execution.

[0035] The processor may also include a memory for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. This memory can store instructions or data that the processor has just used or is reusing. If the processor needs to use the instruction or data again, it can directly call it from the memory. This avoids repeated accesses, reduces processor latency, and thus improves system efficiency.

[0036] The electronic device implements the NL2SQL-based intelligent report generation method of the present application X, which obtains data from various business systems of an enterprise, constructs scenario tables according to personnel, equipment, product, quality, and production dimensions, and determines the correspondence between fields in each scenario table and fields in the business system; uses an ETL tool to periodically extract data from the business system in an incremental extraction manner, processes it, and then saves it in the corresponding scenario table; responds to user natural language query requests, identifies query intent, and retrieves a pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching to determine the associated scenario table; generates and reviews SQL code based on the matching retrieval results, executes the approved SQL code on the associated scenario table to generate a report, and displays the generated report to the user through a front-end adaptation method. This technical solution achieves the beneficial effects of integrating multi-source data, constructing scenario tables, and intelligently generating reports, improving efficiency and accuracy, and reducing labor costs.

[0037] The storage medium provided in this application stores a program product that can implement an intelligent report generation method based on NL2SQL.

[0038] The intelligent report generation method based on NL2SQL includes: obtaining data from various business systems of the enterprise, and constructing scenario tables according to personnel dimensions, equipment dimensions, product dimensions, quality dimensions, and production dimensions, and determining the correspondence between the fields of each scenario table and the fields in the business system; using ETL tools to regularly extract data from the business system in an incremental extraction manner, processing it, and then saving it to the corresponding scenario table; responding to the user's natural language query request, identifying the query intent, and retrieving the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching to determine the associated scenario table; generating SQL code based on the matching retrieval results and reviewing it, executing the approved SQL code on the associated scenario table to generate a report, and presenting the generated report to the user through front-end adaptation.

[0039] In some possible implementations, the NL2SQL-based intelligent report generation method of the present disclosure can be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps of various exemplary implementations of the present disclosure described in the above "Exemplary Method" section of this specification.

[0040] The storage medium of the present disclosure can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or component of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0041] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not limited to the embodiments shown herein but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. An intelligent report generation method based on NL2SQL, characterized in that: The steps include: S1. Obtain data from each business system of the enterprise and construct scenario tables based on personnel, equipment, product, quality, and production dimensions. Determine the correspondence between the fields in each scenario table and the fields in the business system. S2. Use ETL tools to periodically extract data from the business system in an incremental manner, process it, and save it to the corresponding scenario table; S3. Respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; S4. Generate SQL code based on the matching search results and conduct an audit. Execute the audited SQL code to the associated scenario table to generate a report. The generated report is then displayed to the user through front-end adaptation.

2. The NL2SQL-based intelligent report generation method according to claim 1, characterized in that: The specific steps of step S1 are as follows: S11. Construct scenario tables based on the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and predefine the logical structure of each scenario table and the relationship between dimension tables; S12. By analyzing the foreign key constraints and semantic relationships of each business system data, determine the mapping relationship between the scenario table and the business system data fields and the associated fields between the dimension tables; S13. Determine the association relationship based on the association fields between dimension tables and use Neo4j to build a graph database.

3. The intelligent report generation method based on NL2SQL according to claim 2, characterized in that: The specific steps of step S2 are as follows: S21. Use ETL tools to extract data from each business system based on the set timestamp after the last timestamp extraction; S22. The extracted data is cleaned using the cluster detection algorithm, and after data standardization, it is saved in the corresponding dimension table according to the mapping relationship.

4. The intelligent report generation method based on NL2SQL according to claim 3, characterized in that: The specific steps of step S3 are as follows: S31. Build a scenario-wide SQL template for each dimension, and use placeholders to identify variable parameters in the scenario-wide SQL template; S32. Build a scene prompt word library, add thinking chain prompt word templates, instruction fine-tuning prompt word templates, few-shot learning prompt word templates, role prompt prompt templates; S33. Receive a natural language query request input by the user, perform semantic understanding and feature extraction through the LSTM model, and determine the query intent; S34. Match the query intent with the association relationships stored in the graph database, generate a gallery matching result, and determine the relevant scenario; S35. Match the user input with the alias database of the dimension table, identify the keywords using the alias, and convert the corresponding keywords into aliases in the scenario table; S36. Match the query intent with the scenario-wide SQL template. If the match fails, match the query intent with the historical SQL database to obtain the historical SQL with the highest similarity. S37. Filter the business entities and related scenarios involved in the query intent from the scenario table to generate the target table required for SQL; S38. Match the required type of prompt word template from the scene prompt word library according to the relevant scenarios and data characteristics of the query intent; S39. Retrieve the preset data dictionary according to the query intent, search and filter the relevant fields involved, and determine the field information.

5. The intelligent report generation method based on NL2SQL according to claim 4, characterized in that: The specific steps of step S36 are as follows: S361. Convert the natural language corresponding to the query intent and the natural language description of the scene SQL target into vectors through the pre-trained model, and calculate the cosine similarity; If the similarity is higher than the threshold, it is determined that the match is successful and the process goes to step S37; If the similarity is less than the threshold, proceed to step S362; S362. Obtain a historical SQL database, and retrieve the top N historical SQLs similar to the query intent from the historical SQL database based on similarity. Associate metadata such as a natural language description, a business scenario label, and usage frequency metadata with each historical SQL; S363. Based on weighted sorting based on similarity and usage frequency, use the historical SQL with the highest overall score; S364. Check whether the tables and fields involved in the historical SQL are consistent with the current database matching results; If not, discard the historical SQL and search again, and return to step S362; If so, go to step S37.

6. The NL2SQL-based intelligent report generation method according to claim 4, characterized in that: The specific steps of step S4 are as follows: S41. Determine whether the scenario-wide SQL template is matched; If yes, go to step S42; If not, proceed to step S43; S42. Generate SQL code based on the query intent, the library matching results, the matching field information and the variable parameters of the matching alias replacement placeholders, and proceed to step S44. S43 obtains the matching history SQL, according to the matching prompt word template guide through the large model based on the library matching results, matching field information and matching alias to adapt the historical SQL, generate SQL code; S44. Review the generated SQL code using a large model combined with the SVM algorithm; If the review is successful, proceed to step S45; If the audit fails, return to step S33 or step S41; S45. Connect to the target table, execute the generated SQL code to obtain the query data, and filter it according to business needs; S46. Generate a table for the filtered query data in a format adapted to the front end and return it to the user.

7. The NL2SQL-based intelligent report generation method according to claim 6, characterized in that: The specific steps of step S44 are as follows: S441. Perform syntax review of SQL code using an SQL parser; S442. Use support vector machine classifier to judge the logical rationality of SQL; S443. Use the large model to verify the consistency of the generated SQL code with the user's intention; S444. Determine whether the SQL code review is completed; If yes, go to step S45; If not, proceed to step S445; S445. Determine whether the audit process exceeds the preset timeout threshold; If yes, return to step S33 or step S41; If not, wait for the review to be completed and return to step S441.

8. An intelligent report generation system based on NL2SQL, characterized in that: include: The scenario table construction module is used to obtain data from various business systems of the enterprise and construct scenario tables according to the personnel dimension, equipment dimension, product dimension, quality dimension, and production dimension, and determine the correspondence between the fields in each scenario table and the fields in the business system; The data extraction module is used to use ETL tools to periodically extract data from the business system in an incremental manner, process it, and then save it to the corresponding scenario table; The intent recognition and matching module is used to respond to the user's natural language query request, identify the query intent, retrieve the pre-built scenario SQL template library and scenario prompt vocabulary through query intent matching, and determine the associated scenario table; The SQL code generation and execution module is used to generate and review SQL code based on matching search results, execute the reviewed SQL code on the associated scene table to generate a report, and display the generated report to the user through front-end adaptation.

9. An electronic device, characterized in that: The invention comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the NL2SQL-based intelligent report generation method according to any one of claims 1 to 7 are implemented.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the NL2SQL-based intelligent report generation method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • ERP report AI intelligent generation method and system based on natural language interaction

    CN121277968A

  • A method and system for generating a vehicle fleet report dynamically based on natural language intent analysis

    CN122594367A