Notion Knowledge Base Assistant
detail.loadingPreview
An AI-powered assistant that leverages Notion as a knowledge base to answer user queries.
About This Workflow
This workflow acts as an intelligent assistant, connecting to a Notion knowledge base to retrieve and summarize information. It utilizes Langchain's AI Agent and tools to interact with Notion databases, allowing users to query specific information or gain insights from multiple records. The assistant is designed to be concise, accurate, and efficient, providing direct answers with relevant links when possible.
Key Features
- AI-powered Search: Uses GPT-4o (or other OpenAI models) to understand user queries and generate responses.
- Notion Integration: Connects to a specified Notion database for knowledge retrieval.
- Dynamic Tooling: Leverages Langchain tools (
toolHttpRequest) to query Notion's API for searching databases and retrieving page content. - Contextual Memory: Employs
Window Buffer Memoryto maintain conversation context for more coherent interactions. - Structured Data Handling: Extracts and formats data from Notion, including database details and tags, to inform the AI.
- Customizable AI Behavior: Configurable system message for the AI Agent, defining its role, behavior, error handling, and output format.
- Chat Interface: Provides a simple chat interface for user interaction via the
When chat message receivedtrigger.
How To Use
Notion Knowledge Base Assistant Setup Guide
This guide outlines how to set up and use the Notion Knowledge Base Assistant workflow.
Prerequisites:
- n8n Account: You need a running instance of n8n.
- Notion Account: Access to a Notion workspace.
- OpenAI Account: An API key for OpenAI models.
Setup Steps:
-
Add Notion Credentials:
- Navigate to Credentials in your n8n workspace.
- Click Add credential and select Notion API.
- Follow the official Notion guide to create an integration and obtain your API key.
- Give your credential a recognizable name (e.g.,
max-bot).
-
Add OpenAI Credentials:
- Navigate to Credentials in your n8n workspace.
- Click Add credential and select OpenAI API.
- Enter your OpenAI API key.
- Give your credential a recognizable name (e.g.,
Max's DevRel OpenAI account).
-
Configure
Get database detailsNode:- Drag and drop the
Get database detailsnode onto your canvas. - In the Database field, select your Notion database. If you've recently created an integration, you might need to manually enter the
databaseIdor click the refresh/add button to link it. The workflow snippet uses7ea9697d-4875-441e-b262-1105337d232ewhich is likely the ID of the "StarLens Company Knowledge Base". - Ensure the Notion API credential is set to the one you created in Step 1.
- Drag and drop the
-
Configure
Search notion databaseandSearch inside database recordNodes:- These nodes use the
toolHttpRequesttype. - Ensure the Notion API credential is set to the one you created in Step 1 for both nodes.
- The
urlparameter inSearch notion databaseuses{{ $json.notionID }}. ThisnotionIDis dynamically fetched by theFormat schemanode from theGet database detailsnode. - The
placeholderDefinitionsinSearch notion databasedefine how keywords and tags will be passed to the tool. - The
urlparameter inSearch inside database recordexpects apage_idwhich will be dynamically provided by the AI Agent based on search results.
- These nodes use the
-
Configure
OpenAI Chat ModelNode:- Ensure the OpenAI API credential is set to the one you created in Step 2.
- The
modelis set togpt-4o. You can change this to other compatible models if needed.
-
Configure
AI AgentNode:- The
textfield is set to={{ $json.chatInput }}, which comes from theWhen chat message receivedtrigger. - The
systemMessageis crucial for defining the AI's behavior. It instructs the AI on its role, how to query the Notion database, desired output format, and error handling. It also dynamically includes the{{ $json.databaseName }}.
- The
-
Configure
When chat message receivedNode:- This node acts as the chat trigger.
- Ensure the
publicoption is enabled if you want to share the chat URL. - The
initialMessagesprovide a greeting when the chat starts. - The
webhookId(b76d02c0-b406-4d21-b6bf-8ad2c623def3) should be unique to your instance.
-
Workflow Connections:
- The connections in the JSON define the flow:
When chat message receivedtriggers the process,Get database detailsfetches database info,Format schemaprepares variables, and then theAI AgentusesOpenAI Chat Model,Search notion database,Search inside database record, andWindow Buffer Memoryto process the request.
- The connections in the JSON define the flow:
-
Test the Workflow:
- Click the Chat button at the bottom of the
When chat message receivednode to test. - Alternatively, activate the workflow and copy the Chat URL provided by the
When chat message receivednode to interact with the assistant.
- Click the Chat button at the bottom of the
Customization and Notes:
- Notion Database: Ensure the Notion database you are connecting to has fields like 'question' (rich text) and 'tags' (multi-select) for the search functionality to work effectively.
- Tag Options: The
tagsOptionsvariable is dynamically generated from theGet database detailsnode. If your Notion database structure changes, you might need to adjust how this is fetched. - Error Handling: The
Sticky Note1provides important troubleshooting tips, particularly regarding theGet database detailsnode and potential resource not found errors. - Performance: The
Get database detailsnode fetches tag options, which adds a small delay. Refer to the detailed video mentioned inSticky Note1if you wish to optimize this. - AI Model: You can switch the
OpenAI Chat Modelto other models if desired, ensuring compatibility with Langchain.
Apps Used
Workflow JSON
{
"id": "ef913e62-46e2-475e-bb35-b860f37f0010",
"name": "Notion Knowledge Base Assistant",
"nodes": 27,
"category": "AI",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: ef913e62-46e2...
About the Author
Free n8n Workflows Official
System Admin
The official repository for verified enterprise-grade workflows.
Statistics
Related Workflows
Discover more workflows you might like
Build an AI Documentation Expert Chatbot with Gemini RAG
This n8n workflow automates the creation of an AI-powered expert chatbot capable of answering questions based on your documentation. It intelligently ingests, cleans, and processes your knowledge base, preparing it for a Retrieval Augmented Generation (RAG) pipeline with Google Gemini.
Generate Multilingual Image Captions and Overlay
This workflow generates captions for images using Google Gemini and overlays them onto the image, with support for multilingual output.
LangChain Workflow Retriever Example
Demonstrates using LangChain's Retriever QA Chain to query data retrieved from another workflow.