{
  "id": "70nCcZ6MOikosz1s",
  "name": "My workflow",
  "tags": [],
  "nodes": [
    {
      "id": "9dea6e2b-c029-480c-96a6-d274b8fcb835",
      "name": "Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        1168,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "abbf5e04-4ba0-4178-8bbd-acba3ce456a8",
              "name": "sourceIndex",
              "type": "string",
              "value": "https://<your_pinecone_source_index>"
            },
            {
              "id": "3fc450b0-1d66-4c03-80c4-b20751d5fede",
              "name": "sourceNamespace",
              "type": "string",
              "value": "<your_pinecone_namespace>"
            },
            {
              "id": "493093cb-ab83-4a8d-88ad-3c6064b5a877",
              "name": "batchLimit",
              "type": "string",
              "value": "100"
            },
            {
              "id": "8d916161-130f-47d1-bffe-c6c62c13affd",
              "name": "targetCollection",
              "type": "string",
              "value": "<your_weaviate_target_collection>"
            },
            {
              "id": "3fd34e4b-fe97-4c3d-835f-a6f40d02c104",
              "name": "weaviateCluster",
              "type": "string",
              "value": "https://<your_weaviate_cluster_REST>"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "d2bf3d80-dc9a-4f10-9046-ad053472a551",
      "name": "Get Next Page Token",
      "type": "n8n-nodes-base.airtable",
      "position": [
        1392,
        176
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "app4dxOyxKbkYOFfL",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL",
          "cachedResultName": "Cycle"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tblIBrPDIVMwtUMJr",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL/tblIBrPDIVMwtUMJr",
          "cachedResultName": "NextPage"
        },
        "options": {},
        "operation": "search",
        "returnAll": false,
        "filterByFormula": "{Number} = 0 "
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "1da994c9-ff3d-40dd-89c4-cb1cb0cd2b6a",
      "name": "Migration completed",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1936,
        576
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "68919d6c-8cc7-4475-8be0-6260edf5199b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "width": 784,
        "height": 464,
        "content": "## Tool for Transferring an Index from Pinecone to Weaviate\n\nThis tool allows you to migrate vector data from a Pinecone index into a Weaviate class.\n\n**Parameters**\n\nThe following parameters must be provided:\n\n- Source index URL \u2013 the endpoint of the Pinecone index.\n- Source namespace \u2013 the namespace within the Pinecone index.\n- Read limit \u2013 maximum number of vectors retrieved per request (Pinecone supports up to 100).\n- Target collection name \u2013 the name of the Weaviate class where the vectors will be stored.\n- Weaviate Cluster name - the Weaviate Cluster REST Endpoint\n\n**Process**\n\n- Vector retrieval from Pinecone is paginated.\n- Next page token is stored and updated in an Airtable table with 2 columns (Name, Number)\n- The Airtable table must be initialized with the record (INIT,0).\n- When the page token is null, no further IDs are retrieved, and the process stops.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "18bb5baa-0054-40bd-97ba-578516c0b602",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        976,
        176
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "seconds",
              "secondsInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b0be1637-f09a-4798-a83a-d2c37f0b8a04",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1888,
        64
      ],
      "parameters": {
        "width": 2176,
        "height": 432,
        "content": "## Iterations\n"
      },
      "typeVersion": 1
    },
    {
      "id": "bb45d339-53dd-4abb-8e2b-9340d8d3220c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1888,
        528
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 256,
        "content": "## Migration Completed\n"
      },
      "typeVersion": 1
    },
    {
      "id": "499564f0-4434-481a-9339-72e88b30eb7c",
      "name": "Save Next Page Token",
      "type": "n8n-nodes-base.airtable",
      "position": [
        2688,
        144
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "app4dxOyxKbkYOFfL",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL",
          "cachedResultName": "Cycle"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tblIBrPDIVMwtUMJr",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL/tblIBrPDIVMwtUMJr",
          "cachedResultName": "NextPage"
        },
        "columns": {
          "value": {
            "Name": "={{ $json.pagination.next ?? ''}} ",
            "Number": "=0"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "upsert"
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "bcbd68d4-9c07-491d-ad8e-a67ae2381488",
      "name": "Prepare Fetch Body",
      "type": "n8n-nodes-base.code",
      "position": [
        3136,
        144
      ],
      "parameters": {
        "jsCode": "// Gestisci sia array che singoli oggetti\nlet input = $input.first().json;\n\n// Debug iniziale\nconsole.log(\"Input raw:\", JSON.stringify(input, null, 2));\n\n// Se l'input \u00e8 un array, prendi il primo elemento\nif (Array.isArray(input)) {\n  console.log(\"Input \u00e8 un array, prendo il primo elemento\");\n  input = input[0];\n}\n\n// Verifica che vectors esista ed \u00e8 un array\nif (!input.vectors || !Array.isArray(input.vectors)) {\n  console.error(\"Struttura input:\", {\n    hasVectors: input.hasOwnProperty('vectors'),\n    vectorsType: typeof input.vectors,\n    keys: Object.keys(input)\n  });\n  throw new Error(`Il campo 'vectors' \u00e8 mancante o non \u00e8 un array. Input ricevuto: ${JSON.stringify(input, null, 2)}`);\n}\n\n// Verifica che ci siano vettori\nif (input.vectors.length === 0) {\n  throw new Error(\"L'array 'vectors' \u00e8 vuoto.\");\n}\n\n// Estrai gli ID\nconst ids = input.vectors.map(vector => vector.id);\n\n// Restituisci l'oggetto per il fetch\nreturn [{\n  ids: ids,\n  namespace: input.namespace || \"jira\",\n}];\n\n\n\n\n\n\n"
      },
      "typeVersion": 2
    },
    {
      "id": "3223964e-0677-4b19-8062-73656690f678",
      "name": "Fetch Vectors",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3360,
        144
      ],
      "parameters": {
        "url": "={{ $('Parameters').item.json.sourceIndex }}/vectors/fetch",
        "options": {
          "response": {
            "response": {}
          }
        },
        "jsonBody": "={\n  \"ids\": {{ JSON.stringify($json.ids) }},\n  \"namespace\": \"{{ $json.namespace }}\",\n  \"include_values\": true,\n  \"include_metadata\": true\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "pineconeApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "771a089c-f40e-48d1-8cd4-b5b1fa86f673",
      "name": "Format2Weaviate",
      "type": "n8n-nodes-base.code",
      "position": [
        3568,
        144
      ],
      "parameters": {
        "jsCode": "const vectors = items[0].json.vectors;\nconst targetClass = $('Parameters').first().json.targetCollection\n\nreturn Object.entries(vectors).map(([key, vectorObj]) => {\n  const { id, values, metadata } = vectorObj;\n\n  return {\n    json: {\n      class: targetClass,\n      id: id,\n      vector: values,\n      properties: {\n        issue_customer: metadata.issue_customer,\n        issue_id: metadata.issue_id,\n        issue_key: metadata.issue_key,\n        summary: metadata.summary,\n        text: metadata.text,\n        triage: metadata.triage\n      }\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "b2e15a06-9fef-4b9f-a6fe-e91bb7cfbef7",
      "name": "LoadWeAviate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3776,
        144
      ],
      "parameters": {
        "url": "=https://{{ $('Parameters').item.json.weaviateCluster }}/v1/objects",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ $json}}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "80926411-9cc2-4c66-9545-e2da375718f1",
      "name": "First Iteration?",
      "type": "n8n-nodes-base.if",
      "position": [
        1952,
        160
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "bc83b99c-17d5-4530-8e2a-6400681aa388",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.Name.trim() }}",
              "rightValue": "INIT"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b0df747c-4e63-4234-a93a-45423a1c126e",
      "name": "Get Record First Page",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2336,
        144
      ],
      "parameters": {
        "url": "={{ $('Parameters').item.json.sourceIndex }}/vectors/list",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "namespace",
              "value": "={{ $('Parameters').last().json.sourceNamespace }}"
            },
            {
              "name": "limit",
              "value": "={{ $('Parameters').item.json.batchLimit }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "pineconeApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "8161d3c2-8154-471b-a966-0d8a1b037d5e",
      "name": "Get Record Next Page",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2336,
        320
      ],
      "parameters": {
        "url": "={{ $('Parameters').item.json.sourceIndex }}/vectors/list",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "namespace",
              "value": "={{ $('Parameters').last().json.sourceNamespace }}"
            },
            {
              "name": "limit",
              "value": "={{ $('Parameters').item.json.batchLimit }}"
            },
            {
              "name": "pagination_token",
              "value": "={{ $json.Name.trim() }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "pineconeApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "d97df28a-cb8b-40f5-b942-43357d0ab127",
      "name": "Select Ids",
      "type": "n8n-nodes-base.set",
      "position": [
        2928,
        144
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "dbafca81-5ccb-441c-ab6f-3dbf193c8bb6",
              "name": "vectors",
              "type": "array",
              "value": "={{ $('Get Record First Page').item.json.vectors }}"
            },
            {
              "id": "4b2a121c-3afe-42c9-950b-70bef453644d",
              "name": "namespace",
              "type": "string",
              "value": "={{ $('Get Record First Page').item.json.namespace }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "22b96d41-2557-4b8c-a2eb-08696cd786d4",
      "name": "Select Ids1",
      "type": "n8n-nodes-base.set",
      "position": [
        2928,
        320
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "dbafca81-5ccb-441c-ab6f-3dbf193c8bb6",
              "name": "vectors",
              "type": "array",
              "value": "={{ $('Get Record Next Page').item.json.vectors }}"
            },
            {
              "id": "4b2a121c-3afe-42c9-950b-70bef453644d",
              "name": "namespace",
              "type": "string",
              "value": "={{ $('Get Record Next Page').item.json.namespace }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "88b3ec21-dd1d-4743-a3bb-fc9fa66a6562",
      "name": "Save Next Page Token1",
      "type": "n8n-nodes-base.airtable",
      "position": [
        2688,
        320
      ],
      "parameters": {
        "base": {
          "__rl": true,
          "mode": "list",
          "value": "app4dxOyxKbkYOFfL",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL",
          "cachedResultName": "Cycle"
        },
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tblIBrPDIVMwtUMJr",
          "cachedResultUrl": "https://airtable.com/app4dxOyxKbkYOFfL/tblIBrPDIVMwtUMJr",
          "cachedResultName": "NextPage"
        },
        "columns": {
          "value": {
            "Name": "={{ $json.pagination.next ?? ''}} ",
            "Number": "=0"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true
            },
            {
              "id": "Name",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "Number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "upsert"
      },
      "executeOnce": true,
      "typeVersion": 2.1
    },
    {
      "id": "f95c699a-89fb-4a28-b35f-ed9c4485fed2",
      "name": "Is Next Pagination Token null?",
      "type": "n8n-nodes-base.if",
      "position": [
        1600,
        176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "6a5dea40-2fdc-4b8e-8771-aded6ff36d59",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $json.Name.trim().length }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3f97a527-5f68-42f1-abe7-7211ee7f32b8",
  "connections": {
    "Parameters": {
      "main": [
        [
          {
            "node": "Get Next Page Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Ids": {
      "main": [
        [
          {
            "node": "Prepare Fetch Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select Ids1": {
      "main": [
        [
          {
            "node": "Prepare Fetch Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Vectors": {
      "main": [
        [
          {
            "node": "Format2Weaviate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format2Weaviate": {
      "main": [
        [
          {
            "node": "LoadWeAviate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First Iteration?": {
      "main": [
        [
          {
            "node": "Get Record First Page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Record Next Page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Fetch Body": {
      "main": [
        [
          {
            "node": "Fetch Vectors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Next Page Token": {
      "main": [
        [
          {
            "node": "Is Next Pagination Token null?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Record Next Page": {
      "main": [
        [
          {
            "node": "Save Next Page Token1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Next Page Token": {
      "main": [
        [
          {
            "node": "Select Ids",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Record First Page": {
      "main": [
        [
          {
            "node": "Save Next Page Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Next Page Token1": {
      "main": [
        [
          {
            "node": "Select Ids1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Next Pagination Token null?": {
      "main": [
        [
          {
            "node": "First Iteration?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Migration completed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}