Conversational database query method and device based on large language model agent

Through the agent query database method based on large language model, the existing natural language query database solutions have solved the problems of low query accuracy, insufficient understanding of business rules, limited visualization capabilities and difficult integration, and achieved efficient and easy-to-use data Query and analysis, both scalability and compatibility.

CN119494401APending Publication Date: 2025-02-21HASHDATA LTD
View PDF 0 Cites 10 Cited by

Patent Information

Application Number
CN202411487883.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-23
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

Existing natural language query database solutions have problems such as low query accuracy, lack of understanding of business rules and domain-specific knowledge, limited visualization capabilities, slow response speed, and difficulty in seamless integration with existing database systems and BI tools.

Method used

Adopt the agent query database method based on the large language model, and obtain and analyze the query request information, identify the query request intent category, disassemble the query request information, generate SQL statements, and search or use the large language model to generate SQL in the target knowledge base. Statement, execute SQL statements, generate and display the visual code of query results.

Benefits of technology

It greatly improves the efficiency and ease of use of data queries, allowing non-technical users to easily perform complex data analysis, with good scalability and compatibility, and can seamlessly integrate with existing databases and BI systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119494401A_ABST
    Figure CN119494401A_ABST
Patent Text Reader

Abstract

The invention relates to a database query method and device based on a large language model agent and electronic equipment, and the method comprises the steps: obtaining and analyzing query request information, recognizing a query request intention type, carrying out the problem splitting of the query request information according to the query request intention type, and obtaining sub-query request information; searching and obtaining an SQL statement corresponding to the sub-query request information in the target knowledge base according to the category of the query request intention, constructing and generating an SQL statement prompt word and sending the SQL statement prompt word to the large language model when the SQL statement is not searched, executing according to the returned SQL statement to obtain a sub-query result, integrating the sub-query result and obtaining a query result of the query request information, and generating a data visualization code based on the large language model, executing and outputting a query result and a visualization display result thereof. By combining natural language processing, a large language model and a multi-item optimization technology, the efficiency and usability of data query are greatly improved, and non-technical users can conveniently analyze complex data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and in particular to a method, device and electronic device for conversational query of a database based on a large language model intelligent agent. Background Art

[0002] With the advent of the big data era, enterprises and organizations have accumulated a large amount of data assets. However, effectively utilizing these data assets often requires professional database query skills, which is a huge challenge for users with non-technical backgrounds. Traditional database query methods usually require users to master the SQL language, which limits the accessibility and utilization efficiency of data.

[0003] There are some natural language query database solutions on the market, but they usually have the following problems: low query accuracy, especially for complex queries; lack of understanding of business rules and specific domain knowledge; limited visualization capabilities, making it difficult to meet diverse data display needs; lack of optimization for high-frequency queries and slow response speed; and difficulty in seamless integration with existing database systems and BI tools.

[0004] Therefore, there is an urgent need for an intelligent, efficient, and easy-to-use conversational database query system to meet the urgent needs of all walks of life for data analysis. Summary of the invention

[0005] In view of this, the present application proposes a method for querying a database based on a large language model agent to solve the problems reflected in the above-mentioned background technology.

[0006] According to one aspect of the present application, a method for querying a database based on a large language model agent is provided, comprising:

[0007] Get query request information;

[0008] Analyze the query request information to identify the query request intent category;

[0009] Decomposing the query request information according to the query request intention category to obtain sub-query request information;

[0010] Searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information;

[0011] When no corresponding SQL statement is found, a SQL statement prompt word is constructed and sent to the large language model, and the SQL statement returned by the large language model is obtained;

[0012] Execute the SQL statement to obtain a sub-query result corresponding to the sub-query request information;

[0013] The sub-query results are integrated to obtain the query result of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visualization display result are output.

[0014] As an optional implementation scheme of the present application, when no corresponding SQL statement is searched, constructing a generated SQL statement prompt word and sending it to the large language model, and obtaining the SQL statement returned by the large language model, including:

[0015] Obtaining a summary of database composition information of the query request intent category;

