AutomationFlowsAI & RAG › Btl AI Page Management

Btl AI Page Management

BTL AI Page Management. Uses documentDefaultDataLoader, embeddingsOpenAi, googleDrive, googleDriveTrigger. Event-driven trigger; 37 nodes.

Event trigger★★★★★ complexityAI-powered37 nodesDocument Default Data LoaderOpenAI EmbeddingsGoogle DriveGoogle Drive TriggerMemory Postgres ChatSupabaseText Splitter Character Text SplitterAgent
AI & RAG Trigger: Event Nodes: 37 Complexity: ★★★★★ AI nodes: yes Added:

This workflow follows the Agent → Documentdefaultdataloader 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": "BTL AI Page Management",
  "nodes": [
    {
      "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": "fac92469-5d03-4854-96ba-e69ab33cc6a1",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1,
      "position": [
        2340,
        1160
      ]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "options": {}
      },
      "id": "e1491f95-a5e9-48fe-a46b-af8177bd2efd",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [
        2220,
        1140
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Set File ID').item.json.file_id }}",
          "mode": "id"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain"
            }
          }
        }
      },
      "id": "af2c3660-2937-4425-98da-4038c414e99f",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1120,
        1200
      ],
      "executeOnce": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1b5yhwsmaFmf39uSJiRnECuyk4ILuE0g6",
          "mode": "list",
          "cachedResultName": "BTL AI Page Management Documents",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1b5yhwsmaFmf39uSJiRnECuyk4ILuE0g6"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "855522d3-3f00-40ec-ab1e-28dc15b75b7f",
      "name": "File Created",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -200,
        1260
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1b5yhwsmaFmf39uSJiRnECuyk4ILuE0g6",
          "mode": "list",
          "cachedResultName": "BTL AI Page Management Documents",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1b5yhwsmaFmf39uSJiRnECuyk4ILuE0g6"
        },
        "event": "fileUpdated",
        "options": {}
      },
      "id": "c9f2e5ff-b523-464c-a245-5134cd486209",
      "name": "File Updated",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -200,
        1460
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "text",
        "options": {}
      },
      "id": "fbe5d17b-6ad7-4592-8bf1-d8c1a024c103",
      "name": "Extract Document Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2000,
        1720
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "tmp"
      },
      "id": "66be7922-2810-402d-9ed6-bb516d669b14",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1,
      "position": [
        140,
        180
      ],
      "notesInFlow": false,
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "delete",
        "tableId": "documents",
        "filterType": "string",
        "filterString": "=metadata->>file_id=like.*{{ $json.file_id }}*"
      },
      "id": "32a5bea5-b53c-4079-97c0-cd663cae9c63",
      "name": "Delete Old Doc Rows",
      "type": "n8n-nodes-base.supabase",
      "typeVersion": 1,
      "position": [
        460,
        1200
      ],
      "alwaysOutputData": true,
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "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"
            }
          ]
        },
        "options": {}
      },
      "id": "569f94c5-7250-4156-bb2d-359416e555d8",
      "name": "Set File ID",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        1200
      ]
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "id": "544ca9f8-b8d5-4637-a45d-9f8e0aa707d3",
      "name": "Extract PDF Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2000,
        940
      ]
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "786e384a-ace5-4f8e-96a3-1ed0d8b99be4",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1780,
        1220
      ]
    },
    {
      "parameters": {},
      "id": "2ad48cc9-a2a8-453c-8f55-3636033c287a",
      "name": "Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter",
      "typeVersion": 1,
      "position": [
        2440,
        1340
      ]
    },
    {
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "concatenate",
              "field": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "2c4cd123-5f78-4a2c-b7b0-bad7b892bbb6",
      "name": "Summarize",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1,
      "position": [
        2000,
        1220
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "B\u1ea1n l\u00e0 tr\u1ee3 l\u00fd \u1ea3o th\u00f4ng minh c\u1ee7a c\u1eeda h\u00e0ng t\u1ea1p h\u00f3a, nhi\u1ec7m v\u1ee5 c\u1ee7a b\u1ea1n l\u00e0 h\u1ed7 tr\u1ee3 kh\u00e1ch h\u00e0ng t\u00ecm ki\u1ebfm th\u00f4ng tin s\u1ea3n ph\u1ea9m m\u1ed9t c\u00e1ch ch\u00ednh x\u00e1c v\u00e0 hi\u1ec7u qu\u1ea3 t\u1eeb kho d\u1eef li\u1ec7u n\u1ed9i b\u1ed9. Kho d\u1eef li\u1ec7u n\u00e0y ch\u1ee9a c\u1ea3 t\u00e0i li\u1ec7u v\u0103n b\u1ea3n (Txt, Docs, PDF) v\u00e0 d\u1eef li\u1ec7u b\u1ea3ng (CSV, Excel).\\n\\nQuy tr\u00ecnh l\u00e0m vi\u1ec7c \u0111\u1ec1 xu\u1ea5t:\\n1.  **Lu\u00f4n b\u1eaft \u0111\u1ea7u b\u1eb1ng T\u00ecm ki\u1ebfm Ng\u1eef ngh\u0129a (RAG):** S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 t\u00ecm ki\u1ebfm RAG \u0111\u1ec3 truy v\u1ea5n c\u01a1 s\u1edf ki\u1ebfn th\u1ee9c \u0111\u00e3 \u0111\u01b0\u1ee3c vector h\u00f3a (b\u1ea3ng \\`documents\\`). \u0110\u00e2y l\u00e0 ph\u01b0\u01a1ng ph\u00e1p hi\u1ec7u qu\u1ea3 nh\u1ea5t cho h\u1ea7u h\u1ebft c\u00e1c c\u00e2u h\u1ecfi th\u00f4ng tin chung.\\n2.  **N\u1ebfu RAG kh\u00f4ng \u0111\u1ee7:**\\n    *   **\u0110\u1ed1i v\u1edbi c\u00e2u h\u1ecfi y\u00eau c\u1ea7u t\u00ednh to\u00e1n/t\u1ed5ng h\u1ee3p tr\u00ean d\u1eef li\u1ec7u b\u1ea3ng (Excel/CSV):** S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 truy v\u1ea5n SQL (b\u1ea3ng \\`document_rows\\`). B\u1ea1n c\u1ea7n bi\u1ebft \\`file_id\\` (t\u1ee9c \\`dataset_id\\`) v\u00e0 c\u1ea5u tr\u00fac (\\`schema\\`) c\u1ee7a t\u1ec7p. N\u1ebfu ch\u01b0a bi\u1ebft, h\u00e3y d\u00f9ng c\u00f4ng c\u1ee5 \\\"List Documents\\\" \u0111\u1ec3 l\u1ea5y th\u00f4ng tin n\u00e0y tr\u01b0\u1edbc.\\n    *   **\u0110\u1ed1i v\u1edbi c\u00e2u h\u1ecfi c\u1ea7n th\u00f4ng tin chi ti\u1ebft h\u01a1n t\u1eeb t\u00e0i li\u1ec7u v\u0103n b\u1ea3n:** S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 \\\"List Documents\\\" \u0111\u1ec3 xem danh s\u00e1ch c\u00e1c t\u00e0i li\u1ec7u c\u00f3 s\u1eb5n v\u00e0 metadata c\u1ee7a ch\u00fang (bao g\u1ed3m \\`file_id\\`, \\`title\\`, \\`url\\`). Ch\u1ecdn \\`file_id\\` ph\u00f9 h\u1ee3p v\u00e0 d\u00f9ng c\u00f4ng c\u1ee5 \\\"Get File Contents\\\" \u0111\u1ec3 l\u1ea5y n\u1ed9i dung \u0111\u00e3 \u0111\u01b0\u1ee3c l\u1eadp ch\u1ec9 m\u1ee5c c\u1ee7a t\u00e0i li\u1ec7u \u0111\u00f3 t\u1eeb b\u1ea3ng \\`documents\\`.\\n3.  **T\u1ed5ng h\u1ee3p v\u00e0 Tr\u1ea3 l\u1eddi:** D\u1ef1a tr\u00ean k\u1ebft qu\u1ea3 t\u1eeb c\u00e1c c\u00f4ng c\u1ee5, h\u00e3y t\u1ed5ng h\u1ee3p c\u00e2u tr\u1ea3 l\u1eddi cu\u1ed1i c\u00f9ng.\\n\\nY\u00eau c\u1ea7u khi tr\u1ea3 l\u1eddi:\\n*   Lu\u00f4n l\u1ecbch s\u1ef1, t\u00f4n tr\u1ecdng v\u00e0 s\u1eed d\u1ee5ng ng\u00f4n ng\u1eef th\u00e2n thi\u1ec7n.\\n*   Cung c\u1ea5p th\u00f4ng tin ch\u00ednh x\u00e1c d\u1ef1a tr\u00ean d\u1eef li\u1ec7u t\u00ecm \u0111\u01b0\u1ee3c, kh\u00f4ng t\u1ef1 b\u1ecba \u0111\u1eb7t.\\n*   N\u1ebfu kh\u00f4ng t\u00ecm th\u1ea5y c\u00e2u tr\u1ea3 l\u1eddi, h\u00e3y th\u00f4ng b\u00e1o r\u00f5 r\u00e0ng v\u00e0 \u0111\u1ec1 xu\u1ea5t c\u00e1c b\u01b0\u1edbc ti\u1ebfp theo (v\u00ed d\u1ee5: ki\u1ec3m tra l\u1ea1i t\u00e0i li\u1ec7u kh\u00e1c, h\u1ecfi l\u1ea1i c\u00e2u h\u1ecfi c\u1ee5 th\u1ec3 h\u01a1n).\\n*   Gi\u1eef c\u00e2u tr\u1ea3 l\u1eddi trong gi\u1edbi h\u1ea1n 2000 k\u00fd t\u1ef1."
        }
      },
      "id": "aca5251c-67a1-4cd4-aed1-41fabf7cd7ce",
      "name": "RAG AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.6,
      "position": [
        240,
        -40
      ]
    },
    {
      "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"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "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"
              }
            },
            {
              "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"
              }
            },
            {
              "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"
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": 3
        }
      },
      "id": "b2167c97-0da8-414e-99ba-ecb9e4bc537c",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        1340,
        1180
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {
          "queryName": "match_documents"
        }
      },
      "id": "fb84821b-d135-4c45-895e-bb9800ff5ddd",
      "name": "Insert into Supabase Vectorstore",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        2240,
        920
      ],
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "xlsx",
        "options": {}
      },
      "id": "bf0facf4-c040-4e91-b141-8689cd438847",
      "name": "Extract from Excel",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1560,
        1140
      ]
    },
    {
      "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": [
        2360,
        1620
      ],
      "id": "37c2c0c3-2e86-49f8-bdec-bc5ecf7d01dc",
      "name": "Set Schema"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1560,
        1520
      ],
      "id": "900196ed-60f3-48a6-b537-9273c84d526b",
      "name": "Extract from CSV"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE document_metadata (\n    id TEXT PRIMARY KEY,\n    title TEXT,\n    url TEXT,\n    created_at TIMESTAMP DEFAULT NOW(),\n    schema TEXT\n);",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        240,
        660
      ],
      "id": "5eabe48c-23f9-4b49-958d-4fb61d3c0e75",
      "name": "Create Document Metadata Table",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE document_rows (\n    id SERIAL PRIMARY KEY,\n    dataset_id TEXT REFERENCES document_metadata(id),\n    row_data JSONB  -- Store the actual row data\n);",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        460,
        660
      ],
      "id": "405fcd33-f6a0-41f7-9007-95d41fdb50ce",
      "name": "Create Document Rows Table (for Tabular Data)",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 n\u00e0y \u0111\u1ec3 l\u1ea5y danh s\u00e1ch metadata c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c t\u00e0i li\u1ec7u c\u00f3 s\u1eb5n t\u1eeb b\u1ea3ng `document_metadata`, bao g\u1ed3m `file_id`, `title`, `url`, v\u00e0 `schema` (c\u1ea5u tr\u00fac c\u1ed9t n\u1ebfu l\u00e0 file Excel/CSV). H\u1eefu \u00edch khi RAG kh\u00f4ng cung c\u1ea5p \u0111\u1ee7 th\u00f4ng tin ho\u1eb7c khi c\u1ea7n t\u00ecm `file_id`/`schema` cho c\u00e1c c\u00f4ng c\u1ee5 kh\u00e1c.",
        "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": [
        260,
        180
      ],
      "id": "cb46e55f-ec21-4b6f-af9b-45bef136b082",
      "name": "List Documents",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 n\u00e0y \u0111\u1ec3 truy xu\u1ea5t n\u1ed9i dung *v\u0103n b\u1ea3n \u0111\u00e3 \u0111\u01b0\u1ee3c l\u1eadp ch\u1ec9 m\u1ee5c v\u00e0 chunk h\u00f3a* c\u1ee7a m\u1ed9t t\u00e0i li\u1ec7u c\u1ee5 th\u1ec3 t\u1eeb b\u1ea3ng `documents` d\u1ef1a v\u00e0o `file_id` \u0111\u01b0\u1ee3c cung c\u1ea5p. Ch\u1ec9 s\u1eed d\u1ee5ng khi RAG kh\u00f4ng \u0111\u1ee7 chi ti\u1ebft v\u00e0 b\u1ea1n c\u1ea7n xem l\u1ea1i to\u00e0n b\u1ed9 n\u1ed9i dung \u0111\u00e3 x\u1eed l\u00fd c\u1ee7a m\u1ed9t t\u00e0i li\u1ec7u v\u0103n b\u1ea3n.",
        "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": [
        380,
        180
      ],
      "id": "62f0e70d-d6cb-4969-978f-949542b16985",
      "name": "Get File Contents",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Th\u1ef1c thi truy v\u1ea5n SQL tr\u00ean d\u1eef li\u1ec7u b\u1ea3ng (t\u1eeb file Excel/CSV) \u0111\u00e3 \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong b\u1ea3ng `document_rows`. S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 n\u00e0y cho c\u00e1c y\u00eau c\u1ea7u t\u00ednh to\u00e1n, t\u1ed5ng h\u1ee3p, ho\u1eb7c l\u1ecdc ph\u1ee9c t\u1ea1p tr\u00ean d\u1eef li\u1ec7u b\u1ea3ng m\u00e0 RAG kh\u00f4ng x\u1eed l\u00fd t\u1ed1t. **Y\u00eau c\u1ea7u:** Ph\u1ea3i cung c\u1ea5p `file_id` (d\u01b0\u1edbi d\u1ea1ng `dataset_id` trong m\u1ec7nh \u0111\u1ec1 WHERE) v\u00e0 bi\u1ebft c\u1ea5u tr\u00fac (`schema`) c\u1ee7a b\u1ea3ng (l\u1ea5y t\u1eeb c\u00f4ng c\u1ee5 'List Documents' n\u1ebfu c\u1ea7n). Lu\u00f4n truy v\u1ea5n c\u1ed9t `row_data` (ki\u1ec3u JSONB) \u0111\u1ec3 truy c\u1eadp d\u1eef li\u1ec7u t\u1eebng h\u00e0ng. V\u00ed d\u1ee5: `SELECT AVG((row_data->>'revenue')::numeric) FROM document_rows WHERE dataset_id = 'your_file_id';` ho\u1eb7c `SELECT row_data->>'category', SUM((row_data->>'sales')::numeric) FROM document_rows WHERE dataset_id = 'your_file_id' GROUP BY row_data->>'category';`\n\n\u0110\u1ecbnh d\u1ea1ng th\u00f4ng tin ng\u00e0y th\u00e1ng m\u1eb7c \u0111\u1ecbnh l\u00e0 dd/mm/yyyy ho\u1eb7c mm/yyyy",
        "operation": "executeQuery",
        "query": "{{ $fromAI('sql_query') }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgresTool",
      "typeVersion": 2.5,
      "position": [
        500,
        180
      ],
      "id": "7fc2fae1-0791-430f-b989-cd01eb18ad9d",
      "name": "Query Document Rows",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolName": "documents",
        "toolDescription": "C\u00f4ng c\u1ee5 ch\u00ednh \u0111\u1ec3 th\u1ef1c hi\u1ec7n t\u00ecm ki\u1ebfm ng\u1eef ngh\u0129a (RAG) tr\u00ean c\u01a1 s\u1edf ki\u1ebfn th\u1ee9c \u0111\u00e3 \u0111\u01b0\u1ee3c vector h\u00f3a (b\u1ea3ng `documents`). S\u1eed d\u1ee5ng c\u00f4ng c\u1ee5 n\u00e0y l\u00e0m b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean \u0111\u1ec3 tr\u1ea3 l\u1eddi h\u1ea7u h\u1ebft c\u00e1c c\u00e2u h\u1ecfi c\u1ee7a ng\u01b0\u1eddi d\u00f9ng v\u1ec1 th\u00f4ng tin s\u1ea3n ph\u1ea9m ho\u1eb7c n\u1ed9i dung t\u00e0i li\u1ec7u.",
        "tableName": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "topK": 8,
        "options": {
          "queryName": "match_documents"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1,
      "position": [
        620,
        200
      ],
      "id": "6a70b73e-0b64-4d9a-90ba-e1f063de5427",
      "name": "Supabase Vector Store1",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        720,
        380
      ],
      "id": "f3618349-52e8-4e30-9ab6-d0c666c1885e",
      "name": "Embeddings OpenAI2",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {
          "reset": false
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        20,
        1360
      ],
      "id": "3132a12e-acd2-4d40-bb6b-9e21d8ba6917",
      "name": "Loop Over Items"
    },
    {
      "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": [
        680,
        1200
      ],
      "id": "699ca4ab-54ed-4d6e-a68b-9ad27e501dab",
      "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 }}"
          },
          "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": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        900,
        1200
      ],
      "id": "ca0f4239-9dcb-4a11-919c-6a877ad7754d",
      "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": [
        1780,
        1420
      ],
      "id": "32500a0c-565d-40ac-bfbb-2bb95806d929",
      "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": [
        2720,
        1620
      ],
      "id": "e6ed184d-f301-4d8b-82fd-5a2fce7854d6",
      "name": "Update Schema for Document Metadata",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "-- Enable the pgvector extension to work with embedding vectors\ncreate extension vector;\n\n-- Create a table to store your documents\ncreate table documents (\n  id bigserial primary key,\n  content text, -- corresponds to Document.pageContent\n  metadata jsonb, -- corresponds to Document.metadata\n  embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed\n);\n\n-- Create a function to search for documents\ncreate function match_documents (\n  query_embedding vector(1536),\n  match_count int default null,\n  filter jsonb DEFAULT '{}'\n) returns table (\n  id bigint,\n  content text,\n  metadata jsonb,\n  similarity float\n)\nlanguage plpgsql\nas $$\n#variable_conflict use_column\nbegin\n  return query\n  select\n    id,\n    content,\n    metadata,\n    1 - (documents.embedding <=> query_embedding) as similarity\n  from documents\n  where metadata @> filter\n  order by documents.embedding <=> query_embedding\n  limit match_count;\nend;\n$$;",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        20,
        660
      ],
      "id": "83116d87-7022-488a-9c08-48d904e0b025",
      "name": "Create Documents Table and Match Function",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -200,
        660
      ],
      "id": "014a8fee-c01b-4919-b1b8-0e812fe0d7bb",
      "name": "When clicking 'Test workflow'"
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -200,
        -40
      ],
      "id": "137ed851-12ca-4fe8-a4c0-cc938bc7cfaa",
      "name": "Telegram Trigger",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1000,
        -40
      ],
      "id": "c968fd88-0f8f-4d42-8bcb-d35c81a7d48c",
      "name": "Telegram",
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "gpt-4.1-2025-04-14",
        "options": {}
      },
      "id": "af532f59-863b-404d-b763-83a5fd93483d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        -20,
        240
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "description": "S\u1eed d\u1ee5ng tool n\u00e0y n\u1ebfu c\u1ea7n suy ngh\u0129 \u0111\u1ec3 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 ph\u1ee9c t\u1ea1p ho\u1eb7c c\u00e1c c\u00e2u l\u1ec7nh sql, ho\u1eb7c n\u1ebfu kh\u00f4ng ch\u1ea1y \u0111\u01b0\u1ee3c sql th\u00ec h\u00e3y d\u00f9ng tool nay \u0111\u1ec3 suy ngh\u0129 v\u00e0 ch\u1ea1y l\u1ea1i"
      },
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "typeVersion": 1,
      "position": [
        980,
        200
      ],
      "id": "f86b337c-7d84-47d7-b37c-04179de32d55",
      "name": "Think"
    }
  ],
  "connections": {
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Document Text": {
      "main": [
        [
          {
            "node": "Insert into Supabase Vectorstore",
            "type": "main",
            "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
          }
        ]
      ]
    },
    "Set File ID": {
      "main": [
        [
          {
            "node": "Delete Old Doc Rows",
            "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": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Extract PDF Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from Excel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from CSV",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Document Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert into Supabase Vectorstore": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Excel": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Insert Table Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Schema": {
      "main": [
        [
          {
            "node": "Update Schema for Document Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from CSV": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Insert Table Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Document Metadata Table": {
      "main": [
        [
          {
            "node": "Create Document Rows Table (for Tabular Data)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Documents": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get File Contents": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Query Document Rows": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Data Rows": {
      "main": [
        [
          {
            "node": "Insert Document Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Document Metadata": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Documents Table and Match Function": {
      "main": [
        [
          {
            "node": "Create Document Metadata Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "Create Documents Table and Match Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Think": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f659e527-0a0e-415d-8f6b-d21ec6427ccc",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "H0Om1jPYNRTiLNXI",
  "tags": []
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

BTL AI Page Management. Uses documentDefaultDataLoader, embeddingsOpenAi, googleDrive, googleDriveTrigger. Event-driven trigger; 37 nodes.

Source: https://github.com/Sgm27/BTL-AI/blob/a23606cf071d6183d99c2c7f2fffd10f4cada12f/BTL_AI_Page_Management.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 comprehensive workflow bundle is designed as a powerful starter kit, enabling you to build a multi-functional AI assistant on Telegram. It seamlessly integrates AI-powered voice interactions, an

Telegram Trigger, Telegram, OpenAI +19
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