AutomationFlowsAI & RAG › Document-based AI Chatbot with Rag, Openai and Cohere Reranker

Document-based AI Chatbot with Rag, Openai and Cohere Reranker

ByAnderson Adelino @andersonadelino on n8n.io

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Chat trigger trigger★★★★☆ complexityAI-powered18 nodesChat TriggerAgentOpenAI ChatOpenAI EmbeddingsMemory Buffer WindowGoogle DriveDocument Default Data LoaderSupabase Vector Store
AI & RAG Trigger: Chat trigger Nodes: 18 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #6401 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "a8afd8c2-2bfd-49f3-9687-0d68c83db4ad",
      "name": "Chat Interface",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        80,
        100
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "00c21cda-1193-4cf5-9681-bf21ac2b269c",
      "name": "RAG Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        300,
        100
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an intelligent assistant with access to a knowledge base. Always search for relevant information before answering questions. Be helpful, accurate, and cite your sources when providing information from the knowledge base."
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c74d3fac-14ef-4809-b290-d0344db04c79",
      "name": "AI Model (OpenAI)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        180,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e8a473c1-4934-491b-8283-80d48982d604",
      "name": "Search Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        540,
        460
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "6fc17058-70f2-4bbe-a8b5-e35116f14853",
      "name": "Conversation Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        340,
        320
      ],
      "parameters": {
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "ba366390-61e3-4a25-8008-fb172145486a",
      "name": "Load Documents Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        100,
        760
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f97d305b-3a96-445c-ace2-535c60055a4f",
      "name": "Download PDF from Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        320,
        760
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "url",
          "value": "{{GOOGLE_DRIVE_FILE_URL}}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "9eec6cb6-f445-4add-8de9-1464b61dfa7a",
      "name": "Document Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        700,
        960
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e64b2357-0238-45ca-87bd-10f8deddd6e4",
      "name": "Process Document Text",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        840,
        960
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "source",
                "value": "={{ $node['Download PDF from Drive'].json.name }}"
              },
              {
                "name": "type",
                "value": "pdf"
              }
            ]
          }
        },
        "jsonData": "={{ $json.text }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1.1
    },
    {
      "id": "8b0645f9-dbcb-4613-9126-9efa824615bc",
      "name": "Knowledge Base Search",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        540,
        320
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 10,
        "options": {
          "queryName": "{{MATCH_FUNCTION_NAME}}"
        },
        "tableName": {
          "__rl": true,
          "mode": "id",
          "value": "{{VECTOR_TABLE_NAME}}"
        },
        "useReranker": true,
        "toolDescription": "Use this tool to search for information in the knowledge base. Always use this before answering questions to ensure accurate, up-to-date responses."
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "4cb8869a-de07-44f5-8f79-9b3c1207d21c",
      "name": "Store in Vector Database",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        700,
        760
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "{{MATCH_FUNCTION_NAME}}"
        },
        "tableName": {
          "__rl": true,
          "mode": "id",
          "value": "{{VECTOR_TABLE_NAME}}"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c8d8674d-ebe7-42fa-918e-ea9c5dc56b98",
      "name": "Extract PDF Content",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        500,
        760
      ],
      "parameters": {
        "options": {
          "maxPages": 500
        },
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "c5af8b70-bbda-4138-9598-dfd6c44a0eb5",
      "name": "Cohere Reranker",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        700,
        460
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c3af22b6-830c-43a6-9a8f-0f38f3dec647",
      "name": "Note: Chat Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 120,
        "content": "### 1\ufe0f\u20e3 Chat Trigger\nReceives messages from users through the chat interface"
      },
      "typeVersion": 1
    },
    {
      "id": "c3655d77-d3ee-4c21-8166-da08b15175d3",
      "name": "Note: RAG Agent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 120,
        "content": "### 2\ufe0f\u20e3 RAG Agent\nOrchestrates the conversation using tools and memory"
      },
      "typeVersion": 1
    },
    {
      "id": "ba9f02ea-6def-433a-9ccc-6f0ec1a1792b",
      "name": "Note: Knowledge Search",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        180
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 100,
        "content": "### 3\ufe0f\u20e3 Knowledge Search\nSearches the vector database for relevant information"
      },
      "typeVersion": 1
    },
    {
      "id": "ba558d29-fa87-4a2d-a63f-64a768bb2efb",
      "name": "Note: Reranker",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        440
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 100,
        "content": "### 4\ufe0f\u20e3 Reranker\nImproves search quality by reordering results"
      },
      "typeVersion": 1
    },
    {
      "id": "0ff39f38-d67e-4517-8f5b-834c032383dd",
      "name": "Note: Configuration",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 260,
        "height": 180,
        "content": "### Configuration Variables\n\nReplace these in the workflow:\n- **GOOGLE_DRIVE_FILE_URL**\n- **VECTOR_TABLE_NAME**\n- **MATCH_FUNCTION_NAME**"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Chat Interface": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cohere Reranker": {
      "ai_reranker": [
        [
          {
            "node": "Knowledge Base Search",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "AI Model (OpenAI)": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Search Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Knowledge Base Search",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Document Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Store in Vector Database",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Content": {
      "main": [
        [
          {
            "node": "Store in Vector Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Knowledge Base Search": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Process Document Text": {
      "ai_document": [
        [
          {
            "node": "Store in Vector Database",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Load Documents Trigger": {
      "main": [
        [
          {
            "node": "Download PDF from Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF from Drive": {
      "main": [
        [
          {
            "node": "Extract PDF Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Source: https://n8n.io/workflows/6401/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow acts as a 24/7 sales agent, engaging leads across WhatsApp, Instagram, Facebook, Telegram, and your website. It intelligently transcribes audio messages, answers questions using a knowle

Chat Trigger, Memory Postgres Chat, Tool Workflow +20
AI & RAG

• Create a Google Drive folder to watch. • Connect your Google Drive account in n8n and authorize access. • Point the Google Drive Trigger node to this folder (new/modified files trigger the flow).

Agent, Chat Trigger, Memory Buffer Window +14
AI & RAG

The workflow operates through a three-step process that handles incoming chat messages with intelligent tool orchestration: Message Trigger: The node triggers whenever a user message arrives and passe

Chat Trigger, Memory Postgres Chat, OpenAI Embeddings +16
AI & RAG

Build an All-Source Knowledge Assistant with Claude, RAG, Perplexity, and Drive. Uses chatTrigger, memoryPostgresChat, embeddingsOpenAi, rerankerCohere. Chat trigger; 40 nodes.

Chat Trigger, Memory Postgres Chat, OpenAI Embeddings +16
AI & RAG

Advanced Ai Demo Presented At Ai Developers 14 Meetup. Uses slack, stickyNote, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi. Chat trigger; 39 nodes.

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14