[0016] Get business rules;

[0017] Generating SQL statement prompt words by combining the sub-query request information with the database composition information summary and the business rule construction;

[0018] The generated SQL statement prompt word is sent to the large language model, and the SQL statement returned by the large language model is received.

[0019] As an optional implementation scheme of the present application, obtaining a summary of database composition information of the query request intent category includes:

[0020] Determining a related database according to the query request intent category;

[0021] In the associated database, performing semantic similarity calculation on the sub-query request information, and extracting a data table according to a preset semantic similarity threshold;

[0022] The relationship between tables is determined according to the attributes of the data tables, and the relationship between tables and the contents of the data tables are integrated to generate a database composition information summary.

[0023] As an optional implementation scheme of the present application, searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information includes:

[0024] Searching the query request intention category in the target knowledge base to obtain SQL statement retrieval results;

[0025] Constructing a modified SQL statement prompt word according to the SQL statement retrieval result and the sub-query request information and sending the prompt word to the large language model, and receiving a corresponding SQL statement returned by the large language model.

[0026] As an optional implementation scheme of the present application, the sub-query results are integrated to obtain the query result of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visual display result are output, and further includes:

[0027] Obtaining feedback information about the query result;

[0028] When query request information of the same query request intent category is obtained, a prompt word for modifying the SQL statement is constructed in combination with the feedback information and sent to the large language model, and a corresponding SQL statement returned by the large language model is received.

[0029] As an optional implementation scheme of the present application, the sub-query results are integrated to obtain the query result of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visualization display result are output, which also includes:

[0030] Obtaining a request for interpreting the SQL statement;

[0031] The SQL statement is interpreted according to the interpretation request, and an interpretation result is output.

[0032] As an optional implementation scheme of the present application, after analyzing the query request information and identifying the query request intent category, the following further includes:

[0033] Get a custom tool library;

[0034] Determining a target tool for the sub-query request information in the custom tool library according to the query request intent category;

[0035] Obtaining a SQL statement template in the target tool;

[0036] The SQL statement template is adjusted according to the sub-query request information to obtain a corresponding SQL statement and execute it to obtain a sub-query result.

[0037] As an optional implementation scheme of the present application, analyzing the query request information and identifying the query request intent category includes:

[0038] Obtaining historical query records of the query request information;

[0039] Based on historical query records, natural language processing analysis is performed on the query request information to identify the query request intent category.

[0040] The present application also provides a large language model-based intelligent agent query database device, comprising:

[0041] Get request module, used to get query request information;

[0042] An intent category identification module is used to analyze the query request information and identify the query request intent category;

[0043] A request decomposition module, used to decompose the query request information according to the query request intention category to obtain sub-query request information;

[0044] A SQL statement search module is used to search in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information;

[0045] A SQL statement generation module is used to construct a SQL statement prompt word and send it to the large language model when no corresponding SQL statement is searched, and obtain the SQL statement returned by the large language model;

[0046] An SQL statement execution module is used to execute the SQL statement to obtain a sub-query result corresponding to the sub-query request information;

[0047] A query result acquisition module is used to integrate the sub-query results to obtain the query result of the query request information, generate data visualization code corresponding to the query result based on the large language model, execute the data visualization code, and output the query result and its visualization display result.

[0048] The present application also provides an electronic device, including:

[0049] processor;

[0050] a memory for storing processor-executable instructions;

[0051] Wherein, the processor is configured to implement the above-mentioned method of querying the database based on a large language model agent when executing the executable instructions.

[0052] Beneficial effects of this application:

[0053] The present invention obtains query request information, analyzes the query request information, identifies the query request intent category, decomposes the query request information according to the query request intent category, obtains sub-query request information, searches in the target knowledge base according to the query request intent category, obtains the SQL statement corresponding to the sub-query request information, and when the corresponding SQL statement is not found, constructs and generates SQL statement prompt words and sends them to the large language model, obtains the SQL statement returned by the large language model, executes the SQL statement, obtains the sub-query result corresponding to the sub-query request information, integrates the sub-query result, obtains the query result of the query request information, generates the data visualization code corresponding to the query result based on the large language model, executes the data visualization code, and outputs the query result and its visual display result. By combining natural language processing, large language model and multiple optimization technologies, the efficiency and ease of use of data query are greatly improved, so that non-technical users can also easily perform complex data analysis. It also has good scalability and compatibility, and can be seamlessly integrated with existing databases and BI systems.

