In this step-by-step guide, I’ll show you how to build your own custom knowledge base AI chatbot—also known as a RAG (Retrieval-Augmented Generation) chatbot—without writing a single line of code. We’ll use the powerful no-code automation platform, N8N, to create a chatbot that you can embed directly on your WordPress site.
By the end of this tutorial, you will have a chatbot that:
- Answers queries only from your provided data.
- Learns automatically when you add new files to a Google Drive folder.
- Logs all conversations to a Google Sheet.
- Is seamlessly embedded on your WordPress website.
What You’ll Need Before Starting
- An N8N account (Cloud or Self-Hosted).
- A Pinecone account (for the vector database).
- An OpenAI account (with billing enabled for API access).
- A Google Account (for Drive and Sheets).
Part 1: Building the “Data Pump” Workflow
This first workflow automatically takes any document you upload to a specific Google Drive folder and sends it to your Pinecone vector database (your chatbot’s “brain”).
Step 1: Create a New Workflow
In your N8N workspace, create a new workflow and name it “Push Data to Vector DB”.
Step 2: Set Up the Google Drive Trigger
- Add a Google Drive Trigger node.
- Set the trigger to “On Changes Involving a Specific Folder”.
- Connect your Google account (if you haven’t, you’ll need to set up credentials—see our N8N beginner tutorial for help).
- Select the folder you want to use (e.g., “N8N Chatbot Tutorial”).
- Set it to watch for “File Created” events.
This node will now activate your workflow anytime a new file is added to that folder.
Step 3: Download the File from Google Drive
- Add a Google Drive node (the regular one, not the trigger).
- Set the operation to “Download a File”.
- Pass the File ID from the trigger node into this node. You can do this by dragging the
fileId
field from the trigger node into the “File ID” field in this node.
Step 4: Configure the Vector Database with Pinecone
- In your Pinecone dashboard, create a new index. Name it
chatbot-tutorial
and selecttext-embedding-3-small
as the model. Note the dimension value (e.g., 512). - Go to the “API Keys” section and create a new key.
- Back in N8N, add a Pinecone Vector Store node and select “Add Documents to Vector Store”.
- Create new credentials using your Pinecone API Key and select the index you just created.
- Crucial: In the node’s options, set the
Namespace
tochatbot-tutorial
and theDimension
to match your index (e.g., 512).
Step 5: Set Up the AI Embeddings
- Add an OpenAI Embeddings node.
- Connect your OpenAI account by generating an API key in your OpenAI platform settings and adding it to N8N.
- Set the model to
text-embedding-3-small
.
Step 6: Connect the Data Flow
- Add a Default Data Loader node between the Google Drive node and the Pinecone node. Set it to “Binary” to format the file data correctly.
- Connect the nodes as shown below. Your final workflow should look like this: Google Drive Trigger → Google Drive (Download) → Default Data Loader → OpenAI Embeddings → Pinecone Vector Store
Step 7: Test the Data Workflow
Upload a .txt
file with some sample content (e.g., information about your business services) to your designated Google Drive folder. Activate and execute the workflow. If successful, you should see the documents processed and uploaded to your Pinecone index. You can check the record count in your Pinecone dashboard to confirm.
Part 2: Building the Main Chatbot Workflow
Now, let’s build the brain that will query this knowledge base and talk to your users.
Step 1: Create a New Workflow
Create a new workflow and name it “Chatbot Tutorial”.
Step 2: Add the Chat Trigger
- Add a Chat Trigger node. This node creates the public interface for your chatbot.
- Keep the default settings for now.
Step 3: Build the AI Agent
- Add an AI Agent node and connect it to the Chat Trigger.
- System Message: This is critical for guiding the chatbot’s behavior. Use a prompt like: “You are a friendly, helpful, and professional AI assistant for the WebSense Pro knowledge base. Your name is WebSense Pro Assistant. Answer the user’s question based only on the provided context. If the answer is not in the context, politely decline to answer. Do not hallucinate or make up information.”
- Chat Model: Add an OpenAI Chat Model node connected to the AI Agent. Select your OpenAI account and choose a model like
gpt-4o-mini
for a good balance of speed and cost. - Memory: Add a Simple Memory node and connect it to the AI Agent. Set the context window to
20
so it remembers the last 20 messages of the conversation.
Step 4: Give the AI Agent Access to Your Knowledge Base
- Add a Vector Store Question Answer Tool node to the AI Agent.
- In the tool’s description, write: “Return data related to WebSense Pro services.” This helps the AI decide when to use this tool.
- Now, connect the same Pinecone Vector Store and OpenAI Embeddings nodes you used in the first workflow. Ensure the
Namespace
andDimensions
are set correctly here as well. - Connect another OpenAI Chat Model node to the tool for its processing.
Your AI Agent setup should look like this inside the node:
- Input: From Chat Trigger
- Model: OpenAI Chat Model
- Memory: Simple Memory
- Tool: Vector Store QA Tool (connected to Pinecone & Embeddings)
Step 5: Test Your Chatbot
Save and activate the workflow. Click “Open Chat” in the Chat Trigger node and ask a question based on the data you uploaded earlier (e.g., “What services do you offer?”). If it answers correctly, you’re on the right track!
Part 3: Adding Chat Logging to Google Sheets
Let’s keep a record of all conversations.
Step 1: Add the Google Sheets Node
- After the AI Agent node, add a Google Sheets node and set the operation to “Append or Update Row in Sheet”.
- Connect your Google account and select (or create) a spreadsheet with a sheet named “Chats”.
- Map the columns:
- Timestamp:
{{ $now }}
(or use a function to get the current time) - User Input:
{{ $node["Chat Trigger"].json["message"] }}
- Bot Response:
{{ $node["AI Agent"].json["response"] }}
- Timestamp:
Step 2: Ensure Smooth Chat Flow
Adding a node after the AI Agent can break the chat memory. To fix this:
- Add a Set node after the Google Sheets node.
- Create a new variable called
text
. - Set its value to the bot’s response from the AI Agent node (e.g.,
{{ $node["AI Agent"].json["response"] }}
). This passes the correct response back to the chat interface.
Your final workflow order should be: Chat Trigger → AI Agent → Google Sheets → Set → (Output back to chat).
Part 4: Embedding on Your WordPress Website
Step 1: Get Your Public Webhook URL
- Double-click on your Chat Trigger node.
- Click on “Make chat publicly available” and copy the generated URL.
Step 2: Add the Code to WordPress
- In your WordPress dashboard, go to Appearance > Theme File Editor.
- Select your active theme and edit the
functions.php
file. - Add the following code snippet to the end of the file, replacing
YOUR_WEBHOOK_URL
with the URL you copied:function add_n8n_chatbot() { ?> <script> window.n8nChatSettings = { webhookUrl: 'YOUR_WEBHOOK_URL', welcomeMessage: 'Hi! I am the WebSense Pro assistant. How can I help you?', }; (function() { var script = document.createElement('script'); script.src = 'https://chat.n8n.io/webchat.js'; document.head.appendChild(script); })(); </script> <?php } add_action('wp_footer', 'add_n8n_chatbot');
- Update the file.
That’s it! Your custom AI chatbot should now be live on your website, ready to answer questions based solely on your data.
Conclusion:
You’ve just built a powerful, no-code AI chatbot with a custom knowledge base. This system is incredibly flexible. To update your chatbot’s knowledge, simply upload a new document to your Google Drive folder and run the first workflow.