{
  "name": "Indexation",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Indexation de fichiers",
        "formDescription": "Formulaire de prise en compte d'un fichier pdf \u00e0 indexer",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Fichier",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".pdf",
              "requiredField": true
            },
            {
              "fieldLabel": "model",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "local"
                  },
                  {
                    "option": "remote"
                  },
                  {
                    "option": "openai"
                  }
                ]
              },
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        208
      ],
      "id": "72bc2d44-cc4c-49d4-a59d-17a86e15002a",
      "name": "Index file"
    },
    {
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "Fichier",
        "options": {
          "joinPages": false
        }
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        224,
        208
      ],
      "id": "3076251d-f573-4b45-97ac-63e544408d3a",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "fieldToSplitOut": "text",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        736,
        208
      ],
      "id": "979db5e3-92a6-4254-9dd0-907ab5a256e0",
      "name": "Split pages"
    },
    {
      "parameters": {
        "model": "nomic-embed-text:latest"
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOllama",
      "typeVersion": 1,
      "position": [
        2960,
        432
      ],
      "id": "86bf83f8-8eaa-492e-8761-04a88e5163af",
      "name": "Embeddings Ollama",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "content-filter",
              "leftValue": "={{ $('Clean Content').item.json.output }}",
              "rightValue": "SKIP",
              "operator": {
                "type": "string",
                "operation": "notContains"
              }
            },
            {
              "id": "min-length",
              "leftValue": "={{ $('Clean Content').item.json.output.length }}",
              "rightValue": 50,
              "operator": {
                "operation": "gte",
                "type": "number"
              }
            },
            {
              "id": "c0946734-9b31-4420-ad94-9ec3a844cbc6",
              "leftValue": "={{ $('Clean Content').item.json.output }}",
              "rightValue": "skip",
              "operator": {
                "type": "string",
                "operation": "notContains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2736,
        208
      ],
      "id": "c9a89967-941b-4d16-b049-d9c5fd5dd3e5",
      "name": "Filter Quality Content"
    },
    {
      "parameters": {
        "chunkOverlap": 200,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "typeVersion": 1,
      "position": [
        3168,
        640
      ],
      "id": "7ed11a42-b0fd-406e-8653-a7ddca5a50d1",
      "name": "Smart Text Chunker"
    },
    {
      "parameters": {
        "numberInputs": 3,
        "rules": {
          "rule": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "ac253c83-e230-4dc4-8321-26635c154859",
                    "leftValue": "={{ $('Index file').item.json.model }}",
                    "rightValue": "local",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "modelIndex": 2,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d6a99a37-231a-43a8-b8f4-d4c42b9ec441",
                    "leftValue": "={{ $('Index file').item.json.model }}",
                    "rightValue": "remote",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "modelIndex": 3,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "bef31ca0-40a7-4bfd-8900-eb4b858af3e7",
                    "leftValue": "={{ $('Index file').item.json.model }}",
                    "rightValue": "openai",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.modelSelector",
      "typeVersion": 1,
      "position": [
        1504,
        224
      ],
      "id": "325da776-80d9-496a-a7b1-89279192af35",
      "name": "Model Selector"
    },
    {
      "parameters": {
        "model": "qwen2.5:3b-instruct-q4_K_M",
        "options": {
          "temperature": 0.4,
          "keepAlive": "-1m"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        1456,
        432
      ],
      "id": "c5fe438c-bd55-403d-b3d4-88f2561ae66f",
      "name": "Local Ollama Agent Model",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": "qwen2.5:7b",
        "options": {
          "temperature": 0.4,
          "keepAlive": "-1m"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        1584,
        432
      ],
      "id": "d0e4d7f2-9403-4d00-a92a-c7f479382ea1",
      "name": "Remote Ollama Agent Model",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "endpointUrl": "http://playwright-mcp:3333/mcp",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "typeVersion": 1.2,
      "position": [
        736,
        736
      ],
      "id": "aff72c1a-db57-41fc-b1c0-e7c702c9487b",
      "name": "playwright_mcp"
    },
    {
      "parameters": {
        "formTitle": "Indexation d'Url",
        "formDescription": "Formulaire de prise en compte d'une url \u00e0 indexer (utilise OpenAI)",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Url",
              "placeholder": "L'url de la page \u00e0 indexer",
              "requiredField": true
            },
            {
              "fieldLabel": "model",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "remote"
                  },
                  {
                    "option": "openai"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        608
      ],
      "id": "ef4bac0a-d128-46a3-858b-d8f7f15c4aab",
      "name": "Index Url"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1712,
        432
      ],
      "id": "22954643-bcf1-4124-89f5-e20f59eef5b3",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n\t\"title\": \"Titre de la page Web\",\n\t\"content\": \"Contenu de la page web en markdown\"\n}",
        "autoFix": true
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        864,
        736
      ],
      "id": "d81a1583-8b66-4483-95ab-fd0bc67d6314",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "mode": "insert",
        "qdrantCollection": {
          "__rl": true,
          "value": "documents",
          "mode": "list",
          "cachedResultName": "documents"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "typeVersion": 1.3,
      "position": [
        2992,
        208
      ],
      "id": "c76ebc9f-971a-4527-aab9-ff74d8daaebd",
      "name": "Documents Qdrant Vector Store",
      "credentials": {
        "qdrantApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "insert",
        "qdrantCollection": {
          "__rl": true,
          "value": "web_documents",
          "mode": "list",
          "cachedResultName": "web_documents"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "typeVersion": 1.3,
      "position": [
        1936,
        608
      ],
      "id": "816cccea-c541-440f-af92-3f9b91cd85bd",
      "name": "Web Documents Qdrant Vector Store1",
      "credentials": {
        "qdrantApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonMode": "expressionData",
        "jsonData": "={{ $('Clean Content').item.json.output }}",
        "textSplittingMode": "custom",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "source_filename",
                "value": "={{ $('Index file').item.json.Fichier.filename }}"
              },
              {
                "name": "source_type",
                "value": "={{ $('Index file').item.json.Fichier.mimetype }}"
              },
              {
                "name": "page_number",
                "value": "={{ $('Split pages').item.json.pageNumber || ($itemIndex + 1) }}"
              },
              {
                "name": "content_length",
                "value": "={{ $json.pageContent?.length || $json.text?.length || 0 }}"
              },
              {
                "name": "chunk_id",
                "value": "={{ $('Index file').item.json.Fichier.filename }}_page_{{ $('Split pages').item.json.pageNumber || ($itemIndex + 1) }}_chunk_{{ $itemIndex }}"
              },
              {
                "name": "indexed_date",
                "value": "={{ new Date().toISOString() }}"
              },
              {
                "name": "document_title",
                "value": "={{ $('Index file').item.json.Fichier.filename.replace('.pdf', '') }}"
              }
            ]
          }
        }
      },
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1.1,
      "position": [
        3088,
        432
      ],
      "id": "9a99b52e-c820-4f83-8e56-2daac8e7f172",
      "name": "Document Data Loader"
    },
    {
      "parameters": {
        "jsonMode": "expressionData",
        "jsonData": "={{ $('Web Scraping').item.json.output.content }}",
        "textSplittingMode": "custom",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "url",
                "value": "={{ $('Index Url').item.json.Url }}"
              },
              {
                "name": "title",
                "value": "={{ $('Web Scraping').item.json.output.title }}"
              },
              {
                "name": "scraped_at",
                "value": "={{ new Date().toISOString() }}"
              },
              {
                "name": "content_type",
                "value": "markdown"
              },
              {
                "name": "domain",
                "value": "={{ new URL($('Index Url').item.json.Url).hostname }}"
              },
              {
                "name": "content_length",
                "value": "={{ $('Web Scraping').item.json.output.content.length() }}"
              }
            ]
          }
        }
      },
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1.1,
      "position": [
        1920,
        832
      ],
      "id": "a14ce718-b9a6-4ef3-a759-b0ae103caa52",
      "name": "Web Document Data Loader"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "Tu es un expert en nettoyage et structuration de documents PDF.\n\nInstructions :\n* Supprime les num\u00e9ros de page, headers, footers r\u00e9p\u00e9titifs\n* Corrige les mots coup\u00e9s en fin de ligne\n* Supprime les lignes vides multiples\n* Garde uniquement le contenu informatif principal\n* Ignore les \u00e9l\u00e9ments de navigation ou publicitaires\n* Structure le texte avec des titres markdown appropri\u00e9s\n* Pr\u00e9serve la structure logique du document\n\nCrit\u00e8res de qualit\u00e9 :\n- Le texte doit \u00eatre informatif et coh\u00e9rent\n- Minimum 50 caract\u00e8res de contenu utile\n- Pas de texte r\u00e9p\u00e9titif ou de bruit\n\nFormat de sortie :\nTexte nettoy\u00e9 et structur\u00e9 en markdown, ou 'SKIP' si le contenu n'est pas pertinent"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        1520,
        0
      ],
      "id": "7b50ec4f-ae1c-4b52-8764-0aac61a3671e",
      "name": "Clean Content"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Index Url').item.json.Url }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "Tu es un expert en extraction et structuration de contenu web en Fran\u00e7ais.\n\nInstructions :\n* Utilise l'outil playwright_mcp pour naviguer sur les pages web demand\u00e9es\n* Extrait le contenu principal en \u00e9vitant les \u00e9l\u00e9ments de navigation, publicit\u00e9s, cookies, headers et footers\n* Supprime les \u00e9l\u00e9ments r\u00e9p\u00e9titifs comme les menus, barres lat\u00e9rales et widgets\n* Corrige la mise en forme et les espaces inutiles\n* Supprime les lignes vides multiples\n* Garde uniquement le contenu informatif principal (articles, textes, descriptions)\n* Ignore les \u00e9l\u00e9ments interactifs (boutons, formulaires) sauf si pertinents\n* Structure le texte avec des titres markdown appropri\u00e9s\n* Pr\u00e9serve la hi\u00e9rarchie logique du contenu (H1, H2, H3...)\n* Extrait les liens importants en conservant leur contexte\n\nCrit\u00e8res de qualit\u00e9 :\n- Le contenu doit \u00eatre informatif et coh\u00e9rent\n- Minimum 50 caract\u00e8res de contenu utile\n- Pas de texte r\u00e9p\u00e9titif ou de bruit\n- Pr\u00e9serve les informations essentielles (dates, auteurs, sources)\n- Maintient la lisibilit\u00e9 et la structure logique\n\nFormat de sortie :\nContenu web nettoy\u00e9 et structur\u00e9 en markdown et en Fran\u00e7ais, ou 'SKIP' si la page n'est pas accessible ou ne contient pas de contenu pertinent"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        672,
        512
      ],
      "id": "5237db7e-2127-4718-b609-1fe936174bf4",
      "name": "Web Scraping"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.start_time = Date.now();\n\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1232,
        208
      ],
      "id": "4eeb885c-636f-4d24-8207-8e64a727a4b1",
      "name": "Set clean content start_time"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.duration_ms = Date.now() - $('Set clean content start_time').item.json.start_time;\n$input.item.json.agent_task = 'Clean Content';\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2000,
        208
      ],
      "id": "b432fc2f-c801-4b3a-8361-d0d8767c5bb0",
      "name": "Set clean content duration"
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "value": "GxOSCX2gt0Mz40IU",
          "mode": "list",
          "cachedResultName": "ai_workflow_metrics",
          "cachedResultUrl": "/projects/kIpFOLTWQHjPaM8F/datatables/GxOSCX2gt0Mz40IU"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "workflow_name": "={{ $workflow.name }}",
            "execution_id": "={{ $execution.id }}",
            "agent_task": "={{ $('Set clean content duration').item.json.agent_task }}",
            "duration_ms": "={{ $('Set clean content duration').item.json.duration_ms }}",
            "model": "={{ $('Index file').item.json.model }}",
            "source": "={{ $('Index file').item.json.Fichier.filename }} - page {{ $('Split pages').item.json.pageNumber || ($itemIndex + 1) }}",
            "output": "={{ $('Clean Content').item.json.output }}",
            "model_name": "={{\n  $('Index file').item.json.model === 'local' ? \n    \"qwen2.5:3b-instruct-q4_K_M\" :\n  $('Index file').item.json.model === 'remote' ? \n    \"qwen2.5:7b\" :\n  $('Index file').item.json.model === 'openai' ? \n    \"gpt-4o-mini\" : 'unknown'\n}}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "workflow_name",
              "displayName": "workflow_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_task",
              "displayName": "agent_task",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model",
              "displayName": "model",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model_name",
              "displayName": "model_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "source",
              "displayName": "source",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "output",
              "displayName": "output",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "execution_id",
              "displayName": "execution_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "optimizeBulk": true
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        2288,
        288
      ],
      "id": "a08a27a9-3e9e-406a-9a98-69d6fb60b8ce",
      "name": "Insert Clean Content Execution time"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.start_time = Date.now();\n\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        608
      ],
      "id": "68a9eeb0-77ef-4c4a-a861-25f97eb62767",
      "name": "Set web scraping start_time"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.duration_ms = Date.now() - $('Set web scraping start_time').item.json.start_time;\n$input.item.json.agent_task = 'Web Scraping';\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1232,
        608
      ],
      "id": "bc3f6273-27d4-444d-ab68-8a1c9fd79427",
      "name": "Set web scraping duration"
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "value": "GxOSCX2gt0Mz40IU",
          "mode": "list",
          "cachedResultName": "ai_workflow_metrics",
          "cachedResultUrl": "/projects/kIpFOLTWQHjPaM8F/datatables/GxOSCX2gt0Mz40IU"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "workflow_name": "={{ $workflow.name }}",
            "execution_id": "={{ $execution.id }}",
            "agent_task": "={{ $('Set web scraping duration').item.json.agent_task }}",
            "duration_ms": "={{ $('Set web scraping duration').item.json.duration_ms }}",
            "model": "={{ $('Index Url').item.json.model }}",
            "source": "={{ $('Index Url').item.json.Url }}",
            "output": "={{ JSON.stringify($('Web Scraping').item.json.output) }}",
            "model_name": "={{\n  $('Index Url').item.json.model === 'remote' ? \n    \"qwen2.5:7b\" :\n  $('Index Url').item.json.model === 'openai' ? \n    \"gpt-4o-mini\" : 'unknown'\n}}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "workflow_name",
              "displayName": "workflow_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_task",
              "displayName": "agent_task",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model",
              "displayName": "model",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model_name",
              "displayName": "model_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "source",
              "displayName": "source",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "output",
              "displayName": "output",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "execution_id",
              "displayName": "execution_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "optimizeBulk": true
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        1584,
        608
      ],
      "id": "950098b9-23ab-4149-b44f-0f758f22ac07",
      "name": "Insert Web Scraping Execution time"
    },
    {
      "parameters": {
        "mode": "chooseBranch"
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        2512,
        208
      ],
      "id": "27f23bb2-6920-4684-9955-1aff60a696b1",
      "name": "Merge"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.start_time = Date.now();\n\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        1120
      ],
      "id": "63478afc-c04b-478f-b488-f363855e595f",
      "name": "Set web image analyse start_time"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$input.item.json.duration_ms = Date.now() - $('Set web image analyse start_time').item.json.start_time;\n$input.item.json.agent_task = 'Image Analyse';\nreturn $input.item;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1232,
        1120
      ],
      "id": "c736dcff-002d-41dc-aa37-f7287877734b",
      "name": "Set web image analyse duration"
    },
    {
      "parameters": {
        "dataTableId": {
          "__rl": true,
          "value": "GxOSCX2gt0Mz40IU",
          "mode": "list",
          "cachedResultName": "ai_workflow_metrics",
          "cachedResultUrl": "/projects/kIpFOLTWQHjPaM8F/datatables/GxOSCX2gt0Mz40IU"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "workflow_name": "={{ $workflow.name }}",
            "execution_id": "={{ $execution.id }}",
            "agent_task": "={{ $('Set web image analyse duration').item.json.agent_task }}",
            "duration_ms": "={{ $('Set web image analyse duration').item.json.duration_ms }}",
            "source": "={{ $('Analyse Image').item.json.imageFichier.filename }}",
            "model": "={{ $('Analyse Image').item.json.model }}",
            "output": "={{ $('Analyse Image1').item.json.output }}",
            "model_name": "={{ $('Analyse Image').item.json.model === 'local' ? \"granite3.2-vision:2b\" : $('Analyse Image').item.json.model === 'remote' ? \"granite3.2-vision:2b\" : $('Analyse Image').item.json.model === 'openai' ? \"gpt-4o-mini\" :   'unknown' }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "workflow_name",
              "displayName": "workflow_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "agent_task",
              "displayName": "agent_task",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "duration_ms",
              "displayName": "duration_ms",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model",
              "displayName": "model",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "model_name",
              "displayName": "model_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "source",
              "displayName": "source",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "output",
              "displayName": "output",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "execution_id",
              "displayName": "execution_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "optimizeBulk": true
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1,
      "position": [
        1584,
        1120
      ],
      "id": "03656a11-3370-4ba0-911f-bd46fc46e6ae",
      "name": "Insert Image Analyse Execution time"
    },
    {
      "parameters": {
        "formTitle": "Analyse d'image",
        "formDescription": "Analyse d'une image avec un mod\u00e8le multimodal",
        "formFields": {
          "values": [
            {
              "fieldLabel": "imageFichier",
              "fieldType": "file",
              "multipleFiles": false,
              "acceptFileTypes": ".jpg, .png",
              "requiredField": true
            },
            {
              "fieldLabel": "model",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "local"
                  },
                  {
                    "option": "remote"
                  },
                  {
                    "option": "openai"
                  }
                ]
              },
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        0,
        1120
      ],
      "id": "1936686c-9e97-4f65-94bc-a78514e5f408",
      "name": "Analyse Image"
    },
    {
      "parameters": {
        "numberInputs": 3,
        "rules": {
          "rule": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "ac253c83-e230-4dc4-8321-26635c154859",
                    "leftValue": "={{ $('Analyse Image').item.json.model }}",
                    "rightValue": "local",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "modelIndex": 2,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d6a99a37-231a-43a8-b8f4-d4c42b9ec441",
                    "leftValue": "={{ $('Analyse Image').item.json.model }}",
                    "rightValue": "remote",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "modelIndex": 3,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "bef31ca0-40a7-4bfd-8900-eb4b858af3e7",
                    "leftValue": "={{ $('Analyse Image').item.json.model }}",
                    "rightValue": "openai",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.modelSelector",
      "typeVersion": 1,
      "position": [
        656,
        1344
      ],
      "id": "42ad19a3-262b-47ea-9b9d-99c83268085b",
      "name": "Model Selector Analyse IMage"
    },
    {
      "parameters": {
        "model": "granite3.2-vision:2b",
        "options": {
          "temperature": 0.4,
          "keepAlive": "-1m"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        672,
        1552
      ],
      "id": "1e0af975-be93-4f64-b517-1f3031dc02fe",
      "name": "Local Ollama Agent Analyse Model",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Analyse Image').item.json.imageFichier.filename }}",
        "options": {
          "systemMessage": "Tu es un analyseur d'image.\n\n**Instructions:**\n* D\u00e9cris moi ce que tu vois\n* Si l'image contient du texte essaie de l'extraire\n* Nettoie ce texte pour le rendre compr\u00e9hensible\n\n\n\n",
          "passthroughBinaryImages": true
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        672,
        1120
      ],
      "id": "22fa5f16-e276-420a-88c1-c1685b98aff5",
      "name": "Analyse Image1"
    },
    {
      "parameters": {
        "operation": "completion",
        "completionTitle": "Analyse de l'image par le modele",
        "completionMessage": "={{ $('Analyse Image1').item.json.output }}",
        "options": {}
      },
      "type": "n8n-nodes-base.form",
      "typeVersion": 2.3,
      "position": [
        2000,
        1120
      ],
      "id": "355c8346-606d-4607-9225-b664f9a85ca9",
      "name": "Form"
    },
    {
      "parameters": {
        "rules": {
          "rule": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d6a99a37-231a-43a8-b8f4-d4c42b9ec441",
                    "leftValue": "={{ $('Index Url').item.json.model }}",
                    "rightValue": "remote",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "modelIndex": 2,
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "bef31ca0-40a7-4bfd-8900-eb4b858af3e7",
                    "leftValue": "={{ $('Index Url').item.json.model }}",
                    "rightValue": "openai",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.modelSelector",
      "typeVersion": 1,
      "position": [
        448,
        736
      ],
      "id": "14031bba-7a67-46a7-a1db-a1e8723c497b",
      "name": "Model Selector Web Scraping"
    },
    {
      "parameters": {
        "model": "granite3.2-vision:2b",
        "options": {
          "temperature": 0.4,
          "keepAlive": "-1m"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        800,
        1552
      ],
      "id": "f7587822-4d53-4606-874c-f0561a390425",
      "name": "Remote Ollama Analyse Agent Model",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Index file": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Split pages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split pages": {
      "main": [
        [
          {
            "node": "Set clean content start_time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Ollama": {
      "ai_embedding": [
        [
          {
            "node": "Documents Qdrant Vector Store",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Web Documents Qdrant Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Filter Quality Content": {
      "main": [
        [
          {
            "node": "Documents Qdrant Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Smart Text Chunker": {
      "ai_textSplitter": [
        [
          {
            "node": "Document Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          },
          {
            "node": "Web Document Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Local Ollama Agent Model": {
      "ai_languageModel": [
        [
          {
            "node": "Model Selector",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Remote Ollama Agent Model": {
      "ai_languageModel": [
        [
          {
            "node": "Model Selector",
            "type": "ai_languageModel",
            "index": 1
          },
          {
            "node": "Model Selector Web Scraping",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Model Selector": {
      "ai_languageModel": [
        [
          {
            "node": "Clean Content",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Index Url": {
      "main": [
        [
          {
            "node": "Set web scraping start_time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "playwright_mcp": {
      "ai_tool": [
        [
          {
            "node": "Web Scraping",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Model Selector",
            "type": "ai_languageModel",
            "index": 2
          },
          {
            "node": "Model Selector Analyse IMage",
            "type": "ai_languageModel",
            "index": 2
          },
          {
            "node": "Model Selector Web Scraping",
            "type": "ai_languageModel",
            "index": 1
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Web Scraping",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Document Data Loader": {
      "ai_document": [
        [
          {
            "node": "Documents Qdrant Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Web Document Data Loader": {
      "ai_document": [
        [
          {
            "node": "Web Documents Qdrant Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Clean Content": {
      "main": [
        [
          {
            "node": "Set clean content duration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Web Scraping": {
      "main": [
        [
          {
            "node": "Set web scraping duration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set clean content start_time": {
      "main": [
        [
          {
            "node": "Clean Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set clean content duration": {
      "main": [
        [
          {
            "node": "Insert Clean Content Execution time",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Clean Content Execution time": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Set web scraping start_time": {
      "main": [
        [
          {
            "node": "Web Scraping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set web scraping duration": {
      "main": [
        [
          {
            "node": "Insert Web Scraping Execution time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Web Scraping Execution time": {
      "main": [
        [
          {
            "node": "Web Documents Qdrant Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Filter Quality Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set web image analyse start_time": {
      "main": [
        [
          {
            "node": "Analyse Image1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set web image analyse duration": {
      "main": [
        [
          {
            "node": "Insert Image Analyse Execution time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyse Image": {
      "main": [
        [
          {
            "node": "Set web image analyse start_time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model Selector Analyse IMage": {
      "ai_languageModel": [
        [
          {
            "node": "Analyse Image1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Local Ollama Agent Analyse Model": {
      "ai_languageModel": [
        [
          {
            "node": "Model Selector Analyse IMage",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Analyse Image1": {
      "main": [
        [
          {
            "node": "Set web image analyse duration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Image Analyse Execution time": {
      "main": [
        [
          {
            "node": "Form",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model Selector Web Scraping": {
      "ai_languageModel": [
        [
          {
            "node": "Web Scraping",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Remote Ollama Analyse Agent Model": {
      "ai_languageModel": [
        [
          {
            "node": "Model Selector Analyse IMage",
            "type": "ai_languageModel",
            "index": 1
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "44093c18-c0b7-4048-a868-c2b8e16be1f5",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "lnZ6c49wc2TZHdlA",
  "tags": []
}