71일차 자료 추가(답 제외)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mcchaeandClaude Opus 5.5 committed 2026-10-23 06:50:50 +09:00
1 parent 505dcd313f
commit 176e195dc2
62 files changed
+6288

No files matched your search

@@ -0,0 +1,271 @@
{
"name": "71 Index policy docs (reference · Lab 01 example 2)",
"nodes": [
{
"name": "Index webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
300
],
"parameters": {
"httpMethod": "POST",
"path": "my-index",
"responseMode": "responseNode",
"options": {}
}
},
{
"name": "List docs",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
200,
300
],
"parameters": {
"url": "http://data-api:8800/docs",
"options": {}
}
},
{
"name": "One item per doc",
"type": "n8n-nodes-base.splitOut",
"typeVersion": 1,
"position": [
400,
300
],
"parameters": {
"fieldToSplitOut": "docs",
"options": {}
}
},
{
"name": "Get doc",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
600,
300
],
"parameters": {
"url": "=http://data-api:8800/docs/{{ $json.name }}",
"options": {}
}
},
{
"name": "Make chunks",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
800,
300
],
"parameters": {
"jsCode": "// Split each policy document into chunks. Body \"chunking\": \"section\" (one chunk per ## section, default) or a number of characters.\nconst body = $('Index webhook').first().json.body ?? {};\nconst CHUNKING = body.chunking ?? 'section';\nconst chunks = [];\nfor (const item of $input.all()) {\n const { name, title, text } = item.json;\n const content = text.split('\\n').slice(1).join('\\n').trim();\n let pieces;\n if (CHUNKING === 'section') {\n pieces = content.split(/\\n(?=## )/).map(part => part.trim()).filter(Boolean);\n } else {\n const size = Number(CHUNKING), step = size - Math.floor(size / 5);\n pieces = [];\n for (let i = 0; i < content.length; i += step) pieces.push(content.slice(i, i + size));\n }\n pieces.forEach((piece, i) => {\n const section = (piece.match(/^## (.+)$/m) ?? [])[1] ?? '';\n chunks.push({ json: { source: name, title, chunk: i + 1, text: `${title}\\n${piece}` } });\n });\n}\nreturn chunks;"
}
},
{
"name": "Store chunks",
"type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
"typeVersion": 1.3,
"position": [
1020,
300
],
"parameters": {
"mode": "insert",
"memoryKey": {
"__rl": true,
"mode": "list",
"value": "my_policy_docs",
"cachedResultName": "my_policy_docs"
},
"clearStore": true
}
},
{
"name": "Embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1.2,
"position": [
960,
520
],
"parameters": {
"model": "text-embedding-3-large",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "openAiCourse0001",
"name": "OpenAI (.env)"
}
}
},
{
"name": "Chunk loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"typeVersion": 1.1,
"position": [
1120,
520
],
"parameters": {
"jsonMode": "expressionData",
"jsonData": "={{ $json.text }}",
"textSplittingMode": "simple",
"options": {
"metadata": {
"metadataValues": [
{
"name": "source",
"value": "={{ $json.source }}"
},
{
"name": "title",
"value": "={{ $json.title }}"
},
{
"name": "chunk",
"value": "={{ $json.chunk }}"
}
]
}
}
}
},
{
"name": "Count",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1260,
300
],
"parameters": {
"jsCode": "// One summary item after all chunks are stored.\nreturn [{ json: { indexed_chunks: $('Make chunks').all().length, chunking: ($('Index webhook').first().json.body ?? {}).chunking ?? 'section' } }];"
}
},
{
"name": "Send result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1460,
300
],
"parameters": {
"respondWith": "json",
"responseBody": "={{ $json }}",
"options": {}
}
}
],
"connections": {
"Index webhook": {
"main": [
[
{
"node": "List docs",
"type": "main",
"index": 0
}
]
]
},
"List docs": {
"main": [
[
{
"node": "One item per doc",
"type": "main",
"index": 0
}
]
]
},
"One item per doc": {
"main": [
[
{
"node": "Get doc",
"type": "main",
"index": 0
}
]
]
},
"Get doc": {
"main": [
[
{
"node": "Make chunks",
"type": "main",
"index": 0
}
]
]
},
"Make chunks": {
"main": [
[
{
"node": "Store chunks",
"type": "main",
"index": 0
}
]
]
},
"Store chunks": {
"main": [
[
{
"node": "Count",
"type": "main",
"index": 0
}
]
]
},
"Count": {
"main": [
[
{
"node": "Send result",
"type": "main",
"index": 0
}
]
]
},
"Embeddings": {
"ai_embedding": [
[
{
"node": "Store chunks",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Chunk loader": {
"ai_document": [
[
{
"node": "Store chunks",
"type": "ai_document",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
}
}
@@ -0,0 +1,203 @@
{
"name": "71 Search policies (reference · Lab 01 example 2)",
"nodes": [
{
"name": "Search webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
300
],
"parameters": {
"httpMethod": "POST",
"path": "my-search",
"responseMode": "responseNode",
"options": {}
}
},
{
"name": "Has question?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
200,
300
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "c0",
"leftValue": "={{ $json.body.question }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
}
},
{
"name": "Reject empty",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
420,
560
],
"parameters": {
"respondWith": "json",
"responseBody": "{ \"error\": \"question is required\" }",
"options": {
"responseCode": 400
}
}
},
{
"name": "Search policies",
"type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
"typeVersion": 1.3,
"position": [
420,
300
],
"parameters": {
"mode": "load",
"memoryKey": {
"__rl": true,
"mode": "list",
"value": "my_policy_docs",
"cachedResultName": "my_policy_docs"
},
"prompt": "={{ $json.body.question }}",
"topK": "={{ $json.body.top_k ?? 3 }}",
"includeDocumentMetadata": true
},
"alwaysOutputData": true
},
{
"name": "Embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1.2,
"position": [
560,
520
],
"parameters": {
"model": "text-embedding-3-large",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "openAiCourse0001",
"name": "OpenAI (.env)"
}
}
},
{
"name": "Build hits",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
860,
300
],
"parameters": {
"jsCode": "// The search contract: { question, hits: [{ rank, source, title, score, text }], top_score, indexed }.\n// Always Output Data is on, so an empty store still gives one empty item: keep only items that have a document.\nconst question = $('Search webhook').first().json.body.question;\nconst hits = $input.all().filter(item => item.json.document).map((item, i) => ({\n rank: i + 1, source: item.json.document.metadata?.source, title: item.json.document.metadata?.title, \n score: Math.round((item.json.score ?? 0) * 1000) / 1000, text: item.json.document.pageContent ?? '' }));\nreturn [{ json: { question, hits, top_score: hits.length ? Math.max(...hits.map(hit => hit.score)) : 0, indexed: hits.length > 0 } }];"
}
},
{
"name": "Send result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1080,
300
],
"parameters": {
"respondWith": "json",
"responseBody": "={{ $json }}",
"options": {}
}
}
],
"connections": {
"Search webhook": {
"main": [
[
{
"node": "Has question?",
"type": "main",
"index": 0
}
]
]
},
"Has question?": {
"main": [
[
{
"node": "Search policies",
"type": "main",
"index": 0
}
],
[
{
"node": "Reject empty",
"type": "main",
"index": 0
}
]
]
},
"Embeddings": {
"ai_embedding": [
[
{
"node": "Search policies",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Search policies": {
"main": [
[
{
"node": "Build hits",
"type": "main",
"index": 0
}
]
]
},
"Build hits": {
"main": [
[
{
"node": "Send result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
}
}
@@ -0,0 +1,398 @@
{
"name": "71 Policy QA (reference · Lab 02 example 2)",
"nodes": [
{
"name": "Question webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
300
],
"parameters": {
"httpMethod": "POST",
"path": "my-policy-qa",
"responseMode": "responseNode",
"options": {}
}
},
{
"name": "Has question?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
200,
300
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "c0",
"leftValue": "={{ $json.body.question }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
}
},
{
"name": "Reject empty",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
420,
560
],
"parameters": {
"respondWith": "json",
"responseBody": "{ \"error\": \"question is required\" }",
"options": {
"responseCode": 400
}
}
},
{
"name": "Search policies",
"type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
"typeVersion": 1.3,
"position": [
420,
300
],
"parameters": {
"mode": "load",
"memoryKey": {
"__rl": true,
"mode": "list",
"value": "my_policy_docs",
"cachedResultName": "my_policy_docs"
},
"prompt": "={{ $json.body.question }}",
"topK": 3,
"includeDocumentMetadata": true
},
"alwaysOutputData": true
},
{
"name": "Embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"typeVersion": 1.2,
"position": [
380,
520
],
"parameters": {
"model": "text-embedding-3-large",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "openAiCourse0001",
"name": "OpenAI (.env)"
}
}
},
{
"name": "Build context",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
300
],
"parameters": {
"jsCode": "// Numbered excerpts for the LLM, and the retrieved sources.\nconst question = $('Question webhook').first().json.body.question;\nconst hits = $input.all().filter(item => item.json.document).map(item => ({\n source: item.json.document.metadata?.source, title: item.json.document.metadata?.title,\n score: Math.round((item.json.score ?? 0) * 1000) / 1000, text: item.json.document.pageContent ?? '' }));\nconst context = hits.map((hit, i) => `[${i + 1}] ${hit.text}`).join('\\n\\n');\nconst minScore = Number($('Question webhook').first().json.body.min_score ?? 0.33);\nconst topScore = hits.length ? Math.max(...hits.map(hit => hit.score)) : 0;\nreturn [{ json: { question, hits, context, top_score: topScore, min_score: minScore, relevant: topScore >= minScore } }];"
}
},
{
"name": "Relevant?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [
860,
300
],
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "c0",
"leftValue": "={{ $json.relevant }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
}
},
{
"name": "Answer from policies",
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [
1080,
200
],
"parameters": {
"promptType": "define",
"text": "=질문: {{ $json.question }}\n\n규정 발췌:\n{{ $json.context }}",
"options": {
"systemMessage": "Answer the employee's question only from the numbered policy excerpts, in Korean, in at most 3 sentences. After each fact, write the number of the excerpt it came from in square brackets, such as [2]. If the excerpts do not contain the answer, answer exactly: 규정에서 답을 찾지 못했습니다.",
"maxIterations": 2
}
}
},
{
"name": "OpenAI chat model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
1040,
420
],
"parameters": {
"model": {
"__rl": true,
"mode": "id",
"value": "gpt-4.1-mini"
},
"options": {
"temperature": 0
}
},
"credentials": {
"openAiApi": {
"id": "openAiCourse0001",
"name": "OpenAI (.env)"
}
}
},
{
"name": "Build answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1320,
200
],
"parameters": {
"jsCode": "// Turn excerpt numbers into document titles and keep which documents were cited.\nconst ctx = $('Build context').first().json;\nconst draft = String($json.output ?? '').trim();\nconst numbers = [...draft.matchAll(/\\[(\\d+)\\]/g)].map(m => Number(m[1])).filter(n => n >= 1 && n <= ctx.hits.length);\nconst cited = [...new Set(numbers.map(n => ctx.hits[n - 1].source))];\nconst answer = draft.replace(/\\[(\\d+)\\]/g, (all, n) => ctx.hits[n - 1] ? `[${ctx.hits[n - 1].title}]` : all);\n\nreturn [{ json: { route: '자동 답변', answer, sources: [...new Set(ctx.hits.map(hit => hit.source))], cited, top_score: ctx.top_score } }];"
}
},
{
"name": "Not in policies",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1080,
520
],
"parameters": {
"assignments": {
"assignments": [
{
"id": "a0",
"name": "route",
"value": "담당자 연결",
"type": "string"
},
{
"id": "a1",
"name": "answer",
"value": "규정에서 답을 찾지 못했습니다. IT 문의 창구로 연결해 드릴게요.",
"type": "string"
},
{
"id": "a2",
"name": "sources",
"value": "={{ [] }}",
"type": "array"
},
{
"id": "a3",
"name": "cited",
"value": "={{ [] }}",
"type": "array"
},
{
"id": "a4",
"name": "top_score",
"value": "={{ $json.top_score }}",
"type": "number"
}
]
},
"options": {}
}
},
{
"name": "Send result",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
1540,
300
],
"parameters": {
"respondWith": "json",
"responseBody": "={{ $json }}",
"options": {}
}
}
],
"connections": {
"Question webhook": {
"main": [
[
{
"node": "Has question?",
"type": "main",
"index": 0
}
]
]
},
"Has question?": {
"main": [
[
{
"node": "Search policies",
"type": "main",
"index": 0
}
],
[
{
"node": "Reject empty",
"type": "main",
"index": 0
}
]
]
},
"Embeddings": {
"ai_embedding": [
[
{
"node": "Search policies",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Search policies": {
"main": [
[
{
"node": "Build context",
"type": "main",
"index": 0
}
]
]
},
"Build context": {
"main": [
[
{
"node": "Relevant?",
"type": "main",
"index": 0
}
]
]
},
"Relevant?": {
"main": [
[
{
"node": "Answer from policies",
"type": "main",
"index": 0
}
],
[
{
"node": "Not in policies",
"type": "main",
"index": 0
}
]
]
},
"OpenAI chat model": {
"ai_languageModel": [
[
{
"node": "Answer from policies",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Answer from policies": {
"main": [
[
{
"node": "Build answer",
"type": "main",
"index": 0
}
]
]
},
"Build answer": {
"main": [
[
{
"node": "Send result",
"type": "main",
"index": 0
}
]
]
},
"Not in policies": {
"main": [
[
{
"node": "Send result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
}
}