{
  "id": "YrTb2xjf031w73kf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Google Gemini File Search RAG System",
  "tags": [],
  "nodes": [
    {
      "id": "62bd25f1-61b6-473a-ad59-3642cb110ed0",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -384,
        -144
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "e66227cc-73c9-42a8-9f73-da6c4139ef7d",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -400,
        240
      ],
      "parameters": {
        "options": {},
        "formTitle": "Test",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "File",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Test"
      },
      "typeVersion": 2.3
    },
    {
      "id": "9aabf070-e13f-48be-af40-8e8bc5bb541d",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        80,
        224
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineAll"
      },
      "typeVersion": 3.2
    },
    {
      "id": "d693f266-3d04-4c5f-ba4b-c5e7b34c85fd",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -384,
        720
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.4
    },
    {
      "id": "ca48038f-4d02-4baf-a233-b80867a40bef",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        384,
        896
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a98fa97f-e25d-44a4-bc7c-45f7f91c9cab",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        80,
        704
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineAll"
      },
      "typeVersion": 3.2
    },
    {
      "id": "8e15d69d-2283-4320-b1e5-a22155d6ac2a",
      "name": "SearchStore",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        720,
        880
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\":\"{{ $fromAI(\"query\",\"the question the user needs an answer to\") }}\"\n        }\n      ]\n    }\n  ],\n  \"tools\": [\n    {\n      \"file_search\": {\n        \"file_search_store_names\": [\n          \"{{ $('Get Store1').item.json['Search Store'] }}\"\n        ]\n      }\n    }\n  ]\n}",
        "sendBody": true,
        "sendQuery": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "XXX"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "15ad91ee-e9b0-42a7-a47a-3ae8bde1b1ac",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        544,
        896
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "2346983a-5aba-4a96-97fe-00f9527871bb",
      "name": "Create Store",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -112,
        -144
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/v1beta/fileSearchStores",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "displayName",
              "value": "XXX"
            }
          ]
        },
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "XXX"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "6896edef-1a7c-4f8d-ad76-407f8be20315",
      "name": "Upload File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        384,
        224
      ],
      "parameters": {
        "url": "https://generativelanguage.googleapis.com/upload/v1beta/files",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendQuery": true,
        "contentType": "binaryData",
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "XXX"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "inputDataFieldName": "File"
      },
      "typeVersion": 4.3
    },
    {
      "id": "3b42498a-c54e-4409-84a7-9ff57f386448",
      "name": "Import to Store",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        592,
        224
      ],
      "parameters": {
        "url": "=https://generativelanguage.googleapis.com/v1beta/{{ $('Get Store').item.json['Search Store'] }}:importFile",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n    \"file_name\":\"{{ $json.file.name }}\"\n} ",
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "XXX"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "00059810-17e5-41aa-9787-6fff626b182a",
      "name": "Get Store1",
      "type": "n8n-nodes-base.set",
      "position": [
        -144,
        592
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "612266b5-c5c0-4091-875e-50cd729cda11",
              "name": "Search Store",
              "type": "string",
              "value": "fileSearchStores/my-store-XXX"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "29356ea0-043e-438a-acbf-99be816475f8",
      "name": "Rag Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        416,
        704
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a helpful assistant. For every question you are asked, always search with the SearchStore tool"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "c5c834de-6a73-4a23-9eef-cbc199ee23ad",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -176
      ],
      "parameters": {
        "color": 6,
        "width": 512,
        "height": 208,
        "content": "```json\n[\n  {\n    \"name\": \"fileSearchStores/my-store-XXXXX\",\n    \"displayName\": \"My Store\",\n    \"createTime\": \"2025-11-22T16:33:57.084623Z\",\n    \"updateTime\": \"2025-11-22T16:33:57.084623Z\"\n  }\n]\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "42c59588-e8a2-4265-a49c-ff982c8e00e5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 352,
        "content": "## STEP 1 - Create a new Search Store\nTriggered manually via the *\u201cExecute workflow\u201d* node, this step sends a request to the Gemini API to create a **FileSearch Store**, which acts as a private vector index for your documents."
      },
      "typeVersion": 1
    },
    {
      "id": "c998f2ea-1721-482a-91ed-bb67cbb06359",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 352,
        "content": "## STEP 2 - Upload a new file to Search Store\nUpload and import a file into the Search Store"
      },
      "typeVersion": 1
    },
    {
      "id": "c96e1b19-2108-4a6b-a78f-b15bb540e97a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        448
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 592,
        "content": "## STEP 3 - Retrieved Context from Search Store\n\nWhen a chat message is received:\n\n* The workflow loads the Search Store identifier.\n* A *LangChain Agent* is used along with the **Google Gemini Chat Model**.\n* The model is configured to **always use the SearchStore tool**"
      },
      "typeVersion": 1
    },
    {
      "id": "72071705-f8e2-4919-a156-742b6a9bbd8a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        80
      ],
      "parameters": {
        "color": 7,
        "width": 208,
        "height": 960,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSet the Search Store created in STEP 1 (eg. fileSearchStores/my-store-XXXXX)"
      },
      "typeVersion": 1
    },
    {
      "id": "7128fcb3-49b8-41ca-bab3-17942a5042b8",
      "name": "Get Store",
      "type": "n8n-nodes-base.set",
      "position": [
        -144,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "612266b5-c5c0-4091-875e-50cd729cda11",
              "name": "Search Store",
              "type": "string",
              "value": "fileSearchStores/my-store-XXX"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0fd1dfbe-fd89-412a-9464-a390dc52caf2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -832
      ],
      "parameters": {
        "width": 1024,
        "height": 496,
        "content": "## RAG with Google Gemini Search Store\n\nThis workflow implements a Retrieval-Augmented Generation (RAG) system using Google Gemini\u2019s File Search API. It allows users to upload files to a dedicated search store and then ask questions about their content in a chat interface.\n\nThe system automatically retrieves relevant information from the uploaded files to provide accurate, context-aware answers.\n\n### **How it works:**\n\nThis workflow creates a fully automated RAG (Retrieval-Augmented Generation) pipeline using Google Gemini\u2019s File Search API. It begins by creating a private File Search Store to hold and index uploaded documents. When users submit a file through the form, the workflow uploads and imports it into the store, making it searchable. During a chat session, the Gemini model\u2014configured with a LangChain Agent\u2014automatically retrieves relevant content from the indexed files to generate context-aware responses. This ensures each query is informed by user-provided documents, enabling an accurate and scalable RAG chatbot experience within n8n.\n\n### **Setup steps:**\n\nStart by adding your valid Google Gemini API key to all HTTP Request nodes handling store creation, file uploads, and search operations. Next, manually execute the \u201cCreate Store\u201d node to generate a new File Search Store and copy its resource name. Update the \u201cGet Store\u201d and \u201cGet Store1\u201d nodes with this value to link the workflow to your store. Finally, activate the workflow to expose public URLs for file upload and chat triggers, which can be embedded into external interfaces for end-user interaction. Once configured, users can upload files and query them via chat seamlessly.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0b26e838-6185-470e-9fe2-63e01042cab7",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Upload File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Rag Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Store": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Store1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SearchStore": {
      "ai_tool": [
        [
          {
            "node": "Rag Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Upload File": {
      "main": [
        [
          {
            "node": "Import to Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Rag Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "Get Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Rag Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Get Store1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Create Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}