{
  "name": "RAG Table-Safe Markdown & HTML Ingestion Pipeline (Apify MCP)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "rag-table-safe-ingest",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "node-rag-webhook",
      "name": "Webhook: Receive Markdown or HTML Doc",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300],
      "notes": "Pass { docId, content } from Google Drive, Notion, Confluence, or internal CMS."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/snowy_divide_r1t~rag-table-aware-chunker/run-sync-get-dataset-items",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.APIFY_TOKEN }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"docId\": {{ JSON.stringify($json.body.docId || 'doc-1') }},\n  \"document\": {{ JSON.stringify($json.body.content || $json.body.document || '') }},\n  \"options\": {\n    \"format\": \"auto\",\n    \"maxTokens\": 512,\n    \"overlapTokens\": 40,\n    \"repeatTableHeaders\": true,\n    \"preserveCodeBlocks\": true,\n    \"injectBreadcrumbs\": true,\n    \"tokenizerProfile\": \"openai-o200k\"\n  }\n}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "node-apify-chunker",
      "name": "Apify: RAG Table-Aware Chunker ($0.002/doc)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [500, 300],
      "notes": "Zero-scraping pure-compute chunker. Protects tables & auto-repeats headers on splits. Store: https://apify.com/snowy_divide_r1t/rag-table-aware-chunker"
    },
    {
      "parameters": {
        "fieldToSplitOut": "content",
        "include": "allOtherFields",
        "options": {}
      },
      "id": "node-split-chunks",
      "name": "Split Out: Prepare Individual Chunk Items",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [780, 300],
      "notes": "Each Apify dataset item already represents one structured chunk with docId, chunkIndex, breadcrumbs, tokenCount, and tableSplitPart."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.VECTOR_DB_UPSERT_URL }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $env.VECTOR_DB_API_KEY }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"id\": \"{{ $json.docId }}::{{ $json.chunkIndex }}\",\n  \"text\": {{ JSON.stringify($json.content) }},\n  \"metadata\": {\n    \"docId\": \"{{ $json.docId }}\",\n    \"chunkIndex\": {{ $json.chunkIndex }},\n    \"totalChunks\": {{ $json.totalChunks }},\n    \"chunkType\": \"{{ $json.chunkType }}\",\n    \"breadcrumbs\": {{ JSON.stringify($json.breadcrumbs) }},\n    \"tokenCount\": {{ $json.tokenCount }},\n    \"tableSplitPart\": {{ JSON.stringify($json.tableSplitPart) }}\n  }\n}",
        "options": {}
      },
      "id": "node-vector-upsert",
      "name": "Vector DB: Upsert Table-Safe Chunk",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1060, 300],
      "notes": "Swap for native Supabase, Pinecone, Qdrant, or Weaviate n8n Vector Store node."
    }
  ],
  "connections": {
    "Webhook: Receive Markdown or HTML Doc": {
      "main": [
        [
          {
            "node": "Apify: RAG Table-Aware Chunker ($0.002/doc)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apify: RAG Table-Aware Chunker ($0.002/doc)": {
      "main": [
        [
          {
            "node": "Split Out: Prepare Individual Chunk Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out: Prepare Individual Chunk Items": {
      "main": [
        [
          {
            "node": "Vector DB: Upsert Table-Safe Chunk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateSource": "https://mcp.miaodui.workers.dev/",
    "apifyActor": "https://apify.com/snowy_divide_r1t/rag-table-aware-chunker"
  },
  "tags": [
    { "name": "rag-pipeline" },
    { "name": "apify-mcp" },
    { "name": "table-chunking" }
  ]
}
