AI-Powered WordPress Content Q&A Agent with RAG
Integrates with:
Overview
Unlock Instant Knowledge Access with this AI Agent
This n8n AI Agent transforms your WordPress website into an interactive knowledge hub. It acts as a specialized "Content Q&A Specialist", automatically ingesting, processing, and understanding your posts and pages. Using Retrieval Augmented Generation (RAG) with OpenAI models, it allows users or internal teams to ask questions in natural language and receive instant, accurate answers sourced directly from your WordPress content. This empowers you to offer superior self-service support, enhance user engagement, and make your website's information more accessible and actionable.
Key Features & Abilities:
- WordPress Content Ingestion & Processing: Automatically fetches all posts and pages (or just updates) from your WordPress site. It then cleans and prepares the content by converting HTML to Markdown, making it optimal for AI processing.
- AI-Driven Text Embedding & Vector Storage: Leverages OpenAI's
text-embedding-3-small
model to generate vector embeddings for your content. These embeddings are stored efficiently in a Supabase/PostgreSQL vector database, enabling fast and relevant semantic search. - Automated Knowledge Base Synchronization: Includes a scheduled sub-workflow to periodically check for new or modified WordPress content. It intelligently updates the vector database by adding new content or refreshing existing entries (by deleting and re-inserting), ensuring your AI Agent's knowledge is always current.
- Intelligent Knowledge Retrieval (RAG): When a user asks a question via the chat interface, the agent first retrieves the most relevant document chunks from your WordPress knowledge base using vector similarity search.
- Conversational AI & Sourced Response Generation: The retrieved content, along with the user's query, is then passed to an OpenAI chat model (e.g.,
gpt-4o-mini
) via Langchain. The AI generates a comprehensive answer, critically, it cites the source(s) by including metadata such as the URL, content type, and publication/modification dates directly in its response. - Chat History Management: Optionally stores conversation history in a PostgreSQL database, allowing for review, analysis, or future improvements to the agent's performance.
- Embeddable Chat Interface: The chat functionality is triggered via a webhook, making it easy to integrate into your website or internal applications.
Use Cases
- **B2C E-commerce:** Provide instant answers to customer product questions, shipping policies, or FAQs directly from your blog posts or product descriptions, reducing support tickets.
- **B2B SaaS:** Offer an intelligent help center where clients can query technical documentation, API guides, or feature explanations, improving self-service support.
- **Content-Rich Websites:** Enable visitors to quickly find specific information within a large archive of articles, blog posts, or case studies, enhancing user experience.
- **Internal Knowledge Base:** Allow team members to easily query internal WordPress-based wikis or documentation for procedures, guidelines, or project details.
Prerequisites
- An n8n instance (Cloud or self-hosted).
- OpenAI API Key with access to embedding models (e.g.,
text-embedding-3-small
) and chat models (e.g.,gpt-4o-mini
). - WordPress site with REST API access enabled. You'll need WordPress credentials for the 'WordPress' nodes and potentially for the 'HTTP Request' nodes if basic auth or other methods are used for
modified_after
queries. - Supabase project (or a separate PostgreSQL database). Credentials for database connection are required.
- Ensure the
pgvector
extension is enabled in your PostgreSQL database. (Supabase enables this by default on new projects; for self-managed Postgres, you'll need to enable it manually).
Setup Instructions
- Download the n8n workflow JSON file.
- Import the workflow into your n8n instance.
- Initial Database Setup (One-time):
- Locate the 'Postgres - Create documents table' and 'Postgres - Create workflow execution history table' nodes (these are initially disconnected, referenced by Sticky Note 4).
- Configure these nodes with your PostgreSQL/Supabase database credentials.
- Manually run these two nodes once to create the necessary tables (
documents
for vector storage,n8n_website_embedding_histories
for logging workflow runs).
- Workflow 1: Initial Content Embedding (Run Manually First):
- Configure the 'Wordpress - Get all posts' and 'Wordpress - Get all pages' nodes with your WordPress credentials and site URL.
- Configure the 'Embeddings OpenAI' node (ID:
3ab719bd-3652-433f-a597-9cd28f8cfcea
) with your OpenAI API Key. - Configure the 'Supabase Vector Store' node (ID:
cd4107cb-e521-4c1e-88e2-3417a12fd585
) with your Supabase/PostgreSQL credentials (for storing embeddings in thedocuments
table). - Configure the 'Supabase - Store workflow execution' node (ID:
391e9ea7-71dd-42ae-bee7-badcae32427c
) with your Supabase/PostgreSQL credentials (for logging ton8n_website_embedding_histories
). - Activate and run this part of the workflow using the 'When clicking ‘Test workflow’' trigger to perform the initial embedding of all your WordPress content.
- Workflow 2: Incremental Content Updates (Scheduled):
- Configure the 'Every 30 seconds' Schedule Trigger (ID:
d19f3a5f-fa42-46d0-a366-4c5a5d09f559
) to your desired update frequency (e.g., daily, hourly). - Configure the 'Postgres' node (ID:
8399976b-340a-49ce-a5b6-f7339957aa9d
, fetches last execution time) with your DB credentials. - Configure the 'Wordpress - Get posts modified after last workflow execution' (ID:
ba25135b-6e6e-406b-b18a-f532a6e37276
) and '...pages' (ID:a1d8572e-2b0d-40a1-a898-bbd563a6b190
) HTTP Request nodes: update the URL to your WordPress site and set up authentication if needed (e.g., WordPress Application Password for REST API). - Ensure 'Embeddings OpenAI2' (ID:
7f392a40-e353-4bb2-9ecf-3ee330110b95
) and 'Store documents on Supabase' (ID:5f59ebbf-ca17-4311-809c-85b74ce624cc
) are configured with your OpenAI and Supabase/Postgres credentials respectively. - This section uses a 'Switch' node to handle new vs. updated documents. For updated documents, it first deletes existing entries ('Supabase - Delete row if documents exists') before inserting new embeddings.
- Configure 'Store workflow execution id and timestamptz' (Supabase node ID:
2422562e-9c95-4d77-ae8c-485b06f9234e
) with your credentials.
- Configure the 'Every 30 seconds' Schedule Trigger (ID:
- Workflow 3: Chat Functionality (Webhook):
- The 'When chat message received' Chat Trigger node (ID:
6c5d8f6a-569e-4f1e-99a6-07ec492575ff
) will provide a webhook URL upon activation. Use this URL in your frontend chat application. - Configure 'Supabase - Retrieve documents from chatinput' (ID:
9a2f17ba-902f-4528-9eef-f8c0e4ddf516
) and 'Embeddings OpenAI1' (ID:27585104-5315-4c11-b333-4b5d27d9bae4
) with your Supabase/Postgres and OpenAI credentials. - Configure the 'OpenAI Chat Model' node (ID:
35269a98-d905-4e4f-ae5b-dadad678f260
) with your OpenAI API Key. - Configure the 'Postgres Chat Memory' node (ID:
cd26b6fa-a8bb-4139-9bec-8656d90d8203
) with your PostgreSQL/Supabase credentials for storing chat history (table namewebsite_chat_histories
). - In the 'AI Agent' node (ID:
43607f23-d33f-4aca-b478-f20ba8c218cf
), review and customize thesystemMessage
parameter. Crucially, replace the placeholder{{your_website_url}}
with your actual website URL.
- The 'When chat message received' Chat Trigger node (ID:
- Activate the workflow (or relevant parts, especially the schedule trigger and chat trigger for continuous operation). Monitor initial runs and adjust configurations as needed.
Want your own unique AI agent?
Talk to us - we know how to build custom AI agents for your specific needs.
Schedule a Consultation