{
  "name": "Local document question answering with Ollama AI, Agentic RAG & PGVector",
  "nodes": [
    {
      "id": "397d00eb-8034-49e5-a8f6-0a0fd9b97d5b",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        3312,
        1280
      ]
    },
    {
      "id": "e57065a2-9087-48e9-839e-d9c5c5fb477f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2304,
        144
      ],
      "parameters": {
        "width": 583.4552380860637,
        "height": 528.85546469693,
        "content": "## Agent Tools for RAG"
      }
    },
    {
      "id": "f7efaf27-78fb-4429-beba-74ffcc700342",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        688
      ],
      "parameters": {
        "width": 3073,
        "height": 867,
        "content": "## Tool to Add a Google Drive File to Vector DB"
      }
    },
    {
      "id": "a137d00b-fb01-408c-9963-645e2beb44d9",
      "name": "Extract Document Text",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2512,
        1280
      ]
    },
    {
      "id": "1aec304d-7264-4e65-8654-cb9294c96c82",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1712,
        512
      ]
    },
    {
      "id": "9c407f2b-4f6a-46d6-a607-225c1c628ae5",
      "name": "Set File ID",
      "type": "n8n-nodes-base.set",
      "position": [
        992,
        960
      ]
    },
    {
      "id": "bc93aa94-10ec-4670-99f4-3bcec36be1ce",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        208
      ],
      "parameters": {
        "width": 1035.6381264595484,
        "height": 464.8027193303974,
        "content": "## RAG AI Agent with Chat Interface"
      }
    },
    {
      "id": "8ccc451e-2fac-49b0-8700-085476add599",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2128,
        288
      ]
    },
    {
      "id": "55abb8ac-7988-430a-ae41-5155471228a2",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1568,
        288
      ]
    },
    {
      "id": "78b3fd17-23e9-4693-b782-918a5a8e5aed",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1312,
        288
      ]
    },
    {
      "id": "06e362d1-d20c-407a-a75a-ed175c07439d",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1312,
        480
      ]
    },
    {
      "id": "e8ba5c17-3426-4d76-b69b-ff91dff7958f",
      "name": "Extract PDF Text",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2512,
        720
      ]
    },
    {
      "id": "b40eb123-d7fc-4799-b248-4b9516aee49e",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2544,
        912
      ]
    },
    {
      "id": "0e3755e8-9532-447f-9137-f65d542c247e",
      "name": "Summarize",
      "type": "n8n-nodes-base.summarize",
      "position": [
        2752,
        992
      ]
    },
    {
      "id": "b185f2be-06bf-4a14-8d58-4b411a709f18",
      "name": "RAG AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1792,
        288
      ]
    },
    {
      "id": "2ee45951-3553-49b7-9f79-3cef3d065e8a",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        1840,
        944
      ]
    },
    {
      "id": "20bf7dde-e073-4288-a9d6-34df3973b5c3",
      "name": "Extract from Excel",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2320,
        912
      ]
    },
    {
      "id": "f1840995-3f1c-4f4e-9d78-bc9225ecbe2b",
      "name": "Set Schema",
      "type": "n8n-nodes-base.set",
      "position": [
        3184,
        848
      ]
    },
    {
      "id": "b79ceb0b-f370-4ffb-9953-14b411acb5d9",
      "name": "Extract from CSV",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2320,
        1088
      ]
    },
    {
      "id": "7067874e-4123-4a6c-a94d-89e4d1878309",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        368
      ],
      "parameters": {
        "width": 680,
        "height": 300,
        "content": "## Run Each Node Once to Set Up Database Tables"
      }
    },
    {
      "id": "130c53e8-d507-4b6f-b1cf-f79dbc571c46",
      "name": "Create Document Metadata Table",
      "type": "n8n-nodes-base.postgres",
      "position": [
        688,
        464
      ]
    },
    {
      "id": "421d2123-b68a-4c51-a482-db5bdffd3f76",
      "name": "Create Document Rows Table (for Tabular Data)",
      "type": "n8n-nodes-base.postgres",
      "position": [
        992,
        464
      ]
    },
    {
      "id": "55ff6535-bedb-479f-b3da-eb45e1127e77",
      "name": "List Documents",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        1840,
        512
      ]
    },
    {
      "id": "ffcb630b-5119-4ff6-b85a-d77eeb8d5713",
      "name": "Get File Contents",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        1984,
        512
      ]
    },
    {
      "id": "f504b2f4-ffb5-4ef7-ba93-753151b77d9e",
      "name": "Query Document Rows",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        2144,
        512
      ]
    },
    {
      "id": "4abe03ca-297c-4509-b0db-7bed4338a158",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        800,
        800
      ]
    },
    {
      "id": "e382d750-85ba-492d-9d3e-eb839af0bfc1",
      "name": "Insert Document Metadata",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1488,
        832
      ]
    },
    {
      "id": "bbf6f704-b4a2-4ff2-ac09-27626526b35f",
      "name": "Insert Table Rows",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2544,
        1088
      ]
    },
    {
      "id": "3265a7df-dd40-421e-b1fb-53293a7460f8",
      "name": "Update Schema for Document Metadata",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3408,
        848
      ]
    },
    {
      "id": "53f9f045-bb08-4b22-a11e-dfd2c964b687",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 540,
        "height": 1320,
        "content": "## 🚀 n8n Local AI Agentic RAG Template\n\n**Author:** [Jadai kongolo](https://my.jadaikongolo.tech)\n\n## What is this?\nThis template provides an entirely local implementation of an **Agentic RAG (Retriev"
      }
    },
    {
      "id": "cdee87fe-e154-47ab-9330-32dee5c213d3",
      "name": "Local File Trigger",
      "type": "n8n-nodes-base.localFileTrigger",
      "position": [
        608,
        800
      ]
    },
    {
      "id": "67311475-7928-4ddc-957a-79817c98d26d",
      "name": "Read/Write Files from Disk",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        1648,
        960
      ]
    },
    {
      "id": "366e800a-9bd7-4822-a11c-f555800bbba6",
      "name": "Embeddings Ollama",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOllama",
      "position": [
        3072,
        1280
      ]
    },
    {
      "id": "be37cfb9-ea40-4244-87d7-b562be315573",
      "name": "Embeddings Ollama1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOllama",
      "position": [
        2560,
        480
      ]
    },
    {
      "id": "1306b972-2b24-4c62-846e-f1c5b3d0482c",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        3200,
        1408
      ]
    },
    {
      "id": "677ad468-8118-4f8f-9a47-f5429cdc7582",
      "name": "Ollama (Change Base URL)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1568,
        512
      ]
    },
    {
      "id": "b3e23401-8868-4b3c-a3fe-37fda44419d5",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        1344
      ],
      "parameters": {
        "width": 540,
        "height": 200,
        "content": "## NOTE\n\nThe Ollama chat model node doesn't work with the RAG nodes - known issue with n8n.\n\nSo for now, we are using the OpenAI chat model but changing the base URL to Ollama when creating the creden"
      }
    },
    {
      "id": "987a6081-cdfd-457e-a2e5-4fa93fa018f4",
      "name": "Delete Old Doc Records",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1168,
        832
      ]
    },
    {
      "id": "619a8a54-5fb8-4d8f-9cac-5a1c2a58f44b",
      "name": "Delete Old Data Records",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1328,
        960
      ]
    },
    {
      "id": "c975f943-3c05-45eb-9b11-4bd254845fbc",
      "name": "Postgres PGVector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "position": [
        3184,
        1072
      ]
    },
    {
      "id": "9bba5830-ad14-454c-b653-48baf03844bb",
      "name": "Postgres PGVector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "position": [
        2464,
        288
      ]
    }
  ],
  "connections": {
    "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
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Summarize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize": {
      "main": [
        [
          {
            "node": "Set Schema",
            "type": "main",
            "index": 0
          },
          {
            "node": "Postgres PGVector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Schema": {
      "main": [
        [
          {
            "node": "Update Schema for Document Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set File ID": {
      "main": [
        [
          {
            "node": "Delete Old Doc Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Documents": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Text": {
      "main": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from CSV": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Insert Table Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Ollama": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Get File Contents": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Ollama1": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Excel": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Insert Table Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Local File Trigger": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Query Document Rows": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Extract Document Text": {
      "main": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Doc Records": {
      "main": [
        [
          {
            "node": "Delete Old Data Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Data Records": {
      "main": [
        [
          {
            "node": "Insert Document Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Document Metadata": {
      "main": [
        [
          {
            "node": "Read/Write Files from Disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama (Change Base URL)": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Read/Write Files from Disk": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}