Intelligent PostgreSQL Database Chat Assistant
Chat with Postgresql Database
Interact with your PostgreSQL database using natural language. AI automatically generates and executes SQL queries, making it easy to gain data insights.
Workflow Overview
This is an AI-powered intelligent conversational assistant workflow for PostgreSQL databases, enabling users to interact with the database through natural language queries. The workflow leverages OpenAI's language model to understand user intent, automatically generate and execute SQL queries, and return results in a user-friendly manner.
Core Features
Intelligent Query Generation
The workflow uses an AI Agent to interpret natural language requests from users and automatically generates SQL queries that conform to the database schema. The AI ensures that all table names include the correct schema prefix to prevent query errors.
Database Schema Awareness
The system automatically retrieves database schema information, including table lists and detailed table definitions (such as column names, data types, foreign key relationships, etc.), enabling the AI to generate accurate queries.
Conversation Memory
Integrated chat history functionality retains the most recent 5 conversation turns by default, allowing the AI to understand context and deliver more coherent dialogue experiences.
Workflow Components
Trigger Node
- When chat message received: A chat message trigger that receives user query requests.
Core Processing Nodes
- AI Agent: An intelligent agent node that orchestrates the entire query process using OpenAI Functions Agent mode.
- OpenAI Chat Model: Employs the GPT-4o-mini model to provide AI capabilities.
- Chat History: A sliding window memory module that manages conversation history.
Tool Nodes (Tools callable by the AI Agent)
- Execute SQL Query: Executes SQL queries generated by the AI.
- Get DB Schema and Tables List: Retrieves all tables in the database along with their corresponding schema names.
- Get Table Definition: Fetches detailed definition information for a specified table, including columns, data types, constraints, and foreign key relationships.
System Prompt Configuration
The AI assistant is configured as a database assistant with the following primary responsibilities:
- Running database queries based on user requests
- Generating custom SQL queries to aggregate data
- Ensuring every table name includes the correct schema prefix
- Retrieving all necessary data for analysis before responding to the user
Technical Highlights
Automated Schema Management
The workflow automatically identifies and manages database schemas to ensure syntactically correct SQL queries.
Intelligent Data Analysis
The AI not only executes queries but also analyzes returned data to provide meaningful explanations and insights to users.
Flexible Model Selection
Supports swapping in other chat models, offering strong extensibility.
Customizable Context Window
Allows adjustment of the number of retained chat history entries to balance performance and contextual understanding.
Use Cases
- Business analysts quickly querying business data
- Non-technical users accessing databases via natural language
- Data exploration and ad-hoc queries
- Automated report generation
- Learning and understanding database structure
Configuration Requirements
- PostgreSQL database credentials
- OpenAI API credentials
- Optional: Adjust the chat history window length (default: 5 turns)
- Optional: Activate the workflow to make the chat publicly accessible