{
  "name": "Gmail to Qdrant Pipeline",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "labelIds": [
            "INBOX"
          ],
          "query": "is:unread"
        },
        "options": {
          "allowUnauthorizedCerts": false,
          "attachments": "include"
        }
      },
      "id": "gmail-trigger",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1,
      "position": [
        240,
        300
      ],
      "webhookId": "gmail-to-qdrant-trigger",
      "credentials": {
        "gmailOAuth2": {
          "id": "gmail-oauth2-credential",
          "name": "Gmail OAuth2"
        }
      }
    },
    {
      "parameters": {
        "content": "## Gmail to Qdrant Pipeline\n\nTen workflow automatycznie:\n1. Pobiera nowe emaile z Gmail\n2. Tworzy embedding za pomocą OpenAI\n3. Zapisuje do Qdrant\n4. Oznacza email jako przeczytany\n\nSkonfiguruj credentials dla Gmail i OpenAI!",
        "height": 160,
        "width": 280
      },
      "id": "instructions",
      "name": "Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        200
      ]
    },
    {
      "parameters": {
        "model": "text-embedding-3-small",
        "dimensions": 1536
      },
      "id": "embedding-model",
      "name": "Embedding Model",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1,
      "position": [
        440,
        200
      ],
      "credentials": {
        "openAiApi": {
          "id": "openai-api-credential",
          "name": "OpenAI API"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $vars.QDRANT_URL }}/collections/knowledge_base/points",
        "authentication": "none",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "api-key",
              "value": "={{ $vars.QDRANT_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "points",
              "value": "=[\n  {\n    \"id\": \"{{ $json.id }}\",\n    \"vector\": {{ $('Embedding Model').item.json.embedding }},\n    \"payload\": {\n      \"title\": \"{{ $json.subject }}\",\n      \"content\": \"{{ $json.textPlain || $json.textHtml }}\",\n      \"from\": \"{{ $json.from }}\",\n      \"date\": \"{{ $json.date }}\",\n      \"source\": \"gmail\",\n      \"created_at\": \"{{ $now }}\"\n    }\n  }\n]"
            }
          ]
        },
        "options": {}
      },
      "id": "qdrant-insert",
      "name": "Qdrant Insert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        640,
        300
      ]
    },
    {
      "parameters": {
        "operation": "modify",
        "messageId": "={{ $json.id }}",
        "addLabelIds": [
          "READ"
        ],
        "removeLabelIds": [
          "UNREAD"
        ],
        "options": {}
      },
      "id": "mark-read",
      "name": "Mark as Read",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2,
      "position": [
        840,
        300
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "gmail-oauth2-credential",
          "name": "Gmail OAuth2"
        }
      }
    },
    {
      "parameters": {
        "content": "=## 📧 Email Processed\n\n**Email ID:** {{ $json.id }}\n**Subject:** {{ $json.subject }}\n**From:** {{ $json.from }}\n**Date:** {{ $json.date }}\n\n**Status:** ✅ Added to Qdrant\n**Embedding:** {{ $('Embedding Model').item.json.embedding?.length || 0 }} dimensions\n**Marked as:** READ",
        "height": 200,
        "width": 300
      },
      "id": "success-log",
      "name": "Success Log",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1040,
        200
      ]
    },
    {
      "parameters": {
        "content": "## ⚙️ Konfiguracja\n\n1. **Gmail OAuth2** - Dodaj credential\n2. **OpenAI API** - Dodaj credential\n3. **Zmienne środowiskowe:**\n   - QDRANT_URL\n   - QDRANT_API_KEY\n\n4. **Utwórz kolekcję w Qdrant:**\n   - Nazwa: knowledge_base\n   - Wymiary: 1536",
        "height": 200,
        "width": 250
      },
      "id": "config-help",
      "name": "Config Help",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        40,
        500
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Embedding Model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embedding Model": {
      "main": [
        [
          {
            "node": "Qdrant Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Qdrant Insert": {
      "main": [
        [
          {
            "node": "Mark as Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark as Read": {
      "main": [
        [
          {
            "node": "Success Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "gmail-to-qdrant-v1",
  "meta": {
    "templateId": "gmail-to-qdrant-pipeline",
    "templateCredsSetupCompleted": false,
    "instanceId": "gmail-to-qdrant-instance"
  },
  "id": "GmailToQdrantPipeline",
  "tags": ["gmail", "qdrant", "embedding", "pipeline", "automation"]
}

