{
  "schemaVersion": "flowdrome.workflow.v1",
  "id": "",
  "name": "AI · 08 — Rerank (best results first)",
  "version": "0",
  "status": "draft",
  "nodes": [
    {
      "id": "seed",
      "type": "input.inject",
      "label": "Search results",
      "category": "trigger",
      "config": {
        "contentType": "application/json",
        "payload": {
          "query": "password reset emails are not arriving",
          "matches": [
            {
              "text": "How to change your profile picture"
            },
            {
              "text": "Fixing email delivery for password reset messages"
            },
            {
              "text": "Billing FAQ: invoices and receipts"
            },
            {
              "text": "Troubleshooting SMTP configuration for outbound mail"
            }
          ]
        }
      },
      "position": {
        "x": 0,
        "y": 0
      }
    },
    {
      "id": "rank",
      "type": "ai.rerank",
      "label": "Rerank",
      "category": "ai",
      "config": {
        "provider": "llm",
        "judgeProvider": "ollama",
        "baseUrl": "",
        "apiKey": "",
        "model": "qwen2.5:1.5b",
        "queryField": "query",
        "documentsField": "matches",
        "topK": 2,
        "timeoutMs": 120000
      },
      "position": {
        "x": 530,
        "y": 0
      },
      "attachments": {
        "model": "llm"
      }
    },
    {
      "id": "llm",
      "type": "ai.model",
      "label": "Ollama (local)",
      "category": "ai",
      "config": {
        "provider": "ollama",
        "baseUrl": "",
        "apiKey": "",
        "model": "qwen2.5:1.5b",
        "models": [],
        "temperature": 0.2,
        "maxTokens": 512
      },
      "position": {
        "x": 530,
        "y": 222
      }
    },
    {
      "id": "fmt",
      "type": "utility.javascript",
      "label": "Format",
      "category": "script",
      "config": {
        "code": "return { ranked: (input.matches || []).map(function (m, i) { return (i + 1) + '. ' + m.text; }).join('  |  ') };",
        "outputs": [
          "output"
        ]
      },
      "position": {
        "x": 1060,
        "y": 0
      }
    },
    {
      "id": "out",
      "type": "utility.console",
      "label": "Ranked",
      "category": "utility",
      "config": {
        "message": "Top matches → {{ $json.ranked }}"
      },
      "position": {
        "x": 1590,
        "y": 0
      }
    }
  ],
  "edges": [
    {
      "id": "e0",
      "sourceNodeId": "seed",
      "sourcePort": "output",
      "targetNodeId": "rank",
      "targetPort": "input"
    },
    {
      "id": "e1",
      "sourceNodeId": "rank",
      "sourcePort": "output",
      "targetNodeId": "fmt",
      "targetPort": "input"
    },
    {
      "id": "e2",
      "sourceNodeId": "fmt",
      "sourcePort": "output",
      "targetNodeId": "out",
      "targetPort": "input"
    }
  ],
  "triggers": [
    {
      "id": "t0",
      "nodeId": "seed"
    }
  ],
  "meta": {
    "snippets": [],
    "source": "template-gallery",
    "description": "Search gave you four candidate snippets — the ◈-wired Rerank has a local model JUDGE which ones actually answer the query and keeps the top two. This is the quality step between retrieval and the final prompt."
  }
}