{
  "name": "Knowledge Base Semantic FAQ",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "faq",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "kbsf0001-0001-4000-8000-000000000001",
      "name": "FAQ Query Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "question",
              "value": "={{ $json.body.question }}",
              "type": "string"
            },
            {
              "name": "knowledgeBase",
              "value": "={{ $json.body.knowledgeBase || [] }}",
              "type": "array"
            }
          ]
        }
      },
      "id": "kbsf0001-0002-4000-8000-000000000002",
      "name": "Prepare Query",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [460, 300]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "options": {}
      },
      "id": "kbsf0001-0003-4000-8000-000000000003",
      "name": "Embed Query",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "mode": "retrieve-as-text",
        "memoryKey": "faq-knowledge-base",
        "topK": 3,
        "options": {}
      },
      "id": "kbsf0001-0004-4000-8000-000000000004",
      "name": "Find Similar FAQs",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "typeVersion": 1,
      "position": [900, 300]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "You are a helpful FAQ assistant. Answer the user's question using the relevant knowledge base entries below. If no entry matches, say 'I don't have information about that yet.'\n\nRelevant Knowledge Base Entries:\n{{ $json.documents }}\n\nUser Question: {{ $('Prepare Query').item.json.question }}"
            }
          ]
        },
        "options": {
          "temperature": 0.2
        }
      },
      "id": "kbsf0001-0005-4000-8000-000000000005",
      "name": "Generate FAQ Answer",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [1120, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "answer",
              "value": "={{ $json.message.content }}",
              "type": "string"
            },
            {
              "name": "question",
              "value": "={{ $('Prepare Query').item.json.question }}",
              "type": "string"
            },
            {
              "name": "answeredAt",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "kbsf0001-0006-4000-8000-000000000006",
      "name": "Return Answer",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [1340, 300]
    }
  ],
  "connections": {
    "FAQ Query Webhook": {
      "main": [[{ "node": "Prepare Query", "type": "main", "index": 0 }]]
    },
    "Prepare Query": {
      "main": [[{ "node": "Embed Query", "type": "main", "index": 0 }]]
    },
    "Embed Query": {
      "main": [[{ "node": "Find Similar FAQs", "type": "main", "index": 0 }]]
    },
    "Find Similar FAQs": {
      "main": [[{ "node": "Generate FAQ Answer", "type": "main", "index": 0 }]]
    },
    "Generate FAQ Answer": {
      "main": [[{ "node": "Return Answer", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