[0054] Other features and aspects of the present application will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the present application and, together with the description, serve to explain the principles of the present application.

[0056] Figure 1 A flowchart showing a method for querying a database based on a large language model agent according to an embodiment of the present application is shown;

[0057] Figure 2 A system architecture diagram showing a method for querying a database based on a large language model agent according to an embodiment of the present application;

[0058] Figure 3 A block diagram of a large language model-based agent query database device according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0059] Various exemplary embodiments, features and aspects of the present application will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0060] Among them, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application or simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.

[0061] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0062] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0063] In addition, in order to better illustrate the present application, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present application can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present application.

[0064] Example 1

[0065] Figure 1 FIG. 1 is a flow chart showing a method for querying a database based on a large language model agent according to an embodiment of the present application. Figure 1 As shown, the flow chart includes:

[0066] S100, obtaining query request information;

[0067] In this embodiment, the Figure 2 The method is implemented in a system architecture where a user inputs a natural language query through a front-end interface, and query request information is obtained by capturing the user's query at the back-end.

[0068] S200, analyzing the query request information to identify the query request intent category;

[0069] Through natural language processing technology, we analyze and understand the content input by users, extract key intentions and needs from them, and classify them into different intent categories, such as general chat, data query, data visualization, SQL statement interpretation, etc.

[0070] S300, decomposing the query request information according to the query request intention category to obtain sub-query request information;

[0071] Generally, users need to obtain information on multiple questions, but entering natural language queries multiple times on the front-end interface for each question becomes cumbersome, so the query request information is usually a compound question entered by the user, that is, one question contains multiple sub-questions.

[0072] For example, if the query request information is: "Query and compare the month-on-month growth of sales in each month in the first quarter of 2024", after analyzing the query request information, it is identified as the intent category of the query data. According to the intent category of the query data, the query request information is decomposed in combination with natural language processing technology to obtain the following sub-questions:

[0073] "Query the month-on-month sales growth in January 2024"; "Query the month-on-month sales growth in February 2024"; "Query the month-on-month sales growth in March 2024" and "Compare the month-on-month sales growth in each month in the first quarter of 2024". These sub-questions are regarded as sub-query request information.

[0074] For another example, the query request information is: "Query the number of patients cared for during the night shift in the surgical ward last night and the list of nurses on duty." After breaking it down, the following sub-questions are obtained: "Query the number of patients cared for during the night shift in the surgical ward last night" and "Query the list of nurses on duty in the surgical ward last night."

[0075] It should be noted that when the content of the query request information only involves the processing of one question, after identifying the intent category and breaking down the question, the obtained sub-query request information is generally consistent with the query request information.

[0076] For example, if the query request information is "query the sales situation on a certain day of a certain month", after breaking down the problem, the sub-query request information obtained is still "query the sales situation on a certain day of a certain month".

[0077] Similarly, if the query request information belongs to the general chat category, SQL statement interpretation category, etc., the query request information is disassembled according to each category in combination with natural language processing technology. When the query request information belongs to the general chat category, each sub-query request information obtained by the disassembly is routed to the chat service, and a suitable reply is generated according to the sub-query request information.

[0078] S400, searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information;

[0079] According to the identified intent category, the query request information is routed to the relevant processing service, and the sub-query request information is processed in turn. For example, when the intent category is general chat, it is routed to the chat service, and a suitable reply is generated based on the sub-query request information obtained from the user's question. When the intent category is query data, the query request information is routed to the query service, and the target knowledge base is searched according to the content to be queried for each sub-query request information to obtain a suitable SQL statement to ensure that each sub-query request information is properly processed. In this embodiment, the target knowledge base is a Schema knowledge base, which stores various data, information, knowledge and experience related to the business scenario. According to the query request intent, a semantic search is performed in the target knowledge base to obtain an output result, which includes the sub-problems involved in the query request information and the SQL statements to solve the sub-problems.

