{
  "id": "BH7SecrHv8u3DSYK",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Upload Google Drive files to an InfraNodus Graph",
  "tags": [],
  "nodes": [
    {
      "id": "5e1af4f1-c707-49fa-92f0-8c87ac899eea",
      "name": "When clicking \u2018Test workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -480,
        -100
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ecec9d6b-e2db-4715-8edf-a986ae35dcc9",
      "name": "Search Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -220,
        -100
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "list",
            "value": "1ep1yoEl7vxMdrTmvdlDnOXRlXwdxZTzX",
            "cachedResultUrl": "https://drive.google.com/drive/folders/1ep1yoEl7vxMdrTmvdlDnOXRlXwdxZTzX",
            "cachedResultName": "GraphRAG"
          }
        },
        "options": {},
        "resource": "fileFolder",
        "returnAll": true,
        "queryString": "*"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "d5c62cbf-6520-46b8-95e2-defffbc5a653",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        40,
        -100
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "4182cf2b-5380-45b1-9c36-263af4835c0e",
      "name": "Retrieve File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        260,
        -180
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "6d59a256-7824-4bc6-b3d3-ee79d5bac3e9",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        680,
        -20
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "pdf",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7b4e792b-ab6d-4b9b-88a1-d8e51bea6853",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": "application/pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "text",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "09b7d7c5-5353-4719-b4e2-072e4da39948",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": "text/plain"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "md",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "cb2e6726-97d8-4541-8383-deafff9b18e6",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": "text/markdown"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "json",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d2763a45-a592-47c8-868f-59dfcd17a71c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": "application/json"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "docs",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "0d9b561f-89c5-479e-a4e2-1f5f05fa8417",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "csv",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6b19deed-5d00-4796-bb9d-b4d87564a751",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{$binary[\"data\"].mimeType}}",
                    "rightValue": "csv"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "de37bfa9-552d-4adb-943f-bebd6cafed4d",
      "name": "Extract from PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        920,
        -260
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "3f321a4c-f608-48a6-a730-5550307e5e0e",
      "name": "Extract from Text File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        920,
        -60
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "11a07c7e-2134-4935-b881-3b63aa72c019",
      "name": "Extract from Markdown",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        920,
        140
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "cc9f9e17-3385-4199-943d-e984f2dac9f9",
      "name": "InfraNodus Save to Graph",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1580,
        240
      ],
      "parameters": {
        "url": "https://infranodus.com/api/v1/graphAndStatements?doNotSave=false&optimize=develop&includeGraph=false&includeGraphSummary=true&includeGraph=false",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "graphrag_from_google_drive"
            },
            {
              "name": "text",
              "value": "={{ $json.data }}"
            },
            {
              "name": "=categories",
              "value": "=[filename: {{ $('Switch').item.json.name }}]"
            },
            {
              "name": "contextSettings",
              "value": "={{{ \"squareBracketsProcessing\":\"IGNORE_BRACKETS\"} }}"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "0807fb37-d747-4cba-b743-92febf88a23d",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        -360
      ],
      "parameters": {
        "width": 500,
        "height": 520,
        "content": "## 1. Retrieve the files from a Google Drive folder\n\n### You need to create the folder first and upload the files there. \n\n\ud83d\udea8 Specify the folder you want to use here"
      },
      "typeVersion": 1
    },
    {
      "id": "9a28e9c8-d425-44ca-9754-61e12d921ba6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -360
      ],
      "parameters": {
        "width": 500,
        "height": 520,
        "content": "## 2. Iterate through every file extracted\n\n### We get the ID of the file and iterate through them one by one\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4c9105f8-8e3e-4b92-9543-d16902d19587",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        580,
        -520
      ],
      "parameters": {
        "width": 500,
        "height": 840,
        "content": "## 3. Extract text from the files\n\n### Use the built-in n8n extractor tools to convert different file formats: PDF, txt, or markdown to plain text.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4e79cffa-4251-44d3-a950-aae699d5f738",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1200,
        -380
      ],
      "parameters": {
        "width": 500,
        "height": 840,
        "content": "## 4. Save the file to InfraNodus\n\n### Save the text content of the file to the graph, using its name as category (so you can manually delete it after) and additional processing settings (in the `body` field of the POST request.\n\nNote: you can use an existing graph name (the `name` field) or specify a new name and the graph will be created.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "19494d9a-848e-4a8d-a3a6-0dcd5d9ab12b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -540,
        -1400
      ],
      "parameters": {
        "color": 6,
        "width": 1060,
        "height": 980,
        "content": "# Upload Google Drive files to an InfraNodus graph\n\n## This workflow uploads the files in your Google drive to your [InfraNodus graph](https://infranodus.com). \n\n### InfraNodus visualizes your text as a knowledge graph, showing the main topics and ideas inside. It also provides API access to your knownledge graphs, so you can use them as \"experts\" for your AI agent n8n workflows.\n\nYou need an [InfraNodus](https://infranodus.com) account to use this workflow.\n\nDetailed tutorial on this workflow: [https://support.noduslabs.com/hc/en-us/articles/20267019838108-Upload-Sync-Your-Google-Drive-Folder-with-InfraNodus-using-n8n](https://support.noduslabs.com/hc/en-us/articles/20267019838108-Upload-Sync-Your-Google-Drive-Folder-with-InfraNodus-using-n8n)\n\n\ud83d\udea8 launch it only once to avoid having duplicate content added\n\n\n![InfraNodus Graph](https://infranodus.com/images/front/infranodus-overview.jpg)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4851a559-bcc3-487f-bfdf-ea7c8c40b11f",
      "name": "Map PDF to Text",
      "type": "n8n-nodes-base.set",
      "position": [
        1240,
        -100
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "fd160009-0b92-46fc-9e34-a1283b810e91",
              "name": "data",
              "type": "string",
              "value": "={{ $json.text }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "62ca951d-1142-4152-ac74-531865c56735",
      "name": "Convert File to PDF",
      "type": "n8n-nodes-base.httpRequest",
      "disabled": true,
      "position": [
        1940,
        60
      ],
      "parameters": {
        "url": "https://v2.convertapi.com/convert/pdf/to/txt",
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/octet-stream"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "notesInFlow": true,
      "typeVersion": 4.2
    },
    {
      "id": "1c459501-ddb5-44a8-a531-0eac9e3c9a29",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1780,
        -380
      ],
      "parameters": {
        "color": 2,
        "width": 500,
        "height": 840,
        "content": "## Optional: Better PDF Conversion\n\n### Standard Map PDF to Text node will split your PDF files into very short chunks, which deteriorates retrieval. \n\nUse can use [ConvertAPI](https://convertapi.com?ref=4l54n) which is a high-quality convertor that will respect the layout of the original document and not cut the paragraphs into short chunks. \n\nHere is an HTTP node that makes a request to their API to convert the PDF into text. If you have a ConvertAPI account, you can replace the \"Map PDF to Text\" node in step 4 with this node. \n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "129ccfd2-b798-4238-8ddc-e364288edc8c",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Extract from PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from Text File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from Markdown",
            "type": "main",
            "index": 0
          }
        ],
        [],
        []
      ]
    },
    "Retrieve File": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Retrieve File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map PDF to Text": {
      "main": [
        [
          {
            "node": "InfraNodus Save to Graph",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from PDF": {
      "main": [
        [
          {
            "node": "Map PDF to Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Google Drive": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Markdown": {
      "main": [
        [
          {
            "node": "InfraNodus Save to Graph",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Text File": {
      "main": [
        [
          {
            "node": "InfraNodus Save to Graph",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "InfraNodus Save to Graph": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Search Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}