{
  "name": "Adaptive RAG strategy with query classification & retrieval (Gemini & Qdrant)",
  "nodes": [
    {
      "id": "856bd809-8f41-41af-8f72-a3828229c2a5",
      "name": "Query Classification",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        380,
        -20
      ]
    },
    {
      "id": "cc2106fc-f1a8-45ef-b37b-ab981ac13466",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        740,
        -40
      ]
    },
    {
      "id": "63889cad-1283-4dbf-ba16-2b6cf575f24a",
      "name": "Factual Strategy - Focus on Precision",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1140,
        -780
      ]
    },
    {
      "id": "020d2201-9590-400d-b496-48c65801271c",
      "name": "Analytical Strategy - Comprehensive Coverage",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1140,
        -240
      ]
    },
    {
      "id": "c35d1b95-68c8-4237-932d-4744f620760d",
      "name": "Opinion Strategy - Diverse Perspectives",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1140,
        300
      ]
    },
    {
      "id": "363a3fc3-112f-40df-891e-0a5aa3669245",
      "name": "Contextual Strategy - User Context Integration",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1140,
        840
      ]
    },
    {
      "id": "45887701-5ea5-48b4-9b2b-40a80238ab0c",
      "name": "Chat",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -280,
        120
      ]
    },
    {
      "id": "7f7df364-4829-4e29-be3d-d13a63f65b8f",
      "name": "Factual Prompt and Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1540,
        -780
      ]
    },
    {
      "id": "590d8667-69eb-4db2-b5be-714c602b319a",
      "name": "Contextual Prompt and Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1540,
        840
      ]
    },
    {
      "id": "fa3228ee-62d8-4c02-9dca-8a1ebc6afc74",
      "name": "Opinion Prompt and Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1540,
        300
      ]
    },
    {
      "id": "c769a76a-fb26-46a1-a00d-825b689d5f7a",
      "name": "Analytical Prompt and Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1540,
        -240
      ]
    },
    {
      "id": "fcd29f6b-17e8-442c-93f9-b93fbad7cd10",
      "name": "Gemini Classification",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        360,
        180
      ]
    },
    {
      "id": "c0828ee3-f184-41f5-9a25-0f1059b03711",
      "name": "Gemini Factual",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1120,
        -560
      ]
    },
    {
      "id": "98f9981d-ea8e-45cb-b91d-3c8d1fe33e25",
      "name": "Gemini Analytical",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1120,
        -20
      ]
    },
    {
      "id": "c85f270d-3224-4e60-9acf-91f173dfe377",
      "name": "Chat Buffer Memory Analytical",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1280,
        -20
      ]
    },
    {
      "id": "c39ba907-7388-4152-965a-e28e626bc9b2",
      "name": "Chat Buffer Memory Factual",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1280,
        -560
      ]
    },
    {
      "id": "52dcd9f0-e6b3-4d33-bc6f-621ef880178e",
      "name": "Gemini Opinion",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1120,
        520
      ]
    },
    {
      "id": "147a709a-4b46-4835-82cf-7d6b633acd4c",
      "name": "Chat Buffer Memory Opinion",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1280,
        520
      ]
    },
    {
      "id": "3cb6bf32-5937-49b9-acf7-d7d01dc2ddd1",
      "name": "Gemini Contextual",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        1120,
        1060
      ]
    },
    {
      "id": "5916c4f1-4369-4d66-8553-2fff006b7e69",
      "name": "Chat Buffer Memory Contextual",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1280,
        1060
      ]
    },
    {
      "id": "d33377c2-6b98-4e4d-968f-f3085354ae50",
      "name": "Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        2060,
        200
      ]
    },
    {
      "id": "32d9a0c0-0889-4cb2-a088-8ee9cfecacd3",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        -900
      ],
      "parameters": {
        "width": 700,
        "height": 520,
        "content": "## Factual Strategy\n**Retrieve precise facts and figures.**"
      }
    },
    {
      "id": "064a4729-717c-40c8-824a-508406610a13",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        -360
      ],
      "parameters": {
        "width": 700,
        "height": 520,
        "content": "## Analytical Strategy\n**Provide comprehensive coverage of a topics and exploring different aspects.**"
      }
    },
    {
      "id": "9fd52a28-44bc-4dfd-bdb7-90987cc2f4fb",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        180
      ],
      "parameters": {
        "width": 700,
        "height": 520,
        "content": "## Opinion Strategy\n**Gather diverse viewpoints on a subjective issue.**"
      }
    },
    {
      "id": "3797b21f-cc2a-4210-aa63-6d181d413c5e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        720
      ],
      "parameters": {
        "width": 700,
        "height": 520,
        "content": "## Contextual Strategy\n**Incorporate user-specific context to fine-tune the retrieval.**"
      }
    },
    {
      "id": "16fa1531-9fb9-4b12-961c-be12e20b2134",
      "name": "Concatenate Context",
      "type": "n8n-nodes-base.summarize",
      "position": [
        2440,
        -20
      ]
    },
    {
      "id": "4d6147d1-7a3d-42ab-b23f-cdafe8ea30b0",
      "name": "Retrieve Documents from Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        2080,
        -20
      ]
    },
    {
      "id": "7e68f9cb-0a0d-4215-8083-3b9ef92cd237",
      "name": "Set Prompt and Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1880,
        -20
      ]
    },
    {
      "id": "0c623ca1-da85-48a3-9d8b-90d97283a015",
      "name": "Gemini Answer",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2720,
        200
      ]
    },
    {
      "id": "fab91e48-1c62-46a8-b9fc-39704f225274",
      "name": "Answer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2760,
        -20
      ]
    },
    {
      "id": "d69f8d62-3064-40a8-b490-22772fbc38cd",
      "name": "Chat Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        2900,
        200
      ]
    },
    {
      "id": "a399f8e6-fafd-4f73-a2de-894f1e3c4bec",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1800,
        -220
      ],
      "parameters": {
        "width": 820,
        "height": 580,
        "content": "## Perform adaptive retrieval\n**Find document considering both query and context.**"
      }
    },
    {
      "id": "7f10fe70-1af8-47ad-a9b5-2850412c43f8",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2640,
        -220
      ],
      "parameters": {
        "width": 740,
        "height": 580,
        "content": "## Reply to the user integrating retrieval context"
      }
    },
    {
      "id": "5cd0dd02-65f4-4351-aeae-c70ecf5f1d66",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        3120,
        -20
      ]
    },
    {
      "id": "4c56ef8f-8fce-4525-bb87-15df37e91cc4",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        280,
        -220
      ],
      "parameters": {
        "width": 700,
        "height": 580,
        "content": "## User query classification\n**Classify the query into one of four categories: Factual, Analytical, Opinion, or Contextual.**"
      }
    },
    {
      "id": "3ef73405-89de-4bed-9673-90e2c1f2e74b",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        -280,
        -140
      ]
    },
    {
      "id": "0785714f-c45c-4eda-9937-c97e44c9a449",
      "name": "Combined Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        40,
        -20
      ]
    },
    {
      "id": "57a93b72-4233-4ba2-b8c7-99d88f0ed572",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        400
      ],
      "parameters": {
        "width": 1280,
        "height": 1300,
        "content": "# Adaptive RAG Workflow\n\nThis n8n workflow implements a version of the Adaptive Retrieval-Augmented Generation (RAG) approach. It classifies user queries and applies different retrieval and generation"
      }
    },
    {
      "id": "bec8070f-2ce9-4930-b71e-685a2b21d3f2",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -220
      ],
      "parameters": {
        "width": 320,
        "height": 580,
        "content": "## ⚠️  If using in Chat mode\n\nUpdate the `vector_store_id` variable to the corresponding Qdrant ID needed to perform the documents retrieval."
      }
    }
  ],
  "connections": {
    "Chat": {
      "main": [
        [
          {
            "node": "Combined Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Factual Strategy - Focus on Precision",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Analytical Strategy - Comprehensive Coverage",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Opinion Strategy - Diverse Perspectives",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Contextual Strategy - User Context Integration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Retrieve Documents from Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Answer": {
      "ai_languageModel": [
        [
          {
            "node": "Answer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Factual": {
      "ai_languageModel": [
        [
          {
            "node": "Factual Strategy - Focus on Precision",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Opinion": {
      "ai_languageModel": [
        [
          {
            "node": "Opinion Strategy - Diverse Perspectives",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Combined Fields": {
      "main": [
        [
          {
            "node": "Query Classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Analytical": {
      "ai_languageModel": [
        [
          {
            "node": "Analytical Strategy - Comprehensive Coverage",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Contextual": {
      "ai_languageModel": [
        [
          {
            "node": "Contextual Strategy - User Context Integration",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Chat Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "Answer",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Concatenate Context": {
      "main": [
        [
          {
            "node": "Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Classification": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Classification": {
      "ai_languageModel": [
        [
          {
            "node": "Query Classification",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt and Output": {
      "main": [
        [
          {
            "node": "Retrieve Documents from Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Factual Prompt and Output": {
      "main": [
        [
          {
            "node": "Set Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Opinion Prompt and Output": {
      "main": [
        [
          {
            "node": "Set Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Buffer Memory Factual": {
      "ai_memory": [
        [
          {
            "node": "Factual Strategy - Focus on Precision",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Chat Buffer Memory Opinion": {
      "ai_memory": [
        [
          {
            "node": "Opinion Strategy - Diverse Perspectives",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Analytical Prompt and Output": {
      "main": [
        [
          {
            "node": "Set Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contextual Prompt and Output": {
      "main": [
        [
          {
            "node": "Set Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Buffer Memory Analytical": {
      "ai_memory": [
        [
          {
            "node": "Analytical Strategy - Comprehensive Coverage",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Chat Buffer Memory Contextual": {
      "ai_memory": [
        [
          {
            "node": "Contextual Strategy - User Context Integration",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Combined Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Documents from Vector Store": {
      "main": [
        [
          {
            "node": "Concatenate Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Factual Strategy - Focus on Precision": {
      "main": [
        [
          {
            "node": "Factual Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Opinion Strategy - Diverse Perspectives": {
      "main": [
        [
          {
            "node": "Opinion Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analytical Strategy - Comprehensive Coverage": {
      "main": [
        [
          {
            "node": "Analytical Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contextual Strategy - User Context Integration": {
      "main": [
        [
          {
            "node": "Contextual Prompt and Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}