{
  "name": "PDF Q&A over Fetched Document",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "pdf-qa",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "pqfd0001-0001-4000-8000-000000000001",
      "name": "Receive Question Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "url": "={{ $json.body.pdfUrl }}",
        "options": {
          "timeout": 60000,
          "responseType": "arraybuffer"
        }
      },
      "id": "pqfd0001-0002-4000-8000-000000000002",
      "name": "Fetch PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [460, 300]
    },
    {
      "parameters": {
        "dataType": "binary",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "source",
                "value": "={{ $('Receive Question Webhook').item.json.body.pdfUrl }}"
              }
            ]
          }
        }
      },
      "id": "pqfd0001-0003-4000-8000-000000000003",
      "name": "Load PDF Content",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "chunkSize": 800,
        "chunkOverlap": 150,
        "options": {}
      },
      "id": "pqfd0001-0004-4000-8000-000000000004",
      "name": "Split Text",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "typeVersion": 1,
      "position": [900, 300]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "options": {}
      },
      "id": "pqfd0001-0005-4000-8000-000000000005",
      "name": "Embed Text",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [1120, 300]
    },
    {
      "parameters": {
        "mode": "retrieve-as-text",
        "memoryKey": "pdf-qa-store",
        "topK": 4,
        "options": {}
      },
      "id": "pqfd0001-0006-4000-8000-000000000006",
      "name": "Search Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "typeVersion": 1,
      "position": [1340, 300]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "Answer the following question based ONLY on the provided context. If the answer is not in the context, say 'I could not find that in the document.'\n\nContext:\n{{ $json.documents }}\n\nQuestion: {{ $('Receive Question Webhook').item.json.body.question }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1
        }
      },
      "id": "pqfd0001-0007-4000-8000-000000000007",
      "name": "Answer Question",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [1560, 300]
    }
  ],
  "connections": {
    "Receive Question Webhook": {
      "main": [[{ "node": "Fetch PDF", "type": "main", "index": 0 }]]
    },
    "Fetch PDF": {
      "main": [[{ "node": "Load PDF Content", "type": "main", "index": 0 }]]
    },
    "Load PDF Content": {
      "main": [[{ "node": "Split Text", "type": "main", "index": 0 }]]
    },
    "Split Text": {
      "main": [[{ "node": "Embed Text", "type": "main", "index": 0 }]]
    },
    "Embed Text": {
      "main": [[{ "node": "Search Vector Store", "type": "main", "index": 0 }]]
    },
    "Search Vector Store": {
      "main": [[{ "node": "Answer Question", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