[0080] S500, when no corresponding SQL statement is found, construct and generate a SQL statement prompt word and send it to the large language model, and obtain the SQL statement returned by the large language model;

[0081] When the SQL statement that solves the subquery request information is not obtained from the target knowledge base, the powerful language understanding and generation capabilities of the large language model will be used to understand the disassembled subquery request information and output the corresponding SQL statement that solves the subquery request information. It should be noted that before using the large model, the large language model needs to be trained, and common query questions and corresponding SQL statements are input into the large language model for learning.

[0082] S600, executing the SQL statement to obtain a sub-query result corresponding to the sub-query request information;

[0083] After decomposing the query request information to obtain multiple sub-query request information, obtain the SQL statement for each sub-query request information in turn. For example, after continuing the above decomposition, the following sub-problems are obtained: "Query the number of patients who received night shift care in the surgical ward last night" and "Query the list of nurses on duty in the surgical ward last night". Execute the SQL statement corresponding to "Query the number of patients who received night shift care in the surgical ward last night" and the SQL statement corresponding to "Query the list of nurses on duty in the surgical ward last night", and obtain the corresponding sub-query results on the number of patients and the list of nurses on duty, respectively.

[0084] S700, integrating the sub-query results to obtain the query result of the query request information, generating a data visualization code corresponding to the query result based on the large language model, executing the data visualization code, and outputting the query result and its visualization display result.

[0085] After obtaining the SQL statement corresponding to the subquery request information, the subquery result can be obtained by executing it. What the user needs is the full result of the query request information, so the subquery results are integrated and summarized to generate query results with appropriate layout and reading habits. When the query results are complex and difficult to understand at a glance, you can also use custom visualization tools or use large language models to automatically generate code to visualize the query results, such as converting the query results into charts, etc., and return them to the front-end users.

[0086] As an optional implementation scheme of the present application, when no corresponding SQL statement is searched, a SQL statement prompt word is constructed and sent to a large language model, and an SQL statement returned by the large language model is obtained, including: obtaining a database composition information summary of the query request intent category; obtaining business rules; constructing a SQL statement prompt word for the sub-query request information in combination with the database composition information summary and the business rules; sending the generated SQL statement prompt word to the large language model, and receiving the SQL statement returned by the large language model.

[0087] When no SQL statement that solves the sub-query request information is found in the target knowledge base, the database schema information is automatically obtained according to the query request intent category, and the relevant tables and columns are intelligently selected to form a summary of the database composition information related to the query request information, that is, the data required for the query request information is preliminarily obtained. Further, the business scenario is determined according to the query request information, and the business rules corresponding to the business scenario are obtained in the business rule management tool. The summary of the database composition information is combined with the business rules and the sub-query request information to construct the generated SQL statement prompt words, that is, according to the query request intent category, some information in the database is determined, and then further combined with the sub-query request information to accurately determine the content to be queried, thereby ensuring that the constructed SQL statement prompt words meet the user's query requirements. The generated SQL statement prompt words are sent to the large language model. After receiving the prompt words, the large language model generates appropriate SQL statements based on the pre-learned knowledge, which improves the accuracy of the sub-query results and ensures the accuracy of the query results.

[0088] The business rule management tool allows users to define and manage specific business rules, such as indicator calculation logic, to ensure that the generated SQL statements meet business requirements. The specific implementation includes: describing business rules in natural language, including supplementary explanations of table structure and relationships between fields; indicator definition, giving indicator names and calculation logic; rule application mechanism, dynamically applying relevant rules during SQL generation.

[0089] As an optional implementation scheme of the present application, a summary of the database composition information of the query request intent category is obtained, including: determining an associated database according to the query request intent category; in the associated database, performing semantic similarity calculation on the sub-query request information, and extracting a data table according to a preset semantic similarity threshold; determining the relationship between tables according to the attributes of the data table, and integrating the relationship between tables and the content of the data table to generate a summary of the database composition information.

