{
  "name": "RAG Chatbot Template",
  "nodes": [
    {
      "parameters": {
        "public": true,
        "mode": "webhook",
        "options": {
          "loadPreviousSession": "memory"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -192,
        0
      ],
      "id": "7a3e30e6-bc46-4e77-9b49-aa6baf9ba618",
      "name": "When chat message received",
      "webhookId": "4091fa09-fb9a-4039-9411-7104d213f601"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        944,
        224
      ],
      "id": "c76c99c9-d34c-4cf1-aefe-4ded62b526f2",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "jLwStW8V16GXToXI",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1168,
        0
      ],
      "id": "8797b752-173f-49dd-a653-c152d901206f",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        560,
        240
      ],
      "id": "4b8cc6db-9d43-4a1c-855a-3e445b4312f6",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('When chat message received').item.json.chatInput }}",
        "options": {
          "systemMessage": "=You are \"WebBot,\" example.com's helpful and friendly AI assistant.\n\nHere are your inputs:  \n- Website Data: {{ $json.pageContent }}\n- User Input: {{ $('When chat message received').item.json.chatInput }}\n\nYour task:  \n1. Understand the user’s input.  \n2. Search through the provided example.com data.  \n3. Use the information on the website to provide the user with the relevant article/page link and a small description of what you are providing.\n4. Use markdown when providing links to the user [Example Page](https://example.com/example-page/).\n5. If the user asks for information outside of example.com context (such as how to make mansaf) direct them in a humurous manner back to example.com.\n6. Do not invent information. \n7. Don't tell users to visit the website as they are already on the website talking to you.\n8. If the user’s query cannot be answered from the provided example.com data, politely explain that you don’t have the information and suggest contacting example.com directly by providing the contact page [Contact Page](https://example.com/contactus/).\n9. Always stay professional yet approachable, and keep your answers clear, accurate, and concise.\n10. Your role is to answer users’ questions based ONLY on the official example.com data provided to you.\n\nNow respond to the user input accordingly.  "
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        800,
        0
      ],
      "id": "b3c80988-f0db-41cc-93c3-31a03c78245e",
      "name": "AI Agent1"
    },
    {
      "parameters": {
        "mode": "load",
        "tableName": "n8n_vectors_store",
        "prompt": "={{ $json.chatInput }}",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "typeVersion": 1.3,
      "position": [
        224,
        0
      ],
      "id": "bc52dc9a-3628-4f4f-8ae4-f5fd014a3fbc",
      "name": "Postgres PGVector Store1",
      "credentials": {
        "postgres": {
          "id": "D16yOKVojkVrlAiX",
          "name": "Postgres account 2"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        96,
        240
      ],
      "id": "652adecf-242f-44e5-9161-f5ac040ab775",
      "name": "Embeddings OpenAI2",
      "credentials": {
        "openAiApi": {
          "id": "jLwStW8V16GXToXI",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "document.pageContent"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        544,
        0
      ],
      "id": "6c74d762-7cfd-4b8e-8f42-5c261fb64f3a",
      "name": "Aggregate"
    }
  ],
  "pinData": {},
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "Postgres PGVector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent1",
            "type": "ai_memory",
            "index": 0
          },
          {
            "node": "When chat message received",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent1": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store1": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f5954e6d-7192-4c23-8bf9-9f988656999d",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "e592fdf17e0f5e1e2d257cb5482246d085959171f9a8a3e9366dee0ceb93a8c3"
  },
  "id": "Ra2xPvhaEbSTkaI7",
  "tags": [
    {
      "updatedAt": "2025-09-25T13:48:23.826Z",
      "createdAt": "2025-09-25T13:48:23.826Z",
      "id": "izuw1hSIhVc1N4I0",
      "name": "RAG Chatbot"
    }
  ]
}