Database management service integration Dify method and system
By integrating Dify into the database management service, using the large language model and database table structure knowledge base, the intelligent problem of traditional database management services is solved, intelligent question-and-answer, index optimization and SQL tuning are realized, and the intelligence level of database management services is improved.
Patent Information
- Application Number
- CN202510586339.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-08-19
AI Technical Summary
Traditional database management services have high barriers to non-professional personnel, and it is difficult to achieve intelligent Q&A, index optimization and SQL tuning.
Integrate Dify into database management services, integrate Dify's entrance through SQL forms and intelligent assistants, pass in problem and database table structure knowledge base information, call large language models for SQL execution, and maintain the association relationship of database table structure knowledge base, update regularly, and support multi-source database connections.
It realizes the intelligence of database management services, improves the capabilities of intelligent Q&A, index optimization and SQL tuning, empowers traditional database management services to artificial intelligence capabilities, and supports intelligent Q&A and optimization of a variety of open source and domestic databases.
Smart Images

Figure CN120508588A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a database management service integration Dify method and system. Background Art
[0002] Traditional database management services often require specialized database knowledge and skills, creating a high barrier to entry for non-professionals. The rapid development of artificial intelligence and machine learning technologies has provided technical support for the upgrading of database management services. Large models, as a key achievement in the field of artificial intelligence, possess powerful language understanding, knowledge reasoning, and learning capabilities. Their application to database management services is an inevitable trend in technological development.
[0003] Therefore, how to improve the intelligence of database management services and realize database capabilities such as intelligent question answering, index optimization, and SQL tuning is a technical problem that needs to be solved urgently. Summary of the Invention
[0004] The technical task of the present invention is to provide a database management service integrated Dify method and system to solve the problem of how to improve the intelligence of database management services and realize the database capabilities of intelligent question answering, index optimization and SQL tuning.
[0005] The technical task of the present invention is achieved in the following manner: a database management service integrated Dify method, the method is as follows:
[0006] Integrate Dify into the database management service. From the SQL form and the intelligent assistant, enter the question, database connection information, and database table structure knowledge base information into Dify. The Dify workflow calls the database management service database connection API and directly accesses the database for SQL execution based on the database connection information and generated SQL.
[0007] Maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified;
[0008] The database management service accesses the large language model through Dify, and Dify connects to different databases through the database management service database.
[0009] Preferably, in the SQL form, enter the question with a shortcut command starting with " / / " or right-click the "Generate SQL", "SQL Optimize" and "SQL Explain" buttons to quickly call the Dify Agent API.
[0010] As a preferred option, the intelligent assistant embeds the Dify Agent page into the database management service and calls the Dify Agent page through a dialog box;
[0011] Among them, Dify Agent is generated by workflow orchestration and calls different nodes of "Generate SQL", "SQL Optimization" and "SQL Interpretation" according to the problem type through conditional branching.
[0012] Preferably, the large language model is called in the Dify workflow node, the large language model type and Token are configured in the Dify workflow node, and prompt words and database table structure knowledge base are assembled; at the same time, different large model prompt words are generated according to the differences in node types.
[0013] As a preferred approach, the large language model is deployed locally based on Ollma. When calling the large language model node, the assembly question and the database table structure knowledge base become prompt words. Each database creates a knowledge base in Dify, which is used to store the table structure. The table structure information includes table creation statements, index information, primary key information, and foreign key information.
[0014] Among them, the prompt words require SQL to only extract standard table names and field names from the pre-built database table structure knowledge base, combine the semantic analysis results of user questions, and generate structured query statements according to SQL grammar specifications; among them, the grammar specifications are mandatory, such as the inclusion of a where clause in conditional query scenarios to ensure the accuracy and completeness of data retrieval; at the same time, the types of SQL statements generated are strictly limited through preset instructions, and the inclusion of delete, alter, update data manipulation language (DML) and data definition language (DDL) instructions is explicitly prohibited to avoid data modification and structural change risks from the source; and it is required to automatically start the SQL injection detection mechanism to perform security verification on the generated SQL statements to ensure compliance with established security specifications.
[0015] Better yet, Dify calls the database connection API of the database management service to execute the SQL generated by the large language model;
[0016] Among them, the database management service uploads the current database connection information when calling the Dify Agent API.
[0017] More optimally, Dify calls the database management service database connection API to execute the SQL generated by the large language model as follows:
[0018] Receive the Structured Query Language (SQL) instructions output by the large language model, call the database connection API of the database management service based on the pre-configured database connection parameters, and achieve a secure connection with the target database instance;
[0019] After the connection is successfully established, the received SQL instructions will be executed, and the original SQL statement and its execution results will be encapsulated into a data structure in a specific format, and finally returned to the front-end intelligent assistant interaction page for users to view and analyze.
[0020] A database management service integration Dify system, which is used to execute the database management service integration Dify method as described above; the system includes an integration module, a knowledge base management module and a multi-source database connection module;
[0021] The integration module is used to integrate Dify into the database management service. From the SQL form and the intelligent assistant integration Dify portal, questions, database connection information, and database table structure knowledge base information are passed to Dify. The database connection API of the database management service is called in the Dify workflow. Based on the database connection information and the generated SQL, the database is directly accessed for SQL execution.
[0022] The knowledge base management module is used to maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified;
[0023] The multi-source database connection module is used to access the large language model through Dify in the database management service. Dify connects to different databases through the database management service database.
[0024] An electronic device comprising: a memory and at least one processor;
[0025] wherein the memory stores computer-executable instructions;
[0026] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the database management service integration Dify method as described above.
[0027] A computer-readable storage medium stores computer-executable instructions, and when a processor executes the computer-executable instructions, the above-mentioned database management service integration Dify method is implemented.
[0028] The database management service integrated Dify method and system of the present invention has the following advantages:
[0029] (1) The present invention realizes the integration of database management services and Dify, and the mutual call access between the database management services and Dify. The Dify Agent entrance is integrated into the database management service page. Through the integration module, knowledge base management module and multi-source database connection module, the intelligent database management service is realized.
[0030] (2) This invention, based on Dify's large language model development and process orchestration capabilities, improves the intelligence of database management services and implements database capabilities such as intelligent question answering, index optimization, and SQL tuning;
[0031] (3) The present invention is based on Dify's large language model development and process orchestration capabilities, which improves the intelligence of database management services, gives traditional database management services AI capabilities, and realizes database intelligent capabilities such as intelligent question answering, index optimization, and SQL tuning for domestic databases such as Hangao, Damang, and Renmin University of China Jincang. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The present invention will be further described below with reference to the accompanying drawings.
[0033] Attachment Figure 1 Flowchart for integrating the Dify approach into database management services. DETAILED DESCRIPTION
[0034] The database management service integration Dify method and system of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments.
[0035] Example 1:
[0036] This embodiment provides a Dify method for integrating a database management service. The method is as follows:
[0037] S1. Integrate Dify into the database management service. From the SQL form and the intelligent assistant, enter the question, database connection information, and database table structure knowledge base information into Dify. The Dify workflow calls the database management service database connection API and directly accesses the database for SQL execution based on the database connection information and generated SQL.
[0038] S2. Maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified;
[0039] S3. The database management service accesses the large language model through Dify, and Dify connects to different databases through the database management service database.
[0040] In this embodiment, the Dify Agent API is quickly called by entering a question with a shortcut command starting with " / / " in the SQL form or by right-clicking the "Generate SQL", "SQL Optimize" and "SQL Explain" buttons.
[0041] In this embodiment, the intelligent assistant embeds the Dify Agent page into the database management service and calls the Dify Agent page through a dialog box;
[0042] Among them, Dify Agent is generated by workflow orchestration and calls different nodes of "Generate SQL", "SQL Optimization" and "SQL Interpretation" according to the problem type through conditional branching.
[0043] In this embodiment, the large language model is called in the Dify workflow node, the large language model type and Token are configured in the Dify workflow node, and prompt words and database table structure knowledge base are assembled; at the same time, different large model prompt words are generated according to the difference in node type.
[0044] In this embodiment, the large language model is deployed locally based on Ollma, and can deploy a variety of mainstream large language models such as DeepSeek, Qwen, and OpenAI. In the call to the large language model node, the assembly question and the database table structure knowledge base become prompt words. Each database creates a knowledge base in Dify, which is used to store the table structure. The table structure information includes table creation statements, index information, primary key information, and foreign key information.
[0045] Among them, the prompt words require SQL to only extract standard table names and field names from the pre-built database table structure knowledge base, combine the semantic analysis results of user questions, and generate structured query statements according to SQL grammar specifications; among them, the grammar specifications are mandatory, such as the inclusion of a where clause in conditional query scenarios to ensure the accuracy and completeness of data retrieval; at the same time, the types of SQL statements generated are strictly limited through preset instructions, and the inclusion of delete, alter, update data manipulation language (DML) and data definition language (DDL) instructions is explicitly prohibited to avoid data modification and structural change risks from the source; and it is required to automatically start the SQL injection detection mechanism to perform security verification on the generated SQL statements to ensure compliance with established security specifications.
[0046] In this embodiment, Dify calls the database management service database connection API to execute the SQL generated by the large language model;
[0047] Among them, the database management service uploads the current database connection information when calling the Dify Agent API.
[0048] The database management service is a one-stop management platform provided by Inspur Cloud that provides database development, operation and maintenance, monitoring, inspection, auditing and other management capabilities; it supports the management of cloud and offline databases, including mainstream open source and domestic databases such as MySQL, PostgreSql, Hangao, Damang, Renmin University of China Jinkang, and Nanjing University General.
[0049] In this embodiment, Dify calls the database management service database connection API to execute the SQL generated by the large language model as follows:
[0050] ① Receive the Structured Query Language (SQL) instructions output by the large language model, call the database connection API of the database management service based on the pre-configured database connection parameters, and achieve a secure connection with the target database instance;
[0051] ② After the connection is successfully established, the received SQL instructions will be executed, and the original SQL statement and its execution results will be encapsulated into a data structure in a specific format, and finally returned to the front-end intelligent assistant interaction page for users to view and analyze.
[0052] Example 2:
[0053] This embodiment provides a database management service integration Dify system, which is used to execute the database management service integration Dify method as described in Example 1; the system includes an integration module, a knowledge base management module, and a multi-source database connection module;
[0054] The integration module is used to integrate Dify into the database management service. From the SQL form and the intelligent assistant integration Dify portal, questions, database connection information, and database table structure knowledge base information are passed to Dify. The database connection API of the database management service is called in the Dify workflow. Based on the database connection information and the generated SQL, the database is directly accessed for SQL execution.
[0055] The knowledge base management module is used to maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified;
[0056] The multi-source database connection module is used to access the large language model through Dify in the database management service. Dify connects to different databases through the database management service database. The multi-source database connection module supports connecting to multiple databases, including MySQL, PostgreSql, Hangao, Damang, Renmin University of China Jincang, Nanjing University of Science and Technology, and other mainstream open source and domestic databases.
[0057] The database management service in this embodiment integrates large language model capabilities, providing AI capabilities including but not limited to SQL generation, SQL optimization, SQL interpretation, database intelligent dialogue, and intelligent chart generation. The database intelligent service supports both open source and domestic databases, including MySQL, PostgreSql, Hangao, Dameng, Renda Jincang, and Nanjing University General.
[0058] Example 3:
[0059] As attached Figure 1 As shown, this embodiment provides a database management service integration Dify method, which is as follows:
[0060] First, on the database management service smart assistant page, click the "Generate SQL" button or directly access the Dify API. Figure 1 DMS stands for Database Management Service. When calling the Dify API, you must pass in the question content, database connection information, and database table structure knowledge base information.
[0061] Secondly, in the Dify workflow, based on the "Generate SQL" question type, the "Generate SQL" node is called to convert the question and database table structure knowledge base into professional prompts, and then the large language model deployed locally by Ollma is called.
[0062] Again, in the prompt words, SQL is required to extract only standard table names and field names from the pre-built database table structure knowledge base, and generate structured query statements based on the SQL grammar specifications in combination with the semantic analysis results of user questions; the grammar specifications are mandatory, such as the inclusion of a where clause in conditional query scenarios to ensure the accuracy and completeness of data retrieval. At the same time, the types of SQL statements generated are strictly limited through preset instructions, and the inclusion of data manipulation language (DML) and data definition language (DDL) instructions such as delete, alter, and update is explicitly prohibited, avoiding the risks of data modification and structural changes from the source. It is required to automatically start the SQL injection detection mechanism to perform security verification on the generated SQL statements to ensure that they comply with established security specifications.
[0063] Finally, the system receives the Structured Query Language (SQL) instructions output by the large language model and, based on pre-configured database connection parameters, calls the database management service's database connection API to securely connect to the target database instance. Once the connection is successfully established, the system executes the SQL instructions and encapsulates the original SQL statements and their results into a specifically formatted data structure, ultimately returning them to the front-end intelligent assistant interface for user review and analysis.
[0064] Example 4:
[0065] This embodiment also provides an electronic device, including: a memory and at least one processor;
[0066] wherein the memory stores computer-executable instructions;
[0067] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the database management service integration Dify method according to any one of the present inventions.
[0068] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.
[0069] The memory can be used to store computer programs and / or modules. The processor implements various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area. The program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created based on the use of the terminal, etc. In addition, the memory can also include high-speed random access memory and non-volatile memory, such as a hard disk, internal memory, a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state memory devices.
[0070] Example 5:
[0071] This embodiment further provides a computer-readable storage medium storing a plurality of instructions, which are loaded by a processor to cause the processor to execute the database management service integration Dify method according to any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, wherein the storage medium stores software program code that implements the functions of any of the above-described embodiments, and a computer (or CPU or MPU) of the system or device can read and execute the program code stored in the storage medium.
[0072] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute part of the present invention.
[0073] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code can be downloaded from a server computer via a communication network.
[0074] In addition, it should be clear that the functions of any of the above embodiments can be achieved not only by executing the program code read by the computer, but also by enabling the operating system operating on the computer to complete part or all of the actual operations based on the instructions of the program code.
[0075] In addition, it can be understood that the program code read from the storage medium is written into the memory provided in the expansion board inserted into the computer or into the memory provided in the expansion unit connected to the computer, and then based on the instructions of the program code, the CPU installed on the expansion board or expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A database management service integration Dify method, characterized in that: The method is as follows: Integrate Dify into the database management service. From the SQL form and the intelligent assistant, enter the question, database connection information, and database table structure knowledge base information into Dify. The Dify workflow calls the database management service database connection API and directly accesses the database for SQL execution based on the database connection information and generated SQL. Maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified; The database management service accesses the large language model through Dify, and Dify connects to different databases through the database management service database.
2. The database management service integration Dify method according to claim 1, characterized in that: In the SQL form, enter a question using shortcut commands starting with " / / " or right-click the "Generate SQL", "SQL Optimize" and "SQL Explain" buttons to quickly call the Dify Agent API.
3. The database management service integration Dify method according to claim 1, characterized in that: The intelligent assistant embeds the DifyAgent page into the database management service and calls the Dify Agent page through a dialog box; Among them, Dify Agent is generated by workflow orchestration and calls different nodes of "Generate SQL", "SQL Optimization" and "SQL Interpretation" according to the problem type through conditional branching.
4. The database management service integration Dify method according to claim 1, characterized in that: The large language model is called in the Dify workflow node. The large language model type and token are configured in the Dify workflow node, and prompt words and database table structure knowledge base are assembled. At the same time, different large model prompt words are generated according to the differences in node types.
5. The database management service integration Dify method according to claim 1, characterized in that: The large language model is deployed locally based on Ollma. When calling the large language model node, assembly questions and the database table structure knowledge base serve as prompts. Each database creates a knowledge base in Dify, which stores the table structure. The table structure information includes table creation statements, index information, primary key information, and foreign key information. Among them, the prompt words require SQL to only extract standard table names and field names from the pre-built database table structure knowledge base, combine the semantic analysis results of user questions, and generate structured query statements according to SQL syntax specifications; at the same time, the types of SQL statements generated are strictly limited through preset instructions, and the inclusion of delete, alter, and update data operation languages and data definition language instructions is explicitly prohibited, avoiding the risks of data modification and structural changes from the source; and it is required to automatically start the SQL injection detection mechanism to perform security verification on the generated SQL statements to ensure compliance with established security specifications.
6. The database management service integration Dify method according to any one of claims 1 to 5, characterized in that: Dify calls the database connection API of the database management service to execute the SQL generated by the large language model; Among them, the database management service uploads the current database connection information when calling the Dify Agent API.
7. The database management service integration Dify method and system according to claim 6, characterized in that: Dify calls the database management service database connection API to execute the SQL generated by the large language model as follows: Receive the structured query language instructions output by the large language model, call the database connection API of the database management service based on the pre-configured database connection parameters, and achieve a secure connection with the target database instance; After the connection is successfully established, the received SQL instructions will be executed, and the original SQL statement and its execution results will be encapsulated into a data structure in a specific format, and finally returned to the front-end intelligent assistant interaction page for users to view and analyze.
8. A database management service integrated Dify system, characterized in that: The system is used to execute the database management service integration Dify method according to any one of claims 1 to 7; the system includes an integration module, a knowledge base management module and a multi-source database connection module; The integration module is used to integrate Dify into the database management service. From the SQL form and the intelligent assistant integration Dify portal, questions, database connection information, and database table structure knowledge base information are passed to Dify. The database connection API of the database management service is called in the Dify workflow. Based on the database connection information and the generated SQL, the database is directly accessed for SQL execution. The knowledge base management module is used to maintain the relationship between the database and the database table structure knowledge base in Dify, regularly update the database table structure knowledge base in Dify, monitor table structure change events through DDL triggers, and update the database table structure knowledge base in seconds when the table structure is modified; The multi-source database connection module is used to access the large language model through Dify in the database management service. Dify connects to different databases through the database management service database.
9. An electronic device, characterized in that: include: memory and at least one processor; wherein the memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the database management service integration Dify method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the database management service integration Dify method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data processing method, front end and computer readable storage medium
CN113849574A
Log analysis method, data synchronization system, electronic equipment and storage medium
CN115730008A
Method, device and equipment for automatically optimizing SQL (Structured Query Language) execution performance and medium
CN119003574A
Data processing method and system of intelligent organization construction system
CN119597863A
TAMMER CONTROL DEVICE
RU3767U1
Cited By
Method and system for realizing NL2SQL based on large model
CN121524202A