[0090] Taking the database Schama as an example, in this system architecture, schema information is automatically captured and updated, including tables, column names, data types, comments, primary key and foreign key relationships, etc. Based on the disassembled subquery information request, the semantic similarity algorithm is used to select the most relevant tables and columns. The method of presetting the semantic similarity threshold can be adopted. For example, when the similarity exceeds the semantic similarity threshold, the data table is extracted. For multiple extracted data tables, a subgraph structure related to the subquery request information is constructed according to the attributes of the data table, including the necessary table relationships, integrating the table relationships and the content of the data table. Since the database Schama will also be updated, the database composition information summary will be dynamically generated in combination with the latest data in the database Schema, and used as one of the inputs of the large language model.

[0091] In this embodiment, the system architecture also includes a database connection management module, which supports uploading SQL scripts to create databases or associate existing databases to achieve flexible data source management. This module includes support for multiple database types, including relational databases such as PostgreSQL, MySQL, etc. and non-relational database MongoDB. It includes database upload management, which supports users to upload databases through SQL code; includes database connection pool management, which is used to optimize the use of connection resources; includes database annotation management, which is used to support users to annotate databases, tables, and columns; includes a permission management system, which is used to control user access rights to different data sources; includes data source information management, which includes connection parameters, update time, usage statistics, etc.

[0092] As an optional implementation scheme of the present application, searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information includes: searching the query request intention category in the target knowledge base to obtain the SQL statement retrieval result; constructing and modifying the SQL statement prompt word according to the SQL statement retrieval result and the sub-query request information and sending it to the large language model, and receiving the SQL statement corresponding to the sub-query request information returned by the large language model.

[0093] The SQL statements retrieved from the target knowledge base are used to obtain SQL statement retrieval results that include solutions to problems similar to the query request information and corresponding SQL statements. The obtained SQL statements may not be applicable to all disassembled sub-query request information. At this time, combined with the sub-query request information, a prompt word for rewriting the SQL statement is constructed and sent to the large language model. The large language model modifies the SQL statement based on the prompt word, such as modifying different parameters according to different sub-query request information, etc., and returns the modified SQL statement, executes the rewritten SQL statement, and improves the accuracy of the sub-query result.

[0094] As an optional implementation scheme of the present application, the sub-query results are integrated to obtain the query result of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visual display result are output, and it also includes: obtaining feedback information about the query result; when obtaining query request information of the same query request intention category, constructing a modified SQL statement prompt word in combination with the feedback information and sending it to the large language model, and receiving the corresponding SQL statement returned by the large language model.

[0095] Collect user feedback on query results, obtain user satisfaction with the display of query results from the feedback information, and analyze the feedback information when receiving query request information of similar query request intention category based on the satisfaction, extract the feedback content corresponding to each sub-query request information, and use it as part of rewriting SQL statements, so as to ultimately dynamically adjust the visual display processing of query results of similar query request information accordingly, so that the displayed query results are clearer.

[0096] When collecting user feedback information, a simple and intuitive feedback mechanism can be provided in the user interaction interface, such as likes and dislikes, and the feedback information can be analyzed as feedback data to identify common problems and improvement points. An automatic learning mechanism can be established to continuously optimize query generation and result presentation for feedback information. An A / B testing framework can be used to evaluate the effects of new functions and optimizations.

[0097] You can also add a query optimization module to the system architecture to build a high-frequency query knowledge base based on retrieval enhancement and SQL rewriting technology to improve the system response speed. This can be achieved from the following aspects: query logs and analyze them to identify high-frequency query patterns; use vectorized storage engines to support efficient semantic similarity retrieval; use SQL rewriting algorithms to intelligently adjust new query requests based on historical queries; build a cache mechanism to reasonably cache common query results to improve response speed.

