{
  "nodes": [
    {
      "id": "b7fa47a6-76cb-4aab-93d0-83a68004453e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1104,
        -240
      ],
      "parameters": {
        "width": 496,
        "height": 800,
        "content": "# Create a Lookio RAG Assistant from a CSV Text Corpus\n\nThis advanced workflow ingests a corpus of text from a CSV file, uploads each row as a separate resource to [Lookio](https://www.lookio.app), and provisions a new Assistant scoped specifically to that data.\n\n**How it works:**\n\n1. **Upload a CSV** (Form) collects the file and Assistant settings (Name, Context, Guidelines).\n2. **Convert to txt** transforms the text content of each row into a binary file.\n3. **Loop & Upload** sends each file to Lookio via the `add-resource` API.\n4. **Create Lookio assistant** uses the aggregated Resource IDs to create a bot that only accesses this specific corpus.\n\n**Setup Requirements:**\n\n1. **Credentials:** You must replace `<YOUR-API-KEY>` and `<YOUR-WORKSPACE-ID>` in **two** nodes:\n* `Create Lookio assistant` (HTTP Request)\n* `Import resource to Lookio` (HTTP Request)\n\n\n2. **CSV Structure:** Your CSV needs at least two columns: one for the **Title** (resource name) and one for the **Content** (text body).\n3. **Form Map:** When running the form, simply map your CSV headers to the requested fields.\n\n\n*A workflow by Guillaume Duvernay*"
      },
      "typeVersion": 1
    },
    {
      "id": "6ab43461-7e57-4e22-8aa2-0810e1683bf4",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## Action required\n\nMake sure to set your Lookio API key and workspace ID in here."
      },
      "typeVersion": 1
    },
    {
      "id": "3c75f7cd-2208-4ca8-a815-f30797885c81",
      "name": "Convert to txt",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        176,
        416
      ],
      "parameters": {
        "options": {
          "fileName": "={{ $json[\n  $('Upload a CSV').item.json[\"Name of the column that contains the resource title\"]\n] }}"
        },
        "operation": "toText",
        "sourceProperty": "={{ $('Upload a CSV').item.json[\"Name of the column that contains the resource text\"] }}",
        "binaryPropertyName": "=data"
      },
      "typeVersion": 1.1
    },
    {
      "id": "500e2a33-403d-4fe6-a178-f8b8dc6a82c2",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        400,
        416
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "5d67d456-f302-4bf2-b8fe-a924117699d5",
      "name": "Convert CSV to JSON",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -48,
        416
      ],
      "parameters": {
        "options": {},
        "binaryPropertyName": "csv"
      },
      "typeVersion": 1.1
    },
    {
      "id": "20e9fd7e-dd10-4c6f-bf15-01ff742dc25a",
      "name": "Upload a CSV",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -384,
        416
      ],
      "parameters": {
        "options": {},
        "formTitle": "CSV",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "csv",
              "requiredField": true,
              "acceptFileTypes": ".csv"
            },
            {
              "fieldLabel": "Assistant name",
              "placeholder": "RFP bot",
              "requiredField": true
            },
            {
              "fieldLabel": "Assistant context",
              "placeholder": "You help the Sales team to answer ...",
              "requiredField": true
            },
            {
              "fieldLabel": "Assistant output guidelines",
              "placeholder": "Answer in 3 concise bullet points, quote the resource titles in parenthesis...",
              "requiredField": true
            },
            {
              "fieldLabel": "Name of the column that contains the resource text",
              "placeholder": "content",
              "requiredField": true
            },
            {
              "fieldLabel": "Name of the column that contains the resource title",
              "placeholder": "title",
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "9135b6b3-a2ea-4cf5-8c10-2fcb0ed6cc16",
      "name": "Aggregate success messages",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        624,
        272
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "9173f114-3be2-453d-97c3-25fcba6cffdb",
      "name": "Convert IDs into an Array",
      "type": "n8n-nodes-base.set",
      "position": [
        848,
        272
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "2c807751-a41a-4f39-bb81-26f26cdd9a8b",
              "name": "IDs",
              "type": "array",
              "value": "={{ $json.data.map(item => item[\"Resource ID\"]) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a91503f2-6a84-44ef-b8d8-661157502cff",
      "name": "Success message form ending",
      "type": "n8n-nodes-base.form",
      "position": [
        1344,
        272
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "completionTitle": "Successful upload!",
        "completionMessage": "=Your assistant \"{{ $json['Assistant name'] }}\" has been successfully created and is set to answer based on the {{ $('Aggregate success messages').item.json.data.length }} uploaded text resources via CSV.\nAssistant ID: {{ $json['Assistant ID'] }}"
      },
      "typeVersion": 2.3
    },
    {
      "id": "805a94d8-1085-4acb-b6f9-d3622b3eed5e",
      "name": "Create Lookio assistant",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1088,
        272
      ],
      "parameters": {
        "url": "https://api.lookio.app/webhook/create-assistant",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "workspace_id",
              "value": "<YOUR-WORKSPACE-ID>"
            },
            {
              "name": "assistant_name",
              "value": "={{ $('Upload a CSV').item.json['Assistant name'] }}"
            },
            {
              "name": "context",
              "value": "={{ $('Upload a CSV').item.json['Assistant context'] }}"
            },
            {
              "name": "output_guidelines",
              "value": "={{ $('Upload a CSV').item.json['Assistant output guidelines'] }}"
            },
            {
              "name": "resources_access_type",
              "value": "Limited selection"
            },
            {
              "name": "allowed_resources",
              "value": "={{ $json.IDs }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "<YOUR-API-KEY>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "d3d01a00-af81-4532-b8c9-677999557006",
      "name": "Import resource to Lookio",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        800,
        608
      ],
      "parameters": {
        "url": "https://api.lookio.app/webhook/add-resource",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "workspace_id",
              "value": "<YOUR-WORKSPACE-ID>"
            },
            {
              "name": "method",
              "value": "file"
            },
            {
              "name": "source_title",
              "value": "={{ $binary.data.fileName }}"
            },
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "<YOUR-API-KEY>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "2fe20497-a22c-4248-8611-2c68a3a582ff",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        -96
      ],
      "parameters": {
        "color": 7,
        "width": 368,
        "height": 656,
        "content": "## Form Input Helper\n\nThis form configures the Assistant and maps your CSV data.\n\n**Assistant Settings:**\n\n* **Name:** The display name (e.g., \"HR Bot\").\n* **Context:** The system instructions (e.g., \"You are a helpful HR assistant...\").\n* **Guidelines:** Formatting rules (e.g., \"Keep answers short.\").\n\n**CSV Column Mapping:**\nTo ensure the workflow reads your file correctly, you must specify your CSV header names here:\n\n* **Resource Text Column:** Type the exact header name where the text body is located (e.g., `content`, `body`).\n* **Resource Title Column:** Type the exact header name to use as the file name (e.g., `title`, `topic`)."
      },
      "typeVersion": 1
    },
    {
      "id": "c744fbaf-a4e9-42f8-8969-f1c5f00c1aab",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## Action required\n\nMake sure to set your Lookio API key and workspace ID in here."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Upload a CSV": {
      "main": [
        [
          {
            "node": "Convert CSV to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to txt": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Aggregate success messages",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Import resource to Lookio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert CSV to JSON": {
      "main": [
        [
          {
            "node": "Convert to txt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Lookio assistant": {
      "main": [
        [
          {
            "node": "Success message form ending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert IDs into an Array": {
      "main": [
        [
          {
            "node": "Create Lookio assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Import resource to Lookio": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate success messages": {
      "main": [
        [
          {
            "node": "Convert IDs into an Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}