{
  "name": "Chat with PDFs (Neon pgvector RAG)",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "5dd91861-0d86-42b8-8fcf-5d88fda4f557",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.5,
      "position": [
        0,
        208
      ]
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are a document assistant. Answer questions strictly from the PDF Knowledge Base tool results.\nAlways search the PDF Knowledge Base tool before answering a question about documents.\nCite the source file name (metadata.source_file) for every claim drawn from a document.\nIf the retrieved context does not contain the answer, say you could not find it in the indexed documents.",
          "maxIterations": 5
        }
      },
      "id": "908abca5-4a74-43b9-8efc-048bc94a7019",
      "name": "RAG Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        288,
        208
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-5-mini"
        },
        "responsesApiEnabled": false,
        "options": {}
      },
      "id": "b2b05476-98c6-4954-a2a9-35060c367602",
      "name": "Neon AI Gateway Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        224,
        432
      ]
    },
    {
      "parameters": {
        "contextWindowLength": 10
      },
      "id": "27401bf3-e2f9-4cc9-b228-5bf1e3d8fa77",
      "name": "Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.4,
      "position": [
        352,
        432
      ]
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Search the indexed PDF document knowledge base. Call this tool whenever the user asks a question that may be answered by the stored PDF documents. Returns the most relevant text chunks with their source file names.",
        "tableName": "pdf_chunks",
        "topK": 5,
        "options": {
          "distanceStrategy": "cosine"
        }
      },
      "id": "3b098a18-a51b-492f-9367-19d92a109cfb",
      "name": "PDF Knowledge Base",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "typeVersion": 1.3,
      "position": [
        480,
        432
      ]
    },
    {
      "parameters": {
        "model": "qwen3-embedding-0-6b",
        "options": {
          "batchSize": 10,
          "encodingFormat": "float"
        }
      },
      "id": "d4794579-b129-4ab9-85de-a981f47773a9",
      "name": "Neon AI Gateway Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        480,
        640
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Neon AI Gateway Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "PDF Knowledge Base": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Neon AI Gateway Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "PDF Knowledge Base",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "tags": []
}
