AutomationFlowsAI & RAG › RAG Reranking

RAG Reranking

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

Chat trigger trigger★★★★☆ complexityAI-powered26 nodesGoogle DriveDocument Default Data LoaderChat TriggerLm Chat Open RouterReranker CohereVector Store SupabaseEmbeddings Open AiAgent
AI & RAG Trigger: Chat trigger Nodes: 26 Complexity: ★★★★☆ AI nodes: yes

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
{
  "name": "RAG Reranking",
  "nodes": [
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "16ahWlNwBvd53xFHA4UUh6EbkFd8ogxBv",
          "mode": "list",
          "cachedResultName": "Rules_of_Golf_Simplified.pdf",
          "cachedResultUrl": "https://drive.google.com/file/d/16ahWlNwBvd53xFHA4UUh6EbkFd8ogxBv/view?usp=drivesdk"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -100,
        -320
      ],
      "id": "d690d954-6291-4355-9b51-42fe9ab2791a",
      "name": "Download File",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonMode": "expressionData",
        "jsonData": "={{ $('Code').item.json.fullText }}",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "ruleNumber",
                "value": "={{ $json.ruleNumber }}"
              }
            ]
          }
        }
      },
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1.1,
      "position": [
        460,
        -180
      ],
      "id": "ad9a4d3c-ace1-428c-8957-edb456bf864f",
      "name": "Default Data Loader"
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        40,
        -320
      ],
      "id": "f6d44c38-8cb4-43ad-8130-7ab8cd142c9a",
      "name": "Extract from File"
    },
    {
      "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;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        180,
        -320
      ],
      "id": "dfc604ab-b7bd-4a08-b65d-f8fe2c3b5c13",
      "name": "Code"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -280,
        -1180
      ],
      "id": "cc659be4-709e-4d59-a386-d7cc60166293",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        -100,
        -1040
      ],
      "id": "9f02235d-8c3f-4309-bd14-d4c6bcdfab11",
      "name": "GPT 4.1-mini",
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "typeVersion": 1,
      "position": [
        520,
        -1040
      ],
      "id": "dad869f9-4c1d-44a4-b523-31f007efccc7",
      "name": "Reranker Cohere",
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        320,
        -320
      ],
      "id": "24cbdd3d-afee-46d2-83ef-888d432b4874",
      "name": "Upload to Supabase",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to search the database",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "topK": 20,
        "useReranker": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        360,
        -1180
      ],
      "id": "f80184cb-fc7e-40d7-bf2d-a723350c9f0f",
      "name": "Supabase Vector Store",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        220,
        -600
      ],
      "id": "de08fce1-3db6-4452-a30a-27294328bdb9",
      "name": "GPT 4.1-mini1",
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "typeVersion": 1,
      "position": [
        780,
        -620
      ],
      "id": "2fbb1dbc-aeb3-4f5d-b1b1-f8947bec45e4",
      "name": "Reranker Cohere1",
      "credentials": {
        "cohereApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        620,
        -620
      ],
      "id": "64140fce-9e7c-4cd2-a5ba-2bfb4c8bdaad",
      "name": "Embeddings OpenAI2",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to search the database",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "topK": 20,
        "useReranker": true,
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "ruleNumber",
                "value": "={{ $('Metadata Agent').item.json.output }}"
              }
            ]
          }
        }
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        620,
        -760
      ],
      "id": "fe882466-73db-4141-8c70-baff299b4e1c",
      "name": "Supabase Vector Store1",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "# Vectorize Document w/ Metadata\n(this code node is set up for the golf rules PDF specifically)",
        "height": 440,
        "width": 1000,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -320,
        -460
      ],
      "id": "12e4fe9d-d97d-4252-a235-66017fadad66",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "# RAG Agent\n",
        "height": 380,
        "width": 620,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -320,
        -1280
      ],
      "id": "406521ff-0f01-4688-a352-62ae49d71ff6",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Vector Store w/ Reranker\n",
        "height": 380,
        "width": 380,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        300,
        -1280
      ],
      "id": "11f6a7fd-b540-43d9-ad55-86c2874e8ddd",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        300,
        -180
      ],
      "id": "d295d851-b64b-41c9-9289-f7c5c640b704",
      "name": "Embeddings OpenAI1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        360,
        -1040
      ],
      "id": "5b11e4ea-c497-4d18-8dfe-3dcdcadde1e6",
      "name": "Embeddings OpenAI",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "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"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -220,
        -760
      ],
      "id": "62282da2-0dc5-4758-8182-13a7bf1afff9",
      "name": "Metadata Agent"
    },
    {
      "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. "
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -80,
        -1180
      ],
      "id": "9fbd11cd-195d-4bbe-aa81-718c063d1133",
      "name": "RAG Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "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. "
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        200,
        -760
      ],
      "id": "150a92c9-fdb4-45e0-a838-45364dd6140b",
      "name": "RAG Agent 2"
    },
    {
      "parameters": {
        "content": "# RAG Agent\n",
        "height": 400,
        "width": 440,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        120,
        -880
      ],
      "id": "e149b963-2f39-472b-962a-12bdd270e63b",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Vector Store w/ Reranker & Metadata\n",
        "height": 400,
        "width": 380,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        560,
        -880
      ],
      "id": "ede1b0d8-d402-4fa5-abe0-8ee4169be45b",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "# Metadata Agent\n",
        "height": 400,
        "width": 440,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -320,
        -880
      ],
      "id": "c56cce9d-2d8c-4942-94fa-a8d62e062842",
      "name": "Sticky Note5"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -240,
        -320
      ],
      "id": "7e6dd534-9f8a-42c2-bac0-0bb0e4fa99e6",
      "name": "Manual Trigger"
    },
    {
      "parameters": {
        "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",
        "height": 800,
        "width": 700
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1040,
        -1280
      ],
      "id": "85ee82ce-f0b2-49f0-852e-9b888b9235a9",
      "name": "Sticky Note6"
    }
  ],
  "connections": {
    "Download File": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Upload to Supabase",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Upload to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT 4.1-mini": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Reranker Cohere": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "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
          }
        ]
      ]
    },
    "Reranker Cohere1": {
      "ai_reranker": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent 2",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Upload to Supabase",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Metadata Agent": {
      "main": [
        [
          {
            "node": "RAG Agent 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "80eccd78-53ac-4cca-aedd-63ddf77ff7af",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "p8bHqYEvjtOrvz3q",
  "tags": []
}

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.

About this workflow

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

Source: https://github.com/Zie619/n8n-workflows — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →