AI-Powered Q&A Agent for Your Documents using Supabase & OpenAI
Integrates with:
Overview
Unlock Instant Answers from Your Content with this AI Agent
This AI Agent ingests documents (starting with an EPUB example from Google Drive, as shown in the workflow for 'How To Transform Your Life' by Venerable Geshe Kelsang Gyatso), processes them, and stores them in a Supabase vector database. It then provides a chat interface where users can ask questions about the document's content. OpenAI models are used for embedding generation and answering questions based on retrieved context. This agent essentially creates a custom ChatGPT for your specific documents, enabling powerful 'knowledge base Q&A' and 'document comprehension' abilities.
The workflow also includes guidance and example setups for managing your vector store in Supabase, covering insertion, upserting, and advice on deletion operations.
Key Features & Benefits
- Document Ingestion & Indexing: Automatically loads (e.g., EPUBs via Google Drive), chunks, and embeds content from your documents into a Supabase vector store using OpenAI.
- AI-Powered Q&A: Leverages OpenAI's embedding and Langchain's chat models to understand user questions and provide accurate, context-aware answers retrieved from your indexed documents.
- Interactive Chat Interface: Offers a simple chat trigger for users to interact with the knowledge base in real-time.
- Scalable Knowledge Base: Utilizes Supabase with the
pgvector
extension for efficient storage and semantic retrieval of document embeddings. - Customizable & Extensible: Easily adapt to different document types and expand functionalities within n8n to suit your specific needs.
- Comprehensive Vector Store Management: Includes workflow sections and detailed sticky notes for inserting new documents, upserting existing ones, and instructions for deleting records in your Supabase vector store.
Use Cases
- For B2C E-commerce: Create an AI assistant to answer customer questions about product manuals, usage guides, or FAQs from your knowledge base, reducing support load.
- For B2B SaaS: Build an internal AI knowledge bot from technical documentation, API guides, or company policies for faster onboarding and support for your team.
- Transform extensive e-books or research papers into an interactive learning tool for students, researchers, or personal study.
- Automate responses to common inquiries based on your company's internal knowledge base, improving internal efficiency and knowledge accessibility.
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-3.5-turbo
orgpt-4
). - Supabase account with a project set up.
pgvector
extension enabled in your Supabase database (refer to 'Sticky Note2' in the workflow for commands).- A Supabase table configured for vector storage. Example schema (from workflow notes):
your_table_name
with columnsid BIGINT
,content TEXT
,metadata JSONB
,embedding VECTOR(1536)
. Adjust vector dimensions (e.g., 1536 fortext-embedding-3-small
) based on your chosen OpenAI embedding model. - The
match_documents
SQL function created in your Supabase SQL Editor (refer to 'Sticky Note2' in the workflow for the function code, ensuring you replace"YOUR TABLE NAME"
with your actual table name and match vector dimensions). - Credentials for your OpenAI and Supabase accounts configured in n8n.
- If using the Google Drive node for document input: Google Drive credentials/connection configured in n8n and the file (e.g., EPUB) accessible.
Setup Instructions
- Download the n8n workflow JSON file.
- Import the workflow into your n8n instance.
- Supabase Database Preparation (Crucial - refer to 'Sticky Note2' in the workflow for detailed SQL queries):
a. In your Supabase project, ensure the
pgvector
extension is enabled. b. Create a table (e.g.,Kadampa
as used in the Q&A example, or your chosen name) with appropriate columns:id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY
,content TEXT
,metadata JSONB
, andembedding VECTOR(1536)
. Ensure the vector dimension (e.g., 1536) matches your OpenAI embedding model. c. Create thematch_documents
PL/pgSQL function in the Supabase SQL Editor, making sure to replace"YOUR TABLE NAME"
with your actual table name used in step 3b, and verify vector dimensions match. - Configure Credentials in n8n:
a. OpenAI Nodes: In 'Embeddings OpenAI Insertion', 'Embeddings OpenAI Retrieval', 'Embeddings OpenAI Upserting', and 'OpenAI Chat Model' nodes, select/create your OpenAI credentials. Choose your preferred embedding (e.g.,
text-embedding-3-small
) and chat models. Ensure the same embedding model is used for insertion and retrieval paths. b. Supabase Nodes: In 'Insert Documents', 'Retrieve by Query', and 'Update Documents' nodes, select/create your Supabase credentials. Set the correctTable Name
(e.g.,Kadampa
for the main Q&A part). - Configure Workflow Nodes:
a. Document Input: If using, configure the 'Google Drive' node with your file ID/URL. The 'Default Data Loader' is set for EPUBs; adjust if using other file types.
b. Text Splitting: Review and adjust the 'Recursive Character Text Splitter1' node parameters if needed.
c. Vector Store Operations: For 'Retrieve by Query' and 'Update Documents' nodes, ensure the
Query Name
parameter is set tomatch_documents
(or your custom function name). - Data Ingestion (Populating the Vector Store): a. To load your primary document (e.g., the EPUB book), manually execute the workflow path starting from the 'Google Drive' node through to 'Insert Documents'. This will process your document and store its embeddings in Supabase.
- Chat Interface:
a. The 'When chat message received' node acts as the trigger. You can customize its
initialMessages
. b. Once the workflow is active, use its public webhook URL to interact with the Q&A agent. - Upserting and Deletion: a. The workflow includes a separate path for upserting documents ('Placeholder (File/Content to Upsert)' -> 'Update Documents'). Configure and use this as an example for updating existing vector entries. b. For deleting documents, refer to 'Sticky Note4' which provides guidance on using the n8n HTTP Request node to call the Supabase API, as a direct delete node for Supabase vectors is not standard.
- Activate the workflow to enable the chat interface and other triggers.
Want your own unique AI agent?
Talk to us - we know how to build custom AI agents for your specific needs.
Schedule a Consultation