{
  "id": "6naAx0wcjHZbs2pM",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "RAG chatbot using Google Drive",
  "tags": [],
  "nodes": [
    {
      "id": "4191c842-b484-467e-bea5-d2ff44af79e0",
      "name": "Complete Setup Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 760,
        "height": 908,
        "content": "## \ud83d\ude80 COMPLETE SETUP GUIDE - READ FIRST!\n\n### Step 1: Required Services\n1. **Google Drive** - For document storage\n2. **OpenAI Account** - For embeddings and chat (API key required)\n3. **Supabase Account** - For vector database (free tier OK)\n4. **PostgreSQL Database** - For chat memory (can use Supabase or separate)\n\n### Step 2: Supabase Vector Database Setup\nRun these SQL commands in Supabase SQL editor:\nhttps://supabase.com/docs/guides/ai/langchain?database-method=sql\n\n### Step 3: Credentials Setup\n1. **Google Drive OAuth2** - Enable Drive API, create OAuth2 credentials\n2. **OpenAI API** - Get API key from OpenAI dashboard\n3. **Supabase API** - Get URL and service role key from project settings\n4. **PostgreSQL** - Use Supabase connection string or separate DB\n\n### Step 4: Configure Workflow\n1. Update Google Drive folder IDs in both trigger nodes\n2. Ensure all credential connections are set\n3. Test with a single PDF file first\n\n### Step 5: Testing\n1. Upload a document to your Google Drive folder\n2. Check Supabase documents table for new entries\n3. Activate workflow and test chat interface\n4. Ask questions about your document content\n\n### \ud83d\udccb Quick Checklist:\n\u2610 Supabase database and functions created\n\u2610 Google Drive folder IDs configured\n\u2610 All 4 credentials added to n8n\n\u2610 Test PDF uploaded to Drive folder\n\u2610 Workflow activated successfully\n\u2610 Chat interface responding correctly"
      },
      "typeVersion": 1
    },
    {
      "id": "5e8a89f6-ef3c-4691-959f-e1a6870f8b97",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        -176
      ],
      "parameters": {
        "color": 4,
        "width": 2020,
        "height": 820,
        "content": "## Data Ingestion: Adding Google Drive PDF files to Vector DB"
      },
      "typeVersion": 1
    },
    {
      "id": "e833cbb0-3dde-4d15-bd0d-ee3d53b976c0",
      "name": "File Updated",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        976,
        192
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_DRIVE_FOLDER_ID",
          "cachedResultUrl": "https://drive.google.com/drive/folders/YOUR_FOLDER_ID",
          "cachedResultName": "Your Watch Folder"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0b1d7b3b-1840-4f82-b4e8-3f3dd9c22c38",
      "name": "Set File ID",
      "type": "n8n-nodes-base.set",
      "position": [
        1232,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "79e9c100-c2d0-4fbd-97da-b2559a263eaa",
              "name": "file_id",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ed7a80c0-893d-41a5-b5c2-1b7ea5c6c64a",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2352,
        16
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "0f4833f8-ac06-4069-b935-d4c80fcaae97",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        2576,
        16
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e5c920c4-06d4-4ed4-8ab7-e7271c7aa495",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        2624,
        304
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "file_id",
                "value": "={{ $('Set File ID').item.json.file_id }}"
              }
            ]
          }
        },
        "jsonData": "={{ $json.data }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1
    },
    {
      "id": "15b7a747-6c48-4980-b9fe-342ef2695290",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        2624,
        512
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "0bd90ef9-eadd-40ee-a355-679c25ea00b8",
      "name": "File Created",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        976,
        -96
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_DRIVE_FOLDER_ID_2",
          "cachedResultUrl": "https://drive.google.com/drive/folders/YOUR_FOLDER_ID_2",
          "cachedResultName": "Your Second Watch Folder"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b7b355c9-f5b9-4284-8279-4ef65e9fafae",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2432,
        304
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "e9d25ee5-28f0-445d-9fff-4ddb0fdc253f",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1472,
        16
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "4e46f442-6012-4144-924b-4987caee00f1",
      "name": "Delete a row",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1776,
        -16
      ],
      "parameters": {
        "tableId": "documents",
        "operation": "delete",
        "filterType": "string",
        "filterString": "=metadata->>file_id=like.*{{ $json.file_id }}*"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "32a5b87c-2082-4784-8fda-9d2b216b9692",
      "name": "Download the file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2096,
        -16
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Set File ID').item.json.file_id }}"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain"
            }
          }
        },
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "ce5c5e25-7b29-43ca-ae6c-37478f7311b6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        672
      ],
      "parameters": {
        "width": 1160,
        "height": 700,
        "content": "## Conversational RAG AI agent"
      },
      "typeVersion": 1
    },
    {
      "id": "cab8ef92-84f1-40b1-ab48-60be42f2af2a",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1488,
        1056
      ],
      "parameters": {
        "sessionKey": "={{ $json.user}}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a7d2d794-0989-4cb3-bae7-8c3cd8efce94",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1376,
        1056
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "a43a8218-e3ff-41b3-aa7b-a2a77f565a74",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1088,
        816
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "d72474db-da71-4ae5-9fbc-ab575842a5e1",
      "name": "RAG Vector store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1696,
        1008
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 6,
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "toolDescription": "Use this knowledge base to answer questions from the user",
        "includeDocumentMetadata": false
      },
      "typeVersion": 1.3
    },
    {
      "id": "af193ff9-dfce-423f-a7b6-28b4be9d3a50",
      "name": "RAG AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1392,
        816
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an intelligent AI assistant connected to a dynamic knowledge base stored in a Supabase vector store. The information in this knowledge base can vary depending on the user and the data they have provided.\nInstructions:\nWhenever you receive a question, always search the knowledge base using the connected tool to retrieve relevant information before answering.\nIf a user asks what you can help with, or about your capabilities, query the knowledge base for a summary or list of available topics, documents, or areas of expertise.\nClearly mention that your abilities depend on the information currently available in the knowledge base, and provide specific examples or categories based on the retrieved data.\nIf the knowledge base is empty or does not contain relevant information, politely inform the user that you currently have no data to assist with their request.\nExample Behaviors:\nIf asked, \"What can you help me with?\"\n\n\u2192 Search the knowledge base for available topics or documents and respond with a summary, e.g.,\n\n\"Based on the current knowledge base, I can assist you with topics such as [Topic A], [Topic B], and [Topic C]. Please let me know what you'd like to know more about!\"\nIf asked a specific question,\n\n\u2192 Retrieve relevant information from the knowledge base and answer accordingly, citing the source or context if appropriate.\nIf the knowledge base is empty,\n\n\u2192 \"I currently do not have any information in my knowledge base. Please add some data or let me know how I can assist you further.\"\nAlways ensure your responses are based on the most recent and relevant information from the knowledge base.\n"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6ce5b725-2692-4dee-8100-72fe32cfacd1",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1680,
        1168
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7502b182-44d3-4034-b44d-a50ba225cd07",
  "connections": {
    "Set File ID": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a row": {
      "main": [
        [
          {
            "node": "Download the file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Delete a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG Vector store": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Download the file": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "RAG Vector store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}