[0098] In this embodiment, the system architecture includes a large language model interface module, which is responsible for interacting with the locally deployed Text2SQL large model or the cloud MaaS service, and generating SQL query statements based on user queries and related Schema information. The main implementations of this module include: supporting interaction with multiple large language models, such as locally deployed open source models ChatGLM, LLaMA, etc. or cloud API ChatGPT, Claude, etc.; designing professional prompt word templates for integrating query request information, Schema data information summaries and business rules; implementing post-processing of large language model output, including SQL statement syntax checking and optimization for similar query request intent categories; in the case of multiple large language models, providing model selection and switching mechanisms to select appropriate models according to query complexity.

[0099] As an optional implementation scheme of the present application, the sub-query results are integrated to obtain the query results of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visual display result are output, which also includes: obtaining a request for interpreting the SQL statement; interpreting the SQL statement according to the interpretation request, and outputting the interpretation result.

[0100] In this embodiment, the function of interpreting SQL statements can also be provided to provide natural language interpretation of SQL statements for non-technical users, enhance the interpretability of the system, and allow users to more intuitively understand the intent and execution steps of SQL statement queries. When the user's query request information is for interpreting SQL statements or the user has raised a demand for interpreting SQL statements after viewing the query results, the following aspects of the SQL statement are mainly interpreted: the keywords, data tables, calculation logic, and query intent in the SQL statement are interpreted. After the interpretation is completed, it is integrated into a natural language text and output to the user. It should be noted that it can also be directly set to be before each query result is output, when the user's query request information includes a SQL statement interpretation requirement, the interpretation result of the corresponding SQL statement can be integrated as part of the query result.

[0101] As an optional implementation scheme of the present application, after analyzing the query request information and identifying the query request intent category, it also includes: obtaining a custom tool library; determining a target tool for the sub-query request information in the custom tool library based on the query request intent category; obtaining an SQL statement template in the target tool; adjusting the SQL statement template based on the sub-query request information, obtaining a corresponding SQL statement and executing it to obtain a sub-query result.

[0102] The custom tool library includes multiple databases as the method of using tools. For each tool, set the tool name, which indicates the purpose, and add the tool description and the corresponding SQL template. For example, the tool name is the month-on-month growth rate of sales, and the tool description is when the subquery request information is to inquire about the month-on-month growth rate of sales, this function is selected. This function is the SQL statement in the SQL template, and lists the list of modifiable parameters. Combined with the subquery request information, modify the template SQL statement to obtain the SQL statement suitable for the subquery request information and execute it to obtain more accurate subquery results.

[0103] In the custom tool library, you can also predefine commonly used query modes, such as month-on-month calculation, customer retention rate, inventory turnover rate, etc. When the above query request intention is recognized, you can directly call the corresponding SQL statement template and set the template parameterization mechanism. The system will dynamically fill the SQL statement template with parameters according to the disassembled sub-query request information.

[0104] Furthermore, the custom tool library also includes a visualization tool API that integrates with mainstream BI tools such as Tableau and PowerBI. Custom visualization functions can also be used to allow users to create visualization effects for specific business scenarios.

[0105] As an optional implementation scheme of the present application, analyzing the query request information and identifying the query request intent category includes: obtaining historical query records of the query request information; performing natural language processing analysis on the query request information based on the historical query records to identify the query request intent category.

[0106] When users continue to make query request information, the context of the conversation with the user is maintained. When understanding the query request information, the correct understanding of the user's intent is also maintained in combination with historical query records, so as to more accurately identify the query request intent category.

[0107] To ensure the scalability of the system and its compatibility with existing systems, the embodiments of the present application also provide the following integration mechanisms: RESTful API, which allows external systems to integrate the functions of the system at a lower cost; WebSocket, which supports real-time query and result push; a plug-in system, which supports third-party developers to expand system functions; an event-driven architecture, which achieves loose coupling and efficient communication of internal modules of the system.

[0108] Taking into account the sensitivity of the data, the system also provides the following security protection measures: end-to-end encryption to protect the security of data during transmission; fine-grained access control to control user permissions based on roles and data sensitivity; query audit logs to record all operations for subsequent analysis; data desensitization technology to automatically protect sensitive information when displaying results.

