AutomationFlowsAI & RAG › Base to Copy

Base to Copy

05. Base_To_Copy. Uses lmChatOpenAi, documentDefaultDataLoader, embeddingsOpenAi, googleDrive. Event-driven trigger; 54 nodes.

Event trigger★★★★★ complexityAI-powered54 nodesOpenAI ChatDocument Default Data LoaderOpenAI EmbeddingsGoogle DriveGoogle Drive TriggerMemory Postgres ChatSupabaseChat Trigger
AI & RAG Trigger: Event Nodes: 54 Complexity: ★★★★★ AI nodes: yes Added:

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

The workflow JSON

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

Download .json
{
  "name": "05. Base_To_Copy",
  "nodes": [
    {
      "parameters": {
        "model": "gpt-4.1-mini",
        "options": {}
      },
      "id": "b3bf4dd2-2b1c-4950-8aa2-eb7bdabe8cc9",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        1020,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonMode": "expressionData",
        "jsonData": "={{ $json.data || $json.text || $json.concatenated_data }}",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "=file_id",
                "value": "={{ $('Set File ID_!').first().json.file_id }}"
              },
              {
                "name": "file_title",
                "value": "={{ $('Set File ID_!').first().json.file_title }}"
              }
            ]
          }
        }
      },
      "id": "838d704b-9cc7-491a-98f5-9a64074e9b32",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1,
      "position": [
        3020,
        1140
      ]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "options": {}
      },
      "id": "bd616066-88e0-4017-83f7-0bf564c91c56",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [
        2740,
        1080
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## Agent Tools for RAG",
        "height": 469,
        "width": 583,
        "color": 4
      },
      "id": "2734c39e-6cf9-4790-bcb1-af0a9cc126a3",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1780,
        0
      ]
    },
    {
      "parameters": {
        "content": "## Tool to Add a Google Drive File to Vector DB",
        "height": 80,
        "width": 573,
        "color": 5
      },
      "id": "90788588-0a0a-45c1-b924-cf393b192095",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        20,
        480
      ]
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Set File ID_!').item.json.file_id }}",
          "mode": "id"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain",
              "sheetsToFormat": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            }
          }
        }
      },
      "id": "76ba7880-7fc7-4b43-94fc-212fd3d62e52",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1140,
        800
      ],
      "executeOnce": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "authentication": "serviceAccount",
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV",
          "mode": "list",
          "cachedResultName": "05. UD_Doc1",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "d8321081-6069-462d-a0b2-745426090683",
      "name": "File Created",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -220,
        560
      ],
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "authentication": "serviceAccount",
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV",
          "mode": "list",
          "cachedResultName": "05. UD_Doc1",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV"
        },
        "event": "fileUpdated",
        "options": {}
      },
      "id": "ae4736a0-23f8-48ec-a987-74d531dbee9e",
      "name": "File Updated",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -200,
        800
      ],
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Edit Fields').item.json.sessionId }}"
      },
      "id": "4c5a40e8-6d6d-4d80-a0f8-253726366cc7",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1,
      "position": [
        1160,
        300
      ],
      "notesInFlow": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "documents",
        "filterType": "string",
        "filterString": "=metadata->>file_id=like.*{{ $json.file_id }}*"
      },
      "id": "ac295a19-f4ab-410a-aa1b-89857cd89f24",
      "name": "Delete Old Doc Rows",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        540,
        600
      ],
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "## RAG AI Agent with Chat Interface",
        "height": 464.8027193303974,
        "width": 1035.6381264595484
      },
      "id": "5804aff9-c83c-49ea-b686-77c358574562",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        720,
        0
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "eeba5ac4-58d3-4901-94de-97d1c9743ee9",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1580,
        80
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9a9a245e-f1a1-4282-bb02-a81ffe629f0f",
              "name": "chatInput",
              "value": "={{ $json?.chatInput || $json.body.chatInput }}",
              "type": "string"
            },
            {
              "id": "b80831d8-c653-4203-8706-adedfdb98f77",
              "name": "sessionId",
              "value": "={{ $json?.sessionId || $json.body.sessionId}}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "50fb4b63-ac5d-4b64-a066-346c6b541c8e",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1020,
        80
      ]
    },
    {
      "parameters": {
        "public": true,
        "options": {}
      },
      "id": "63691437-686d-4c74-94da-29238695bb71",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        760,
        80
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "5e7bc971-122a-4d85-9bbd-34b5cf75104d",
        "authentication": "headerAuth",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "86a57582-b496-4475-b068-ba2f5b0c5794",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        760,
        260
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "id": "095b2574-2fde-447a-99df-2f61b22d26b6",
      "name": "Extract PDF Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2160,
        540
      ]
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "213a4299-69de-4f3f-82b1-48ba79e7aca1",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        2220,
        700
      ]
    },
    {
      "parameters": {
        "chunkOverlap": 100
      },
      "id": "48164ebe-9b07-491c-a01b-aa6f2c7541be",
      "name": "Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter",
      "typeVersion": 1,
      "position": [
        3100,
        1320
      ]
    },
    {
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "concatenate",
              "field": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "86f39476-8286-429d-a39c-13364fa9e01a",
      "name": "Summarize",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1,
      "position": [
        2420,
        780
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=# Prompt cho AI Agent N8n - Tr\u1ee3 l\u00fd T\u00e0i li\u1ec7u Th\u00f4ng minh\n\n## Vai tr\u00f2 v\u00e0 Ch\u1ee9c n\u0103ng\nB\u1ea1n l\u00e0 m\u1ed9t tr\u1ee3 l\u00fd AI chuy\u00ean nghi\u1ec7p, gi\u00fap t\u00ecm ki\u1ebfm v\u00e0 truy xu\u1ea5t th\u00f4ng tin t\u1eeb kho t\u00e0i li\u1ec7u \u0111a \u0111\u1ecbnh d\u1ea1ng. Nhi\u1ec7m v\u1ee5 ch\u00ednh c\u1ee7a b\u1ea1n l\u00e0:\n\n- T\u00ecm ki\u1ebfm th\u00f4ng tin ch\u00ednh x\u00e1c t\u1eeb c\u00e1c t\u00e0i li\u1ec7u v\u0103n b\u1ea3n (TXT, DOC, PDF)\n- Truy xu\u1ea5t d\u1eef li\u1ec7u t\u1eeb c\u00e1c file b\u1ea3ng t\u00ednh (CSV, Excel)\n- X\u1eed l\u00fd v\u00e0 cung c\u1ea5p link truy c\u1eadp video khi \u0111\u01b0\u1ee3c y\u00eau c\u1ea7u\n- \u0110\u1ea3m b\u1ea3o t\u00ednh ch\u00ednh x\u00e1c v\u00e0 \u0111\u1ea7y \u0111\u1ee7 c\u1ee7a th\u00f4ng tin \u0111\u01b0\u1ee3c cung c\u1ea5p\n\n## Quy tr\u00ecnh X\u1eed l\u00fd Y\u00eau c\u1ea7u\n\n### B\u01b0\u1edbc 1: Ph\u00e2n t\u00edch Y\u00eau c\u1ea7u v\u00e0 Ki\u1ec3m tra Ti\u00eau \u0111\u1ec1\n- \u0110\u1ecdc k\u1ef9 c\u00e2u h\u1ecfi c\u1ee7a ng\u01b0\u1eddi d\u00f9ng\n- **LU\u00d4N KI\u1ec2M TRA TI\u00caU \u0110\u1ec0 T\u00c0I LI\u1ec6U TR\u01af\u1edaC**: Qu\u00e9t qua t\u1ea5t c\u1ea3 ti\u00eau \u0111\u1ec1 \u0111\u1ec3 t\u00ecm t\u00e0i li\u1ec7u li\u00ean quan\n- \u01afu ti\u00ean t\u00ecm file .mp4 c\u00f3 ti\u00eau \u0111\u1ec1 kh\u1edbp v\u1edbi y\u00eau c\u1ea7u (v\u00ed d\u1ee5: \"h\u01b0\u1edbng d\u1eabn l\u1eb7p qu\u1ea1t 3 c\u00e1nh\" \u2192 t\u00ecm ti\u00eau \u0111\u1ec1 ch\u1ee9a \"qu\u1ea1t 3 c\u00e1nh\", \"l\u1eb7p qu\u1ea1t\", \"h\u01b0\u1edbng d\u1eabn l\u1eafp qu\u1ea1t\")\n- N\u1ebfu c\u00e2u h\u1ecfi kh\u00f4ng r\u00f5 r\u00e0ng, y\u00eau c\u1ea7u l\u00e0m r\u00f5 th\u00eam\n\n### B\u01b0\u1edbc 2: Truy v\u1ea5n Supabase Vector Store\n- **B\u1eaeT BU\u1ed8C**: Lu\u00f4n th\u1ef1c hi\u1ec7n t\u00ecm ki\u1ebfm trong Supabase Vector Store\n- S\u1eed d\u1ee5ng t\u1eeb kh\u00f3a li\u00ean quan \u0111\u1ec3 t\u00ecm ki\u1ebfm to\u00e0n di\u1ec7n\n- Ki\u1ec3m tra t\u1ea5t c\u1ea3 k\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1, bao g\u1ed3m c\u1ea3 metadata c\u1ee7a video\n\n### B\u01b0\u1edbc 3: Ki\u1ec3m tra v\u00e0 X\u00e1c th\u1ef1c D\u1eef li\u1ec7u\n- Ki\u1ec3m tra k\u1ef9 ti\u00eau \u0111\u1ec1 v\u00e0 n\u1ed9i dung c\u1ee7a t\u00e0i li\u1ec7u t\u00ecm \u0111\u01b0\u1ee3c\n- \u0110\u1ed1i chi\u1ebfu th\u00f4ng tin v\u1edbi y\u00eau c\u1ea7u c\u1ee7a ng\u01b0\u1eddi d\u00f9ng\n- X\u00e1c nh\u1eadn t\u00ednh ch\u00ednh x\u00e1c tr\u01b0\u1edbc khi ph\u1ea3n h\u1ed3i\n\n### B\u01b0\u1edbc 4: X\u1eed l\u00fd \u0110\u1eb7c bi\u1ec7t cho Video v\u00e0 H\u01b0\u1edbng d\u1eabn\n- **QUY T\u1eaeC QUAN TR\u1eccNG**: Ch\u1ec9 d\u1ef1a v\u00e0o TI\u00caU \u0110\u1ec0 file .mp4 \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh n\u1ed9i dung video\n- **KH\u00d4NG XEM** \u0111\u01b0\u1ee3c n\u1ed9i dung b\u00ean trong video, ch\u1ec9 ph\u00e2n t\u00edch ti\u00eau \u0111\u1ec1\n- **TH\u1ee8 T\u1ef0 \u01afU TI\u00caN**:\n  1. T\u00ecm file .mp4 c\u00f3 ti\u00eau \u0111\u1ec1 kh\u1edbp v\u1edbi y\u00eau c\u1ea7u \u2192 Tr\u1ea3 link ngay l\u1eadp t\u1ee9c\n  2. Sau \u0111\u00f3 m\u1edbi t\u00ecm n\u1ed9i dung trong t\u00e0i li\u1ec7u v\u0103n b\u1ea3n kh\u00e1c\n- **V\u00cd D\u1ee4**: H\u1ecfi \"h\u01b0\u1edbng d\u1eabn l\u1eb7p qu\u1ea1t 3 c\u00e1nh\" \u2192 T\u00ecm ti\u00eau \u0111\u1ec1 .mp4 ch\u1ee9a \"qu\u1ea1t 3 c\u00e1nh\" ho\u1eb7c \"l\u1eb7p qu\u1ea1t\"\n- Ki\u1ec3m tra trong file Excel/CSV c\u00f3 ch\u1ee9a URL video v\u1edbi ti\u00eau \u0111\u1ec1 ph\u00f9 h\u1ee3p\n\n## Nguy\u00ean t\u1eafc Ho\u1ea1t \u0111\u1ed9ng\n\n### \u2705 PH\u1ea2I L\u00c0M\n- **LU\u00d4N KI\u1ec2M TRA TI\u00caU \u0110\u1ec0 TR\u01af\u1edaC**: Qu\u00e9t to\u00e0n b\u1ed9 danh s\u00e1ch ti\u00eau \u0111\u1ec1 t\u00e0i li\u1ec7u tr\u01b0\u1edbc khi t\u00ecm ki\u1ebfm\n- **\u01afU TI\u00caN VIDEO .MP4**: T\u00ecm file .mp4 c\u00f3 ti\u00eau \u0111\u1ec1 li\u00ean quan \u0111\u1ea7u ti\u00ean\n- **CH\u1ec8 D\u1ef0A V\u00c0O TI\u00caU \u0110\u1ec0**: Kh\u00f4ng suy \u0111o\u00e1n n\u1ed9i dung video, ch\u1ec9 ph\u00e2n t\u00edch ti\u00eau \u0111\u1ec1 file\n- **TH\u1ee8 T\u1ef0**: Video .mp4 tr\u01b0\u1edbc \u2192 Link ngay \u2192 Sau \u0111\u00f3 m\u1edbi t\u00ecm t\u00e0i li\u1ec7u kh\u00e1c\n- Cung c\u1ea5p th\u00f4ng tin ch\u00ednh x\u00e1c 100% t\u1eeb ngu\u1ed3n d\u1eef li\u1ec7u\n- Tr\u1ea3 v\u1ec1 link video clickable \u0111\u1ec3 ng\u01b0\u1eddi d\u00f9ng xem tr\u1ef1c ti\u1ebfp\n\n### \u274c KH\u00d4NG \u0110\u01af\u1ee2C L\u00c0M\n- B\u1ecba \u0111\u1eb7t ho\u1eb7c suy di\u1ec5n n\u1ed9i dung video t\u1eeb ti\u00eau \u0111\u1ec1\n- **KH\u00d4NG \u0110O\u00c1N** n\u1ed9i dung b\u00ean trong file .mp4\n- B\u1ecf qua vi\u1ec7c ki\u1ec3m tra ti\u00eau \u0111\u1ec1 tr\u01b0\u1edbc khi t\u00ecm ki\u1ebfm\n- T\u00ecm t\u00e0i li\u1ec7u kh\u00e1c tr\u01b0\u1edbc khi ki\u1ec3m tra video .mp4\n- Tr\u1ea3 l\u1eddi m\u00e0 kh\u00f4ng ki\u1ec3m tra danh s\u00e1ch ti\u00eau \u0111\u1ec1 \u0111\u1ea7y \u0111\u1ee7\n- \u0110\u01b0a ra th\u00f4ng tin kh\u00f4ng ch\u00ednh x\u00e1c v\u1ec1 video\n\n## C\u00e1ch Ph\u1ea3n h\u1ed3i\n\n### Khi t\u00ecm th\u1ea5y video .mp4 ph\u00f9 h\u1ee3p:\n```\n\ud83c\udfa5 **T\u00ccM TH\u1ea4Y VIDEO H\u01af\u1edaNG D\u1eaaN**: \n\n\ud83d\udc49 **[Ti\u00eau \u0111\u1ec1 video]** - [Link video tr\u1ef1c ti\u1ebfp - Click \u0111\u1ec3 xem]\n\n\ud83d\udcdd **Ghi ch\u00fa**: Video \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh d\u1ef1a tr\u00ean ti\u00eau \u0111\u1ec1 \"[ti\u00eau \u0111\u1ec1 file]\"\n\n---\n\ud83d\udcda **Th\u00f4ng tin b\u1ed5 sung t\u1eeb t\u00e0i li\u1ec7u kh\u00e1c** (n\u1ebfu c\u00f3):\n[N\u1ed9i dung t\u1eeb t\u00e0i li\u1ec7u v\u0103n b\u1ea3n li\u00ean quan]\n```\n\n### Khi t\u00ecm th\u1ea5y th\u00f4ng tin kh\u00e1c:\n```\nD\u1ef1a tr\u00ean t\u00e0i li\u1ec7u [t\u00ean t\u00e0i li\u1ec7u], t\u00f4i t\u00ecm th\u1ea5y th\u00f4ng tin sau:\n\n[N\u1ed9i dung ch\u00ednh x\u00e1c t\u1eeb t\u00e0i li\u1ec7u]\n\n[N\u1ebfu c\u00f3 video]: \ud83c\udfa5 Link video: [URL]\nNgu\u1ed3n: [T\u00ean file/t\u00e0i li\u1ec7u]\n```\n\n### Khi kh\u00f4ng t\u00ecm th\u1ea5y th\u00f4ng tin:\n```\nT\u00f4i \u0111\u00e3 t\u00ecm ki\u1ebfm trong to\u00e0n b\u1ed9 kho t\u00e0i li\u1ec7u nh\u01b0ng kh\u00f4ng t\u00ecm th\u1ea5y th\u00f4ng tin v\u1ec1 [ch\u1ee7 \u0111\u1ec1]. \n\nB\u1ea1n c\u00f3 th\u1ec3 cung c\u1ea5p th\u00eam chi ti\u1ebft ho\u1eb7c t\u1eeb kh\u00f3a kh\u00e1c \u0111\u1ec3 t\u00f4i h\u1ed7 tr\u1ee3 t\u1ed1t h\u01a1n kh\u00f4ng?\n```\n\n### Khi c\u1ea7n l\u00e0m r\u00f5:\n```\n\u0110\u1ec3 t\u00f4i c\u00f3 th\u1ec3 h\u1ed7 tr\u1ee3 ch\u00ednh x\u00e1c, b\u1ea1n c\u00f3 th\u1ec3 l\u00e0m r\u00f5 th\u00eam v\u1ec1:\n- [C\u00e2u h\u1ecfi c\u1ee5 th\u1ec3 1]\n- [C\u00e2u h\u1ecfi c\u1ee5 th\u1ec3 2]\n```\n\n## L\u01b0u \u00fd \u0110\u1eb7c bi\u1ec7t\n\n1. **KI\u1ec2M TRA TI\u00caU \u0110\u1ec0 \u0110\u1ea6U TI\u00caN**: Lu\u00f4n qu\u00e9t danh s\u00e1ch ti\u00eau \u0111\u1ec1 t\u00e0i li\u1ec7u tr\u01b0\u1edbc m\u1ecdi thao t\u00e1c kh\u00e1c\n2. **GI\u1edaI H\u1ea0N VIDEO**: Ch\u1ec9 bi\u1ebft n\u1ed9i dung video qua ti\u00eau \u0111\u1ec1 file .mp4, kh\u00f4ng xem \u0111\u01b0\u1ee3c b\u00ean trong\n3. **TH\u1ee8 T\u1ef0 X\u1eec L\u00dd**: Ti\u00eau \u0111\u1ec1 .mp4 \u2192 Link video \u2192 T\u00e0i li\u1ec7u v\u0103n b\u1ea3n \u2192 T\u1ed5ng h\u1ee3p\n4. **V\u00cd D\u1ee4 TH\u1ef0C T\u1ebe**: \n   - H\u1ecfi: \"h\u01b0\u1edbng d\u1eabn l\u1eb7p qu\u1ea1t 3 c\u00e1nh\"\n   - T\u00ecm: Ti\u00eau \u0111\u1ec1 ch\u1ee9a \"qu\u1ea1t 3 c\u00e1nh\", \"l\u1eb7p qu\u1ea1t\", \"h\u01b0\u1edbng d\u1eabn qu\u1ea1t\"\n   - Tr\u1ea3 v\u1ec1: Link video ngay l\u1eadp t\u1ee9c\n5. **T\u1eeb kh\u00f3a Matching**: So kh\u1edbp t\u1eeb kh\u00f3a trong c\u00e2u h\u1ecfi v\u1edbi ti\u00eau \u0111\u1ec1 file\n6. **Link Click-able**: \u0110\u1ea3m b\u1ea3o link video c\u00f3 th\u1ec3 click tr\u1ef1c ti\u1ebfp\n7. **Ki\u1ec3m tra Metadata**: Xem x\u00e9t metadata c\u1ee7a file Excel/CSV ch\u1ee9a URL video\n\n## C\u00f4ng c\u1ee5 C\u1ea7n s\u1eed d\u1ee5ng\n- Supabase Vector Store Query Tool\n- Document Analysis Tool  \n- Excel/CSV Reader Tool\n- Video Link Extractor Tool\n\n---\n*Ghi nh\u1edb: T\u00ednh ch\u00ednh x\u00e1c v\u00e0 \u0111\u1ea7y \u0111\u1ee7 l\u00e0 \u01b0u ti\u00ean h\u00e0ng \u0111\u1ea7u. Lu\u00f4n t\u00ecm ki\u1ebfm tr\u01b0\u1edbc khi tr\u1ea3 l\u1eddi.*"
        }
      },
      "id": "5f253f23-f199-4141-a5e7-b46a9bcf823c",
      "name": "RAG AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        1240,
        80
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/pdf",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "2d5d8bc1-7088-4b65-a833-301c3987bfbe"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Pdf"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "2ae7faa7-a936-4621-a680-60c512163034",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Excel 1"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "b3b66a9e-8aca-4f0d-9864-f2e03c7a27cd",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Excel 3"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "fc193b06-363b-4699-a97d-e5a850138b0e",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "=application/vnd.google-apps.spreadsheet",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Excel 2"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "bb391e81-4667-4854-8033-e2771d1f69fb",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.ms-excel",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Excel 4"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "f5de71c8-289a-477b-ae62-f336e7286a0c",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "text/csv",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Csv"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "b69f5605-0179-4b02-9a32-e34bb085f82d",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.google-apps.document",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Txt"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "a605d52b-093e-47ce-bed4-6c040b465b79",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/msword",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Word 1"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "043262f3-55dc-40b0-af44-f2f67aae3aa9",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Word 2"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 1
                },
                "conditions": [
                  {
                    "id": "291a9806-5b16-46b4-a253-4806491d92bc",
                    "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
                    "rightValue": "application/vnd.ms-word",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Word 3"
            },
            {
              "renameOutput": true,
              "outputKey": "None"
            }
          ]
        },
        "options": {
          "fallbackOutput": 10
        }
      },
      "id": "8d95bb71-b7da-4c18-901f-30e261e2637b",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        1320,
        720
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "id": "28e94ed5-0b5b-48ca-9b51-d893cdd23a23",
      "name": "Insert into Supabase Vectorstore",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        2900,
        860
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "xlsx",
        "options": {}
      },
      "id": "8c50f2dd-b6b0-4005-a263-caf13c621acb",
      "name": "Extract from Excel",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1780,
        700
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f422e2e0-381c-46ea-8f38-3f58c501d8b9",
              "name": "schema",
              "value": "={{ $('Extract from Excel').isExecuted ? $('Extract from Excel').first().json.keys().toJsonString() : $('Extract from CSV').first().json.keys().toJsonString() }}",
              "type": "string"
            },
            {
              "id": "bb07c71e-5b60-4795-864c-cc3845b6bc46",
              "name": "data",
              "value": "={{ $json.concatenated_data }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2860,
        640
      ],
      "id": "942f461e-38d6-4291-8e10-930960db0e2d",
      "name": "Set Schema"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1780,
        880
      ],
      "id": "647531df-e4be-4289-a08c-aab1a68106f3",
      "name": "Extract from CSV"
    },
    {
      "parameters": {
        "content": "## Run Each Node Once to Set Up Database Tables",
        "height": 300,
        "width": 680,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1,
      "id": "d6c2c4ce-dfac-4881-9bf1-d8eb2560a1d3",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to fetch all available documents, including the table schema if the file is a CSV or Excel file.",
        "operation": "select",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "document_metadata",
          "mode": "list",
          "cachedResultName": "document_metadata"
        },
        "returnAll": true,
        "options": {}
      },
      "type": "n8n-nodes-base.postgresTool",
      "typeVersion": 2.5,
      "position": [
        1300,
        300
      ],
      "id": "96cf0eb8-5145-46ec-af9d-de493ef764d3",
      "name": "List Documents",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Given a file ID, fetches the text from the document.",
        "operation": "executeQuery",
        "query": "SELECT \n    string_agg(content, ' ') as document_text\nFROM documents\n  WHERE metadata->>'file_id' = $1\nGROUP BY metadata->>'file_id';",
        "options": {
          "queryReplacement": "={{ $fromAI('file_id') }}"
        }
      },
      "type": "n8n-nodes-base.postgresTool",
      "typeVersion": 2.5,
      "position": [
        1440,
        300
      ],
      "id": "e881266f-855f-47c2-aad3-4b6a88fe45a9",
      "name": "Get File Contents",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolName": "documents",
        "toolDescription": "Use RAG to look up information in the knowledgebase.",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        1880,
        220
      ],
      "id": "72df36a8-99e9-4ed9-8132-33d023a54e58",
      "name": "Supabase Vector Store1",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        1980,
        340
      ],
      "id": "ab968cd3-b734-47c3-929b-18352a96de89",
      "name": "Embeddings OpenAI2",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        20,
        580
      ],
      "id": "18a4143e-717e-4daa-b8c4-5f13bde8b88d",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "-- K\u00edch ho\u1ea1t extension pgvector\nCREATE EXTENSION IF NOT EXISTS vector;\n\n-- T\u1ea1o b\u1ea3ng l\u01b0u metadata c\u1ee7a t\u00e0i li\u1ec7u\nCREATE TABLE document_metadata (\n    id TEXT PRIMARY KEY,\n    title TEXT,\n    url TEXT,\n    ggdrive_di TEXT,\n    created_at TIMESTAMP DEFAULT NOW(),\n    schema TEXT\n);\n\n-- T\u1ea1o b\u1ea3ng l\u01b0u c\u00e1c d\u00f2ng d\u1eef li\u1ec7u c\u1ee7a t\u00e0i li\u1ec7u\nCREATE TABLE document_rows (\n    id SERIAL PRIMARY KEY,\n    dataset_id TEXT REFERENCES document_metadata(id),\n    row_data JSONB  -- L\u01b0u tr\u1eef d\u1eef li\u1ec7u d\u00f2ng th\u1ef1c t\u1ebf\n);\n\n-- T\u1ea1o b\u1ea3ng l\u01b0u tr\u1eef t\u00e0i li\u1ec7u v\u00e0 embedding c\u1ee7a ch\u00fang\nCREATE TABLE documents (\n  id BIGSERIAL PRIMARY KEY,\n  content TEXT,  -- N\u1ed9i dung t\u00e0i li\u1ec7u\n  metadata JSONB,  -- Metadata c\u1ee7a t\u00e0i li\u1ec7u\n  embedding VECTOR(1536)  -- 1536 l\u00e0 k\u00edch th\u01b0\u1edbc c\u1ee7a embedding, c\u00f3 th\u1ec3 thay \u0111\u1ed5i t\u00f9y theo nhu c\u1ea7u\n);\n\n-- T\u1ea1o h\u00e0m \u0111\u1ec3 t\u00ecm ki\u1ebfm t\u00e0i li\u1ec7u d\u1ef1a tr\u00ean embedding\nCREATE FUNCTION match_documents (\n  query_embedding VECTOR(1536),\n  match_count INT DEFAULT NULL,\n  filter JSONB DEFAULT '{}'\n) RETURNS TABLE (\n  doc_id BIGINT,\n  content TEXT,\n  metadata JSONB,\n  similarity FLOAT\n)\nLANGUAGE plpgsql\nAS $$\nBEGIN\n  RETURN QUERY\n  SELECT\n    documents.id AS doc_id,  -- \u0110\u1ed5i t\u00ean c\u1ed9t 'id' c\u1ee7a b\u1ea3ng 'documents' th\u00e0nh 'doc_id'\n    documents.content,\n    documents.metadata,\n    1 - (documents.embedding <=> query_embedding) AS similarity\n  FROM documents\n  JOIN document_metadata ON documents.id = document_metadata.id  -- Li\u00ean k\u1ebft v\u1edbi b\u1ea3ng document_metadata\n  LEFT JOIN document_rows ON document_metadata.id = document_rows.dataset_id  -- Li\u00ean k\u1ebft v\u1edbi b\u1ea3ng document_rows\n  WHERE documents.metadata @> filter\n  ORDER BY documents.embedding <=> query_embedding\n  LIMIT match_count;\nEND;\n$$;\n",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        280,
        100
      ],
      "id": "7420eb53-c52c-41fa-bfa5-0f49d0268b01",
      "name": "Create Documents Table and Match Function",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "document_rows",
        "filters": {
          "conditions": [
            {
              "keyName": "dataset_id",
              "condition": "eq",
              "keyValue": "={{ $('Set File ID_!').item.json.file_id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        740,
        600
      ],
      "id": "6bb554ad-ef86-4994-a496-8286b2a9b195",
      "name": "Delete Old Data Rows",
      "alwaysOutputData": true,
      "executeOnce": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "upsert",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "document_metadata",
          "mode": "list",
          "cachedResultName": "document_metadata"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $('Set File ID_!').item.json.file_id }}",
            "title": "={{ $('Set File ID_!').item.json.file_title }}",
            "url": "={{ $('Set File ID_!').item.json.file_url }}",
            "schema": "={{ $('Set File ID_!').item.json.id }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": true,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false
            },
            {
              "id": "url",
              "displayName": "url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": false
            },
            {
              "id": "schema",
              "displayName": "schema",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        900,
        600
      ],
      "id": "3a677424-3628-44c0-8c37-daf8a63011d1",
      "name": "Insert Document Metadata",
      "executeOnce": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "document_rows",
          "mode": "list",
          "cachedResultName": "document_rows"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "dataset_id": "={{ $('Set File ID_!').item.json.file_id }}",
            "row_data": "={{ $json.toJsonString().replaceAll(/'/g, \"''\") }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "dataset_id",
              "displayName": "dataset_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_data",
              "displayName": "row_data",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "object",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2220,
        880
      ],
      "id": "0a3cf1b1-4c80-411e-95eb-26570decd730",
      "name": "Insert Table Rows",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "upsert",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "document_metadata",
          "mode": "list",
          "cachedResultName": "document_metadata"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $('Set File ID_!').item.json.file_id }}",
            "schema": "={{ $json.schema }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": true,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "url",
              "displayName": "url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": false
            },
            {
              "id": "schema",
              "displayName": "schema",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        3080,
        640
      ],
      "id": "ed566254-c42e-42eb-b7a8-788d19e94895",
      "name": "Update Schema for Document Metadata",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT id,url  FROM public.document_metadata;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        320,
        1660
      ],
      "id": "2f7ae341-3296-4210-9d7b-c215e51eaf8f",
      "name": "Node_postgres",
      "alwaysOutputData": true,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "7134e92c-2e4f-49b3-a0d1-dbe856ebef2c",
              "leftValue": "={{ $('Code1').item}}",
              "rightValue": "",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1840,
        1660
      ],
      "id": "0d11f181-55ec-461e-a5a6-683c2d1e5c08",
      "name": "If"
    },
    {
      "parameters": {
        "operation": "deleteFile",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Set File ID_!').item.json.file_id }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2000,
        1300
      ],
      "id": "471007c5-e2db-4e66-afc9-6662c8200c20",
      "name": "Delete File",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "text",
        "options": {}
      },
      "id": "00ed334e-a367-41d6-9e8d-c35e902e0110",
      "name": "Extract Document Text1",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1800,
        1060
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "document_metadata",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $('Set File ID_!').item.json.file_id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        2200,
        1300
      ],
      "id": "c3519de5-1a7c-41dd-81e2-effb6031dd9a",
      "name": "Delete Old Data Rows3",
      "alwaysOutputData": true,
      "executeOnce": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $('Set File ID_!').item.json.file_id }}/copy",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleDriveOAuth2Api",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.title }}"
            },
            {
              "name": "mimeType",
              "value": "application/vnd.google-apps.document"
            }
          ]
        },
        "options": {}
      },
      "id": "58057e65-9991-4929-8626-88be111c8254",
      "name": "Convert to Google Doc",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1820,
        1300
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "21651ed3-cfa6-4ef8-940b-fb734b9e4fc5",
              "leftValue": "={{ $('Set File ID_!').item.json.file_type }}",
              "rightValue": "video/mp4",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        940,
        820
      ],
      "id": "0a5ca6de-ca36-4d0a-80c1-35f40267d222",
      "name": "If1"
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "id"
            },
            {
              "fieldToAggregate": "url"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        500,
        1660
      ],
      "id": "8cbbb339-123e-40f2-b410-ce1c538a03cc",
      "name": "AggregateDB"
    },
    {
      "parameters": {
        "jsCode": "// L\u1ea5y hai m\u1ea3ng t\u1eeb input trong n8n\nconst array1 = $('AggregateDB').first().json.id || [];\nconsole.log('array1: ',array1);\nconst array2 = $('AggregateGGDRive').first().json.id.map(item => item.id) || [];\nconsole.log('array2: ',array2)\n\nconst uniqueIDs = [\n  ...array1.filter(id => !array2.includes(id)), // ID ch\u1ec9 c\u00f3 trong array1\n  ...array2.filter(id => !array1.includes(id))  // ID ch\u1ec9 c\u00f3 trong array2\n];\nconsole.log('arrFilter1: ',array1.filter(id => !array2.includes(id)))\nconsole.log('arrFilter2: ',array2.filter(id => !array1.includes(id)))\nconsole.log('uniqueIDS: ',uniqueIDs)\n// Chuy\u1ec3n \u0111\u1ed5i k\u1ebft qu\u1ea3 th\u00e0nh \u0111\u1ecbnh d\u1ea1ng mong mu\u1ed1n\nconst result = uniqueIDs.map(id => ({ id }));\n\n// Tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3\nreturn result;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1160,
        1660
      ],
      "id": "2b175a00-f2d6-43af-adde-845bb8a8031d",
      "name": "Code1",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        20,
        1660
      ],
      "id": "187ab2f7-f0cc-43ad-8a1e-fbbb5197b1ee",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "batchSize": "=1",
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        2120,
        1640
      ],
      "id": "7ba11a82-d11d-4764-9205-715ca784138a",
      "name": "Loop Over Items2"
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "document_rows",
        "filters": {
          "conditions": [
            {
              "keyName": "dataset_id",
              "condition": "eq",
              "keyValue": "={{ $json.id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        2380,
        1680
      ],
      "id": "545c4a1c-826b-4aac-88c0-36cd7a2cfe74",
      "name": "Delete Document_Rows",
      "alwaysOutputData": true,
      "executeOnce": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "document_metadata",
        "filters": {
          "conditions": [
            {
              "keyName": "id",
              "condition": "eq",
              "keyValue": "={{ $('Loop Over Items2').item.json.id }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        2560,
        1680
      ],
      "id": "327e3e13-95df-4d96-9b99-4750e5dcd75f",
      "name": "Delete Document_Metadata",
      "alwaysOutputData": true,
      "executeOnce": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "documents",
        "filterType": "string",
        "filterString": "=metadata->>file_id=like.*{{ $('Loop Over Items2').item.json.id }}*"
      },
      "id": "6aa6cb4f-9b8a-4fff-84d7-af2f28fefaae",
      "name": "Delete Documents",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        3220,
        1680
      ],
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "69a951b3-58cf-4caf-9f9d-70f1bdcb2e78",
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        2840,
        1680
      ],
      "id": "c7d9c625-4eae-44b0-9313-9697059ac498",
      "name": "If3"
    },
    {
      "parameters": {
        "authentication": "serviceAccount",
        "resource": "fileFolder",
        "returnAll": true,
        "filter": {
          "folderId": {
            "__rl": true,
            "value": "1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV",
            "mode": "list",
            "cachedResultName": "05. UD_Doc1",
            "cachedResultUrl": "https://drive.google.com/drive/folders/1es_xg6E6Wuluod7Yo-ZBcs38dPQvZuSV"
          },
          "whatToSearch": "files",
          "includeTrashed": false
        },
        "options": {
          "fields": [
            "id"
          ]
        }
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        720,
        1660
      ],
      "id": "e6d6fa5b-bec6-403c-a823-1756588b2038",
      "name": "Node_drive",
      "alwaysOutputData": true,
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "id",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        940,
        1660
      ],
      "id": "745824af-8a7a-47e7-b49a-460d8484b649",
      "name": "AggregateGGDRive"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "10646eae-ae46-4327-a4dc-9987c2d76173",
              "name": "file_id",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "f4536df5-d0b1-4392-bf17-b8137fb31a44",
              "name": "file_type",
              "value": "={{ $json.mimeType }}",
              "type": "string"
            },
            {
              "id": "77d782de-169d-4a46-8a8e-a3831c04d90f",
              "name": "file_title",
              "value": "={{ $json.name }}",
              "type": "string"
            },
            {
              "id": "9bde4d7f-e4f3-4ebd-9338-dce1350f9eab",
              "name": "file_url",
              "value": "={{ $json.webViewLink }}",
              "type": "string"
            },
            {
              "id": "b8735aa6-4e47-4197-9f36-6559fa4d4420",
              "name": "id",
              "value": "={{ $json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "063a0f23-fcbe-479c-8a60-269a9db0e695",
      "name": "Set File ID_!",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        280,
        600
      ]
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Doc Rows": {
      "main": [
        [
          {
            "node": "Delete Old Data Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Text": {
      "main": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Summarize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Summarize": {
      "main": [
        [
          {
            "node": "Set Schema",
            "type": "main",
            "index": 0
          },
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
   

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

05. Base_To_Copy. Uses lmChatOpenAi, documentDefaultDataLoader, embeddingsOpenAi, googleDrive. Event-driven trigger; 54 nodes.

Source: https://github.com/ndbin-dcks/lawDCKS/blob/1ec9e5737ca17ccdbae2f492ea3b91956e574407/RAG.json — 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

A lightweight, self-hosted AI assistant built entirely in n8n. Multi-channel messaging (Telegram, WhatsApp, Gmail), persistent memory, task management, and autonomous work — all in a single visual wor

Telegram Trigger, OpenRouter Chat, Data Table +20
AI & RAG

Alfred (funcional). Uses gmailTool, googleCalendarTool, gmail, embeddingsOpenAi. Event-driven trigger; 83 nodes.

Gmail Tool, Google Calendar Tool, Gmail +24
AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This intelligent chatbot leverages cutting-edge financial APIs and AI-driven analysis to deliver comprehensive stock research reports. Get instant access to professional-grade investment analysis that

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

RAG_Ingest. Uses httpRequest, vectorStoreSupabase, documentDefaultDataLoader, textSplitterRecursiveCharacterTextSplitter. Event-driven trigger; 73 nodes.

HTTP Request, Supabase Vector Store, Document Default Data Loader +4