Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG
Needs changesWhat this workflow does
This AI workflow has 24 nodes and runs when a chat message arrives (plus 3 other triggers). Along the way it connects OpenAI Chat Model, Embeddings OpenAI, Google Drive and Postgres PGVector Store and 2 more.
How it runs
Trigger: When a chat message arrives (plus 3 other triggers).
- TestData (Edit Fields (Set)): sets or maps fields
- 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: OpenAI Chat Model; 1 tool (Docs RAG Tool); memory: Chat Memory
- Set File ID (Edit Fields (Set)): sets or maps fields
- Delete Old Doc Records (Postgres): uses Postgres
- Download File (Google Drive): uses Google Drive
- Extract Document Text (Extract from File): extracts data from a file
- Create Chunks From Doc (Code): runs custom JavaScript code
- Chunks To List (Split Out): splits a list into separate items
- Generate Contextual Text (Basic LLM Chain): sends a prompt to an LLM, with model: OpenAI Chat Model
…plus 2 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 (18)
- OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - Default Data Loader
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - Embeddings OpenAI
@n8n/n8n-nodes-langchain.embeddingsOpenAi - Google Drive
n8n-nodes-base.googleDrive - Google Drive Trigger
n8n-nodes-base.googleDriveTrigger - Extract from File
n8n-nodes-base.extractFromFile - Edit Fields (Set)
n8n-nodes-base.set - AI Agent
@n8n/n8n-nodes-langchain.agent - Loop Over Items (Split in Batches)
n8n-nodes-base.splitInBatches - Recursive Character Text Splitter
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - Chat Trigger
@n8n/n8n-nodes-langchain.chatTrigger - Code
n8n-nodes-base.code - Split Out
n8n-nodes-base.splitOut - Basic LLM Chain
@n8n/n8n-nodes-langchain.chainLlm - Postgres PGVector Store
@n8n/n8n-nodes-langchain.vectorStorePGVector - Postgres
n8n-nodes-base.postgres - Execute Workflow Trigger
n8n-nodes-base.executeWorkflowTrigger - Postgres Chat Memory
@n8n/n8n-nodes-langchain.memoryPostgresChat
From the author
🤖 AI Q&A Chatbot Workflow – Build Your Own AI Agent Trained on Private Documents This powerful AI automation add-on upgrades your Telegram Bot Starter Template by integrating a fully functional AI chatbot and a context-aware AI agent that answers user…