Local document question answering with Ollama AI, Agentic RAG & PGVector
Needs changesWhat this workflow does
This AI workflow has 35 nodes and runs when a chat message arrives (plus 2 other triggers). Along the way it connects Postgres Chat Memory, Postgres, Embeddings Ollama and OpenAI Chat Model and 1 more.
How it runs
Trigger: When a chat message arrives (plus 2 other triggers).
- Edit Fields (Edit Fields (Set)): sets 2 fields: chatInput, sessionId
- Loop Over Items (Loop Over Items (Split in Batches)): loops over the items in batches
- RAG AI Agent (AI Agent): runs an AI agent, with model: Ollama (Change Base URL); 4 tools (List Documents, Get File Contents, Query Document Rows, Postgres PGVector Store); memory: Postgres Chat Memory
- Set File ID (Edit Fields (Set)): sets 3 fields: file_id, file_type, file_title
- Respond to Webhook: sends the response back to the webhook caller
- Delete Old Doc Records (Postgres): run a query
- Delete Old Data Records (Postgres): run a query
- Insert Document Metadata (Postgres): create or update
- Read/Write Files from Disk: reads a file from disk
- Switch: routes items into 4 branches
…plus 12 more steps. See the full node list below.
Services it uses
Before you upgrade to n8n 3.0
1 thing in this workflow is removed in n8n 3.0. Fix it before you upgrade:
- AI Agent v1 (old agent modes) in RAG AI Agent (v1.6): replace with Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent.
Rather not rewrite it? Many of these flows can be rebuilt in Make (free plan).
| Removed in 3.0 | Replace with |
|---|---|
| AI Agent v1 (old agent modes) RAG AI Agent (v1.6) | Latest AI Agent node (Tools Agent). For SQL Agent, use a Postgres or MySQL tool with a recent AI Agent. |
Nodes used (20)
- Default Data Loader
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - Extract from File
n8n-nodes-base.extractFromFile - Postgres Chat Memory
@n8n/n8n-nodes-langchain.memoryPostgresChat - Edit Fields (Set)
n8n-nodes-base.set - Respond to Webhook
n8n-nodes-base.respondToWebhook - Chat Trigger
@n8n/n8n-nodes-langchain.chatTrigger - Webhook
n8n-nodes-base.webhook - Aggregate
n8n-nodes-base.aggregate - Summarize
n8n-nodes-base.summarize - AI Agent
@n8n/n8n-nodes-langchain.agent - Switch
n8n-nodes-base.switch - Postgres
n8n-nodes-base.postgres - Postgres Tool
n8n-nodes-base.postgresTool - Loop Over Items (Split in Batches)
n8n-nodes-base.splitInBatches - Local File Trigger
n8n-nodes-base.localFileTrigger - Read/Write Files from Disk
n8n-nodes-base.readWriteFile - Embeddings Ollama
@n8n/n8n-nodes-langchain.embeddingsOllama - Recursive Character Text Splitter
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - Postgres PGVector Store
@n8n/n8n-nodes-langchain.vectorStorePGVector
From the author
🚀 n8n Local AI Agentic RAG Template Author: Jadai kongolo What is this? This template provides an entirely local implementation of an Agentic RAG (Retrieval Augmented Generation) system in n8n that can be extended easily for your specific use case and…