{
  "id": "FlinqLvMatch0001",
  "name": "flinq LV matching",
  "nodes": [
    {
      "parameters": {
        "content": "## How it works\n\nMatches positions from a GAEB tender against a product catalog, even when the wording differs. Downloads a sample X83 and a catalog CSV, parses the tender with flinq /v1/extract, then scores each position against the catalog with /v1/rerank. Output: one row per position with the best SKU and a score.\n\n## Setup\n\n1. Create a free account at https://console.flinq.ai/signup\n2. Create an API key in the console\n3. Add a Header Auth credential \"flinq API\": name `Authorization`, value `Bearer flq_...`\n4. Assign it to \"Extract tender positions\" and \"Match position to catalog\"\n5. Run it\n\nOwn data: swap the two download URLs (GAEB .x81-.x86, catalog CSV with sku,name,description).\n\nPricing and current limits: https://flinq.ai/docs/pricing/\nPython version of the same pipeline: https://flinq.ai/docs/examples/lv-matching/",
        "width": 560,
        "height": 660
      },
      "id": "c0ffee0000000001",
      "name": "Sticky Note 1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -620,
        -300
      ]
    },
    {
      "parameters": {
        "content": "## 1. Load the catalog\n\nFetches the sample CSV and joins name + description into one match text per row. Keep the User-Agent header: the flinq.ai host rejects n8n's default agent with a 503.",
        "width": 620,
        "height": 400,
        "color": 7
      },
      "id": "c0ffee0000000002",
      "name": "Sticky Note 2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        256,
        -120
      ]
    },
    {
      "parameters": {
        "content": "## 2. Parse the tender\n\nFetches the sample X83 and runs it through /v1/extract. The Code node flattens the group tree into one item per position (rno, qty, unit, text).",
        "width": 620,
        "height": 400,
        "color": 7
      },
      "id": "c0ffee0000000003",
      "name": "Sticky Note 3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        960,
        -120
      ]
    },
    {
      "parameters": {
        "content": "## 3. Match positions\n\n/v1/rerank scores each position against all catalog texts. Calls are paced to stay inside the API's concurrency limit, see https://flinq.ai/docs/limits/ before raising the pace.",
        "width": 430,
        "height": 400,
        "color": 7
      },
      "id": "c0ffee0000000004",
      "name": "Sticky Note 4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1664,
        -120
      ]
    },
    {
      "parameters": {},
      "id": "a1b2c3d4e5f60001",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        60
      ]
    },
    {
      "parameters": {
        "url": "https://flinq.ai/docs/samples/sample-catalog.csv",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "flinq-example/1.0"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "a1b2c3d4e5f60002",
      "name": "Download product catalog",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        304,
        60
      ]
    },
    {
      "parameters": {
        "operation": "csv",
        "options": {}
      },
      "id": "a1b2c3d4e5f60003",
      "name": "Parse catalog CSV",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        496,
        60
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const items = $input.all().map(i => i.json);\nreturn [{ json: {\n  texts: items.map(c => `${c.name}. ${c.description}`),\n  skus: items.map(c => c.sku),\n}}];"
      },
      "id": "a1b2c3d4e5f60004",
      "name": "Build catalog texts",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        688,
        60
      ]
    },
    {
      "parameters": {
        "url": "https://flinq.ai/docs/samples/sample-lv.x83",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "flinq-example/1.0"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "a1b2c3d4e5f60005",
      "name": "Download GAEB tender",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1008,
        60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.flinq.ai/v1/extract",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4e5f60006",
      "name": "Extract tender positions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        60
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "flinqheaderauth1",
          "name": "flinq API"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const positions = [];\nfunction walk(nodes) {\n  for (const node of nodes) {\n    if (node.type === 'item') {\n      let text = node.short_text;\n      if (node.long_text) text += '. ' + node.long_text;\n      positions.push({ rno: node.rno, qty: node.qty, unit: node.unit, text });\n    } else if (node.type === 'group') {\n      walk(node.children);\n    }\n  }\n}\nwalk($input.first().json.tree);\nreturn positions.map(p => ({ json: p }));"
      },
      "id": "a1b2c3d4e5f60007",
      "name": "Flatten positions",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1392,
        60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.flinq.ai/v1/rerank",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: \"flinq-rerank-2.0\", query: $json.text, documents: $('Build catalog texts').first().json.texts, task: \"lv_matching\", top_k: 3 }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 1,
              "batchInterval": 2000
            }
          }
        }
      },
      "id": "a1b2c3d4e5f60008",
      "name": "Match position to catalog",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1712,
        60
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "flinqheaderauth1",
          "name": "flinq API"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 4000
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const pos = $('Flatten positions').item.json;\nconst cat = $('Build catalog texts').first().json;\nconst best = $json.data[0];\nreturn { json: {\n  rno: pos.rno,\n  qty: `${pos.qty} ${pos.unit}`,\n  position: pos.text,\n  sku: cat.skus[best.index],\n  score: Number(best.relevance_score.toFixed(2)),\n}};"
      },
      "id": "a1b2c3d4e5f60009",
      "name": "Pick best match",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1904,
        60
      ]
    }
  ],
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Download product catalog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download product catalog": {
      "main": [
        [
          {
            "node": "Parse catalog CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse catalog CSV": {
      "main": [
        [
          {
            "node": "Build catalog texts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build catalog texts": {
      "main": [
        [
          {
            "node": "Download GAEB tender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download GAEB tender": {
      "main": [
        [
          {
            "node": "Extract tender positions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract tender positions": {
      "main": [
        [
          {
            "node": "Flatten positions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flatten positions": {
      "main": [
        [
          {
            "node": "Match position to catalog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Match position to catalog": {
      "main": [
        [
          {
            "node": "Pick best match",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}