Automate Notion Knowledge Base Bot: Chatbot over Your Knowledge Base in n8n — Step by Step
Your Notion workspace holds months — maybe years — of accumulated knowledge: SOPs, meeting notes, product specs, onboarding docs, competitor research. And yet, every time a new hire joins or a client
Your Notion workspace holds months — maybe years — of accumulated knowledge: SOPs, meeting notes, product specs, onboarding docs, competitor research. And yet, every time a new hire joins or a client asks a question, someone has to manually hunt through dozens of pages to find the answer. That friction compounds daily. The knowledge exists. The problem is retrieval.
This guide shows you exactly how to build a RAG-powered chatbot over your Notion workspace using n8n — one that answers questions via Telegram, Slack, or a webhook, and cites the exact Notion page it pulled from. No more "I think it's in the wiki somewhere."
Why Notion Search Alone Isn't Enough
Notion's native search is keyword-based. Ask it "what's our refund policy for annual plans?" and it returns every page that contains "refund" or "annual" — ranked by recency, not relevance. You still have to read five pages to find the one sentence you need.
This is the core problem with documentation at scale: the content is there, but the interface forces you to know what you're looking for before you look. Teams end up with three failure modes:
- Repeated questions in Slack — people ask teammates instead of searching because search is unreliable
- Stale onboarding — new hires can't self-serve, so senior people get interrupted constantly
- Knowledge silos — tribal knowledge stays tribal because it's never surfaced contextually
A semantic search layer powered by embeddings and GPT-4o changes the retrieval model entirely. Instead of matching keywords, it understands the intent of the question and returns a synthesized answer from your actual content — with citations.
How the Notion Knowledge Base Bot Works
The architecture follows a standard RAG (Retrieval-Augmented Generation) pattern, implemented entirely inside n8n without custom code infrastructure:
- Ingestion pipeline: n8n reads your Notion pages via the Notion API, chunks the content, generates embeddings using OpenAI's
text-embedding-ada-002model, and stores them in a vector database (Pinecone or Supabase pgvector) - Query pipeline: When a user sends a question via Telegram, Slack, or webhook, n8n embeds the query, runs a similarity search against your vector store, retrieves the top-k matching chunks, and passes them as context to GPT-4o
- Response: GPT-4o synthesizes an answer using only the retrieved chunks, then returns it with a citation to the source Notion page
The result is a chatbot that knows exactly what's in your Notion workspace and can answer in natural language — sourced and verifiable.
Step-by-Step Setup in n8n
Step 1: Connect Notion and Configure the Ingestion Workflow
Start with the Notion node in n8n. Set the operation to Get Many on the Database object. You'll need your Notion Integration Token — create one at notion.so/my-integrations and share your target database with it.
In the Notion node settings, select the database that contains your knowledge base pages. If your content spans multiple databases (e.g., one for SOPs, one for product docs), use an IF node or a Switch node to fan out to multiple Notion nodes in parallel.
After fetching pages, add a Function node to chunk the content. Notion returns pages as rich-text blocks — you'll want to flatten them to plain text and split into chunks of roughly 500 tokens with 50-token overlap. This overlap prevents answers from being cut off at chunk boundaries.
Step 2: Generate Embeddings and Store in Vector DB
Connect the chunked output to the OpenAI node. Set the operation to Create Embedding, select the text-embedding-ada-002 model, and map the chunk text to the input field. This returns a 1536-dimension vector for each chunk.
Next, connect to your vector store. If you're using Pinecone, use the HTTP Request node with a POST to https://your-index.svc.environment.pinecone.io/vectors/upsert. Include the vector, a unique ID (combine page ID + chunk index), and metadata fields: page_id, page_title, page_url, and chunk_text. That metadata is what gets returned later and becomes your citation.
If you prefer Supabase, use the Supabase node to insert into a table with a vector column type. The pgvector extension handles similarity search natively via SQL.
Run this ingestion workflow manually the first time. Then schedule it with a Cron node — daily or weekly depending on how frequently your Notion workspace changes. You can also trigger it via webhook whenever a Notion page is updated using Notion's built-in automation feature to call the n8n webhook.
Step 3: Build the Query Workflow
Create a second workflow for handling user queries. Start with the appropriate trigger:
- Webhook node for API-based access or custom interfaces
- Telegram Trigger node for a Telegram bot (requires a bot token from @BotFather)
- Slack Trigger node for a Slack app with Events API enabled
Extract the user's question from the trigger payload. For Telegram, it's {{ $json.message.text }}. For Slack, it's {{ $json.event.text }}.
Pass the question to the OpenAI node again — this time also with Create Embedding — to generate the query vector. Then send that vector to Pinecone's /query endpoint (or run a pgvector similarity search in Supabase) requesting the top 5 matches with their metadata.
Now build the prompt. Use a Function node to construct a context block from the retrieved chunks:
const chunks = $input.all().map(item => {
return `Source: ${item.json.metadata.page_title} (${item.json.metadata.page_url})\n${item.json.metadata.chunk_text}`;
}).join('\n\n---\n\n');
return [{
json: {
prompt: `You are a helpful assistant with access to our internal knowledge base. Answer the question below using ONLY the provided context. If the context doesn't contain enough information, say so. Always cite the source page.\n\nContext:\n${chunks}\n\nQuestion: ${$node["Webhook"].json.query}`
}
}];
Feed this into the OpenAI node set to Message a Model, using gpt-4o. Set temperature to 0 — you want deterministic answers grounded in your content, not creative elaboration.
Finally, route the response back to the user via Telegram, Slack, or a webhook response node.
Step 4: Handle Multi-Turn Conversations (Optional)
For Telegram or Slack bots where context across messages matters, add a Redis node or use n8n's built-in static data to store conversation history per user ID. Pass the last 3-4 exchanges as additional context in your prompt. This lets users ask follow-up questions like "can you expand on that?" without losing the thread.
Key Benefits for Technical Founders and Ops Teams
Instant self-service for common questions. New hires can onboard without pulling senior team members away from deep work. Support staff can answer client questions in seconds instead of hunting through wikis.
Auditable answers with citations. Every response includes the source Notion page URL. If the answer is wrong or outdated, you know exactly where to go to fix it. This is critical for compliance-sensitive content like HR policies or financial procedures.
No infrastructure to maintain. The entire pipeline runs inside n8n — no separate Python service, no Docker containers, no GPU instances. If you're already running n8n (self-hosted or cloud), this adds zero operational overhead.
Incremental sync. You don't need to re-embed your entire knowledge base every time a page changes. Filter the Notion query by last_edited_time to only re-process pages modified since the last sync run.
Multi-channel with one workflow. The same query logic works for Telegram, Slack, and webhook. You build it once and route inputs from different sources to the same processing chain.
Common Pitfalls and How to Avoid Them
Chunk size misconfiguration. Chunks that are too small lose context — the answer requires reading two chunks together to make sense, but your retrieval only returns isolated fragments. Chunks that are too large inflate token costs and dilute relevance scores. Start at 400-500 tokens with 10% overlap and adjust based on your content type.
Stale embeddings. If your Notion pages are updated frequently and the cron sync isn't running often enough, the bot will answer from outdated content. Implement a webhook-triggered re-indexing for high-priority pages and use the incremental sync filter for everything else.
Not storing page URLs in metadata. This is the most common mistake. If you don't save the Notion page URL at ingestion time, you can't include citations in responses. Always store page_url, page_title, and last_edited_time as vector metadata fields.
Hallucination when context is thin. GPT-4o will sometimes synthesize an answer when retrieved chunks don't actually contain the information — especially if your prompt doesn't explicitly restrict it. Add a hard instruction: "If the provided context does not contain sufficient information to answer, respond with: 'I don't have that information in the knowledge base.'" Test this by asking questions about topics deliberately absent from your Notion.
Pinecone free tier limitations. The Pinecone free tier limits you to 100k vectors per index. For a large Notion workspace with thousands of pages, this fills up faster than expected. Either use Supabase pgvector (unlimited on self-hosted Postgres) or plan for a paid Pinecone tier from the start.
Missing Notion page permissions. The Notion integration only sees pages explicitly shared with it. A common setup error is sharing only the root database but not the pages inside it. In Notion, share the integration at the workspace level or individually add it to each database you want indexed.
Once deployed, this workflow runs silently in the background. Your team asks questions via Telegram or Slack, gets instant cited answers, and your Notion workspace becomes genuinely useful as a knowledge retrieval system — not just a place where documentation goes to be forgotten.
Ja construimos isso pra voce
Nao comece do zero. O Notion Knowledge Base Bot: Chatbot over Your Knowledge Base e um workflow n8n pronto para instalar — conecta suas ferramentas em minutos, sem codigo.
Instalar por $59 →