{
  "name": "Handle customer support queries with cache-first RAG using Redis, LangCache and OpenAI",
  "nodes": [
    {
      "id": "af6e85ef-2255-454f-8281-517b17a112c0",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -80,
        736
      ]
    },
    {
      "id": "f5884164-83b2-48d0-806d-381c1ba9b802",
      "name": "decompose_query",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        496,
        736
      ]
    },
    {
      "id": "2c48cfdb-bba2-4d9e-88c5-72176c0d9595",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        704,
        1040
      ]
    },
    {
      "id": "0c52729a-53e9-4f18-a4b4-845cc2384bec",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        800,
        736
      ]
    },
    {
      "id": "6410933e-dde4-4de5-9f72-5444f0f51891",
      "name": "Search LangCache",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1248,
        528
      ]
    },
    {
      "id": "65f6963c-6faf-46a4-971d-bf162a2cf49d",
      "name": "Is Cache Hit?",
      "type": "n8n-nodes-base.if",
      "position": [
        1488,
        448
      ]
    },
    {
      "id": "0f16f03d-6fe1-4da8-9cc5-1fbba5012f30",
      "name": "LangCache Config",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        736
      ]
    },
    {
      "id": "b142939c-814c-4b36-87bd-45a955f3c564",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1024,
        880
      ]
    },
    {
      "id": "ea1352da-745e-4a86-8365-5ddfe8ed93ab",
      "name": "synthesize_response_node",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1408,
        864
      ]
    },
    {
      "id": "7548562c-2a2a-4c4b-8aae-5ed08d5dfb25",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1248,
        864
      ]
    },
    {
      "id": "aecc43ec-bb69-4d13-a7a4-00bb91453172",
      "name": "Redis Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreRedis",
      "position": [
        1440,
        -112
      ]
    },
    {
      "id": "2344ea11-5412-4d6d-9d59-005d5748a475",
      "name": "Redis Vector Store2",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreRedis",
      "position": [
        2128,
        672
      ]
    },
    {
      "id": "84e92cea-0cf7-45c8-b346-d87126052efc",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2112,
        816
      ]
    },
    {
      "id": "7a76f285-d661-4fd7-83cc-f20f050dbcc9",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1120,
        144
      ]
    },
    {
      "id": "bfe94569-e5c7-4282-b2f9-c710a076907d",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1408,
        144
      ]
    },
    {
      "id": "27cd82d3-d938-49bc-92f2-213d80000e43",
      "name": "example Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1216,
        -112
      ]
    },
    {
      "id": "b05e94c5-98ff-4be8-aa56-1739a99019f5",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1072,
        1072
      ]
    },
    {
      "id": "b02d24fa-1de0-4240-b7bb-02f02c2619f8",
      "name": "Save to LangCache",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2528,
        944
      ]
    },
    {
      "id": "a45a8b97-dd9f-4d09-989f-1a59944c493a",
      "name": "search_node1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2000,
        480
      ]
    },
    {
      "id": "96f48cc5-8734-4c00-9977-a55a21c75ec1",
      "name": "evaluate_quality",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2448,
        528
      ]
    },
    {
      "id": "dad250fb-5286-4cca-9d58-99b04298fbae",
      "name": "low quality ?",
      "type": "n8n-nodes-base.if",
      "position": [
        2944,
        528
      ]
    },
    {
      "id": "1cfea78d-da68-4c4e-af21-a3085f842a39",
      "name": "increase iteration",
      "type": "n8n-nodes-base.set",
      "position": [
        3360,
        480
      ]
    },
    {
      "id": "a650cdaf-4a8e-4938-af44-182d94b34193",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1024,
        -112
      ]
    },
    {
      "id": "e250b675-af0c-4c59-8749-d027da7b72f8",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        512,
        1056
      ]
    },
    {
      "id": "726bfd01-9dac-42ff-816c-151cbe58f897",
      "name": "Simple Memory1",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1952,
        784
      ]
    },
    {
      "id": "0677630f-5809-408c-8233-85d734f2a732",
      "name": "Simple Memory2",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1328,
        1056
      ]
    },
    {
      "id": "5f9e7ddc-9454-451d-8f19-28a145aaa9b2",
      "name": "current_iteration",
      "type": "n8n-nodes-base.set",
      "position": [
        1840,
        464
      ]
    },
    {
      "id": "fdf91552-525c-4b3d-8e0f-de910525e648",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        -800
      ],
      "parameters": {
        "width": 880,
        "height": 1120,
        "content": "# Customer support RAG workflow:\n## Workflow Overview\nCache-first **RAG** workflow for customer support.\n\n**Flow:**  \nChat → Decompose → Cache → Redis Search → Quality Check → Cache → Respond\n\n**Goals"
      }
    },
    {
      "id": "7994e6ea-45d6-44b6-8a1b-fc9b347f32eb",
      "name": "getScore",
      "type": "n8n-nodes-base.set",
      "position": [
        2768,
        528
      ]
    },
    {
      "id": "e6978f27-8803-4851-b148-fdbf9911648c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        512
      ],
      "parameters": {
        "width": 320,
        "height": 656,
        "content": "#### Configuration (Edit First)\nUpdate in **LangCache Config**:\n- `langcacheBaseUrl`\n- `langcacheCacheId`\n- `similarityThreshold` (default `0.75`)\n- `max_iterations` (default `2`)"
      }
    },
    {
      "id": "d44f3c0c-fb23-4bd1-97b4-96d32f446e8c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        512
      ],
      "parameters": {
        "width": 464,
        "height": 656,
        "content": "## Query Decomposition\nSplits complex user input into focused questions to improve retrieval and caching.\n"
      }
    },
    {
      "id": "981cbf1e-7179-4c77-8a79-b46d50dfdf90",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        384
      ],
      "parameters": {
        "width": 704,
        "height": 352,
        "content": "#### Cache-First Strategy\nEach question is checked in **LangCache** first.\n- Hit → reuse answer  \n- Miss → search Redis\n\nReduces latency and API cost."
      }
    },
    {
      "id": "8c35a870-1f2b-4207-9827-6c8aeae2550b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1728,
        384
      ],
      "parameters": {
        "width": 688,
        "height": 784,
        "content": "#### Redis Vector Retrieval\nRuns only on cache miss.\nUses embeddings to retrieve relevant knowledge from Redis."
      }
    },
    {
      "id": "bb7f7b45-eee6-41ac-89d7-7b39062d04af",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2432,
        384
      ],
      "parameters": {
        "width": 704,
        "height": 384,
        "content": "## Quality Evaluation\nEach answer is scored (`0.0 – 1.0`).\n- ≥ `0.7` → accept  \n- < `0.7` → retry if allowed"
      }
    },
    {
      "id": "8b0d0a12-df24-4a78-a8f2-5d987c8da340",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3168,
        384
      ],
      "parameters": {
        "width": 384,
        "height": 784,
        "content": "## Retry Control\nRetries are limited by `max_iterations` to avoid loops and high cost."
      }
    },
    {
      "id": "f1a6f21c-fba8-42eb-b479-b6e10b2c8339",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2432,
        800
      ],
      "parameters": {
        "width": 704,
        "height": 368,
        "content": "## ## Save to Cache\nOnly high-quality answers are saved to **LangCache** for future reuse."
      }
    },
    {
      "id": "da62019e-6e0e-41cd-9918-fe295ddc9659",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        992,
        768
      ],
      "parameters": {
        "width": 704,
        "height": 400,
        "content": "## Generate the respoonse"
      }
    },
    {
      "id": "70286448-0f9d-44d6-ba62-666efd454d5b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        -192
      ],
      "parameters": {
        "width": 752,
        "height": 480,
        "content": "## Prepare the Knowledge Base -  Example Data"
      }
    }
  ],
  "connections": {
    "getScore": {
      "main": [
        [
          {
            "node": "low quality ?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "synthesize_response_node",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "example Data": {
      "main": [
        [
          {
            "node": "Redis Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "search_node1": {
      "main": [
        [
          {
            "node": "evaluate_quality",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Cache Hit?": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "current_iteration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "decompose_query",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "low quality ?": {
      "main": [
        [
          {
            "node": "increase iteration",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save to LangCache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory1": {
      "ai_memory": [
        [
          {
            "node": "search_node1",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory2": {
      "ai_memory": [
        [
          {
            "node": "synthesize_response_node",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Search LangCache",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "decompose_query": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LangCache Config": {
      "main": [
        [
          {
            "node": "decompose_query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "example Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search LangCache": {
      "main": [
        [
          {
            "node": "Is Cache Hit?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "current_iteration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "evaluate_quality": {
      "main": [
        [
          {
            "node": "getScore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Redis Vector Store2",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "decompose_query",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "synthesize_response_node",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "search_node1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Save to LangCache": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "current_iteration": {
      "main": [
        [
          {
            "node": "search_node1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Redis Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "increase iteration": {
      "main": [
        [
          {
            "node": "current_iteration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Redis Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Redis Vector Store2": {
      "ai_tool": [
        [
          {
            "node": "search_node1",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "decompose_query",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "LangCache Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}