{
  "name": "RFP 01 - Knowledge Library Manager",
  "nodes": [
    {
      "id": "8c52dff98c91f21d",
      "name": "Control Gate",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1220,
        -460
      ],
      "parameters": {
        "content": "## Knowledge Library Manager\nOnly APPROVED, non-expired documents are embedded. The checksum makes updates traceable. Classification, region, owner and validity travel with each chunk as retrieval metadata.",
        "width": 760,
        "height": 310,
        "color": 5
      }
    },
    {
      "id": "19db06c0fe701607",
      "name": "Manual Demo Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1140,
        0
      ],
      "parameters": {}
    },
    {
      "id": "e2f3783b068f221a",
      "name": "Load Fictional Evidence Fixture",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -900,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const docs=[{\"document_id\":\"DOC-SEC-001\",\"title\":\"Security and Privacy Controls\",\"department\":\"Security\",\"classification\":\"INTERNAL\",\"region\":\"GLOBAL\",\"status\":\"APPROVED\",\"version\":\"3.2\",\"valid_until\":\"2027-12-31\",\"source_url\":\"https://drive.example/security-controls\",\"content\":\"Fictional Acme Cloud maintains annual independent SOC 2 Type II assessments. Customer data is encrypted in transit with TLS 1.2 or later and at rest using AES-256. Production access requires SSO, MFA, role-based access, and quarterly access reviews. Security incidents follow a documented triage process with customer notification according to contract and applicable law. This fictional sample is for workflow testing only.\",\"checksum\":\"700568ec47845c9d72245f4411bee7b79f070021bec48857bfa89ded9b749b04\"},{\"document_id\":\"DOC-SLA-001\",\"title\":\"Enterprise Service Levels\",\"department\":\"Operations\",\"classification\":\"PUBLIC\",\"region\":\"GLOBAL\",\"status\":\"APPROVED\",\"version\":\"2.0\",\"valid_until\":\"2027-06-30\",\"source_url\":\"https://drive.example/service-levels\",\"content\":\"Fictional Acme Cloud targets 99.95% monthly availability for the Enterprise tier. Priority 1 support has a 30-minute initial response target, Priority 2 has a 2-hour target, and lower priorities receive a response within one business day. Service credits are governed by the signed order form. This fictional sample is for workflow testing only.\",\"checksum\":\"4c46f1c148da3c5a2ec3380be01682b7926b6c864ae29fb3026a60bffe211289\"},{\"document_id\":\"DOC-IMPL-001\",\"title\":\"Implementation Methodology\",\"department\":\"Professional Services\",\"classification\":\"PUBLIC\",\"region\":\"GLOBAL\",\"status\":\"APPROVED\",\"version\":\"1.4\",\"valid_until\":\"2027-09-30\",\"source_url\":\"https://drive.example/implementation\",\"content\":\"Fictional Acme Cloud uses a four-phase implementation: discovery, design, configuration, and validation. A standard deployment typically takes six to eight weeks after access and stakeholder prerequisites are complete. Each project includes a named implementation lead, weekly status reporting, a risk register, administrator enablement, and acceptance testing. This fictional sample is for workflow testing only.\",\"checksum\":\"26308f7070021b1550c73e632cc618b0631b5f982a7c240e8a6866029a2e6e0a\"},{\"document_id\":\"DOC-PRICE-OLD\",\"title\":\"Legacy Pricing Notes\",\"department\":\"Finance\",\"classification\":\"CONFIDENTIAL\",\"region\":\"EMEA\",\"status\":\"EXPIRED\",\"version\":\"0.8\",\"valid_until\":\"2025-01-01\",\"source_url\":\"https://drive.example/legacy-pricing\",\"content\":\"Legacy fictional pricing content. This document is expired and must never be used in a customer response.\",\"checksum\":\"1707c121f2968f434257e864a9d6921112ccebfd0ad31db45eca311d24abc228\"}]; return docs.map(d=>({json:d}));"
      }
    },
    {
      "id": "9d61e9bc21a131c6",
      "name": "Validate and Fingerprint Document",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -650,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const d=$json; const required=[\"document_id\",\"title\",\"department\",\"classification\",\"region\",\"status\",\"version\",\"valid_until\",\"content\"];\nconst missing=required.filter(k=>!String(d[k]??\"\").trim()); if(missing.length) return {json:{...d,ingest_status:\"REJECTED\",rejection_reason:\"Missing: \"+missing.join(\", \")}};\nconst allowed=[\"PUBLIC\",\"INTERNAL\",\"CONFIDENTIAL\"]; const now=new Date();\nconst ok=String(d.status).toUpperCase()===\"APPROVED\"&&allowed.includes(String(d.classification).toUpperCase())&&new Date(d.valid_until)>=now;\nreturn {json:{...d,classification:String(d.classification).toUpperCase(),status:String(d.status).toUpperCase(),ingest_status:ok?\"READY\":\"REJECTED\",rejection_reason:ok?\"\":\"Document is not approved or is expired\",indexed_at:new Date().toISOString()}};"
      }
    },
    {
      "id": "c3ebca3fef4cd9ab",
      "name": "Approved for Indexing?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -390,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "Approved for Indexing?-condition",
              "leftValue": "={{ $json.ingest_status }}",
              "rightValue": "READY",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "b2ddf855514012fa",
      "name": "Loop Through Approved Documents",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -130,
        -100
      ],
      "parameters": {
        "batchSize": 1,
        "options": {}
      }
    },
    {
      "id": "bf5721c29b405dfe",
      "name": "Upsert Approved Evidence to Qdrant",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "typeVersion": 1.3,
      "position": [
        170,
        -20
      ],
      "parameters": {
        "mode": "insert",
        "qdrantCollection": {
          "mode": "id",
          "value": "rfp_sales_evidence"
        },
        "embeddingBatchSize": 50,
        "options": {}
      },
      "alwaysOutputData": true
    },
    {
      "id": "0817c411cc0828b6",
      "name": "NVIDIA Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsNvidia",
      "typeVersion": 1,
      "position": [
        160,
        250
      ],
      "parameters": {
        "model": {
          "mode": "id",
          "value": "nvidia/nv-embedqa-e5-v5"
        },
        "options": {
          "batchSize": 50,
          "stripNewLines": true,
          "timeout": 60000
        }
      }
    },
    {
      "id": "2320a7d8e61de82e",
      "name": "Controlled Document Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "typeVersion": 1.1,
      "position": [
        420,
        250
      ],
      "parameters": {
        "dataType": "json",
        "jsonMode": "expressionData",
        "jsonData": "={{ $json.content }}",
        "textSplittingMode": "simple",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "document_id",
                "value": "={{ $json.document_id }}"
              },
              {
                "name": "title",
                "value": "={{ $json.title }}"
              },
              {
                "name": "department",
                "value": "={{ $json.department }}"
              },
              {
                "name": "classification",
                "value": "={{ $json.classification }}"
              },
              {
                "name": "region",
                "value": "={{ $json.region }}"
              },
              {
                "name": "status",
                "value": "={{ $json.status }}"
              },
              {
                "name": "version",
                "value": "={{ $json.version }}"
              },
              {
                "name": "valid_until",
                "value": "={{ $json.valid_until }}"
              },
              {
                "name": "source_url",
                "value": "={{ $json.source_url }}"
              },
              {
                "name": "checksum",
                "value": "={{ $json.checksum }}"
              }
            ]
          }
        }
      }
    },
    {
      "id": "957e00cac87110a5",
      "name": "Build Ingestion Audit Row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        170,
        -190
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const rows=$(\"Validate and Fingerprint Document\").all().map(i=>i.json).filter(d=>d.ingest_status===\"READY\"); return rows.map(d=>({json:{event_id:`ING-${Date.now()}-${d.document_id}`,event_type:\"KNOWLEDGE_INGESTED\",project_id:\"\",requirement_id:\"\",document_id:d.document_id,actor:\"SYSTEM\",decision:d.ingest_status,reason:d.rejection_reason||\"Approved document embedded\",evidence_ids:d.document_id,created_at:new Date().toISOString()}}));"
      }
    },
    {
      "id": "6504de9845de10af",
      "name": "Append Knowledge Ingestion Audit",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        470,
        -190
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "mode": "id",
          "value": "SET_OPERATIONS_WORKBOOK_ID"
        },
        "sheetName": {
          "mode": "name",
          "value": "Audit Log"
        },
        "dataMode": "autoMapInputData",
        "options": {
          "handlingExtraData": "ignoreIt"
        }
      },
      "alwaysOutputData": false
    },
    {
      "id": "40e059884e3eee8b",
      "name": "Append Rejected Document",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -90,
        90
      ],
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "append",
        "documentId": {
          "mode": "id",
          "value": "SET_OPERATIONS_WORKBOOK_ID"
        },
        "sheetName": {
          "mode": "name",
          "value": "Exception Queue"
        },
        "dataMode": "autoMapInputData",
        "options": {
          "handlingExtraData": "ignoreIt"
        }
      },
      "alwaysOutputData": false
    },
    {
      "id": "fdb2f80cd870de4a",
      "name": "Enterprise source adapters",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1140,
        440
      ],
      "parameters": {
        "content": "## Optional source adapters (disconnected)\nAdd Google Drive, SharePoint, Confluence, or S3 triggers here. Map every source into the canonical fields used by **Validate and Fingerprint Document**. Keep source permissions upstream and never widen classification during mapping.",
        "width": 820,
        "height": 270,
        "color": 6
      }
    },
    {
      "id": "9b9d364a36280b23",
      "name": "Google Drive Trigger - Disconnected",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -960,
        790
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {}
      }
    },
    {
      "id": "59dbef162889eb33",
      "name": "Google Drive Download - Disconnected",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -680,
        790
      ],
      "parameters": {
        "resource": "file",
        "operation": "download",
        "fileId": "={{ $json.id }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Manual Demo Trigger": {
      "main": [
        [
          {
            "node": "Load Fictional Evidence Fixture",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Fictional Evidence Fixture": {
      "main": [
        [
          {
            "node": "Validate and Fingerprint Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate and Fingerprint Document": {
      "main": [
        [
          {
            "node": "Approved for Indexing?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approved for Indexing?": {
      "main": [
        [
          {
            "node": "Loop Through Approved Documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Append Rejected Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Through Approved Documents": {
      "main": [
        [
          {
            "node": "Build Ingestion Audit Row",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Upsert Approved Evidence to Qdrant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NVIDIA Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Upsert Approved Evidence to Qdrant",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Controlled Document Loader": {
      "ai_document": [
        [
          {
            "node": "Upsert Approved Evidence to Qdrant",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Upsert Approved Evidence to Qdrant": {
      "main": [
        [
          {
            "node": "Loop Through Approved Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Ingestion Audit Row": {
      "main": [
        [
          {
            "node": "Append Knowledge Ingestion Audit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "Africa/Lagos",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "executionTimeout": 600
  }
}
