-
Notifications
You must be signed in to change notification settings - Fork 810
Add AI functionality to pgAdmin #9472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dpage
wants to merge
11
commits into
pgadmin-org:master
Choose a base branch
from
dpage:pgadmin_ai
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ac4bd31
Core infrastructure for LLM integration.
dpage 51d076d
Add support for a number of different AI generated reports on securit…
dpage cdba797
Add a Natural Language AI assistant to the Query Tool.
dpage 1d89408
Add an AI Insights panel to the EXPLAIN tool in the Query Tool, to an…
dpage 21af7b2
Address PR review comments for AI features
dpage 77201eb
Address additional PR review comments
dpage 8baf3fd
Ensure new tabs are loaded correctly.
dpage b12ddd9
Ensure screenshots are 950px wide.
dpage 75ff6d1
Rename migration file to follow existing naming convention.
dpage 55bd203
Address additional PR review comments.
dpage 114ea07
Merge remote-tracking branch 'upstream/master' into pgadmin_ai
dpage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| .. _ai_tools: | ||
|
|
||
| ******************* | ||
| `AI Reports`:index: | ||
| ******************* | ||
|
|
||
| **AI Reports** is a feature that provides AI-powered database analysis and insights | ||
| using Large Language Models (LLMs). Use the *Tools → AI Reports* menu to access | ||
| the various AI-powered reports. | ||
|
|
||
| The AI Reports feature allows you to: | ||
|
|
||
| * Generate security reports to identify potential security vulnerabilities and configuration issues. | ||
|
|
||
| * Create performance reports with optimization recommendations for queries and configurations. | ||
|
|
||
| * Perform design reviews to analyze database schema structure and suggest improvements. | ||
|
|
||
| **Prerequisites:** | ||
|
|
||
| Before using AI Reports, you must: | ||
|
|
||
| 1. Ensure AI features are enabled in the server configuration (set ``LLM_ENABLED`` to ``True`` in ``config.py``). | ||
|
|
||
| 2. Configure an LLM provider in :ref:`Preferences → AI <preferences>`. | ||
|
|
||
| **Note:** | ||
|
|
||
| * AI Reports using cloud providers (Anthropic, OpenAI) require an active internet connection. | ||
| Local providers (Ollama, Docker Model Runner) do not require internet access. | ||
|
|
||
| * API usage may incur costs depending on your LLM provider's pricing model. | ||
| Local providers (Ollama, Docker Model Runner) are free to use. | ||
|
|
||
| * The quality and accuracy of reports depend on the LLM provider and model configured. | ||
|
|
||
|
|
||
| Configuring AI Reports | ||
| ********************** | ||
|
|
||
| To configure AI Reports, navigate to *File → Preferences → AI* (or click the *Settings* | ||
| button and select *AI*). | ||
|
|
||
| .. image:: images/preferences_ai.png | ||
| :alt: AI preferences | ||
| :align: center | ||
|
|
||
| Select your preferred LLM provider from the dropdown: | ||
|
|
||
| **Anthropic** | ||
| Use Claude models from Anthropic. Requires an Anthropic API key. | ||
|
|
||
| * **API Key File**: Path to a file containing your Anthropic API key (obtain from https://console.anthropic.com/). | ||
| * **Model**: Select from available Claude models (e.g., claude-sonnet-4-20250514). | ||
|
|
||
| **OpenAI** | ||
| Use GPT models from OpenAI. Requires an OpenAI API key. | ||
|
|
||
| * **API Key File**: Path to a file containing your OpenAI API key (obtain from https://platform.openai.com/). | ||
| * **Model**: Select from available GPT models (e.g., gpt-4). | ||
|
|
||
| **Ollama** | ||
| Use locally-hosted open-source models via Ollama. Requires a running Ollama instance. | ||
|
|
||
| * **API URL**: The URL of your Ollama server (default: http://localhost:11434). | ||
| * **Model**: Enter the name of the Ollama model to use (e.g., llama2, mistral). | ||
|
|
||
| **Docker Model Runner** | ||
| Use models running in Docker Desktop's built-in model runner (available in Docker Desktop 4.40+). | ||
| No API key is required. | ||
|
|
||
| * **API URL**: The URL of the Docker Model Runner API (default: http://localhost:12434). | ||
| * **Model**: Select from available models or enter a custom model name. | ||
|
|
||
| After configuring your provider, click *Save* to apply the changes. | ||
|
|
||
|
|
||
| Security Reports | ||
| **************** | ||
|
|
||
| Security Reports analyze your PostgreSQL server, database, or schema for potential | ||
| security vulnerabilities and configuration issues. | ||
|
|
||
| To generate a security report: | ||
|
|
||
| 1. In the *Browser* tree, select a server, database, or schema. | ||
|
|
||
| 2. Choose *Tools → AI Reports → Security* from the menu, or right-click the | ||
| object and select *Security* from the context menu. | ||
|
|
||
| 3. The report will be generated and displayed in a new tab. | ||
|
|
||
| .. image:: images/ai_security_report.png | ||
| :alt: AI security report | ||
| :align: center | ||
|
|
||
| **Security Report Scope:** | ||
|
|
||
| * **Server Level**: Analyzes server configuration, authentication settings, roles, and permissions. | ||
|
|
||
| * **Database Level**: Reviews database-specific security settings, roles with database access, and object permissions. | ||
|
|
||
| * **Schema Level**: Examines schema permissions, object ownership, and access controls. | ||
|
|
||
| Each report includes: | ||
|
|
||
| * **Security Findings**: Identified vulnerabilities or security concerns. | ||
|
|
||
| * **Risk Assessment**: Severity levels for each finding (Critical, High, Medium, Low). | ||
|
|
||
| * **Recommendations**: Specific actions to remediate security issues. | ||
|
|
||
| * **Best Practices**: General security recommendations for PostgreSQL. | ||
|
|
||
|
|
||
| Performance Reports | ||
| ******************* | ||
|
|
||
| Performance Reports analyze query performance, configuration settings, and provide | ||
| optimization recommendations. | ||
|
|
||
| To generate a performance report: | ||
|
|
||
| 1. In the *Browser* tree, select a server or database. | ||
|
|
||
| 2. Choose *Tools → AI Reports → Performance* from the menu, or right-click the | ||
| object and select *Performance* from the context menu. | ||
|
|
||
| 3. The report will be generated and displayed in a new tab. | ||
|
|
||
| **Performance Report Scope:** | ||
|
|
||
| * **Server Level**: Analyzes server configuration parameters, resource utilization, and overall server performance metrics. | ||
|
|
||
| * **Database Level**: Reviews database-specific configuration, query performance, index usage, and table statistics. | ||
|
|
||
| Each report includes: | ||
|
|
||
| * **Performance Metrics**: Key performance indicators and statistics. | ||
|
|
||
| * **Configuration Analysis**: Review of relevant configuration parameters. | ||
|
|
||
| * **Query Optimization**: Recommendations for improving slow queries. | ||
|
|
||
| * **Index Recommendations**: Suggestions for adding, removing, or modifying indexes. | ||
|
|
||
| * **Capacity Planning**: Resource utilization trends and recommendations. | ||
|
|
||
|
|
||
| Design Review Reports | ||
| ********************* | ||
|
|
||
| Design Review Reports analyze your database schema structure and suggest | ||
| improvements for normalization, naming conventions, and best practices. | ||
|
|
||
| To generate a design review report: | ||
|
|
||
| 1. In the *Browser* tree, select a database or schema. | ||
|
|
||
| 2. Choose *Tools → AI Reports → Design* from the menu, or right-click the | ||
| object and select *Design* from the context menu. | ||
|
|
||
| 3. The report will be generated and displayed in a new tab. | ||
|
|
||
| **Design Review Scope:** | ||
|
|
||
| * **Database Level**: Reviews overall database structure, schema organization, and cross-schema dependencies. | ||
|
|
||
| * **Schema Level**: Analyzes tables, views, functions, and other objects within the schema. | ||
|
|
||
| Each report includes: | ||
|
|
||
| * **Schema Structure Analysis**: Review of table structures, relationships, and constraints. | ||
|
|
||
| * **Normalization Review**: Recommendations for database normalization (1NF, 2NF, 3NF, etc.). | ||
|
|
||
| * **Naming Conventions**: Suggestions for consistent naming patterns. | ||
|
|
||
| * **Data Type Usage**: Review of data type choices and recommendations. | ||
|
|
||
| * **Index Design**: Analysis of indexing strategy. | ||
|
|
||
| * **Best Practices**: General PostgreSQL schema design recommendations. | ||
|
|
||
|
|
||
| Working with Reports | ||
| ******************** | ||
|
|
||
| All AI reports are displayed in a dedicated panel with the following features: | ||
|
|
||
| **Report Display** | ||
| Reports are formatted as Markdown and rendered with syntax highlighting for SQL code. | ||
|
|
||
| **Toolbar Actions** | ||
|
|
||
| * **Stop** - Cancel the current report generation. This is useful if the report | ||
| is taking too long or if you want to change parameters. | ||
|
|
||
| * **Regenerate** - Generate a new report for the same object. Useful when you | ||
| want to get a fresh analysis or if data has changed. | ||
|
|
||
| * **Download** - Download the report as a Markdown (.md) file. The filename | ||
| includes the report type, object name, and date for easy identification. | ||
|
|
||
| **Multiple Reports** | ||
| You can generate and view multiple reports simultaneously. Each report opens in | ||
| a new tab, allowing you to compare reports across different servers, databases, | ||
| or schemas. | ||
|
|
||
| **Report Management** | ||
| Each report tab can be closed individually by clicking the *X* in the tab. | ||
| Panel titles show the object name and report type for easy identification. | ||
|
|
||
| **Copying Content** | ||
| You can select and copy text from reports to use in documentation or share with | ||
| your team. | ||
|
|
||
|
|
||
| Troubleshooting | ||
| *************** | ||
|
|
||
| **"AI features are disabled in the server configuration"** | ||
| The administrator has disabled AI features on the server. Contact your | ||
| pgAdmin administrator to enable the ``LLM_ENABLED`` configuration option. | ||
|
|
||
| **"Please configure an LLM provider in Preferences"** | ||
| You need to configure an LLM provider before using AI Reports. See *Configuring AI Reports* above. | ||
|
|
||
| **"Please connect to the server/database first"** | ||
| You must establish a connection to the server or database before generating reports. | ||
|
|
||
| **API Connection Errors** | ||
| * Verify your API key is correct (for Anthropic and OpenAI). | ||
| * Check your internet connection (for cloud providers). | ||
| * For Ollama, ensure the Ollama server is running and accessible. | ||
| * For Docker Model Runner, ensure Docker Desktop 4.40+ is running with the model runner enabled. | ||
| * Check that your firewall allows connections to the LLM provider's API. | ||
|
|
||
| **Report Generation Fails** | ||
| * Check the pgAdmin logs for detailed error messages. | ||
| * Verify the database connection is still active. | ||
| * Ensure the selected model is available for your account/subscription. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,4 @@ PL/SQL code. | |
| schema_diff | ||
| erd_tool | ||
| psql_tool | ||
| ai_tools | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
dpage marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
dpage marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
dpage marked this conversation as resolved.
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.