{
  "name": "Product Recommendation with Shopify",
  "nodes": [
    {
      "parameters": {},
      "id": "335e13b0-8633-48c9-90b4-96400b180999",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        1420,
        400
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "b97db0c9-ee0a-4cd8-8f79-9bab45ba0e06",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1420,
        1240
      ],
      "webhookId": "71bfe0f8-227e-466b-9d07-69fd9fe4a27b",
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "860f001a-ce1c-4620-b365-f121995e1f53",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1580,
        1460
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "sXG31Tn7DxVbKluH",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {},
      "id": "b27a6b99-af5e-4a46-ac75-9fdb08d05673",
      "name": "Window Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1720,
        1460
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "content": "## Query to get product recommendations by chat (for testing)\n",
        "height": 538,
        "width": 795
      },
      "id": "006e2426-a73a-4d67-bf2a-cb6e7e2c122e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1320,
        1100
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "125a40d6-6d7a-4ef3-b7ba-20384c78b80b",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2220,
        620
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "sXG31Tn7DxVbKluH",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "dataType": "binary",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "file_url",
                "value": "={{ $json.file_url }}"
              },
              {
                "name": "file_name",
                "value": "={{ $('Add in metadata').item.json.file_name }}"
              }
            ]
          }
        }
      },
      "id": "47f41663-edce-40c9-94ed-3b470f23a00e",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        2460,
        600
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "chunkSize": 3000,
        "chunkOverlap": 200,
        "options": {}
      },
      "id": "8a029070-9398-4d6d-b40c-a59cc4cee682",
      "name": "Recursive Character Text Splitter1",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        2500,
        760
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Get data and store vectors\nSplit data into chunks and insert into a vector database\n\n**Note that running this part multiple times will insert multiple copies into your DB**",
        "height": 760,
        "width": 1421
      },
      "id": "605cd406-2cc1-43f4-a030-b3067442df4c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1340,
        200
      ]
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "8467d75e-f1b5-43db-8b21-2ebc485cce55",
      "name": "Embeddings OpenAI2",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2640,
        1440
      ],
      "typeVersion": 1,
      "credentials": {
        "openAiApi": {
          "id": "sXG31Tn7DxVbKluH",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d77956c4-0ff4-4c64-80c2-9da9d4c8ad34",
              "name": "text",
              "type": "string",
              "value": "={{ $json.answer }} {{ $if(!$json.citations.isEmpty(), \"\\n\" + $json.citations.join(\"\"), '') }}"
            }
          ]
        },
        "options": {}
      },
      "id": "1fbc27f1-2ee8-4fe9-af28-79309cdbb4c0",
      "name": "Generate response",
      "type": "n8n-nodes-base.set",
      "position": [
        3060,
        1240
      ],
      "typeVersion": 3.3
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "69d83f70-e7a9-4aba-a90b-6cfb2f9e135a",
              "name": "id",
              "value": "={{ $json.id }}",
              "type": "number"
            },
            {
              "id": "df1076a7-0639-4465-8d1e-69f51ba86343",
              "name": "title",
              "value": "={{ $json.title }}",
              "type": "string"
            },
            {
              "id": "c31d3a58-681f-41b4-8c4d-b6f730c72e8f",
              "name": "vendor",
              "value": "={{ $json.vendor }}",
              "type": "string"
            },
            {
              "id": "15551395-bf49-40ac-9d62-7e2e05376aa4",
              "name": "product_type",
              "value": "={{ $json.product_type }}",
              "type": "string"
            },
            {
              "id": "be13ac17-a964-4dac-b89e-bf7a3450533b",
              "name": "image",
              "value": "={{ $json.image }}",
              "type": "object"
            },
            {
              "id": "ce1fb7d6-1d5c-46b8-816f-6e9a7cb895f5",
              "name": "variants",
              "value": "={{ $json.variants }}",
              "type": "array"
            },
            {
              "id": "9e497536-a1bb-4e11-abbc-c71b7ca6336d",
              "name": "user_email",
              "value": "[IT GOES HERE]",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "8934c3bb-780e-4256-b355-849e4c4dcc93",
      "name": "Define structure with user_email",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2000,
        400
      ]
    },
    {
      "parameters": {
        "mode": "insert",
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "test-index",
          "cachedResultName": "test-index"
        },
        "options": {}
      },
      "id": "1e123e94-417c-4568-8e26-038047c09072",
      "name": "Store preferences to user_email",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        2320,
        380
      ],
      "typeVersion": 1,
      "credentials": {
        "pineconeApi": {
          "id": "MTSEamCpRUuY5Xt6",
          "name": "PineconeApi account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "id": "93454308-d45e-4fc1-a425-5415c74fa460",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        3320,
        1240
      ]
    },
    {
      "parameters": {
        "content": "## Generate Product Recommendation\n",
        "height": 535.6336106358975,
        "width": 1413.70081834604
      },
      "id": "9200f3df-d3c1-4348-80da-f817a728e814",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2200,
        1100
      ]
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are a Product Recommender Tool using a Vector Database under the hood. Provide top-10 product recommendations returned by the database, based on user email\n"
        }
      },
      "id": "54b86892-6cdf-4392-aa12-48c0116a69af",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1640,
        1240
      ],
      "typeVersion": 1.6
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "__CUSTOM_API_CALL__"
      },
      "id": "dc0406d5-e29e-4957-98ce-87065ca32c4d",
      "name": "Shopify",
      "type": "n8n-nodes-base.shopify",
      "typeVersion": 1,
      "position": [
        1720,
        400
      ],
      "credentials": {
        "shopifyOAuth2Api": {
          "id": "yBBzGtru8cUeFXX7",
          "name": "Reica / Dev Store"
        }
      }
    },
    {
      "parameters": {
        "url": "http://localhost:5678/webhook-test/f64faa14-0ebd-4547-a828-6a89ab98e3e5"
      },
      "id": "83c462ae-29a5-48a8-b1fb-420b403a534a",
      "name": "Send request to webhook",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        1840,
        1460
      ]
    },
    {
      "parameters": {
        "path": "f64faa14-0ebd-4547-a828-6a89ab98e3e5",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "941f6577-8adf-4e5b-9a7f-4b81a4b7bfcd",
      "name": "Waiting for user email",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        2360,
        1240
      ],
      "webhookId": "f64faa14-0ebd-4547-a828-6a89ab98e3e5"
    },
    {
      "parameters": {
        "mode": "load",
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "test-index",
          "cachedResultName": "test-index"
        },
        "prompt": "=\"Analyze the order history of user {user_id}. Use the following details:\n- Previously purchased products: {product_history}\n- Purchase frequency: {purchase_frequency}\n- Preferred categories: {preferred_categories}\n\nGenerate a list of personalized product recommendations, ranked by relevance and likelihood of future purchase. Also provide a relevance score for each recommendation. The results should be optimized for a marketing email, using persuasive and clear language, including a maximum of 5 products.\"\n\nExpected JSON output example:\n[\n    {\n        \"product_name\": \"Product Name\",\n        \"relevance_score\": 0.95,\n        \"category\": \"Category\",\n        \"purchase_probability\": \"High\"\n    }\n]\n",
        "options": {}
      },
      "id": "df95a279-855c-4ecc-b4de-dc0a9f015b12",
      "name": "Get top order history",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        2640,
        1240
      ],
      "typeVersion": 1,
      "credentials": {
        "pineconeApi": {
          "id": "MTSEamCpRUuY5Xt6",
          "name": "PineconeApi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Shopify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Store preferences to user_email",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Store preferences to user_email",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter1": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI2": {
      "ai_embedding": [
        [
          {
            "node": "Get top order history",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Define structure with user_email": {
      "main": [
        [
          {
            "node": "Store preferences to user_email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shopify": {
      "main": [
        [
          {
            "node": "Define structure with user_email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send request to webhook": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Waiting for user email": {
      "main": [
        [
          {
            "node": "Get top order history",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get top order history": {
      "main": [
        [
          {
            "node": "Generate response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "16b0c9d7-dc45-479e-bee4-14f2ead533ac",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "ba1ee3cb283f555c8259933930d7eed40bbd9b6f053facc8f3835cd568408124"
  },
  "id": "ilTj2Vmx96qbtAbh",
  "tags": [
    {
      "createdAt": "2024-12-02T15:08:18.373Z",
      "updatedAt": "2024-12-02T15:08:18.373Z",
      "id": "0FSW1zVaMXhFvXIu",
      "name": "small-product"
    }
  ]
}