Building a RAG Knowledge Base Chatbot
- Build a complete end-to-end RAG system with separate ingestion and query workflows
- Configure both workflows to use the same embedding model and vector store index
- Test the system with in-scope, follow-up, and out-of-scope questions
- Implement a strategy for keeping the knowledge base current when source documents change
Putting It All Together
This lesson builds the complete RAG system: an ingestion workflow that loads your documents into a vector store, and a chat workflow where an AI Agent retrieves the most relevant chunks and uses them to answer questions accurately. This architecture powers most AI-powered help centres, internal knowledge bases, and documentation assistants.
Workflow 1: The Ingestion Pipeline
Create a new workflow for ingestion. This runs manually on demand and again whenever your knowledge base needs updating:
- Manual Trigger — start with a Manual Trigger so you control when ingestion runs.
- Google Drive node (or HTTP Request) — fetch the documents to index. A shared Google Drive folder where your team drops documentation files works well.
- Default Data Loader — converts binary files (PDF, DOCX, TXT) to text the splitter can process.
- Recursive Character Text Splitter — chunk size 800, overlap 160.
- OpenAI Embeddings sub-node — model: text-embedding-3-small. This is the model you must use again in the query workflow.
- Vector Store node in insert mode — connect Pinecone or Qdrant with your credentials and index name (for example, support-docs). Each chunk, its embedding, and source metadata are stored together.
Run this workflow once to build the initial knowledge base. Re-run whenever documents are added or updated.
Workflow 2: The Chat Query Pipeline
Create a second workflow for real-time queries:
- n8n Chat Trigger — the entry point for user messages.
- AI Agent node — with a system prompt that instructs the agent to check the knowledge base before answering:
"You are a support assistant. Always search the knowledge base before answering. If you cannot find a relevant answer there, say so clearly — do not invent information."
- Chat Model sub-node — connect your chosen LLM (same provider as usual).
- Window Buffer Memory sub-node — keeps conversation context across turns.
- Vector Store Tool sub-node — connects to the same Pinecone or Qdrant index used in ingestion, using the same text-embedding-3-small embeddings model. Description: "Search the support documentation for relevant answers to product questions."
Testing the System
After both workflows are active, open the Chat Trigger URL and run three types of tests:
- A question clearly covered in your documentation — the agent should find and cite relevant content.
- A follow-up question referencing the previous message — memory should maintain context correctly.
- A question not in the knowledge base — the agent should acknowledge the gap, not guess.
Read the execution trace after each test to confirm the Vector Store Tool was called and the retrieved chunks were relevant.
Keeping the Knowledge Base Current
The ingestion workflow should re-run whenever documents change. Common patterns:
- Add a Schedule Trigger to re-ingest nightly or weekly alongside the Manual Trigger.
- Add a Google Drive Trigger to fire ingestion automatically when a file is added or modified.
- Clear the vector index before re-ingesting to avoid accumulating duplicate chunks from previous runs.
- The ingestion workflow builds the knowledge base; the query workflow serves answers — they run independently
- Instruct the agent in its system prompt to search the knowledge base first before answering
- Testing with out-of-scope questions is essential — verify the agent admits gaps rather than hallucinating
- Clearing the index before re-ingestion prevents duplicate chunks from multiple ingestion runs accumulating over time