AutomationFlowsAI & RAG › Google Drive to Supabase Contextual Vector Database Sync for RAG Applications

Google Drive to Supabase Contextual Vector Database Sync for RAG Applications

ByMichael Taleb @michaeltaleb on n8n.io

• 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).

Chat trigger trigger★★★★★ complexityAI-powered76 nodesAgentChat TriggerMemory Buffer WindowOpenAI ChatGoogle DriveSupabaseCryptoChain Llm
AI & RAG Trigger: Chat trigger Nodes: 76 Complexity: ★★★★★ AI nodes: yes Added:
Google Drive to Supabase Contextual Vector Database Sync for RAG Applications — n8n workflow card showing Agent, Chat Trigger, Memory Buffer Window integration

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

This workflow follows the Agent → Chainllm 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": "XwFvFryyo4goPzpd",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Contextual Hybrid RAG AI copy",
  "tags": [
    {
      "id": "YINdrIOThMQjiVkB",
      "name": "RAG",
      "createdAt": "2025-06-18T21:07:48.174Z",
      "updatedAt": "2025-06-18T21:07:48.174Z"
    },
    {
      "id": "j0SNhalFSbPAhdWo",
      "name": "n8n creator",
      "createdAt": "2025-09-02T01:40:23.866Z",
      "updatedAt": "2025-09-02T01:40:23.866Z"
    }
  ],
  "nodes": [
    {
      "id": "c1422e6a-289f-4499-b19b-62df452010b2",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -2544,
        -736
      ],
      "parameters": {
        "options": {
          "systemMessage": "Only generate answers based on the results from the connected database. Do no under any circumstance, get answers from anywhere else.\nfor every query check the database to see if you can find an answer. If you can not or are not sure, then say 'Sorry, I don\u2019t know'. Never come up with answers. Only get answers from the database"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "efb0bd4c-0b6d-4b96-8e8d-d1b511174151",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -2784,
        -736
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "3c285b17-d4f0-4e8e-809b-38be2a5ede94",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -2544,
        -528
      ],
      "parameters": {
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "8a624394-5019-4a67-a31c-c56fad7b1406",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -2704,
        -528
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "317048f7-1423-4922-ac19-ad1b79152359",
      "name": "Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -3536,
        304
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "27074acb-2256-4b79-a093-df35755ca0e8",
      "name": "Search Record Manager",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -2608,
        304
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "gd_file_id",
              "keyValue": "={{ $('Loop Over Items').item.json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "record_managerhs",
        "operation": "getAll"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "cc825e4c-1f68-4688-8e32-5d08b3aab1ac",
      "name": "Create Row in Record Manager",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1808,
        48
      ],
      "parameters": {
        "tableId": "record_managerhs",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "gd_file_id",
              "fieldValue": "={{ $('Loop Over Items').item.json.id }}"
            },
            {
              "fieldId": "hash",
              "fieldValue": "={{ $('Generate Hash').item.json.hash }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "39445058-69b3-4bf1-8236-99a4a55e7d86",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -2416,
        288
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "does not exist",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "231bfd13-5f93-4801-b0f5-9ff2d949c165",
                    "operator": {
                      "type": "object",
                      "operation": "empty",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "modified",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "b311878c-297f-4d5b-ba2f-f1babb9c9f7b",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $json.hash }}",
                    "rightValue": "={{ $('Generate Hash').item.json.hash }}"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "exist",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "dc26f05e-859a-40a4-b0e3-49abc55397a5",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Generate Hash').item.json.hash }}",
                    "rightValue": "={{ $json.hash }}"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.2
    },
    {
      "id": "10062467-974d-4103-aeb3-bff32d0c6e3f",
      "name": "Delete Previous Vectors",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -2016,
        368
      ],
      "parameters": {
        "tableId": "documentshs",
        "operation": "delete",
        "filterType": "string",
        "filterString": "=metadata->>file_id=eq.{{ $('Loop Over Items').item.json.id }}"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "e145b247-04d6-40f9-b3ab-7ad034aa0a31",
      "name": "Generate Hash",
      "type": "n8n-nodes-base.crypto",
      "position": [
        -2848,
        304
      ],
      "parameters": {
        "type": "SHA256",
        "value": "={{ $json.text }}",
        "dataPropertyName": "hash"
      },
      "typeVersion": 1
    },
    {
      "id": "40aa27bb-4577-4d2d-abc4-0ed103fc0cbd",
      "name": "Update Record Manager",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1600,
        368
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "keyValue": "={{ $('Search Record Manager').item.json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "record_managerhs",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "hash",
              "fieldValue": "={{ $('Generate Hash').item.json.hash }}"
            }
          ]
        },
        "operation": "update"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f0c2dcd5-5fe8-4968-a510-0f7d997d3b2f",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1824,
        368
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "56bc70d8-aba3-4534-be6b-05cce089505a",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        -1248,
        272
      ],
      "parameters": {
        "text": "=# File Name\n{{ $('Loop Over Items').item.json.name}}\n\n# File Content\n{{ $('Set Text').item.json.text.split(/\\s+/).length > 500\n? $('Set Text').item.json.text.split(/\\s+/).slice(0, 500).join(' ') + '...'\n: $('Set Text').item.json.text}}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "=Based on the provided file name and file contents, extract out a 1 sentence description of what the document is about and classify the document based on motorsport category. \n\n Only output JSON in the following format \n\n{ \n\"document_summary\": \"document summary\"\n}\n\nIf you are unsure, just output N/A in the field. \n\n"
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.7
    },
    {
      "id": "c99060a8-fe04-44c8-86ad-76ad9c0f2f6c",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -1072,
        432
      ],
      "parameters": {
        "jsonSchemaExample": "{ \n\"documentSummary\": \"document summary\"\n} "
      },
      "typeVersion": 1.3
    },
    {
      "id": "478f6320-0c37-478c-8321-8083e5d903fe",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -1264,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "responseFormat": "json_object"
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3e9028df-ff29-4599-9ae9-c08a3811f047",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -3344,
        304
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "df98c1e9-b29c-4558-bbe4-a8925fd5a2f1",
      "name": "Set Text",
      "type": "n8n-nodes-base.set",
      "position": [
        -3104,
        304
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "766bf659-155f-4d60-a033-085b3a752933",
              "name": "text",
              "type": "string",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "258005cc-104e-4e31-96f0-a3fae138da93",
      "name": "Loop Over Items1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2224,
        976
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "84ac45bc-27c8-4fce-8e03-be8c9cf18fe8",
      "name": "Search Record Manager1",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1936,
        976
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "gd_file_id",
              "keyValue": "={{ $('Loop Over Items1').item.json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "record_managerhs",
        "operation": "getAll"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "81fc8e77-f1fb-4914-87b7-489bdcdf3f9d",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        -1728,
        976
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "21ca0db4-5ca4-49e8-86c1-9e09c469122d",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{$json}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9561c9dd-0b82-4cdb-bed0-a3307d206394",
      "name": "Delete Previous Vectors1",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1472,
        976
      ],
      "parameters": {
        "tableId": "documentshs",
        "operation": "delete",
        "filterType": "string",
        "filterString": "=metadata->>file_id=eq.{{ $('Loop Over Items1').item.json.id }}"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "31cc03e7-50db-4c6d-b266-136225457218",
      "name": "Aggregate1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1280,
        976
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "0c76dd9b-be10-4fdd-8536-ea3eb75a6cba",
      "name": "Delete Record from Record Manager1",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -1072,
        976
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "keyValue": "={{ $('Search Record Manager1').item.json.id }}",
              "condition": "eq"
            }
          ]
        },
        "tableId": "record_managerhs",
        "operation": "delete"
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "c41851a0-ba52-432d-ae00-752bb630cead",
      "name": "Google Drive2",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -848,
        976
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Loop Over Items1').item.json.id }}"
        },
        "options": {},
        "operation": "deleteFile"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "03516980-317e-483d-9471-6cf9e3148415",
      "name": "Watch GD Trash",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -2432,
        976
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1gwf7pIH8X5wU-i0YMw-j7qPSA4MnA40L",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1gwf7pIH8X5wU-i0YMw-j7qPSA4MnA40L",
          "cachedResultName": "Trash"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a791c6a2-1311-40cc-837e-c875425774cc",
      "name": "Watch GD RAG Files",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -3984,
        304
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1e1Af14X5nlPq6oVEqbHs4h7pQtYktzAM",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1e1Af14X5nlPq6oVEqbHs4h7pQtYktzAM",
          "cachedResultName": "RAG Files"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3024e04e-86c4-43d6-819d-22f45ef40750",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -2016,
        -544
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "query"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "5da16ea7-5c2c-4326-8069-7228ea20041f",
      "name": "Query Vector Store",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -2272,
        -512
      ],
      "parameters": {
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "XwFvFryyo4goPzpd",
          "cachedResultName": "Contextual Hybrid RAG AI copy"
        },
        "description": "Call this tool to get knowledge from our vector database",
        "workflowInputs": {
          "value": {
            "query": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('query', ``, 'string') }}"
          },
          "schema": [
            {
              "id": "query",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "query",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "query"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "467f3d3b-8727-413b-aa8d-7547ac7d8a68",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -3776,
        304
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "7d2d4e71-ce5f-4e08-a5fb-2ca01d17e6a6",
      "name": "Set Text for Chunking",
      "type": "n8n-nodes-base.set",
      "position": [
        -864,
        272
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5fb33f33-8d7f-467e-ab8b-784c411b63b2",
              "name": "content",
              "type": "string",
              "value": "={{ $('Set Text').item.json.text }}"
            },
            {
              "id": "d0fdcb3c-915f-4e39-93de-ac8244415be5",
              "name": "documentSummary",
              "type": "string",
              "value": "={{ $json.output.document_summary }}"
            },
            {
              "id": "5ffe4726-56f1-4478-9f89-ba862efce940",
              "name": "file_id",
              "type": "string",
              "value": "={{ $('Loop Over Items').item.json.id }}"
            },
            {
              "id": "df951786-5196-4590-9e32-fed42ef35200",
              "name": "fileName",
              "type": "string",
              "value": "={{ $('Loop Over Items').item.json.name }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9a68682b-7a2f-40ca-91a9-e0d935ec7ed3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4016,
        144
      ],
      "parameters": {
        "width": 160,
        "height": 304,
        "content": "### Watch GD folder\n"
      },
      "typeVersion": 1
    },
    {
      "id": "22acc35b-1370-450f-90f2-ff4a2c9f61e4",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3136,
        144
      ],
      "parameters": {
        "width": 160,
        "height": 300,
        "content": "### Set Text"
      },
      "typeVersion": 1
    },
    {
      "id": "cb0d4e98-3716-4bba-8f33-a1c0ee5224a7",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2896,
        144
      ],
      "parameters": {
        "width": 172,
        "height": 308,
        "content": " ### Generate Hash based on the text. If text changes we have a different hash"
      },
      "typeVersion": 1
    },
    {
      "id": "6f0493ae-8973-48c8-9338-f62d1b826445",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2656,
        144
      ],
      "parameters": {
        "width": 188,
        "height": 308,
        "content": "### Search the record manager to see if we have any files in the database, that have the same file id. If it does, it will return the hash"
      },
      "typeVersion": 1
    },
    {
      "id": "6336a34a-fade-435c-b0a7-5257b48c5579",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2432,
        112
      ],
      "parameters": {
        "width": 180,
        "height": 340,
        "content": "### Compare the Hash from generated hash and (if it exists) hash from record manager search to determine if file exists or not and if modified"
      },
      "typeVersion": 1
    },
    {
      "id": "be85f58e-3cff-42f7-b1ff-d1f22c781961",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2080,
        256
      ],
      "parameters": {
        "width": 640,
        "height": 280,
        "content": "### If the doc is modified, we delete all the vectors related to that google id and update record manager id and hash"
      },
      "typeVersion": 1
    },
    {
      "id": "79ee3377-d001-4bd7-8d25-c48e5676aff7",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        176
      ],
      "parameters": {
        "width": 380,
        "height": 220,
        "content": "### Create summary of document for metadata"
      },
      "typeVersion": 1
    },
    {
      "id": "2943dad5-ae6b-4fde-a293-eb8e319bc41b",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        176
      ],
      "parameters": {
        "width": 160,
        "height": 224,
        "content": "### Set text to send to sub-workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "6109b822-9860-4a85-860b-15dd4494bac7",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2464,
        864
      ],
      "parameters": {
        "width": 156,
        "height": 280,
        "content": "### Watch GD Trash folder"
      },
      "typeVersion": 1
    },
    {
      "id": "4522d72b-9a92-4614-a2c8-f6a739d2169d",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1984,
        864
      ],
      "parameters": {
        "width": 192,
        "height": 264,
        "content": "### Search record manager on corresponding GD file id"
      },
      "typeVersion": 1
    },
    {
      "id": "c57592c9-e02e-4861-a1e3-189f3b24f7cf",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        864
      ],
      "parameters": {
        "width": 160,
        "height": 264,
        "content": "### if records exist for this id or not\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9af264c1-de52-4fd7-9366-7d573499b02a",
      "name": "Sticky Note17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1520,
        864
      ],
      "parameters": {
        "width": 580,
        "height": 264,
        "content": "### Delete records from supabase"
      },
      "typeVersion": 1
    },
    {
      "id": "0403746d-e354-4d88-93d4-a05f9faa4aea",
      "name": "Sticky Note18",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        864
      ],
      "parameters": {
        "width": 150,
        "height": 264,
        "content": "### Delete file from GD"
      },
      "typeVersion": 1
    },
    {
      "id": "d48e00db-570d-41b5-a5db-4435059fe3ec",
      "name": "Sticky Note19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2304,
        -624
      ],
      "parameters": {
        "width": 1020,
        "height": 240,
        "content": "## Query Seach Supabase Database Tool with workflow"
      },
      "typeVersion": 1
    },
    {
      "id": "1af9acb3-e6a8-435d-9d91-cb84c5fd608b",
      "name": "Sticky Note20",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        192
      ],
      "parameters": {
        "width": 150,
        "height": 248,
        "content": "### Set up data\n"
      },
      "typeVersion": 1
    },
    {
      "id": "936e7ead-1a8c-4337-b784-5732ef2784ac",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6000,
        -16
      ],
      "parameters": {
        "width": 752,
        "height": 800,
        "content": "## Setting up Supabase\n\n\n### Create a project, and fill in the details as guided by Supabase.  On the left hand side, you will find the Project Overview section. Scroll down to connecting your project section and you will find the url and api key, which you can place in the credentials section or in the create new credentials in a supabase node.\n\n\n\n\n\n## Setting up the Hybrid Search in Supabase\n### You can learn more about hybrid search here: https://supabase.com/docs/guides/ai/hybrid-search\n\n### Go to the SQL Editor tab, and delete the existing code. First we will create the documents for the Hybrid Search called documentsHS. Find the code in a note in this workflow to the left of this sticky note. Copy & paste the code in the SQL Editor and click run. You will get a message saying pg_notify. The documentsHS is complete. Now delete the code and copy paste the code for the record manager called record_managerHS in the sticky note on the left. You will get a message saying Success. No Rows Returned. You have now created the tables for the hybrid search. \n\n## To call the hybrid search, we will use the edge function.\n### To create the edge function, go to the edge function (left hand side bar), click deploy a new function, and select Via AI Assistant.  Paste \"Create a new edge function that calls on the match_documentshs_hybrid so it can be called through API\". This will create your edge function and you can click on deploy to deploy it. In the details section, you will find the endpoint URL that you can paste into the URL in the HTTP Request (called Edge Function). Make sure to copy the Bearer YOUR_TOKEN_HERE as well and create a Header Auth to store it. You will find that in the Generic Auth Type under Header Auth. That will go in the Value section and the word 'Authorization' in the Name. You have now successfully completed the setup for the hybrid search."
      },
      "typeVersion": 1
    },
    {
      "id": "76cf1951-f712-4d05-ab00-c5201a4bdf15",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -7456,
        -784
      ],
      "parameters": {
        "width": 656,
        "height": 2416,
        "content": "# documentHS\n\n\n-- Extensions\ncreate extension if not exists vector;\ncreate extension if not exists pg_trgm;\n\n-- Table\ncreate table if not exists documentsHS (\n  id bigserial primary key,\n  content text,\n  metadata jsonb,\n  embedding vector(1536),\n  tokens tsvector generated always as (\n    to_tsvector('english', coalesce(content, ''))\n  ) stored\n);\n\n-- Indexes\ncreate index if not exists documentsHS_tokens_gin\n  on documentsHS using gin (tokens);\n\ncreate index if not exists documentsHS_embedding_ivfflat\n  on documentsHS using ivfflat (embedding vector_cosine_ops) with (lists = 100);\n\ncreate index if not exists documentsHS_metadata_gin\n  on documentsHS using gin (metadata);\n\n-- ==========================================\n-- Single HYBRID function exposed via RPC\n-- ==========================================\ncreate or replace function public.match_documentshs_hybrid(\n  query_embedding float4[],           -- required; send as JSON array\n  query_text text,                    -- required\n  match_count int default 10,\n  semantic_weight float default 0.5,  -- 0..1 (higher = more semantic)\n  filter jsonb default '{}'           -- optional structured filter\n)\nreturns table (\n  id bigint,\n  content text,\n  metadata jsonb,\n  similarity double precision,\n  keyword_rank double precision,\n  hybrid_score double precision\n)\nlanguage sql\nstable\nas $$\n  with base as (\n    select\n      d.id,\n      d.content,\n      d.metadata,\n      (1 - (d.embedding <=> (query_embedding::vector(1536)))) as sim,\n      ts_rank(d.tokens, plainto_tsquery('english', query_text)) as kw_rank\n    from documentsHS d\n    where d.metadata @> filter\n  ),\n  stats as (\n    select max(sim) as max_sim, max(kw_rank) as max_kw from base\n  )\n  select\n    b.id,\n    b.content,\n    b.metadata,\n    b.sim as similarity,\n    b.kw_rank as keyword_rank,\n    (\n      coalesce(case when s.max_sim > 0 then b.sim / s.max_sim else 0 end, 0) * semantic_weight\n      +\n      coalesce(case when s.max_kw  > 0 then b.kw_rank / s.max_kw else 0 end, 0) * (1 - semantic_weight)\n    ) as hybrid_score\n  from base b cross join stats s\n  where (b.sim > 0) or (b.kw_rank > 0)\n  order by hybrid_score desc\n  limit match_count;\n$$;\n\n-- Optional helpers\ncreate or replace function public.match_documentshs_vector_only(\n  query_embedding float4[],\n  match_count int default 10,\n  filter jsonb default '{}'\n)\nreturns table (\n  id bigint,\n  content text,\n  metadata jsonb,\n  similarity double precision\n)\nlanguage sql\nstable\nas $$\n  select\n    d.id, d.content, d.metadata,\n    (1 - (d.embedding <=> (query_embedding::vector(1536)))) as similarity\n  from documentsHS d\n  where d.metadata @> filter\n  order by d.embedding <=> (query_embedding::vector(1536))\n  limit match_count;\n$$;\n\ncreate or replace function public.match_documentshs_keyword_only(\n  query_text text,\n  match_count int default 10,\n  filter jsonb default '{}'\n)\nreturns table (\n  id bigint,\n  content text,\n  metadata jsonb,\n  keyword_rank double precision\n)\nlanguage sql\nstable\nas $$\n  select\n    d.id, d.content, d.metadata,\n    ts_rank(d.tokens, plainto_tsquery('english', query_text)) as keyword_rank\n  from documentsHS d\n  where d.metadata @> filter\n    and plainto_tsquery('english', query_text) @@ d.tokens\n  order by keyword_rank desc\n  limit match_count;\n$$;\n\n-- Reload API schema\nselect pg_notify('pgrst', 'reload schema');"
      },
      "typeVersion": 1
    },
    {
      "id": "ae127c8a-15e8-485a-913b-932e7a3f0f15",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6784,
        -784
      ],
      "parameters": {
        "width": 592,
        "height": 224,
        "content": "# record_managerHS code\n\ncreate table public.record_managerHS (\n  id bigint generated by default as identity not null,\n  created_at timestamp with time zone not null default now(),\n  gd_file_id text not null,\n  hash text not null,\n  constraint record_managerHS_pkey primary key (id)\n) TABLESPACE pg_default;"
      },
      "typeVersion": 1
    },
    {
      "id": "4e8a1b14-2fd5-4dfc-89f4-73898134d384",
      "name": "Edge Function",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1552,
        -544
      ],
      "parameters": {
        "url": "Your Edge Function URL Here",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "jsonBody": "={\n    \"query_text\":       \"{{ $('When Executed by Another Workflow').item.json.query }}\",\n    \"query_embedding\":  [{{ $json.data[0].embedding }}],\n    \"match_count\":      5, \n    \"full_text_weight\": 1.0,\n    \"semantic_weight\": 1.0,\n    \"rrf_k\":            50\n  } ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "cf18ef2b-6044-4526-9f0f-b1ec4d7a547d",
      "name": "Call My Sub-workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        -656,
        336
      ],
      "parameters": {
        "options": {},
        "workflowId": {
          "__rl": true,
          "mode": "list",
          "value": "OB2T8YYdXtHcujuT",
          "cachedResultName": "My Sub-workflow"
        },
        "workflowInputs": {
          "value": {
            "content": "={{ $json.content }}",
            "file_id": "={{ $json.file_id }}",
            "fileName": "={{ $json.fileName }}",
            "documentSummary": "={{ $json.documentSummary }}"
          },
          "schema": [
            {
              "id": "content",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "content",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "documentSummary",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "documentSummary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "file_id",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "file_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "fileName",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "fileName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "content",
            "documentSummary",
            "file_id",
            "fileName"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "61e693a0-bebc-4f32-8531-67110fc08e38",
      "name": "Supabase Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1440,
        336
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documentshs",
          "cachedResultName": "documentshs"
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "7588feea-e4d2-4a67-91a8-2a35d4439293",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1440,
        512
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "db23a77d-2805-421d-a3c0-43de5a78e0a5",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1568,
        528
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "file_id",
                "value": "={{ $('Metadata').item.json.file_id }}"
              },
              {
                "name": "motorsport_category",
                "value": "={{ $('Metadata').item.json.motorsportCategory }}"
              },
              {
                "name": "file_name",
                "value": "={{ $('Metadata').item.json.fileName }}"
              },
              {
                "name": "file_summary",
                "value": "={{ $('Metadata').item.json.documentSummary }}"
              }
            ]
          }
        },
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "fa1ce78e-ef3c-45e9-9b89-b6afa3e3a119",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1536,
        656
      ],
      "parameters": {
        "options": {},
        "chunkSize": 1400
      },
      "typeVersion": 1
    },
    {
      "id": "c4771f8f-dabe-4815-8fe2-d862234cbec7",
      "name": "Recursive Splitter2",
      "type": "n8n-nodes-base.code",
      "position": [
        -80,
        336
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const chunkSize = 1000;\nconst chunkOverlap = 200;\nconst text = $input.item.json.content.replace(/\\n/, '');\n\nconst chunks = [];\nlet remainingText = text;\n\nwhile (remainingText.length > 0) {\n    let splitPoint;\n\n    // Try splitting at paragraph level first\n    splitPoint = remainingText.lastIndexOf(\"\\n\\n\", chunkSize);\n    \n    // If no paragraph split, try splitting at sentence level\n    if (splitPoint === -1) {\n        splitPoint = remainingText.lastIndexOf(\". \", chunkSize);\n    }\n\n    // If no sentence split, try splitting at word level\n    if (splitPoint === -1) {\n        splitPoint = remainingText.lastIndexOf(\" \", chunkSize);\n    }\n\n    // If still no split point, force cut at chunkSize\n    if (splitPoint === -1 || splitPoint < chunkSize * 0.5) {  \n        splitPoint = chunkSize; // Hard split if no good split point\n    }\n\n    // Extract chunk and adjust remaining text with overlap\n    let chunk = remainingText.substring(0, splitPoint).trim();\n    chunks.push(chunk);\n\n    // Move the pointer forward while keeping the overlap\n    remainingText = remainingText.substring(Math.max(0, splitPoint - chunkOverlap)).trim();\n\n    // Break if remaining text is too small to form another chunk\n    if (remainingText.length < chunkSize * 0.2) {\n        chunks.push(remainingText);\n        break;\n    }\n}\n\nreturn { chunks };"
      },
      "typeVersion": 2
    },
    {
      "id": "0969dc28-0e90-47ad-9dde-b4425978a6eb",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        128,
        336
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "chunks"
      },
      "typeVersion": 1
    },
    {
      "id": "b279aabb-d27f-44d4-9290-e0bf9abca567",
      "name": "Set Up Chunks for Embedding",
      "type": "n8n-nodes-base.set",
      "position": [
        912,
        336
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "caed5bb3-bd1e-475f-94ad-db0b73cdedf0",
              "name": "text",
              "type": "string",
              "value": "={{ $json.text }} \n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2f58e5f1-afe1-4e34-8cf1-e02f932a2e99",
      "name": "Metadata",
      "type": "n8n-nodes-base.set",
      "position": [
        -288,
        336
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "93527bdc-6f91-4942-b5da-d7d5f1a67f9d",
              "name": "content",
              "type": "string",
              "value": "={{ $json.content }}"
            },
            {
              "id": "15ac4402-e7a1-40fc-a45d-bafd8302358a",
              "name": "documentSummary",
              "type": "string",
              "value": "={{ $json.documentSummary }}"
            },
            {
              "id": "79781e9e-8d64-4ebb-b96a-5d9954e62939",
              "name": "motorsportCategory",
              "type": "string",
              "value": "={{ $json.motorsportCategory }}"
            },
            {
              "id": "ca42a5a1-d11b-4a1e-a9f1-b696d31b4251",
              "name": "file_id",
              "type": "string",
              "value": "={{ $json.file_id }}"
            },
            {
              "id": "97242570-a638-454d-8d5e-62a1eb6c8376",
              "name": "fileName",
              "type": "string",
              "value": "={{ $json.fileName }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "02d36503-b3ad-451b-8f90-9ee50d9e3c53",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        1104,
        336
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "f0e1c571-d615-4942-a9cc-2529aa401cef",
      "name": "Add Context",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        576,
        336
      ],
      "parameters": {
        "text": "=<document> \n{{ $('Metadata').item.json.content}}\n</document> \n\nHere is the chunk we want to situate within the overall document:\n\n<chunk> \n{{ $('Loop Over Items2').item.json.chunks }}\n</chunk> \n\nPlease:\n- Provide a short and succinct **context** to situate this chunk within the document for improved search retrieval.\n- Return the **original chunk** exactly as provided unless a correction is necessary.\n- If the chunk contains an **incomplete number, percentage, or entity**, correct it using the full document.\n- If part of a **sentence is cut off**, reconstruct the missing words only if necessary for clarity.\n- If the chunk is part of a table, include the complete table entry to maintain data integrity\n- Do not add any additional explanations or formatting beyond the required output.\n\nFill in the following format:\n[succinct context] : [original chunk or corrected version if necessary]\n\nYour response should contain only the text that replaces these placeholders, without including the placeholder labels themselves.",
        "promptType": "define"
      },
      "typeVersion": 1.5
    },
    {
      "id": "9153a959-d4a9-4392-a072-8db62ecd4008",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        576,
        544
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-nano",
          "cachedResultName": "gpt-4.1-nano"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "25cb00db-559f-4eb0-baf6-3118fc6c6bf0",
      "name": "Loop Over Items2",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        352,
        336
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "756c06ae-1b66-44a0-b4a6-076856cf01b5",
      "name": "Aggregate2",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        544,
        80
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {}
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "1b2f5f20-f2f3-49c4-900a-d63d297b3fc2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        224
      ],
      "parameters": {
        "width": 176,
        "height": 280,
        "content": "### Set up data\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a321d862-fcb5-4895-bb44-2f1d038c4614",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        224
      ],
      "parameters": {
        "width": 356,
        "height": 280,
        "content": "### Chuck document into multiple chunks based chunk size"
      },
      "typeVersion": 1
    },
    {
      "id": "dfb50197-9be2-4189-ab3c-0f11de6b62c1",
      "name": "Sticky Note21",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        224
      ],
      "parameters": {
        "width": 264,
        "height": 280,
        "content": "### Add context to each chunk\n"
      },
      "typeVersion": 1
    },
    {
      "id": "48bbb8a8-56de-4e68-acf2-beb25a583145",
      "name": "Sticky Note22",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        224
      ],
      "parameters": {
        "width": 420,
        "height": 284,
        "content": "### Set up text chunks and add timer so create limits are not reached"
      },
      "typeVersion": 1
    },
    {
      "id": "044811b8-f03e-4954-a6b0-1522030aa109",
      "name": "Sticky Note23",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1344,
        224
      ],
      "parameters": {
        "width": 472,
        "height": 576,
        "content": "### Upsert into vector database."
      },
      "typeVersion": 1
    },
    {
      "id": "57986be6-d5b8-47d8-8e14-f9be28282e59",
      "name": "Sticky Note24",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        64
      ],
      "parameters": {
        "color": 3,
        "width": 2192,
        "height": 752,
        "content": "# This is the Call My Sub-Workflow "
      },
      "typeVersion": 1
    },
    {
      "id": "f28c07f0-e1d7-482f-bacc-bd2bc3ba011b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6000,
        -784
      ],
      "parameters": {
        "width": 752,
        "height": 752,
        "content": "# Workflow Summary\n\n### This automation keeps your Supabase vector database synchronized with documents stored in Google Drive, while also making the data contextual and vector based for better retrieval.\n\n### When a file is added or modified, the workflow extracts its text, splits it into smaller chunks, and enriches each chunk with contextual metadata (such as summaries and document details). It then generates embeddings using OpenAI and stores both the vector data and metadata in Supabase. If a file changes, the old records are replaced with updated, contextualized content.\n\n### The result is a continuously updated and context-aware vector database, enabling highly accurate hybrid search and retrieval. \n\n\n# To setup\n\n## 1. Connect Google Drive\n\u2022\tCreate a Google Drive folder to watch.\n\u2022\tConnect your Google Drive account in n8n and authorize access.\n\u2022\tPoint the Google Drive Trigger node to this folder (new/modified files trigger the flow).\n\n## 2. Configure Supabase\n\u2022\tPlease refer to the Setting Up Supabase Sticky Note. \n\n## 3. Connect OpenAI (or your embedding model)\n\u2022\tAdd your OpenAI API key in n8n credentials.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7c719413-7945-4e8e-9db2-02c6f3ee49c2",
      "name": "Sticky Note26",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3808,
        144
      ],
      "parameters": {
        "width": 150,
        "height": 304,
        "content": "### Loop over each item, as more than 1 file can be placed in the Google Drive"
      },
      "typeVersion": 1
    },
    {
      "id": "f5d30b0f-d7cc-4574-9939-9a53e7b02d12",
      "name": "Sticky Note28",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3568,
        144
      ],
      "parameters": {
        "width": 160,
        "height": 304,
        "content": "### Download file"
      },
      "typeVersion": 1
    },
    {
      "id": "f9c3a219-dbf0-470a-a54a-2c5775da45c4",
      "name": "Sticky Note29",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3376,
        144
      ],
      "parameters": {
        "width": 160,
        "height": 304,
        "content": "### Extract text from pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "aced0ee1-a1d5-40fd-b866-c2640136802e",
      "name": "Sticky Note30",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -96
      ],
      "parameters": {
        "width": 176,
        "height": 304,
        "content": "### Create new record in record manager since file is new and doesn't exist in database"
      },
      "typeVersion": 1
    },
    {
      "id": "ae132431-fb89-45b5-9849-96812a46dcfd",
      "name": "Sticky Note25",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2592,
        -832
      ],
      "parameters": {
        "width": 336,
        "height": 208,
        "content": "## AI Agent to communicate with the database"
      },
      "typeVersion": 1
    },
    {
      "id": "c8d17104-e110-453d-97ca-e8e79bf589c1",
      "name": "Embedding",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1792,
        -544
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/embeddings",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "input",
              "value": "={{ $json.query }}"
            },
            {
              "name": "model",
              "value": "text-embedding-3-small"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "60d22f47-01bc-4326-b282-0d742ef48480",
  "connections": {
    "If1": {
      "main": [
        [
          {
            "node": "Delete Previous Vectors1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Create Row in Record Manager",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete Previous Vectors",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Metadata": {
      "main": [
        [
          {
            "node": "Recursive Splitter2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Text": {
      "main": [
        [
          {
            "node": "Generate Hash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Update Record Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embedding": {
      "main": [
        [
          {
            "node": "Edge Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Delete Record from Record Manager1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Context": {
      "main": [
        [
          {
            "node": "Set Up Chunks for Embedding",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Hash": {
      "main": [
        [
          {
            "node": "Search Record Manager",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive2": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Watch GD Trash": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Set Text for Chunking",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [],
        [
          {
            "node": "Search Record Manager1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items2": {
      "main": [
        [
          {
            "node": "Aggregate2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Add Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Set Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Add Context",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Query Vector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Watch GD RAG Files": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Splitter2": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call My Sub-workflow": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Record Manager": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Text for Chunking": {
      "main": [
        [
          {
            "node": "Call My Sub-workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Record Manager": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Record Manager1": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store1": {
      "main": [
        [
          {
            "node": "Loop Over Items2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Previous Vectors": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Previous Vectors1": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Up Chunks for Embedding": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Row in Record Manager": {
      "main": [
        [
          {
            "node"

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

How this works

This workflow keeps a Google Drive folder in sync with a Supabase vector store so that AI agents can retrieve accurate, up-to-date context for retrieval-augmented generation. It watches for new or changed files, extracts their content, creates embeddings with OpenAI, and stores the vectors in Supabase for fast similarity searches. Users who run customer-support bots, internal knowledge bases, or research agents benefit most from the automatic refresh that removes manual re-indexing.

Use it when documents change regularly and you need reliable retrieval without constant upkeep. Skip it for static archives or single-use queries where a one-off load suffices. Common variations include swapping the OpenAI embedding model for a cheaper alternative or restricting the folder scope to specific subfolders.

About this workflow

• 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).

Source: https://n8n.io/workflows/8200/ — 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

⚡AI-Powered YouTube Playlist & Video Summarization and Analysis v2. Uses lmChatGoogleGemini, agent, splitOut, chainLlm. Chat trigger; 72 nodes.

Google Gemini Chat, Agent, Chain Llm +11
AI & RAG

This n8n workflow transforms entire YouTube playlists or single videos into interactive knowledge bases you can chat with. Ask questions and get summaries without needing to watch hours of content. 🔗

Google Gemini Chat, Agent, Chain Llm +11
AI & RAG

Final. Uses chatTrigger, agent, n8n-nodes-upstage, httpRequest. Chat trigger; 55 nodes.

Chat Trigger, Agent, N8N Nodes Upstage +10
AI & RAG

use cases: research stock market in Indonesia. analyze the performance of companies belonging to certain subsectors or company comparing financial metrics between BBCA and BBRI providing technical ana

Chat Trigger, Chat, Telegram Trigger +10