diff --git a/docs/servers/PLAUSIBLEDENABILITY.md b/docs/servers/PLAUSIBLEDENABILITY.md index dc1a315..d600e8a 100644 --- a/docs/servers/PLAUSIBLEDENABILITY.md +++ b/docs/servers/PLAUSIBLEDENABILITY.md @@ -31,9 +31,10 @@ Primary Docker host running all production workloads. RTX 2080 Ti used by: - Plex (hardware transcoding) - immich-ml (CUDA face recognition) -- Whisper (CUDA speech-to-text, port 8786) - Ollama light-tier inference (qwen2.5:14b and smaller) +> **Note:** Whisper moved to N.O.M.A.D. (10.5.1.16:8786) as CPU inference — avoids VRAM conflict with Ollama. See [NOMAD.md](NOMAD.md). + Recommended models for 11GB VRAM: | Model | VRAM | Best for | |-------|------|---------| diff --git a/n8n-workflows/08-class-recording-rag-v1.1.json b/n8n-workflows/08-class-recording-rag-v1.1.json new file mode 100644 index 0000000..3a1f8cc --- /dev/null +++ b/n8n-workflows/08-class-recording-rag-v1.1.json @@ -0,0 +1,538 @@ +{ + "updatedAt": "2026-05-07T01:16:50.340Z", + "createdAt": "2026-05-07T01:16:50.340Z", + "id": "91I278E72FAaQenD", + "name": "Class Recording → RAG v1.1", + "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;\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$/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}];" + }, + "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.1.16: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": 600000 + } + }, + "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.1.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 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 = 500;\nconst OVERLAP = 50;\n\nconst chunks = [];\nconst sentences = text.split(/(?<=[.!?])\\s+/);\nlet current = '';\n\nfor (const sentence of sentences) {\n if ((current + ' ' + sentence).length > CHUNK_SIZE && current.length > 0) {\n chunks.push(current.trim());\n const words = current.split(' ');\n current = words.slice(-OVERLAP).join(' ') + ' ' + sentence;\n } else {\n current = current ? current + ' ' + sentence : sentence;\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.1.6:11434/v1/embeddings", + "sendHeaders": true, + "headerParameters": { + "parameters": [ + { + "name": "Content-Type", + "value": "application/json" + } + ] + }, + "sendBody": true, + "specifyBody": "json", + "jsonBody": "={\n \"model\": \"nomic-embed-text\",\n \"input\": \"{{ $json.chunk }}\"\n}", + "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.1.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: `🎓 ${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 defs = Object.entries(notes.definitions || {}).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].join('\\n');\nconst title = `${rag.className} — ${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 ", + "type": "personal", + "icon": null, + "description": null, + "creatorId": "47b2227f-2fc2-4a08-bd35-ea157b92df0d" + } + } + ], + "versionMetadata": { + "name": "Version d64293a7", + "description": "" + } +} diff --git a/n8n-workflows/README.md b/n8n-workflows/README.md index 3ce921c..f62cddb 100644 --- a/n8n-workflows/README.md +++ b/n8n-workflows/README.md @@ -11,7 +11,7 @@ | 05 | Paperless → RAG | `POST /webhook/paperless/rag-ingest` | Auto-ingests Paperless documents into Qdrant for RAG search; notifies via Gotify | | 06 | RSS Digest | Scheduled (every 6h) + `POST /webhook/scrape/summarize` | Fetches RSS feeds, deduplicates via Postgres, AI-summarizes per-feed, pushes to Gotify | | 07 | Git Commit Summarizer | `POST /webhook/git/push` | Receives git push webhooks, AI-summarizes changes, notifies via Gotify | -| 08 | Class Recording → RAG | Watches `/mnt/data/class-recordings/` | Auto-transcribes new .wav files, extracts key notes, ingests into RAG by class, saves notes to Paperless, notifies via Gotify | +| 08 | Class Recording → RAG | `POST /webhook/class/upload` | Transcribes uploaded .wav, extracts key notes, ingests into RAG by class, saves notes to Paperless, notifies via Gotify | | 14 | Paperless Inbox Reminder | Scheduled (Monday 9 AM) | Queries Paperless for untagged documents; sends Gotify reminder with oldest items listed, or a ✅ clear if inbox is empty | | 15 | n8n Self-Health Monitor | Scheduled (every 15 min) | Checks n8n execution history for failures in the past hour; deduplicates via Postgres; pushes Gotify alert with workflow name and error summary | | 16 | NFS Mount Watchdog | Scheduled (every 5 min) | Probes NFS mount points on PD; if missing: runs mount script, re-probes, restarts affected containers (Plex, Audiobookshelf, Immich); notifies via Gotify on heal or escalation | @@ -188,7 +188,7 @@ curl -X POST https://n8n.paccoco.com/webhook/transcribe/summarize \ ### Add a class recording (just drop a file): ``` -/mnt/data/class-recordings/ +/mnt/tank/class-recordings/ ├── CS101-Java/ │ ├── lecture-01-intro.wav │ ├── lecture-02-variables.wav @@ -199,8 +199,9 @@ curl -X POST https://n8n.paccoco.com/webhook/transcribe/summarize \ └── essay-workshop.wav ``` -The workflow detects the class from the subfolder name and the lecture title from the filename. -Just drop a `.wav` file into the right class folder and it auto-processes. +Workflow 08 uses a webhook trigger (`POST /webhook/class/upload`), not a folder watcher. Upload the file via curl and include the class name and lecture title as form fields (see curl example below). + +> **Note:** The folder structure above shows suggested organization on disk. The workflow does not watch the folder — you must POST to the webhook. ### Query RAG for class-specific content: ```bash @@ -213,20 +214,31 @@ The RAG system stores class name metadata with each chunk, so when you mention a ### Class Recordings Setup (Workflow 08) -Requires n8n volume mount to the NFS share. Add to n8n's docker-compose: -```yaml -volumes: - - /mnt/tank/docker/appdata/n8n:/home/node/.n8n - - /mnt/data/class-recordings:/data/class-recordings -``` - -Create class subfolders: +Create class subfolders on PD (already done for CS101-Java): ```bash -mkdir -p /mnt/data/class-recordings/CS101-Java -mkdir -p /mnt/data/class-recordings/MATH201 +sudo mkdir -p /mnt/tank/class-recordings/CS101-Java +sudo mkdir -p /mnt/tank/class-recordings/MATH201 ``` -Then restart n8n and activate the workflow. Any `.wav` dropped into a subfolder triggers automatic transcription + RAG ingest. +Add to n8n's **automation/.env**: +``` +PAPERLESS_TAG_LECTURE_NOTES=11 +``` + +Add to n8n's **automation/docker-compose.yaml** under the n8n `environment:` section: +```yaml + PAPERLESS_TAG_LECTURE_NOTES: ${PAPERLESS_TAG_LECTURE_NOTES} +``` + +Then restart n8n and import/activate `08-class-recording-rag-v1.1.json`. + +To upload a class recording: +```bash +curl -X POST https://n8n.paccoco.com/webhook/class/upload \ + -F "data=@lecture-01-intro.wav" \ + -F "class_name=CS101-Java" \ + -F "lecture_title=lecture-01-intro" +``` ### Trigger RSS digest manually: ```bash