{
  "id": "CkgF5zRqCL4BS6I5",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "IPL Cricket Rules Q&A Chat Bot using RAG and Google Gemini API",
  "tags": [],
  "nodes": [
    {
      "id": "4c32f558-efff-4eff-b714-202c7419a96c",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1216,
        192
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "352186bb-07d1-4d7d-9f0f-b57e0880fc11",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1008,
        64
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a cricket expert. \n\nYou are tasked with answering questions on ipl cricket queries. Information should only be referred to and provided if it is provided explicitly in the data base to you. Your goal is to provide accurate information based on this information.\n\nIf information is not provided to you explicitly or if you can not answer the question using the provided information, say \"Sorry I donot know\""
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "15f7fbdc-ab77-4007-9a8e-8ddbe881d984",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -784,
        336
      ],
      "parameters": {
        "contextWindowLength": 20
      },
      "typeVersion": 1.3
    },
    {
      "id": "dc61d50a-fdd8-4a21-974f-33aa8aab5c0a",
      "name": "Simple Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -720,
        176
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 10,
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key"
        },
        "toolDescription": "This is a repository of ipl cricket rules and international cricket rules"
      },
      "typeVersion": 1.3
    },
    {
      "id": "69f8782c-c5d2-4693-bc00-a2ab58c61e08",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -944,
        336
      ],
      "parameters": {
        "options": {
          "topP": 0.3
        }
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "33d9a2a4-6f13-4cbe-a3b3-19f3d0b7d6a1",
      "name": "Embeddings Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -608,
        320
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "05bbad6c-877c-4d6d-90e1-6c82d6560ae2",
      "name": "Simple Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -896,
        -544
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "34948452-2e69-40cc-9b86-b78500873aab",
      "name": "Embeddings Google Gemini1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -896,
        -320
      ],
      "parameters": {},
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d6b2871c-78c6-4785-8913-262eb2364f7d",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -720,
        -400
      ],
      "parameters": {
        "options": {},
        "dataType": "binary",
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "6818e50a-ecc1-40e5-aac9-9d38fc85d3ec",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        -704,
        -256
      ],
      "parameters": {
        "options": {},
        "chunkOverlap": 200
      },
      "typeVersion": 1
    },
    {
      "id": "48da425a-c41f-4301-b4a7-df00f604ba5b",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1040,
        -448
      ],
      "parameters": {
        "url": "https://documents.iplt20.com/bcci/documents/1742707993986_Match_Playing_Conditions.pdf",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "3fc9062b-fdef-421d-a7a3-d348c83cb51c",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1232,
        -448
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "60491e32-d0c1-4e4a-922f-8ce976b481d1",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2576,
        -48
      ],
      "parameters": {
        "color": 6,
        "width": 2144,
        "height": 624,
        "content": "## Step 2\n## 2.1 Chat Trigger to initiate n8n native chat interface\n## 2.2 Simple Memory keeps the last 20 chat turns for context. This value can be edited within the node\n## 2.3 Simple Vector Store (retrieve-as-tool mode) receives the user\u2019s query embedding, \n## finds the top-10 most relevant chunks stored in step 1, and supplies them as tool output. This will drive RAG\n**The name of vector store should match from Step 1, the embedding rule should match step 1\n## 2.4 Google Gemini Chat Model is the language model that is used as the llm model\n## 2.5 AI Agent orchestrates everything:\n** Uses the system prompt (\u201cYou are a cricket expert\u2026 If info is missing, say \u2018Sorry I don\u2019t know\u2019\u201d). to prompt the model\n** Has access to the memory (2.2) and the RAG tool (2.3).\n** Generates the final response with Google Gemini, strictly limited to the retrieved IPL cricket rules data.\n\n\n\n\n\n\n## Note: Google gemini API key credential needed\n##Using simple memory store nodes provided by n8n is the best way to get started to test out the workflow before you switch to more enterprise grade vector store nodes"
      },
      "typeVersion": 1
    },
    {
      "id": "1909411f-90b0-4cd5-823a-39f4f918cc5e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2576,
        -624
      ],
      "parameters": {
        "width": 2160,
        "height": 544,
        "content": "## Step 1\n## Load the reference material (run once via the Manual Trigger)\n## 1.1 Manual Trigger \u2192 HTTP Request downloads the IPL \u201cMatch Playing Conditions\u201d PDF. \n## 1.2 Default Data Loader extracts text from the PDF.\n   **Type of data is binary\n## 1.3 Recursive Character Text Splitter breaks the text into overlapping chunks.\n   **This step ensures that the data chunks that are created in vector store have some overlap and hence less chance of hallucination\n   **Chunk size and chunk overlap are 2 variables to manage this \n## 1.4 Embeddings Google Gemini (1) converts each chunk to a vector.\n   **Connect the model with google gemini model. You will need your own api key for this\n   **Make note of the embedding model also since the same embedding model has to be selected in Step 2\n## 1.5 Simple Vector Store 1 inserts those vectors into an in-memory store under key\n   **Make note of the vector store name since it is same vector store you will have to use in Step 2\n\n\n## Note: Google gemini API key credential needed\n##Using Vector store nodes provided by n8n is the best way to get started to test out the workflow before you switch to more enterprise grade vector store nodes"
      },
      "typeVersion": 1
    },
    {
      "id": "63e38b73-3e30-47d7-86bb-afa2ad92dc2b",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2576,
        -768
      ],
      "parameters": {
        "color": 5,
        "width": 2160,
        "height": 128,
        "content": "## This workflow has 2 Broad Steps\n## Step 1 - Vector store creation with set of ipl rules using Google Gemini Embedding. This will we used to drive RAG for model grouding    \n## Step 2 - Connecting the vector store with google gemini API model and enabling a chat interface to drive the chat bot\n"
      },
      "typeVersion": 1
    },
    {
      "id": "f45e2852-88a8-4f70-a124-01f2b06d9a19",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        -544
      ],
      "parameters": {
        "color": 3,
        "width": 278,
        "height": 80,
        "content": "## Step 1.1"
      },
      "typeVersion": 1
    },
    {
      "id": "0b72e856-23c6-42c2-860e-8f761f861d95",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -304
      ],
      "parameters": {
        "color": 3,
        "width": 166,
        "height": 128,
        "content": "## Step 1.2\n## Step 1.3"
      },
      "typeVersion": 1
    },
    {
      "id": "96c343b7-3961-49c1-97e0-35b4eee90d78",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 80,
        "content": "## Step 1.4"
      },
      "typeVersion": 1
    },
    {
      "id": "f78516ba-4b17-4e48-9450-ba5d7cb123f1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -544
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 80,
        "content": "## Step 1.5"
      },
      "typeVersion": 1
    },
    {
      "id": "b97281a4-6b1f-41a1-9a1e-c48be5a6854c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1248,
        96
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 80,
        "content": "## Step 2.1"
      },
      "typeVersion": 1
    },
    {
      "id": "a8de0dce-eaa0-441d-b050-5374741f3b5f",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -976,
        464
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 80,
        "content": "## Step 2.4"
      },
      "typeVersion": 1
    },
    {
      "id": "1f405862-c83e-4687-b919-3e128bcd2073",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        64
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 80,
        "content": "## Step 2.3"
      },
      "typeVersion": 1
    },
    {
      "id": "dfb4cbe2-f6b0-45c4-bda7-d5f33a3b8e5f",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        464
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 80,
        "content": "## Step 2.2"
      },
      "typeVersion": 1
    },
    {
      "id": "c5cfbb0b-2d09-40b8-ba18-5c4028d8a556",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        -32
      ],
      "parameters": {
        "color": 4,
        "width": 160,
        "height": 80,
        "content": "## Step 2.5"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "98c130a5-eef0-4246-8a95-88a29c4e8ce6",
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Simple Vector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Simple Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini1": {
      "ai_embedding": [
        [
          {
            "node": "Simple Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}