{
  "name": "RAG - Ingesta Automatizada de Documentos",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      },
      "id": "trigger-schedule",
      "name": "Verificar cada 5 minutos",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "list",
        "path": "/data/documentos",
        "options": {}
      },
      "id": "list-files",
      "name": "Listar archivos en carpeta",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        470,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-ext",
              "leftValue": "={{ $json.fileName }}",
              "rightValue": ".pdf",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "filter-docs",
      "name": "Filtrar PDF y DOCX",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2,
      "position": [
        690,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://api:8000/api/ingest",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "archivo",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "ingest-api",
      "name": "Enviar a API de Ingesta",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        910,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  results.push({\n    json: {\n      status: 'procesado',\n      documento: item.json.documento || 'desconocido',\n      fragmentos: item.json.fragmentos_creados || 0,\n      mensaje: item.json.mensaje || 'Procesado',\n      timestamp: new Date().toISOString()\n    }\n  });\n}\n\nreturn results;"
      },
      "id": "log-result",
      "name": "Registrar resultado",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1130,
        300
      ]
    }
  ],
  "connections": {
    "Verificar cada 5 minutos": {
      "main": [
        [
          {
            "node": "Listar archivos en carpeta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Listar archivos en carpeta": {
      "main": [
        [
          {
            "node": "Filtrar PDF y DOCX",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrar PDF y DOCX": {
      "main": [
        [
          {
            "node": "Enviar a API de Ingesta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviar a API de Ingesta": {
      "main": [
        [
          {
            "node": "Registrar resultado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": [
    {
      "name": "RAG",
      "id": "1"
    },
    {
      "name": "Ingesta",
      "id": "2"
    }
  ]
}