Animated data flow diagram

AI Chat Agent for WordPress using RAG, OpenAI & Supabase

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

WordPress OpenAI Supabase PostgreSQL

Overview

Unlock Intelligent Q&A on Your WordPress Site with this AI Agent

This n8n AI Agent transforms your WordPress website into an interactive knowledge hub. It automatically fetches your posts and pages, converts them into intelligent embeddings using OpenAI, and stores them in a Supabase/PostgreSQL vector database. When a visitor asks a question via the integrated chat interface, the agent uses Retrieval Augmented Generation (RAG) to find the most relevant content from your site and provides an accurate, context-aware answer through an OpenAI language model. It's designed to keep your AI's knowledge up-to-date by periodically checking for and embedding new or modified content.

Key Features & Benefits

  • Automated Content Sync: Keeps your AI agent's knowledge base current by regularly ingesting posts and pages from your WordPress site.
  • AI-Powered Embeddings: Utilizes OpenAI's text-embedding-3-small model to create rich vector representations of your content for effective semantic search.
  • RAG Architecture: Employs Retrieval Augmented Generation, combining powerful LLMs (like OpenAI's gpt-4o-mini) with your specific website content to deliver highly relevant and factual answers.
  • Vector Storage: Leverages Supabase (interfacing with PostgreSQL and pgvector) for efficient storage and fast retrieval of content embeddings.
  • Incremental Updates: Smartly handles new and modified content, ensuring your AI agent always has the latest information.
  • Conversational Interface: Provides a chat trigger and webhook, allowing you to embed a Q&A chatbot directly on your website.
  • Persistent Chat History: Stores conversation logs in PostgreSQL for review and potential future fine-tuning.
  • Scalable & Customizable: Built with n8n's modularity, allowing for easy adaptation and extension.

Use Cases

  • Providing instant, AI-driven answers to visitor questions on your WordPress site.
  • Automating customer support by letting an AI agent handle common queries based on your content.
  • Creating an interactive knowledge base from your blog posts and pages.
  • Enhancing user engagement by offering a conversational way to explore website content.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key with access to text-embedding-3-small (or compatible) and a chat model like gpt-4o-mini (or gpt-3.5-turbo, gpt-4).
  • WordPress site with REST API enabled. Credentials for WordPress (e.g., Application Password or other authentication method for HTTP Request nodes).
  • Supabase project:
    • API URL and Anon Key.
    • A PostgreSQL database (often included with Supabase) with the pgvector extension enabled.
    • Table named documents (schema provided in workflow for initial setup).
  • PostgreSQL database credentials (if separate from Supabase, or for direct connection) for storing chat histories in a table like website_chat_histories and workflow execution history in n8n_website_embedding_histories (schemas provided in workflow for initial setup).

Setup Instructions

  1. Download the n8n workflow JSON file and import it into your n8n instance.
  2. Database Setup (One-Time):
    • Connect your PostgreSQL/Supabase instance.
    • If the documents (for content embeddings) and n8n_website_embedding_histories tables don't exist, manually run the 'Postgres - Create documents table' and 'Postgres - Create workflow execution history table' nodes. These define the schema and enable pgvector.
    • Ensure a table for chat history (e.g., website_chat_histories) is also present or created (the 'Postgres Chat Memory' node will attempt to use this).
  3. Configure Credentials:
    • WordPress: In 'Wordpress - Get all posts' / '...pages' and the HTTP Request nodes for updates, set up your WordPress credentials or API access. Update URLs in HTTP Request nodes (e.g., https://mydomain.com/...).
    • OpenAI: Configure all 'Embeddings OpenAI' and 'OpenAI Chat Model' nodes with your OpenAI API Key.
    • Supabase/Postgres: Configure 'Supabase Vector Store', 'Supabase - Delete row...', 'Postgres - Filter on existing documents', 'Postgres Chat Memory', and other Postgres nodes with your database credentials.
  4. Workflow 1: Initial Content Embedding (Manual Trigger)
    • This flow starts with 'When clicking ‘Test workflow’'.
    • Review and adjust any filters in the WordPress data fetching nodes if needed.
    • Run this flow once to fetch all existing publishable content, convert it to Markdown, create embeddings, and store them in your 'documents' table via the 'Supabase Vector Store' node.
  5. Workflow 2: Upsert New/Updated Content (Scheduled Trigger)
    • This flow starts with 'Every 30 seconds' (Schedule Trigger). Adjust the schedule to your needs.
    • It fetches recently modified content, processes it, checks if it's new or an update to an existing document in Supabase, and then inserts/updates the embeddings.
  6. Workflow 3: AI Chat Agent (Chat Trigger)
    • This flow starts with 'When chat message received'.
    • Note the Webhook URL from this trigger to integrate the chat into your website.
    • In the 'AI Agent' node, customize the systemMessage prompt. Specifically, replace {{your_website_url}} with your actual website URL and refine instructions for the AI's persona and response style.
  7. Activate Workflows: Save and activate the 'Upsert' and 'Chat Agent' workflows (or the entire workflow if you prefer managing it as one). The initial embedding is a manual run.

Tags:

AI AgentRAGWordPressOpenAIChatbotCustomer SupportContent AutomationKnowledge BaseSupabasePostgreSQLpgvectorVector DatabaseGenerative AILLMSolopreneur ToolStartup Automation

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation