AutomationFlowsAI & RAG › Answer Questions From Documents with RAG Using Supabase, Openai & Cohere…

Answer Questions From Documents with RAG Using Supabase, Openai & Cohere…

Original n8n title: Answer Questions From Documents with RAG Using Supabase, Openai & Cohere Reranker

ByLuan Correia @luanstartflow on n8n.io

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

Chat trigger trigger★★★★☆ complexityAI-powered26 nodesGoogle DriveDocument Default Data LoaderChat TriggerOpenRouter ChatReranker CohereSupabase Vector StoreOpenAI EmbeddingsAgent
AI & RAG Trigger: Chat trigger Nodes: 26 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #6345 — 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
{
  "id": "p8bHqYEvjtOrvz3q",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "RAG Reranking",
  "tags": [],
  "nodes": [
    {
      "id": "d690d954-6291-4355-9b51-42fe9ab2791a",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -100,
        -320
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "16ahWlNwBvd53xFHA4UUh6EbkFd8ogxBv",
          "cachedResultUrl": "https://drive.google.com/YOUR_AWS_SECRET_KEY_HERE/view?usp=drivesdk",
          "cachedResultName": "Rules_of_Golf_Simplified.pdf"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "ad9a4d3c-ace1-428c-8957-edb456bf864f",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        460,
        -180
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "ruleNumber",
                "value": "={{ $json.ruleNumber }}"
              }
            ]
          }
        },
        "jsonData": "={{ $('Code').item.json.fullText }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f6d44c38-8cb4-43ad-8130-7ab8cd142c9a",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        40,
        -320
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "dfc604ab-b7bd-4a08-b65d-f8fe2c3b5c13",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        180,
        -320
      ],
      "parameters": {
        "jsCode": "// n8n Code Node - Split Golf Rules\n// This code takes the input text and splits it into separate items for each rule\n\n// Get the input text from the first item\nconst inputText = $input.first().json.text;\n\n// Split the text by \"Rule\" pattern, keeping the \"Rule\" text with each section\nconst ruleSections = inputText.split(/(?=Rule \\d+)/);\n\n// Remove the first empty element (everything before the first \"Rule\")\nconst cleanedSections = ruleSections.filter(section => section.trim().startsWith('Rule'));\n\n// Create output items - one for each rule\nconst outputItems = cleanedSections.map((ruleText, index) => {\n  // Extract rule number from the text\n  const ruleMatch = ruleText.match(/Rule (\\d+)/);\n  const ruleNumber = ruleMatch ? ruleMatch[1] : (index + 1).toString();\n  \n  // Extract rule title (everything between \"Rule X \u2013\" and the first numbered item)\n  const titleMatch = ruleText.match(/Rule \\d+ \u2013 (.+?)(?=\\n1\\.|\\n\\d+\\.)/);\n  const ruleTitle = titleMatch ? titleMatch[1].trim() : 'Unknown Rule';\n  \n  return {\n    json: {\n      ruleNumber: ruleNumber,\n      ruleTitle: ruleTitle,\n      fullText: ruleText.trim(),\n      originalIndex: index\n    }\n  };\n});\n\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "cc659be4-709e-4d59-a386-d7cc60166293",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -280,
        -1180
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "9f02235d-8c3f-4309-bd14-d4c6bcdfab11",
      "name": "GPT 4.1-mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        -100,
        -1040
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "dad869f9-4c1d-44a4-b523-31f007efccc7",
      "name": "Reranker Cohere",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        520,
        -1040
      ],
      "parameters": {},
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "24cbdd3d-afee-46d2-83ef-888d432b4874",
      "name": "Upload to Supabase",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        320,
        -320
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f80184cb-fc7e-40d7-bf2d-a723350c9f0f",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        360,
        -1180
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 20,
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "useReranker": true,
        "toolDescription": "Use this tool to search the database"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "de08fce1-3db6-4452-a30a-27294328bdb9",
      "name": "GPT 4.1-mini1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        220,
        -600
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2fbb1dbc-aeb3-4f5d-b1b1-f8947bec45e4",
      "name": "Reranker Cohere1",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        780,
        -620
      ],
      "parameters": {},
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "64140fce-9e7c-4cd2-a5ba-2bfb4c8bdaad",
      "name": "Embeddings OpenAI2",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        620,
        -620
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fe882466-73db-4141-8c70-baff299b4e1c",
      "name": "Supabase Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        620,
        -760
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 20,
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "ruleNumber",
                "value": "={{ $('Metadata Agent').item.json.output }}"
              }
            ]
          }
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "useReranker": true,
        "toolDescription": "Use this tool to search the database"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "12e4fe9d-d97d-4252-a235-66017fadad66",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -460
      ],
      "parameters": {
        "color": 2,
        "width": 1000,
        "height": 440,
        "content": "# Vectorize Document w/ Metadata\n(this code node is set up for the golf rules PDF specifically)"
      },
      "typeVersion": 1
    },
    {
      "id": "406521ff-0f01-4688-a352-62ae49d71ff6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -1280
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 380,
        "content": "# RAG Agent\n"
      },
      "typeVersion": 1
    },
    {
      "id": "11f6a7fd-b540-43d9-ad55-86c2874e8ddd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -1280
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 380,
        "content": "## Vector Store w/ Reranker\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d295d851-b64b-41c9-9289-f7c5c640b704",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        300,
        -180
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5b11e4ea-c497-4d18-8dfe-3dcdcadde1e6",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        360,
        -1040
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "62282da2-0dc5-4758-8182-13a7bf1afff9",
      "name": "Metadata Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -220,
        -760
      ],
      "parameters": {
        "options": {
          "systemMessage": "=# Overview\nYour job is to understand the rule number that the human is requesting and output only the number.\n\n## Example\nInput - what's rule number 27?\nOutput - 27"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "9fbd11cd-195d-4bbe-aa81-718c063d1133",
      "name": "RAG Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -80,
        -1180
      ],
      "parameters": {
        "options": {
          "systemMessage": "=# Overview\nYou are an AI agent who is an expert at the rules of golf. You will receive a question from the human, and you must use your tool called \"Supabase Vector Store\" in order to retrieve information from the database to make sure you are answering the question accurately. "
        }
      },
      "typeVersion": 2
    },
    {
      "id": "150a92c9-fdb4-45e0-a838-45364dd6140b",
      "name": "RAG Agent 2",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        200,
        -760
      ],
      "parameters": {
        "text": "={{ $('When chat message received').item.json.chatInput }}",
        "options": {
          "systemMessage": "=# Overview\nYou are an AI agent who is an expert at the rules of golf. You will receive a question from the human, and you must use your tool called \"Supabase Vector Store\" in order to retrieve information from the database to make sure you are answering the question accurately. "
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "e149b963-2f39-472b-962a-12bdd270e63b",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        120,
        -880
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 400,
        "content": "# RAG Agent\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ede1b0d8-d402-4fa5-abe0-8ee4169be45b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -880
      ],
      "parameters": {
        "color": 5,
        "width": 380,
        "height": 400,
        "content": "## Vector Store w/ Reranker & Metadata\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c56cce9d-2d8c-4942-94fa-a8d62e062842",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -880
      ],
      "parameters": {
        "color": 6,
        "width": 440,
        "height": 400,
        "content": "# Metadata Agent\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7e6dd534-9f8a-42c2-bac0-0bb0e4fa99e6",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -240,
        -320
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "85ee82ce-f0b2-49f0-852e-9b888b9235a9",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        -1280
      ],
      "parameters": {
        "width": 700,
        "height": 800,
        "content": "# \ud83d\udee0\ufe0f Setup Guide  \n**Author:** [Nate Herk](https://www.youtube.com/@nateherk)\n\nFollow the steps below to get your Retrieval-Augmented Generation (RAG) workflow up and running:\n\n### \u2705 Step 1: Connect Your [Supabase](https://supabase.com/) Vector Store  \nEnsure your Supabase instance is ready and accessible. This will store your embedded documents with metadata.\nHere is a [video tutorial](https://youtu.be/JjBofKJnYIU) on setting that up.\n\n### \u2705 Step 2: Connect Your [OpenAI](https://platform.openai.com/account/api-keys) Embeddings  \nUse the `text-embedding-3-small` or similar model for embedding your documents. Make sure your API key is active.\n\n### \u2705 Step 3: Connect Your [OpenAI API Key](https://platform.openai.com/account/api-keys)  \nThis powers your embedding generation model. Add it via the HTTP Request node or a credential.\n\n### \u2705 Step 4: Add Your [OpenRouter](https://openrouter.ai/) API Key  \nUse this for your main RAG agent\u2014add your key via HTTP request or credential node.\n\n### \u2705 Step 5: Connect a [Cohere](https://dashboard.cohere.com/api-keys) Re-Ranker  \nThe re-ranker improves answer quality. Add your API key for better relevance ranking on retrieved documents.\n\n### \u2705 Step 6: Vectorize Documents with Metadata  \nEnsure your data ingestion process tags documents with meaningful metadata before vectorization. This helps with structured retrieval.\n\n### \ud83d\udcac Final Step: Start Chatting  \nPrompt your agent and test the RAG flow end-to-end\u2014watch it pull context-rich answers from your vector store.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "80eccd78-53ac-4cca-aedd-63ddf77ff7af",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Upload to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT 4.1-mini": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT 4.1-mini1": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent 2",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Metadata Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Metadata Agent": {
      "main": [
        [
          {
            "node": "RAG Agent 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reranker Cohere": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Reranker Cohere1": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Upload to Supabase",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Upload to Supabase",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent 2",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "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/6345/ — 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

• 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

RAG Reranking. Uses googleDrive, documentDefaultDataLoader, extractFromFile, chatTrigger. Chat trigger; 26 nodes.

Google Drive, Document Default Data Loader, Chat Trigger +5
AI & RAG

This workflow provides comprehensive AI-driven stock analysis, generating detailed deep reports by leveraging advanced vector-based data retrieval and API integrations for precise financial analytics

Tool Think, Supabase Vector Store, OpenAI Embeddings +9
AI & RAG

RAG Agent supabase. Uses chatTrigger, lmChatOpenAi, embeddingsOpenAi, formTrigger. Chat trigger; 23 nodes.

Chat Trigger, OpenAI Chat, OpenAI Embeddings +7