AI RAG Agent for Notion with Supabase & OpenAI
Integrates with:
Overview
Unlock Real-Time Knowledge Access with this AI RAG Agent
This n8n workflow acts as an intelligent AI Agent that implements a Retrieval Augmented Generation (RAG) pipeline. It continuously synchronizes content from your Notion knowledge base—whether it's product documentation, support articles, or internal wikis—with a Supabase vector store. This ensures your AI Agent always has access to the very latest information. When a question is posed via a chat interface (or any other trigger you configure), the agent intelligently retrieves the most relevant documents from Supabase, leverages OpenAI to understand the query and context, and then uses OpenAI's powerful GPT-4o model to generate a precise, informed answer. This empowers your users, customers, or internal teams with instant, accurate answers drawn directly from your curated 'living data'.
Key Features & Benefits
- Dynamic Knowledge Base Management: Automatically ingests and updates content from specified Notion pages, ensuring your AI's knowledge is always current by refreshing embeddings in Supabase.
- AI-Powered Conversational Q&A: Leverages OpenAI (GPT-4o for generation and text-embedding models for understanding) to provide contextually relevant answers based on your live Notion data.
- Efficient Vector Retrieval: Utilizes Supabase with pgvector for fast and scalable similarity searches across your entire knowledge base.
- Automated Data Pipeline: Handles text extraction from Notion, content concatenation, text splitting, embedding generation, and vector storage automatically.
- Chat-Ready Interface: Includes a 'When chat message received' trigger making it easy to integrate with chatbots or other conversational AI applications.
- Enhanced Answer Reliability: Grounds LLM responses in your specific, up-to-date documentation, significantly reducing hallucinations and improving the accuracy of information provided.
- Scalable & Customizable: Built on n8n, this agent can be easily modified, extended, and integrated with other business systems and data sources.
Use Cases
- **B2C E-commerce:** Deploy an AI chatbot on your storefront that answers customer queries about products, shipping, or return policies by drawing information directly from your Notion-based FAQ or product database, reducing support workload.
- **B2B SaaS:** Equip your sales and customer support teams with an internal AI assistant that can rapidly answer complex questions about product features, pricing tiers, or technical documentation, all sourced from your centralized Notion knowledge base.
- Streamline new employee onboarding by providing an AI agent that answers common questions based on company policies, procedures, and training materials managed in Notion.
- Create an intelligent, self-service knowledge portal for your customers, where an AI agent offers instant answers derived from a dynamically updated Notion database of articles and guides.
Prerequisites
- An n8n instance (Cloud or self-hosted).
- OpenAI API Key with access to a suitable model (e.g., gpt-4o for chat, and an embedding model like text-embedding-ada-002).
- Notion API Key/Credentials and the Database ID of your Notion knowledge base.
- Supabase project credentials (API URL and Service Role Key for full access) and a Supabase table configured for vector storage using the
pgvector
extension (e.g., a table named 'documents' with a vector column).
Setup Instructions
- Download the n8n workflow JSON file.
- Import the workflow into your n8n instance.
- Configure Credentials: a. Set up your 'OpenAI' credentials (used in 'Embeddings OpenAI' and 'OpenAI Chat Model' nodes). b. Set up your 'Notion' credentials (used in 'Get updated pages', 'Notion Trigger', and 'Get page blocks' nodes). c. Set up your 'Supabase' credentials with appropriate permissions (e.g., Service Role Key for write/delete operations) (used in 'Delete old embeddings if exist', 'Supabase Vector Store' for insertion, and 'Supabase Vector Store1' for retrieval).
- Configure Notion Integration:
a. In the 'Get updated pages' node (and 'Notion Trigger' if you enable it), select your Notion credentials and specify your knowledge base Database ID.
b. Verify the 'Get page blocks' node correctly references the page ID from the upstream Notion node using
{{ $('Input Reference').item.json.id }}
. - Configure Supabase Vector Store:
a. In both 'Supabase Vector Store' (insert mode) and 'Supabase Vector Store1' (retrieve mode), select your Supabase credentials and set the correct table name (e.g., 'documents'). This table must have the
pgvector
extension enabled and a vector column. b. In the 'Delete old embeddings if exist' node, ensure the table name and filter logic (=metadata->>id=eq.{{ $('Input Reference').item.json.id }}
) correctly target documents by their Notion ID stored in metadata. - Configure AI Models & Text Processing:
a. In the 'OpenAI Chat Model' node, choose your preferred model (default is 'gpt-4o').
b. In the 'Embeddings OpenAI' node, ensure the default embedding model is suitable or change if needed.
c. Review and adjust the 'Token Splitter' node's
chunkSize
(default 500) andchunkOverlap
. Tune these based on your content density and the embedding model's token limits (e.g., text-embedding-ada-002 allows up to 8191 tokens for chunk size + overlap). - Set Up Triggers: a. Data Sync: The 'Schedule Trigger' is configured to poll Notion for updates every minute. Adjust this interval or consider using the 'Notion Trigger' (currently disabled) for more efficient, event-driven updates (refer to the sticky note in the workflow regarding n8n cloud plan executions). b. Q&A Interface: The 'When chat message received' node provides a public webhook URL. Use this to integrate the Q&A functionality with your chat application or for testing.
- Review Metadata & Data Loading:
a. In the 'Default Data Loader' node, confirm that the metadata fields (
id
andname
) are correctly mapped from your Notion page data ({{ $('Input Reference').item.json.id }}
and{{ $('Input Reference').item.json.name }}
). Thisid
is vital for updating and deleting specific document embeddings. b. Ensure the 'Concatenate to single string' node correctly aggregates page block content before loading. - Activate the workflow. Thoroughly test the data synchronization process by updating a Notion page and verifying changes in Supabase. Then, test the Q&A functionality via the chat trigger.
Want your own unique AI agent?
Talk to us - we know how to build custom AI agents for your specific needs.
Schedule a Consultation