{
  "name": "Pentest RAG Vector Query",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "path": "rag-vector",
        "httpMethod": "POST",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "node-webhook-rag-vector",
      "name": "Vector query webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent?key={{ $env.GEMINI_API_KEY }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"model\": \"models/gemini-embedding-001\", \"content\": {\"parts\": [{\"text\": {{ JSON.stringify($json.body.query) }}}]}}",
        "options": {}
      },
      "id": "node-gemini-embed-query",
      "name": "Gemini embed query",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://neo4j:7474/db/neo4j/tx/commit",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"statements\": [{\"statement\": \"CALL db.index.vector.queryNodes('rapport_chunks', 5, $embedding) YIELD node, score OPTIONAL MATCH (node)-[:BESKRIVER]->(f:Fund) OPTIONAL MATCH (f)-[:FUNDET_MED]->(t:Teknik) RETURN node.chunk_id AS id, node.tekst AS tekst, node.kilde AS kilde, score, f.titel AS fund, f.cvss AS cvss, t.kommando AS teknik ORDER BY score DESC\", \"parameters\": {\"embedding\": {{ JSON.stringify($json.embedding.values) }}}}]}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth"
      },
      "id": "node-neo4j-vector-search",
      "name": "Neo4j vector search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        680,
        300
      ],
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "\nconst input = $input.first().json;\nconst rows = input.results?.[0]?.data || [];\n\nif (rows.length === 0) {\n  return [{ json: { svar: \"Ingen relevante fund i videnbasen.\", antal: 0 }}];\n}\n\nconst resultater = rows.map(r => ({\n  id: r.row[0], tekst: r.row[1], kilde: r.row[2],\n  score: Math.round(r.row[3] * 100) / 100,\n  fund: r.row[4], cvss: r.row[5], teknik: r.row[6]\n}));\n\nconst svar = resultater.map((r, i) =>\n  `${i+1}. [${r.score}] ${r.kilde}: ${r.tekst.substring(0, 200)}` +\n  (r.teknik ? `\\n   \u2192 Teknik: ${r.teknik}` : '')\n).join('\\n\\n');\n\nreturn [{ json: { svar, antal: resultater.length, resultater }}];\n"
      },
      "id": "node-formater-vector-resultat",
      "name": "Formater vector resultat",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Vector query webhook": {
      "main": [
        [
          {
            "node": "Gemini embed query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini embed query": {
      "main": [
        [
          {
            "node": "Neo4j vector search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Neo4j vector search": {
      "main": [
        [
          {
            "node": "Formater vector resultat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "activeVersionId": "ec182336-5837-4045-87b8-f6812982975a",
  "versionCounter": 6,
  "triggerCount": 1,
  "tags": [],
  "shared": [
    {
      "updatedAt": "2026-05-23T10:18:36.803Z",
      "createdAt": "2026-05-23T10:18:36.803Z",
      "role": "workflow:owner",
      "workflowId": "srgbYxP4QHx67Fd6",
      "projectId": "mBwAmYhJNV3JFVeG",
      "project": {
        "updatedAt": "2026-05-23T10:16:37.814Z",
        "createdAt": "2026-05-23T10:14:57.720Z",
        "id": "mBwAmYhJNV3JFVeG",
        "name": "hannibal u-w <hannibal@ussing.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "ddbee286-2878-4f4d-873f-e6c8d1e1c77f"
      }
    }
  ],
  "versionMetadata": {
    "name": null,
    "description": null
  }
}