[0109] This method and the system architecture involved can be widely used in the following scenarios: enterprise data analysis, financial risk control, medical and health data query, education data management, government decision support system, leadership cockpit, etc.

[0110] By combining natural language processing, large language models and multiple optimization technologies, the efficiency and usability of data query have been greatly improved, allowing non-technical users to easily perform complex data analysis. It also has good scalability and compatibility, and can be seamlessly integrated with existing databases and BI systems.

[0111] Example 2

[0112] Based on the same principle as the above method, a large language model-based intelligent agent query database device is also proposed, see Figure 3 , a large language model-based agent query database device 100 of the embodiment of the present disclosure includes:

[0113] The request acquisition module 110 is used to acquire query request information;

[0114] An intent category identification module 120 is used to analyze the query request information and identify the query request intent category;

[0115] A request decomposition module 130 is used to decompose the query request information according to the query request intention category to obtain sub-query request information;

[0116] A SQL statement search module 140 is used to search in a target knowledge base according to the query request intention category to obtain an SQL statement corresponding to the sub-query request information;

[0117] The SQL statement generating module 150 is used to construct a SQL statement prompt word and send it to the large language model when no corresponding SQL statement is searched, and obtain the SQL statement returned by the large language model;

[0118] An SQL statement execution module 160 is used to execute the SQL statement to obtain a sub-query result corresponding to the sub-query request information;

[0119] The query result acquisition module 170 is used to integrate the sub-query results to obtain the query result of the query request information, generate the data visualization code corresponding to the query result based on the large language model, execute the data visualization code, and output the query result and its visualization display result.

[0120] Obviously, those skilled in the art should understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned control methods. The modules or steps of the present invention can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Optionally, they can be implemented by program codes executable by computing devices, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules respectively, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.

[0121] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned control methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, abbreviated as: HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0122] Example 3

[0123] Furthermore, an electronic device is proposed, comprising:

[0124] processor;

[0125] a memory for storing processor-executable instructions;

[0126] Wherein, the processor is configured to implement the method for querying a database based on a large language model agent as described in Example 1 when executing the executable instructions.

[0127] The electronic device of the embodiment of the present disclosure includes a processor and a memory for storing processor executable instructions. The processor is configured to implement any of the above-mentioned methods for querying a database based on a large language model agent when executing the executable instructions.

[0128] It should be noted that the number of processors may be one or more. At the same time, the electronic device of the embodiment of the present disclosure may also include an input device and an output device. The processor, memory, input device, and output device may be connected via a bus or in other ways, which are not specifically limited here.

[0129] The memory is a computer-readable storage medium for the method for querying a database based on a large language model agent, and can be used to store software programs, computer executable programs, and various modules, such as the program or module corresponding to the method for querying a database based on a large language model agent in the embodiment of the present disclosure. The processor executes various functional applications and data processing of the electronic device by running the software programs or modules stored in the memory.

[0130] The input device can be used to receive input numbers or signals. The signal can be a key signal related to user settings and function control of the device / terminal / server. The output device can include a display device such as a display screen.

[0131] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A method for querying a database based on a large language model agent, characterized in that: include: Get query request information; Analyze the query request information to identify the query request intent category; Decomposing the query request information according to the query request intention category to obtain sub-query request information; Searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information; When no corresponding SQL statement is found, a SQL statement prompt word is constructed and sent to the large language model, and the SQL statement returned by the large language model is obtained; Execute the SQL statement to obtain a sub-query result corresponding to the sub-query request information; The sub-query results are integrated to obtain the query result of the query request information, a data visualization code corresponding to the query result is generated based on the large language model, the data visualization code is executed, and the query result and its visualization display result are output.

2. The method for querying a database based on a large language model agent according to claim 1, characterized in that: When no corresponding SQL statement is found, constructing a SQL statement prompt word and sending it to the large language model, and obtaining the SQL statement returned by the large language model, including: Obtaining a summary of database composition information of the query request intent category; Get business rules; Generating SQL statement prompt words by combining the sub-query request information with the database composition information summary and the business rule construction; The generated SQL statement prompt word is sent to the large language model, and the SQL statement returned by the large language model is received.

