AutomationFlowsAI & RAG › Retrieve and Answer Gmail Email Queries with Llama 3.2, Mxbai-embed, and Qdrant

Retrieve and Answer Gmail Email Queries with Llama 3.2, Mxbai-embed, and Qdrant

ByNeloy Barman @neloy-barman on n8n.io

Self-Hosted

Event trigger★★★★★ complexityAI-powered30 nodesGoogle Drive TriggerGoogle DriveN8N Nodes QdrantGmail TriggerHTTP RequestGmailOpenAI
AI & RAG Trigger: Event Nodes: 30 Complexity: ★★★★★ AI nodes: yes Added:

This workflow corresponds to n8n.io template #14268 — we link there as the canonical source.

This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "5dddd013-33eb-4d44-b9b0-19825944060c",
      "name": "Google Drive Trigger",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -320,
        -208
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {}
          ]
        },
        "triggerOn": "specificFile",
        "fileToWatch": {
          "__rl": true,
          "mode": "id",
          "value": "11HH12Rrdy6RGSBsHM8Ci31OYM0VfHZCr"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3de5c51c-02a4-4d0b-b3cd-1a2228a3f5ee",
      "name": "Download file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -128,
        -208
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "6dc2432f-90af-4c20-897f-459196ce4e85",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        48,
        -208
      ],
      "parameters": {
        "options": {},
        "operation": "fromJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "a420b373-77e1-465a-92e2-2509b6a823c7",
      "name": "Create Collection",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        576,
        -448
      ],
      "parameters": {
        "vectors": "{\n  \"size\": 1024,\n  \"distance\": \"Cosine\"\n}",
        "operation": "createCollection",
        "shardNumber": 1,
        "collectionName": "{{ $json.collection }}",
        "requestOptions": {},
        "replicationFactor": 1
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ad05ae8-e8fd-40da-bee6-a89066fd9817",
      "name": "Check If Collection Exists",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        32,
        -464
      ],
      "parameters": {
        "operation": "collectionExists",
        "collectionName": "={{ $json.collection }}",
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d4a30be5-1e1b-4e89-9f47-3400b8a99a36",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        208,
        -464
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "be21728b-7bda-4669-bc81-cfa5fcdc2be6",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.result.exists }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9b00c385-c89b-4086-8cf1-36d1bd017a51",
      "name": "Delete Collection",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        384,
        -576
      ],
      "parameters": {
        "operation": "deleteCollection",
        "collectionName": {
          "__rl": true,
          "mode": "name",
          "value": "{{ $json.collection }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "342e50cc-c02f-4be6-94db-2e9de5da2325",
      "name": "Upsert Points",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        816,
        -448
      ],
      "parameters": {
        "points": "=[\n  {\n    \"id\": {{ $('Data Preprocessing').item.json.id }},\n    \"payload\": {\n        \"id\": \"{{ $('Data Preprocessing').item.json.id }}\",\n        \"topic\": \"{{ $('Data Preprocessing').item.json.topic }}\",\n        \"question\": \"{{ $('Data Preprocessing').item.json.question }}\",\n        \"answer\": \"{{ $('Data Preprocessing').item.json.answer }}\",\n        \"embeddingText\": \"{{ $('Data Preprocessing').item.json.embeddingText }}\"\n    },\n    \"vector\": {{ JSON.stringify($('Embedding Generation').item.json.data[0].embedding) }}\n  }\n] ",
        "resource": "point",
        "operation": "upsertPoints",
        "collectionName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('Data Preprocessing').item.json.collection }}"
        },
        "requestOptions": {}
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b97f6489-35b6-4954-8557-33570f47a8d8",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -336,
        416
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "12a35073-822e-4e1c-bdf4-83d29edcbd7f",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        224,
        400
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2,
      "alwaysOutputData": true
    },
    {
      "id": "e725a619-28bf-450b-b254-ac1a36411d3b",
      "name": "Fetch Collection Name",
      "type": "n8n-nodes-base.code",
      "position": [
        -144,
        -464
      ],
      "parameters": {
        "jsCode": "// QDrant DB Collection\nconst collection = $env.QDRANT_COLLECTION;\n\nreturn {\n  \"collection\": collection\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "cf2e97a9-e0d2-4575-9fd3-cfe1e92bf974",
      "name": "Data Preprocessing",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -208
      ],
      "parameters": {
        "jsCode": "// Input Data\nvar data = $input.first().json.data;\n\n// QDrant DB Collection\nconst collection = $env.QDRANT_COLLECTION;\n\n// Loop through data array\nconst results = [];\n\nfor (const item of data) {\n  // Process each item\n  results.push({\n    id: item.id,\n    topic: item.topic,\n    question: item.question,\n    answer: item.answer,\n    embeddingText: `[${item.topic}] ${item.question}`,\n    collection: `${collection}`\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "676476dd-79de-4c1b-b1db-2f0ac58df3d1",
      "name": "Embedding Generation",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        592,
        -208
      ],
      "parameters": {
        "url": "http://192.168.56.1:1234/v1/embeddings",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"text-embedding-mxbai-embed-large-v1\",\n  \"input\": \"{{ $json.embeddingText }}\"\n}",
        "sendBody": true,
        "jsonHeaders": "{\n  \"Content-Type\": \"application/json\"\n}",
        "sendHeaders": true,
        "specifyBody": "json",
        "specifyHeaders": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "d55fe456-10a8-4125-bda7-d083628a8ed3",
      "name": "Data Fetch",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        -208
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4cc6a859-60d6-46ad-95e8-52dbaec39595",
              "name": "data",
              "type": "array",
              "value": "={{ $json.data.data }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c5551fa5-6ac7-422e-96c4-17b6269e32ea",
      "name": "Query Embedding",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        48,
        224
      ],
      "parameters": {
        "url": "http://192.168.56.1:1234/v1/embeddings",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"text-embedding-mxbai-embed-large-v1\",\n  \"input\": \"{{ $json.email_body }}\"\n}",
        "sendBody": true,
        "jsonHeaders": "{\n  \"Content-Type\": \"application/json\"\n}",
        "sendHeaders": true,
        "specifyBody": "json",
        "specifyHeaders": "json"
      },
      "typeVersion": 4.3
    },
    {
      "id": "0da98ba8-9633-461e-855c-d670e111e5ed",
      "name": "Fields Preparation",
      "type": "n8n-nodes-base.set",
      "position": [
        -144,
        416
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "743b5019-056a-4cd2-9f46-570bb824e4e2",
              "name": "from",
              "type": "string",
              "value": "={{ $json.To }}"
            },
            {
              "id": "0c5e63a4-ebad-4072-8bf0-68b1b61342f0",
              "name": "name",
              "type": "string",
              "value": "={{ $json.From.match(/\\\"(.+?)\\\"/)[1].replace('.', '').trim() }}"
            },
            {
              "id": "79eae785-be4e-4dab-acf0-6f60c68d4625",
              "name": "to",
              "type": "string",
              "value": "={{ $json.From.match(/<(.+?)>/)[1] }}"
            },
            {
              "id": "1644d100-2594-417f-91ac-777217edd1b8",
              "name": "email_id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "fa85272c-25f4-4ffa-b550-a4eafe8a9d2e",
              "name": "thread_id",
              "type": "string",
              "value": "={{ $json.threadId }}"
            },
            {
              "id": "38c84b55-5c28-4df4-adaf-0c74abcc1e22",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.Subject }}"
            },
            {
              "id": "a58fc265-aff6-44ef-aafd-b7b1b25f7141",
              "name": "email_body",
              "type": "string",
              "value": "={{ $json.snippet }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ce84d2bd-ad68-41bf-b5f2-282a3a664d9d",
      "name": "Collection Name Fetch",
      "type": "n8n-nodes-base.code",
      "position": [
        48,
        416
      ],
      "parameters": {
        "jsCode": "// QDrant DB Collection\nconst collection = $env.QDRANT_COLLECTION;\n\nreturn {\n  \"collection\": collection\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "7408cf72-bd53-4ccd-96bd-237e7b44ac27",
      "name": "Similarity Search",
      "type": "n8n-nodes-qdrant.qdrant",
      "position": [
        400,
        400
      ],
      "parameters": {
        "limit": 3,
        "query": "={{ JSON.stringify($json.data[0].embedding) }}",
        "resource": "search",
        "operation": "queryPoints",
        "collectionName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $json.collection }}"
        },
        "requestOptions": {},
        "scoreThreshold": 0.6
      },
      "credentials": {
        "qdrantRestApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "580a03f7-d870-46c2-b0f2-4411990eb24a",
      "name": "Send Repy Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1120,
        224
      ],
      "parameters": {
        "message": "={{ $json.reply_email }}",
        "options": {
          "appendAttribution": false,
          "replyToSenderOnly": true
        },
        "messageId": "={{ $('Fields Preparation').item.json.email_id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "9dda2726-3d88-404d-96cb-f01b1c292c20",
      "name": "Message a model",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        608,
        224
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "llama-3.2-3b-instruct",
          "cachedResultName": "LLAMA-3.2-3B-INSTRUCT"
        },
        "options": {},
        "responses": {
          "values": [
            {
              "role": "system",
              "content": "=You are a professional email response assistant for \nCrestwood University's automated support system \ncalled AEQRS (Automated Email Query Resolution System).\n\n---\n\nABOUT CRESTWOOD UNIVERSITY:\nName     : Crestwood University\nLocation : Austin, Texas\nType     : Private University\nPortal   : portal.crestwooduniversity.edu\nSupport  : support@crestwooduniversity.edu\nHelpdesk : helpdesk@crestwooduniversity.edu\nPhone    : +1 (512) 000-0000\n\n---\n\nYOUR ROLE:\nYou will receive:\n\u2192 Student's name\n\u2192 Student's original email body\n\u2192 Top 3 FAQ answers retrieved from the \n  knowledge base with their similarity \n  scores, topics, matched questions and answers\n\nYour job is to:\n1. Read and understand the student's original email\n2. Analyze the 3 retrieved FAQ answers\n3. Pick the most relevant answer or intelligently \n   combine answers if the student asked about \n   multiple things\n4. Generate ONLY the email body content in HTML\n\n---\n\nRESPONSE INTELLIGENCE RULES:\n1. Carefully read the student's email and understand \n   what they are ACTUALLY asking\n\n2. From the 3 retrieved answers pick the most \n   relevant one:\n   \u2192 If student asked ONE thing    : use best match\n   \u2192 If student asked MULTI things : combine relevant \n     answers naturally into one flow\n\n3. If NONE of the 3 retrieved answers are relevant \n   to the student's question \u2014 use this fallback:\n   \"Thank you for reaching out to Crestwood University.\n   We have received your query and our support team \n   will get back to you within 1-2 business days. \n   We apologize for any inconvenience.\"\n\n4. Address the student by FIRST NAME only\n\n5. Be warm, helpful and professional in tone\n\n6. Do NOT mention any internal system details:\n   \u2192 \"FAQ database\"\n   \u2192 \"similarity scores\"\n   \u2192 \"RAG\" or \"retrieval\"\n   \u2192 \"vector search\"\n   \u2192 \"knowledge base\"\n   \u2192 \"AEQRS system internals\"\n\n7. Do NOT make up or assume any information \n   not present in the retrieved answers\n\n8. Do NOT add unnecessary filler lines like \n   \"Hope this email finds you well\"\n\n---\n\nTONE GUIDELINES:\n\u2192 Professional  : Yes\n\u2192 Warm          : Yes\n\u2192 Overly formal : No\n\u2192 Casual/Slang  : No\n\u2192 Empathetic    : Yes\n\u2192 Concise       : Yes\n\n---\n\nHTML OUTPUT RULES:\nGenerate ONLY these HTML elements \u2014 \nnothing else:\n\n1. GREETING PARAGRAPH\n   \u2192 <p>Dear [First Name],</p>\n\n2. MAIN RESPONSE BODY\n   \u2192 Wrap content in <p> tags\n   \u2192 Use <ul><li> for multiple points\n   \u2192 Use <strong> for important highlights\n   \u2192 Line height handled by template (do not add)\n\n3. CLOSING LINE\n   \u2192 <p>We hope this helps! Feel free to reach \n     out if you have any further questions.</p>\n\nSTRICT OUTPUT RULES:\n\u2192 Output ONLY the HTML elements listed above\n\u2192 No <html>, <head>, <body> tags\n\u2192 No inline styles \u2014 template handles all styling\n\u2192 No markdown, no code blocks, no explanation\n\u2192 No \"Here is the response:\" or any intro text\n\u2192 Start directly with <p>Dear ...\n\u2192 End with the closing </p>"
            },
            {
              "content": "=STUDENT NAME: {{ $('Fields Preparation').item.json.name }}\n\nSTUDENT EMAIL BODY:\n{{ $('Fields Preparation').item.json.email_body }}\n\nRETRIEVED FAQ ANSWERS:\n\nAnswer 1:\nSimilarity Score : {{ $json.result.points[0].score }}\nTopic            : {{ $json.result.points[0].payload.topic }}\nMatched Question : {{ $json.result.points[0].payload.question }}\nAnswer           : {{ $json.result.points[0].payload.answer }}\n\nAnswer 2:\nSimilarity Score : {{ $json.result.points[1].score }}\nTopic            : {{ $json.result.points[1].payload.topic }}\nMatched Question : {{ $json.result.points[1].payload.question }}\nAnswer           : {{ $json.result.points[1].payload.answer }}\n\nAnswer 3:\nSimilarity Score : {{ $json.result.points[2].score }}\nTopic            : {{ $json.result.points[2].payload.topic }}\nMatched Question : {{ $json.result.points[2].payload.question }}\nAnswer           : {{ $json.result.points[2].payload.answer }}"
            }
          ]
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "71575f27-a42c-4d54-b298-3af0aeb7736e",
      "name": "Email Format",
      "type": "n8n-nodes-base.set",
      "position": [
        928,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1ce5a09a-adb5-471a-9911-f80bea3c37c9",
              "name": "=reply_email",
              "type": "string",
              "value": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\" />\n  <meta name=\"viewport\" \n        content=\"width=device-width, \n        initial-scale=1.0\"/>\n  <title>Crestwood University Support</title>\n</head>\n<body style=\"margin:0; padding:0; \n             background-color:#f9f9f9; \n             font-family: Arial, sans-serif;\">\n\n  <table width=\"100%\" cellpadding=\"0\" \n         cellspacing=\"0\" \n         style=\"background-color:#f9f9f9; \n                padding: 30px 0;\">\n    <tr>\n      <td align=\"center\">\n\n        <!-- Email Container -->\n        <table width=\"600\" cellpadding=\"0\" \n               cellspacing=\"0\" \n               style=\"max-width:600px; \n                      width:100%; \n                      background:#ffffff; \n                      border-radius:8px; \n                      overflow:hidden; \n                      box-shadow: 0 2px 8px \n                      rgba(0,0,0,0.08);\">\n\n          <!-- ======= HEADER ======= -->\n          <tr>\n            <td style=\"background-color:#1a3c6e; \n                       padding: 25px 35px;\">\n              <h1 style=\"color:#f0a500; \n                         margin:0; \n                         font-size:22px; \n                         font-weight:bold; \n                         letter-spacing:0.5px;\">\n                Crestwood University\n              </h1>\n              <p style=\"color:#ffffff; \n                        margin: 5px 0 0; \n                        font-size:12px; \n                        letter-spacing:0.3px;\">\n                Student Support \u2014 AEQRS\n              </p>\n            </td>\n          </tr>\n\n          <!-- ======= BODY ======= -->\n          <tr>\n            <td style=\"padding: 35px; \n                       color:#333333; \n                       font-size:15px; \n                       line-height:1.7;\">\n\n              <!-- \n                ===================================\n                INJECT LLM RESPONSE HERE\n                Replace `llm_response` with the\n                actual LLM HTML output in n8n\n                ===================================\n              -->\n              {{ $json.output[0].content[0].text }}\n\n            </td>\n          </tr>\n\n          <!-- ======= DIVIDER ======= -->\n          <tr>\n            <td style=\"padding: 0 35px;\">\n              <hr style=\"border:none; \n                         border-top:1px solid #eeeeee; \n                         margin:0;\" />\n            </td>\n          </tr>\n\n          <!-- ======= CONTACT INFO ======= -->\n          <tr>\n            <td style=\"padding: 25px 35px;\">\n              <p style=\"color:#555555; \n                        font-size:13px; \n                        margin:0 0 10px;\">\n                Need further assistance? \n                We are here to help.\n              </p>\n              <table cellpadding=\"0\" cellspacing=\"0\">\n                <tr>\n                  <td style=\"padding: 3px 0; \n                             font-size:13px; \n                             color:#333333;\">\n                    \ud83d\udce7&nbsp;\n                    <a href=\"mailto:support@crestwooduniversity.edu\"\n                       style=\"color:#1a3c6e; \n                              text-decoration:none;\">\n                      support@crestwooduniversity.edu\n                    </a>\n                  </td>\n                </tr>\n                <tr>\n                  <td style=\"padding: 3px 0; \n                             font-size:13px; \n                             color:#333333;\">\n                    \ud83c\udf10&nbsp;\n                    <a href=\"https://portal.crestwooduniversity.edu\"\n                       style=\"color:#1a3c6e; \n                              text-decoration:none;\">\n                      portal.crestwooduniversity.edu\n                    </a>\n                  </td>\n                </tr>\n                <tr>\n                  <td style=\"padding: 3px 0; \n                             font-size:13px; \n                             color:#333333;\">\n                    \ud83d\udcde&nbsp;+1 (512) 000-0000\n                  </td>\n                </tr>\n              </table>\n            </td>\n          </tr>\n\n          <!-- ======= SIGNATURE ======= -->\n          <tr>\n            <td style=\"padding: 0 35px 30px;\">\n              <p style=\"color:#333333; \n                        font-size:15px; \n                        margin:0;\">\n                Warm regards,<br/>\n                <strong>Crestwood University</strong>\n                <br/>\n                <span style=\"color:#888888; \n                             font-size:13px;\">\n                  Student Support Team\n                </span>\n              </p>\n            </td>\n          </tr>\n\n          <!-- ======= FOOTER ======= -->\n          <tr>\n            <td style=\"background-color:#1a3c6e; \n                       padding: 18px 35px; \n                       text-align:center;\">\n              <p style=\"color:#aaaaaa; \n                        font-size:11px; \n                        margin:0; \n                        line-height:1.6;\">\n                \u00a9 2024 Crestwood University, \n                Austin, Texas. \n                All rights reserved.<br/>\n                This is an automated response \n                generated by AEQRS.\n              </p>\n            </td>\n          </tr>\n\n        </table>\n        <!-- End Container -->\n\n      </td>\n    </tr>\n  </table>\n\n</body>\n</html>"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0fc58067-be90-46b8-92b4-e11b66957da7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        -304
      ],
      "parameters": {
        "width": 640,
        "height": 624,
        "content": "## How it works\n1. **Knowledge Ingestion**: Monitors Google Drive for FAQ file updates, converts them into embeddings, and stores them in Qdrant.\n2. **Email Trigger**: Activates automatically whenever a new email arrives in your connected Gmail inbox.\n3. **Semantic Search**: Converts the incoming email question into an embedding and queries Qdrant to find the most relevant FAQ match.\n4. **AI Reply**: Uses a local LLM via LM Studio to draft a polite, context-aware response and sends it as a threaded reply in Gmail.\n\n## Setup Process\n- [ ] Run n8n and Qdrant using Docker.\n- [ ] Start your LM Studio local server on port `1234` with `mxbai-embed-large-v1` and `llama-3.2-3b-instruct` models.\n- [ ] Configure Google OAuth2 credentials for both Gmail and Google Drive.\n- [ ] Update the URL in the embedding nodes and the OpenAI node to use your LM Studio's local IP (do not use `localhost`).\n- [ ] Select your specific FAQ JSON file in both the **Google Drive Trigger** and **Download File** nodes.\n\n## Customization\n- **AI Persona**: Edit the system prompt in the **Message a Model** node to change the AI's tone and formatting.\n- **Search Strictness**: Adjust the minimum similarity threshold in the Qdrant search node to ensure high-quality matching.\n- **Triggers**: Swap Gmail for another email provider or customer support tool if needed."
      },
      "typeVersion": 1
    },
    {
      "id": "c4c50b1d-c723-417f-9d53-c44d2ffc63f5",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        -256
      ],
      "parameters": {
        "color": 7,
        "width": 1152,
        "height": 352,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Knowledge Base Ingestion\nMonitors Google Drive for updates, downloads the FAQ file, and transforms the text into vector embeddings."
      },
      "typeVersion": 1
    },
    {
      "id": "e3b71e76-3596-4c7e-87bb-fd56aa03793a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -368,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 240,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou must explicitly select your FAQ JSON file ID for the workflow to pull the correct data."
      },
      "typeVersion": 1
    },
    {
      "id": "fb641e30-0415-481e-a849-82c7b73fdd81",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -656
      ],
      "parameters": {
        "color": 7,
        "width": 1088,
        "height": 368,
        "content": "## Vector Database Management\nChecks for existing Qdrant collections, recreates them to prevent duplicates, and upserts the new FAQ "
      },
      "typeVersion": 1
    },
    {
      "id": "39090ff9-0e2e-4108-8914-e39d8f5b0768",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        544,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 368,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## AI Reply Generation\nPrompts the local LLM to draft a professional HTML response and sends it back to the original email thread."
      },
      "typeVersion": 1
    },
    {
      "id": "729f29e0-296f-4652-b893-51ca930cf243",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        576,
        144
      ],
      "parameters": {
        "color": 3,
        "width": 288,
        "height": 224,
        "content": "Ensure LM Studio is actively running the LLaMA model server; otherwise, the response generation will fail."
      },
      "typeVersion": 1
    },
    {
      "id": "c236fa31-8d68-4345-8b5a-1ad70a7007e0",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        128
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 240,
        "content": "The embedding URL must point to your host machine's actual local IP address so Docker can reach it."
      },
      "typeVersion": 1
    },
    {
      "id": "28955379-182f-4053-a82d-531fd6bd9bde",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 912,
        "height": 544,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n## Incoming Email Processing\nCatches incoming emails, generates an embedding for the user's question, and searches Qdrant for the best answer."
      },
      "typeVersion": 1
    },
    {
      "id": "82e18e87-e13b-4a52-8752-16fd58362614",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 224,
        "height": 272,
        "content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe embedding URL must point to your host machine's actual local IP address so Docker can reach it."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Delete Collection",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Collection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Similarity Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data Fetch": {
      "main": [
        [
          {
            "node": "Data Preprocessing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Format": {
      "main": [
        [
          {
            "node": "Send Repy Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Fields Preparation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Points": {
      "main": [
        []
      ]
    },
    "Message a model": {
      "main": [
        [
          {
            "node": "Email Format",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Embedding": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Collection": {
      "main": [
        [
          {
            "node": "Create Collection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Data Fetch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Similarity Search": {
      "main": [
        [
          {
            "node": "Message a model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data Preprocessing": {
      "main": [
        [
          {
            "node": "Embedding Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fields Preparation": {
      "main": [
        [
          {
            "node": "Query Embedding",
            "type": "main",
            "index": 0
          },
          {
            "node": "Collection Name Fetch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embedding Generation": {
      "main": [
        [
          {
            "node": "Upsert Points",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Trigger": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Collection Name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collection Name Fetch": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Fetch Collection Name": {
      "main": [
        [
          {
            "node": "Check If Collection Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Collection Exists": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Self-Hosted

Source: https://n8n.io/workflows/14268/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16
AI & RAG

OIL Rag. Uses lmChatOpenAi, embeddingsOpenAi, agent, telegramTrigger. Event-driven trigger; 53 nodes.

OpenAI Chat, OpenAI Embeddings, Agent +12
AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This intelligent chatbot leverages cutting-edge financial APIs and AI-driven analysis to deliver comprehensive stock research reports. Get instant access to professional-grade investment analysis that

Tool Think, Supabase Vector Store, OpenAI Embeddings +15
AI & RAG

This advanced n8n workflow automates the full lead enrichment, qualification, and personalized outreach process tailored specifically for the B2B real estate sector. Integrating top platforms like Api

N8N Nodes Fillout, OpenAI Chat, Pinecone Vector Store +11