AI chatbot for n8n that answers from a Supabase knowledge base
An n8n chatbot that searches a Supabase vector store before every answer, so it stays accurate on large content, and emails your team when it cannot help.
Prerequisites
- An n8n instance, cloud or self-hosted
- A Supabase table filled by the website ingestion recipe, with the match_documents function
- An OpenAI API key, used for both the chat model and embeddings
- SMTP credentials in n8n for the Send Email node
The AI FAQ chatbot reads one pasted block of text on every turn. This version searches a Supabase vector store instead, pulling back only the handful of chunks relevant to the question, so it stays accurate when your content is large.
You need a populated table first. Follow the website to Supabase recipe to create it.
What you'll build
A chatbot with the same shape as the AI FAQ chatbot, with one change: the knowledge field and the WHAT YOU KNOW block are gone. The agent has a knowledge_base tool instead, and the system prompt tells it to search before answering and to say it is not sure if nothing relevant comes back.
How it works
- A webhook receives each widget message and checks a shared secret.
- The agent searches the Supabase vector store before answering. The search compares the meaning of the question with every stored chunk and returns the closest five.
- If nothing relevant comes back, the bot says it is not sure instead of guessing.
- If it cannot help, it takes an email address and calls the request_contact tool, which emails your team.
Retrieval matches meaning, not keywords, but it is not perfect. If the wording of a question is very different from your source content, a relevant chunk can be missed. The fix is usually to reword the source content to match how people actually ask, not to change the workflow.
What it costs
The workflow is free to download and use. Your AI provider charges per conversation, and your n8n hosting and the plan for the service you connect apply as normal. For N8N Chat UI plans, see pricing. Embeddings for each question are billed by OpenAI per token.
Set it up
- Import the workflow. Download the file with the button at the top of this page and import it with Workflows → Import from File. It holds the main chatbot and its tool workflow on one canvas, each in a labelled section.
- Move the contact tool. For the request contact section below the main flow: select its nodes, copy them, create a new empty workflow and paste. Save it, then open the request_contact tool node under the agent and select that workflow. The knowledge_base tool lives in the main workflow and needs no copying.
- Fill in Chatbot settings. Set
company_name. - Choose a secret. Put a random string in
webhook_secretin Chatbot settings. Your widget sends it so nobody else can call your workflow and run up your AI bill. It is a deterrent, not strong security: anything sent from a browser can be read. - Add your AI credential. Open GPT-4.1 mini model and add your OpenAI credential. Swap the node for another chat model if you prefer.
- Connect Supabase. Create a Supabase API credential (project URL as host, service role key) and attach it to the knowledge_base node. Check its table is
documentsand itsqueryNameismatch_documents. - Add embeddings. Attach your OpenAI credential to Create search embeddings. This must be the same model used at ingestion,
text-embedding-3-smallby default, or the vectors will not be comparable. - Set the handoff address. In the request contact workflow, open Tool settings, set
handoff_email, and attach your SMTP credential to the email node.
Test it
Send a test message before you connect a widget. n8n's built-in chat panel needs a Chat Trigger, so it will not open for this workflow. Instead, click Test workflow, then send a POST request to the Test URL shown on the Chat webhook node:
curl -X POST 'YOUR_TEST_URL' \
-H 'Content-Type: application/json' \
-d '{"chatInput":"Hello","sessionId":"test-1","metadata":{"webhook_secret":"YOUR_SECRET"}}'The test URL listens for one request each time you click Test workflow. For a longer conversation, activate the workflow and send requests to the production URL, then read each run under Executions. Reuse the same sessionId to continue a conversation, because memory is kept per session.
Things to try:
- Ask something your source content covers, but phrase it differently from the source text. The execution log should show the knowledge_base tool call and the chunks it returned.
- Ask something that is not covered anywhere. The bot should say it is not sure.
Add it to your site
Activate the workflow and use its production webhook URL as your widget's chat endpoint. Send the same secret in the widget metadata, for example metadata: { page_url: window.location.href, webhook_secret: 'YOUR_SECRET' }. The metadata docs explain how metadata reaches n8n.
Any chat front end that can POST chatInput, sessionId and metadata to a webhook and read { "output": "..." } back will work. N8N Chat UI is built for exactly this.
Troubleshooting
The bot does not know something that is definitely in my content
Check the execution log for what the agent searched for, and compare it with how your source content phrases the topic. If they are very different, reword the source content.
The bot retrieves irrelevant chunks
n8n's Supabase Vector Store node does not accept a custom relevance cutoff. The match_documents function already drops low-similarity matches with a built-in threshold of 0.75. If irrelevant chunks still get through, lower topK on the knowledge_base node, lower chunk_size in the ingestion workflow so chunks stay focused, or improve the source content. A page that blends two topics in one paragraph can surface for both.
The node fails on every call
The match_documents function does not exist in your database, or the embedding model does not match the vector(1536) column. See the SQL on the ingestion recipe.
The bot replies but the tool never runs
The tool node is not linked to its workflow. Open it and select the workflow you created from the tool section. A bare placeholder ID means it is still unlinked.
My conversations reset when n8n restarts
Memory is an in-memory buffer so the template works as soon as you import it. A restart or redeploy drops conversations in progress. Before a busy launch, swap Conversation memory for Postgres Chat Memory. Nothing else changes.
I get a 401 as soon as I test
The Request from your widget? check compares metadata.webhook_secret in the request with webhook_secret in Chatbot settings. If they differ, or the request has no metadata, the workflow returns a 401 before the agent runs.
Take it further
Each retrieved chunk carries its source URL as metadata, so you can have the agent cite the page it used. It is not enabled here because it changes the tone of every answer. The same swap works for any recipe on this site: remove the knowledge field, add the vector store tool and its embeddings node, and update the prompt.