{
  "updatedAt": "2026-05-07T01:16:50.340Z",
  "createdAt": "2026-05-07T01:16:50.340Z",
  "id": "91I278E72FAaQenD",
  "name": "Class Recording \u2192 RAG v1.2",
  "description": null,
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "class/upload",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {
          "rawBody": true
        }
      },
      "id": "e475f17b-8560-4376-852e-a613ba6b300e",
      "name": "Class Upload Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "d0ee8226-db56-477e-8a3f-572a9129aea9"
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst body = data.body || data;\nconst incomingBinary = $input.first().binary || {};\n\n// Class name comes from:\n// 1. Form field 'class_name' in multipart upload\n// 2. Query parameter ?class=CS101\n// 3. Header X-Class-Name\nconst className = body.class_name || data.headers?.['x-class-name'] || data.query?.class || 'unclassified';\n\n// Lecture title from:\n// 1. Form field 'lecture_title'\n// 2. Query param ?title=...\n// 3. Header X-Lecture-Title\n// 4. Form field 'filename' (original filename)\nconst rawTitle = body.lecture_title || data.headers?.['x-lecture-title'] || data.query?.title || body.filename || 'Untitled Lecture';\nconst lectureTitle = rawTitle.replace(/\\.(wav|mp3|m4a|ogg)$/i, '').replace(/[-_]/g, ' ');\n\nconst classSlug = className.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');\n\nreturn [{\n  json: {\n    className,\n    classSlug,\n    lectureTitle,\n    uploadedAt: new Date().toISOString()\n  },\n  binary: incomingBinary\n}];"
      },
      "id": "24e4a726-ab50-4767-a144-1751616c781d",
      "name": "Extract Class Info",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.5.30.7:8786/v1/audio/transcriptions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            },
            {
              "name": "model",
              "value": "Systran/faster-distil-whisper-small.en"
            },
            {
              "name": "language",
              "value": "en"
            },
            {
              "name": "response_format",
              "value": "verbose_json"
            }
          ]
        },
        "options": {
          "timeout": 3600000
        }
      },
      "id": "fcd1062d-8f60-4214-85ee-f53b914abcbb",
      "name": "Whisper Transcribe",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        448,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const result = $input.first().json;\nconst classInfo = $('Extract Class Info').first().json;\n\nconst segments = result.segments || [];\nconst fullText = result.text || segments.map(s => s.text).join(' ');\nconst duration = result.duration || segments[segments.length - 1]?.end || 0;\n\nconst timestamped = segments.map(s => {\n  const mins = Math.floor(s.start / 60);\n  const secs = Math.floor(s.start % 60);\n  return `[${mins}:${String(secs).padStart(2, '0')}] ${s.text.trim()}`;\n}).join('\\n');\n\nreturn [{\n  json: {\n    className: classInfo.className,\n    classSlug: classInfo.classSlug,\n    lectureTitle: classInfo.lectureTitle,\n    fullText: fullText.trim(),\n    timestampedText: timestamped,\n    durationMinutes: Math.round(duration / 60),\n    segmentCount: segments.length\n  }\n}];"
      },
      "id": "ecf09ad2-327e-4a82-90f3-95da5590e0ac",
      "name": "Format Transcript",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.5.30.6:4000/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Authorization",
              "value": "={{ \"Bearer \" + $env.LITELLM_API_KEY }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"medium\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an academic note-taking assistant. Given a class lecture transcription, provide:\\n1. A concise summary (3-5 sentences)\\n2. Key concepts covered (as a list)\\n3. Important definitions or formulas\\n4. Any assignments or deadlines mentioned\\n\\nRespond in JSON with keys: summary, key_concepts (array), definitions (array of {term, definition}), assignments (array)\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Class: {{ $json.className }}\\nLecture: {{ $json.lectureTitle }}\\n\\nTranscription (first 3000 chars):\\n{{ $json.fullText.substring(0, 3000) }}\"\n    }\n  ],\n  \"max_tokens\": 600,\n  \"temperature\": 0.2,\n  \"response_format\": { \"type\": \"json_object\" }\n}",
        "options": {}
      },
      "id": "e7407d06-f7f4-4105-a817-055d4703d59d",
      "name": "AI Extract Notes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const llmResponse = $input.first().json;\nconst transcriptData = $('Format Transcript').first().json;\n\nlet notes;\ntry {\n  notes = JSON.parse(llmResponse.choices?.[0]?.message?.content || '{}');\n} catch(e) {\n  notes = { summary: 'Could not parse notes', key_concepts: [], definitions: [], assignments: [] };\n}\n\nconst ragText = [\n  `Class: ${transcriptData.className}`,\n  `Lecture: ${transcriptData.lectureTitle}`,\n  `Duration: ${transcriptData.durationMinutes} minutes`,\n  `Summary: ${notes.summary}`,\n  `Key Concepts: ${(notes.key_concepts || []).join(', ')}`,\n  '',\n  'Full Transcript:',\n  transcriptData.fullText\n].join('\\n');\n\nreturn [{\n  json: {\n    className: transcriptData.className,\n    classSlug: transcriptData.classSlug,\n    lectureTitle: transcriptData.lectureTitle,\n    durationMinutes: transcriptData.durationMinutes,\n    fullText: transcriptData.fullText,\n    notes,\n    ragText,\n    source: `class-${transcriptData.classSlug}-${Date.now()}`,\n    metadata: {\n      class_name: transcriptData.className,\n      class_slug: transcriptData.classSlug,\n      lecture_title: transcriptData.lectureTitle,\n      duration_minutes: transcriptData.durationMinutes,\n      type: 'class_recording',\n      recorded_at: new Date().toISOString()\n    }\n  }\n}];"
      },
      "id": "71b0807d-03ba-45b2-b75b-b6fbeee5687e",
      "name": "Prepare for RAG",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1104,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first().json;\nconst text = input.ragText || '';\nconst source = input.source;\nconst metadata = input.metadata;\n\nconst CHUNK_SIZE = 400;\nconst MAX_CHUNK  = 600;\nconst OVERLAP = 50;\n\nconst chunks = [];\nconst sentences = text.split(/(?<=[.!?])\\s+/);\nlet current = '';\n\nfor (const sentence of sentences) {\n  // If a single sentence exceeds MAX_CHUNK, split it by words first\n  const parts = [];\n  if (sentence.length > MAX_CHUNK) {\n    const words = sentence.split(' ');\n    let part = '';\n    for (const word of words) {\n      if ((part + ' ' + word).length > CHUNK_SIZE && part.length > 0) {\n        parts.push(part.trim());\n        part = word;\n      } else {\n        part = part ? part + ' ' + word : word;\n      }\n    }\n    if (part.trim()) parts.push(part.trim());\n  } else {\n    parts.push(sentence);\n  }\n\n  for (const part of parts) {\n    if ((current + ' ' + part).length > CHUNK_SIZE && current.length > 0) {\n      chunks.push(current.trim());\n      const words = current.split(' ');\n      current = words.slice(-OVERLAP).join(' ') + ' ' + part;\n    } else {\n      current = current ? current + ' ' + part : part;\n    }\n  }\n}\nif (current.trim()) chunks.push(current.trim());\n\nreturn chunks.map((chunk, i) => ({\n  json: {\n    chunk,\n    chunkIndex: i,\n    totalChunks: chunks.length,\n    source,\n    metadata\n  }\n}));"
      },
      "id": "9e4bbe70-72b0-4955-848f-0d1b62ae94a4",
      "name": "Chunk Text",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1328,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://10.5.30.7:11434/v1/embeddings",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ ({ model: 'nomic-embed-text:v1.5', input: $json.chunk }) }}",
        "options": {
          "batching": {
            "batch": {
              "batchSize": 5,
              "batchInterval": 500
            }
          }
        }
      },
      "id": "4ae1ab11-c76f-4478-84e0-7bcdfb20b83b",
      "name": "Get Embedding",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1552,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const embeddingResponse = $input.first().json;\nconst chunkData = $('Chunk Text').item;\nconst embedding = embeddingResponse.data?.[0]?.embedding || [];\n\nconst pointId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {\n  const r = Math.random() * 16 | 0;\n  return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);\n});\n\nreturn [{\n  json: {\n    id: pointId,\n    vector: embedding,\n    payload: {\n      text: chunkData.json.chunk,\n      source: chunkData.json.source,\n      chunkIndex: chunkData.json.chunkIndex,\n      totalChunks: chunkData.json.totalChunks,\n      metadata: chunkData.json.metadata,\n      ingested_at: new Date().toISOString()\n    }\n  }\n}];"
      },
      "id": "d4232b02-23fc-4cbd-ac2d-2fdbfbe9583a",
      "name": "Prepare Qdrant Point",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1760,
        0
      ]
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "http://10.5.30.6:6333/collections/knowledge_base/points",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"points\": [\n    {\n      \"id\": \"{{ $json.id }}\",\n      \"vector\": {{ JSON.stringify($json.vector) }},\n      \"payload\": {{ JSON.stringify($json.payload) }}\n    }\n  ]\n}",
        "options": {}
      },
      "id": "845a2aa0-2546-431d-96e8-b36875d1fe7d",
      "name": "Upsert to Qdrant",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1984,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const rag = $('Prepare for RAG').first().json;\nreturn [{\n  json: {\n    title:    `\ud83c\udf93 ${rag.className} Lecture Processed`,\n    message:  `${rag.lectureTitle} (${rag.durationMinutes}min)\\nSummary: ${rag.notes.summary}\\nKey concepts: ${(rag.notes.key_concepts || []).slice(0, 5).join(', ')}`,\n    priority: 5\n  }\n}];"
      },
      "id": "fmt08-0001-0000-0000-000000000008",
      "name": "Format Gotify Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1968,
        0
      ]
    },
    {
      "parameters": {
        "message": "={{ $json.message }}",
        "additionalFields": {
          "priority": "={{ $json.priority }}",
          "title": "={{ $json.title }}"
        },
        "options": {
          "contentType": "text/plain"
        }
      },
      "id": "5b31b660-c414-40d1-82a5-d68511203133",
      "name": "Notify via Gotify",
      "type": "n8n-nodes-base.gotify",
      "typeVersion": 1,
      "position": [
        2208,
        0
      ],
      "credentials": {
        "gotifyApi": {
          "id": "SETUP_REQUIRED",
          "name": "Class Recordings"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const rag = $('Prepare for RAG').first().json;\nconst notes = rag.notes || {};\nconst concepts = (notes.key_concepts || []).map((c,i) => `${i+1}. ${c}`).join('\\n');\nconst defList = notes.definitions || [];\nconst defs = Array.isArray(defList)\n  ? defList.map(d => `${d.term}: ${d.definition}`).join('\\n')\n  : Object.entries(defList).map(([k,v]) => `${k}: ${v}`).join('\\n');\nconst assignments = (notes.assignments || []).map((a,i) => `${i+1}. ${a}`).join('\\n');\nconst content = [\n  `Lecture Notes: ${rag.lectureTitle}`,\n  `Class: ${rag.className}`,\n  `Duration: ${rag.durationMinutes} minutes`,\n  `Date: ${new Date().toISOString()}`, '',\n  `Summary`, `=======`, notes.summary || '', '',\n  `Key Concepts`, `=============`, concepts,\n  ...(defs     ? ['', `Definitions`,    `===========`, defs]        : []),\n  ...(assignments ? ['', `Assignments`, `===========`, assignments] : []),\n  '', `Full Transcript`, `================`, rag.fullText || '',\n].join('\\n');\nconst title = `${rag.className} \u2014 ${rag.lectureTitle}`;\nreturn [{ binary: { document: { data: Buffer.from(content,'utf-8').toString('base64'), mimeType:'text/plain', fileName:`${title}.txt` }}, json: { title, className: rag.className } }];\n"
      },
      "id": "95aea3a7-3b15-4196-9e4a-dc8f6ed8d49e",
      "name": "Prepare Notes Doc",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2208,
        -200
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://paperless.paccoco.com/api/documents/post_document/",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Token {{ $env.PAPERLESS_API_TOKEN }}"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "document",
              "inputDataFieldName": "document"
            },
            {
              "name": "title",
              "value": "={{ $json.title }}"
            },
            {
              "name": "tags[]",
              "value": "={{ $env.PAPERLESS_TAG_LECTURE_NOTES }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "id": "c902a153-ab26-4518-af2a-585f0b72fe6c",
      "name": "Save Notes to Paperless",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2432,
        -200
      ],
      "continueOnFail": true
    }
  ],
  "connections": {
    "Class Upload Webhook": {
      "main": [
        [
          {
            "node": "Extract Class Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Class Info": {
      "main": [
        [
          {
            "node": "Whisper Transcribe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Whisper Transcribe": {
      "main": [
        [
          {
            "node": "Format Transcript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Transcript": {
      "main": [
        [
          {
            "node": "AI Extract Notes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Extract Notes": {
      "main": [
        [
          {
            "node": "Prepare for RAG",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare for RAG": {
      "main": [
        [
          {
            "node": "Chunk Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chunk Text": {
      "main": [
        [
          {
            "node": "Get Embedding",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Embedding": {
      "main": [
        [
          {
            "node": "Prepare Qdrant Point",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Qdrant Point": {
      "main": [
        [
          {
            "node": "Upsert to Qdrant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upsert to Qdrant": {
      "main": [
        [
          {
            "node": "Format Gotify Message",
            "type": "main",
            "index": 0
          },
          {
            "node": "Prepare Notes Doc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Gotify Message": {
      "main": [
        [
          {
            "node": "Notify via Gotify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Notes Doc": {
      "main": [
        [
          {
            "node": "Save Notes to Paperless",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "staticData": null,
  "meta": null,
  "pinData": {},
  "versionId": "d64293a7-5537-4b01-a11b-6b838d6cacbf",
  "activeVersionId": "d64293a7-5537-4b01-a11b-6b838d6cacbf",
  "versionCounter": 11,
  "triggerCount": 1,
  "tags": [
    {
      "updatedAt": "2026-05-07T00:49:56.081Z",
      "createdAt": "2026-05-07T00:49:56.081Z",
      "id": "Q9lCYtCOuy9XmeyL",
      "name": "school"
    },
    {
      "updatedAt": "2026-05-06T22:39:59.716Z",
      "createdAt": "2026-05-06T22:39:59.716Z",
      "id": "tuPxDoKFqpVrrQoX",
      "name": "whisper"
    },
    {
      "updatedAt": "2026-05-06T22:39:33.284Z",
      "createdAt": "2026-05-06T22:39:33.284Z",
      "id": "7uuEyQrIlcuruZBk",
      "name": "rag"
    },
    {
      "updatedAt": "2026-05-06T22:38:51.678Z",
      "createdAt": "2026-05-06T22:38:51.678Z",
      "id": "S9FxzVfHLsHmyzyt",
      "name": "ai"
    }
  ],
  "shared": [
    {
      "updatedAt": "2026-05-07T01:16:50.340Z",
      "createdAt": "2026-05-07T01:16:50.340Z",
      "role": "workflow:owner",
      "workflowId": "91I278E72FAaQenD",
      "projectId": "dxCRnBdX5uJizCGa",
      "project": {
        "updatedAt": "2026-05-06T01:10:37.638Z",
        "createdAt": "2026-05-06T01:08:07.820Z",
        "id": "dxCRnBdX5uJizCGa",
        "name": "Wilfred Fizzlepoof <admin@paccoco.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "47b2227f-2fc2-4a08-bd35-ea157b92df0d"
      }
    }
  ],
  "versionMetadata": {
    "name": "Version d64293a7",
    "description": ""
  }
}
