AutomationFlowsAI & RAG › Create RAG Vector Database From Google Drive Documents Using Gemini & Supabase

Create RAG Vector Database From Google Drive Documents Using Gemini & Supabase

ByMantaka Mahir @mantakamahir on n8n.io

This workflow automates the process of converting Google Drive documents into searchable vector embeddings for AI-powered applications:

Event trigger★★★★☆ complexityAI-powered16 nodesGoogle Gemini EmbeddingsDocument Default Data LoaderPostgresExecute Workflow TriggerGoogle DriveSupabase Vector Store
AI & RAG Trigger: Event Nodes: 16 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Documentdefaultdataloader → Google Gemini Embeddings 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": "97927b62-d8b9-4c98-b3d1-160c81c524e5",
      "name": "Embeddings Google Gemini4",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        208,
        320
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a9afa4ed-5e53-423c-9521-a79b17dbdde1",
      "name": "Default Data Loader2",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        384,
        304
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "id": "478d1053-af37-451e-9baf-7708f43653fa",
      "name": "Execute a SQL query",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -624,
        48
      ],
      "parameters": {
        "query": "DROP TABLE IF EXISTS documents CASCADE;\n\nCREATE EXTENSION IF NOT EXISTS vector;\n\nCREATE TABLE IF NOT EXISTS documents (\n  id bigserial PRIMARY KEY,\n  content text,\n  metadata jsonb,\n  embedding vector(768)\n);\n\nCREATE OR REPLACE FUNCTION match_documents(\n  query_embedding vector(768),\n  match_count int DEFAULT NULL,\n  filter jsonb DEFAULT '{}'::jsonb\n)\nRETURNS TABLE (\n  id bigint,\n  content text,\n  metadata jsonb,\n  similarity double precision\n)\nLANGUAGE sql\nAS $$\n  SELECT\n    d.id,\n    d.content,\n    d.metadata,\n    1 - (d.embedding <=> query_embedding) AS similarity\n  FROM documents d\n  WHERE (filter = '{}'::jsonb OR d.metadata @> filter)\n  ORDER BY d.embedding <=> query_embedding\n  LIMIT match_count;\n$$;\n",
        "options": {},
        "operation": "executeQuery"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "7e4395b7-b822-41b6-aac3-0d4c2e3a749b",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        -848,
        48
      ],
      "parameters": {
        "jsCode": "// Get the Drive_Folder_link from the workflow input\nconst driveUrl = $input.first().json.Drive_Folder_link;\n\n// Extract Google Drive folder/file ID from URL\nfunction getDriveId(url) {\n  const folderMatch = url.match(/\\/folders\\/([a-zA-Z0-9_-]+)/);\n  const fileMatch = url.match(/\\/file\\/d\\/([a-zA-Z0-9_-]+)/);\n  return folderMatch ? folderMatch[1] : (fileMatch ? fileMatch[1] : null);\n}\n\n// Process input items\nreturn items.map(item => {\n  const chatInput = item.json.chatInput || driveUrl || '';\n  const driveId = getDriveId(chatInput);\n\n  return {\n    json: {\n      originalInput: chatInput,\n      folderId: driveId,\n      driveId: driveId\n    }\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "3a4041d1-25ac-4ab4-974e-a5460c9a8ffa",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -1056,
        48
      ],
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n  \"Drive_Folder_link\": \"https://drive.google.com/drive/folders/example\"\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "92141102-016e-4e8a-b69f-f09d0522924d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1504,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 368,
        "height": 512,
        "content": "# \ud83d\udcc1 Drive to Supabase Vector Store for Study RAG\n\nProcesses Google Drive folder files into Supabase vector embeddings for RAG applications.\n\n**Flow:** Drive URL \u2192 Parse ID \u2192 Init DB \u2192 Fetch Files \u2192 Loop \u2192 Download \u2192 Embed \u2192 Store\n\n**Requirements:**\n- Google Drive OAuth2\n- Supabase + Postgres credentials\n- Google Gemini API key\n\n**Input:** `{\"Drive_Folder_link\": \"your_drive_url\"}`\n**Output:** Vector embeddings in Supabase documents table\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6960ace8-fd01-4f9e-acfc-05185a0b197f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1104,
        208
      ],
      "parameters": {
        "width": 176,
        "height": 128,
        "content": "**Trigger Node** - Starts workflow when called from another n8n workflow. Accepts Drive folder URL as input.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2befa4d1-ded3-4eeb-93ec-acdc9a9e22fb",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -864,
        208
      ],
      "parameters": {
        "width": 150,
        "height": 128,
        "content": "**Extract Folder ID** - Parses Google Drive URL using regex to extract folder/file ID for API calls.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e71b4968-43de-477f-9de6-474cd471c405",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -656,
        208
      ],
      "parameters": {
        "width": 176,
        "content": "**Initialize Database** - Creates Supabase vector table with pgvector extension and match_documents search function. \u26a0\ufe0f Drops existing table!\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4ac27951-096f-44ba-8e66-be73b3c0d380",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -192,
        48
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "d556d5eb-6216-4e39-bf8f-07a948fcbb0d",
      "name": "Search files and folders",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -416,
        48
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $('Code in JavaScript').item.json.folderId }}"
          }
        },
        "options": {},
        "resource": "fileFolder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "db2f57b6-1aa9-4926-a211-7362d5d4533e",
      "name": "Insert into Supabase Vectorstore",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        256,
        48
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "09addf62-6c1a-4af4-a5d5-6b2323f64886",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        48,
        64
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain"
            }
          }
        },
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0c929411-a2d2-49ff-ab92-09aeece9d892",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        224
      ],
      "parameters": {
        "width": 176,
        "height": 128,
        "content": "**List Drive Files** - Retrieves all files from the specified Google Drive folder using extracted folder ID.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b2b6df82-5145-4719-b3bc-a5501e31ed08",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -112
      ],
      "parameters": {
        "width": 150,
        "content": "**List Drive Files** - Retrieves all files from the specified Google Drive folder using extracted folder ID.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0d6c2252-f11a-4a12-978c-b121c68c8663",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -208
      ],
      "parameters": {
        "color": 7,
        "height": 240,
        "content": "**Store Embeddings** - Generates 768-dim vectors via Gemini and inserts documents into Supabase for semantic search.\n**AI Embeddings** - Converts text to 768-dimensional vectors using Google Gemini text-embedding-004 model.\n**Document Loader** - Extracts and formats text from binary files for the embedding generator.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Download File": {
      "main": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Execute a SQL query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute a SQL query": {
      "main": [
        [
          {
            "node": "Search files and folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader2": {
      "ai_document": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Search files and folders": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini4": {
      "ai_embedding": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Insert into Supabase Vectorstore": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "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 automates the process of converting Google Drive documents into searchable vector embeddings for AI-powered applications:

Source: https://n8n.io/workflows/10651/ — 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 template creates a comprehensive, production-ready Retrieval-Augmented Generation (RAG) system. It builds a sophisticated AI agent that can answer questions based on documents stored in a specifi

Reranker Cohere, Supabase Vector Store, Agent +10
AI & RAG

A complete AI-powered study assistant system that lets you chat naturally with your documents stored in Google Drive:

Google Gemini Embeddings, Supabase Vector Store, Memory Postgres Chat +9
AI & RAG

Api Schema Extractor. Uses manualTrigger, httpRequest, splitOut, textSplitterRecursiveCharacterTextSplitter. Event-driven trigger; 88 nodes.

HTTP Request, Text Splitter Recursive Character Text Splitter, Document Default Data Loader +9
AI & RAG

Wait Splitout. Uses manualTrigger, httpRequest, splitOut, textSplitterRecursiveCharacterTextSplitter. Event-driven trigger; 88 nodes.

HTTP Request, Text Splitter Recursive Character Text Splitter, Document Default Data Loader +9
AI & RAG

This workflow automates the process of discovering and extracting APIs from various services, followed by generating custom schemas. It works in three distinct stages: research, extraction, and schema

HTTP Request, Text Splitter Recursive Character Text Splitter, Document Default Data Loader +9