3. The method for querying a database based on a large language model agent according to claim 2, characterized in that: Obtaining a summary of database composition information of the query request intent category includes: Determining a related database according to the query request intent category; In the associated database, performing semantic similarity calculation on the sub-query request information, and extracting a data table according to a preset semantic similarity threshold; The relationship between tables is determined according to the attributes of the data tables, and the relationship between tables and the contents of the data tables are integrated to generate a database composition information summary.

4. The method for querying a database based on a large language model agent according to claim 1, characterized in that: Searching in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information includes: Searching the query request intention category in the target knowledge base to obtain SQL statement retrieval results; Constructing a modified SQL statement prompt word according to the SQL statement retrieval result and the sub-query request information and sending the prompt word to the large language model, and receiving a corresponding SQL statement returned by the large language model.

5. The method for querying a database based on a large language model agent according to claim 4, characterized in that: After integrating the sub-query results to obtain the query result of the query request information, generating a data visualization code corresponding to the query result based on the large language model, executing the data visualization code, and outputting the query result and its visualization display result, the method further includes: Obtaining feedback information about the query result; When query request information of the same query request intent category is obtained, a prompt word for modifying the SQL statement is constructed in combination with the feedback information and sent to the large language model, and a corresponding SQL statement returned by the large language model is received.

6. The method for querying a database based on a large language model agent according to claim 5, characterized in that: Integrating the sub-query results to obtain the query result of the query request information, generating data visualization code corresponding to the query result based on the large language model, executing the data visualization code, outputting the query result and its visualization display result, further comprising: Obtaining a request for interpreting the SQL statement; The SQL statement is interpreted according to the interpretation request, and an interpretation result is output.

7. The method for querying a database based on a large language model agent according to claim 5, characterized in that: After analyzing the query request information and identifying the query request intent category, the method further includes: Get a custom tool library; Determining a target tool for the sub-query request information in the custom tool library according to the query request intent category; Obtaining a SQL statement template in the target tool; The SQL statement template is adjusted according to the sub-query request information to obtain a corresponding SQL statement and execute it to obtain a sub-query result.

8. The method for querying a database based on a large language model agent according to any one of claims 1 to 7, characterized in that: Analyze the query request information and identify the query request intent category, including: Obtaining historical query records of the query request information; Based on historical query records, natural language processing analysis is performed on the query request information to identify the query request intent category.

9. A large language model-based intelligent agent query database device, characterized in that: include: Get request module, used to get query request information; An intent category identification module is used to analyze the query request information and identify the query request intent category; A request decomposition module, used to decompose the query request information according to the query request intention category to obtain sub-query request information; A SQL statement search module is used to search in the target knowledge base according to the query request intention category to obtain the SQL statement corresponding to the sub-query request information; A SQL statement generation module is used to construct a SQL statement prompt word and send it to the large language model when no corresponding SQL statement is searched, and obtain the SQL statement returned by the large language model; An SQL statement execution module is used to execute the SQL statement to obtain a sub-query result corresponding to the sub-query request information; A query result acquisition module is used to integrate the sub-query results to obtain the query result of the query request information, generate data visualization code corresponding to the query result based on the large language model, execute the data visualization code, and output the query result and its visualization display result.

10. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to implement the method for querying a database based on a large language model agent as described in any one of claims 1 to 8 when executing the executable instructions.

Citation Information

Cited By

  • Domain knowledge supplement and SQL generation optimization method and device based on large model

    CN119938891A

  • Energy data analysis method and system based on large model and proprietary knowledge base

    CN120179869A

  • An energy data analysis method and system based on large models and proprietary knowledge bases

    CN120179869B

  • Industrial chain analysis method, system and device, storage medium and program product

    CN120216665A

  • Adaptive complex scene information analysis method, electronic equipment, storage medium and program product

    CN120234339A