{
 "name": "[노드 한 장] Question and Answer Chain · 샘플 규칙 검색 후 답하기",
 "nodes": [
  {
   "id": "manual",
   "name": "Run manually",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    0
   ],
   "parameters": {}
  },
  {
   "id": "seed",
   "name": "Self-written sample policy",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    240,
    0
   ],
   "parameters": {
    "jsCode": "return [{json:{sample:true,source:\"SELF_WRITTEN_SAMPLE_RULES\",policy:\"가상 별빛상점 실습용 규칙입니다. 이 문서는 직접 작성한 샘플이며 실제 회사나 고객 정책이 아닙니다.\\n환불 접수는 상품 수령일로부터 3영업일 안에 해야 합니다.\\n포장 파손 문의에는 사진 한 장과 샘플 주문 코드가 필요합니다.\"}}];"
   }
  },
  {
   "id": "insert",
   "name": "Insert only own sample vector",
   "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
   "typeVersion": 1.3,
   "position": [
    480,
    0
   ],
   "parameters": {
    "mode": "insert",
    "memoryKey": {
     "__rl": true,
     "mode": "id",
     "value": "TEST_QA_VECTOR_KEY"
    },
    "clearStore": true
   }
  },
  {
   "id": "loader",
   "name": "Default Data Loader",
   "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
   "typeVersion": 1.1,
   "position": [
    400,
    250
   ],
   "parameters": {
    "dataType": "json",
    "jsonMode": "expressionData",
    "jsonData": "={{ $json.policy }}",
    "textSplittingMode": "simple",
    "options": {
     "metadata": {
      "metadataValues": [
       {
        "name": "source",
        "value": "SELF_WRITTEN_SAMPLE_RULES"
       }
      ]
     }
    }
   }
  },
  {
   "id": "emb",
   "name": "Embeddings OpenAI",
   "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
   "typeVersion": 1.2,
   "position": [
    680,
    450
   ],
   "parameters": {
    "model": "text-embedding-3-small",
    "options": {}
   }
  },
  {
   "id": "lookup",
   "name": "Direct lookup evidence",
   "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
   "typeVersion": 1.3,
   "position": [
    760,
    0
   ],
   "parameters": {
    "mode": "load",
    "memoryKey": {
     "__rl": true,
     "mode": "id",
     "value": "TEST_QA_VECTOR_KEY"
    },
    "prompt": "환불 접수 기한",
    "topK": 5,
    "includeDocumentMetadata": true
   }
  },
  {
   "id": "questions",
   "name": "Prepare sample questions",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    1000,
    0
   ],
   "parameters": {
    "jsCode": "return [{json:{sample:true,case:\"document_answer\",question:\"물건을 받은 뒤 며칠 안에 환불 신청을 넣어야 하나요?\"}},{json:{sample:true,case:\"not_in_document\",question:\"회원 등급별 적립률은 몇 퍼센트인가요?\"}}];"
   }
  },
  {
   "id": "qa",
   "name": "Question and Answer Chain",
   "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
   "typeVersion": 1.7,
   "position": [
    1240,
    0
   ],
   "parameters": {
    "promptType": "define",
    "text": "={{ $json.question }}",
    "options": {
     "systemPromptTemplate": "당신은 가상 규칙 문서 실습의 질의응답 도우미입니다. 다음 검색된 문서 내용만 근거로 질문에 한국어로 답하세요. 문서에 답이 없으면 추측하거나 상식으로 보충하지 말고 \"제공된 샘플 문서에서는 확인할 수 없습니다.\"라고만 답하세요. 답에 근거가 있으면 짧게 설명하고 샘플 문서 기준이라고 명시하세요.\n검색된 문서:\n{context}",
     "batching": {
      "batchSize": 1
     }
    }
   }
  },
  {
   "id": "retriever",
   "name": "Vector Store Retriever",
   "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
   "typeVersion": 1,
   "position": [
    1240,
    250
   ],
   "parameters": {
    "topK": 1
   }
  },
  {
   "id": "retrieve",
   "name": "Retrieve own sample vector",
   "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
   "typeVersion": 1.3,
   "position": [
    1240,
    450
   ],
   "parameters": {
    "mode": "retrieve",
    "memoryKey": {
     "__rl": true,
     "mode": "id",
     "value": "TEST_QA_VECTOR_KEY"
    }
   }
  },
  {
   "id": "model",
   "name": "OpenAI Chat Model",
   "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
   "typeVersion": 1.3,
   "position": [
    1450,
    250
   ],
   "parameters": {
    "model": {
     "__rl": true,
     "mode": "id",
     "value": "gpt-4.1-mini"
    },
    "responsesApiEnabled": false,
    "options": {
     "temperature": 0,
     "maxTokens": 200
    }
   }
  },
  {
   "id": "show",
   "name": "Show sample AI answers",
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "position": [
    1540,
    0
   ],
   "parameters": {
    "jsCode": "return $input.all().map((i,n)=>({json:{sample:true,question:$('Prepare sample questions').all()[n].json.question,answer:i.json.response??i.json.text??i.json.output??JSON.stringify(i.json),note:'직접 쓴 가상 규칙 · 실제 AI 출력'}}));"
   }
  }
 ],
 "connections": {
  "Run manually": {
   "main": [
    [
     {
      "node": "Self-written sample policy",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Self-written sample policy": {
   "main": [
    [
     {
      "node": "Insert only own sample vector",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Insert only own sample vector": {
   "main": [
    [
     {
      "node": "Direct lookup evidence",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Direct lookup evidence": {
   "main": [
    [
     {
      "node": "Prepare sample questions",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Prepare sample questions": {
   "main": [
    [
     {
      "node": "Question and Answer Chain",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Question and Answer Chain": {
   "main": [
    [
     {
      "node": "Show sample AI answers",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "Default Data Loader": {
   "ai_document": [
    [
     {
      "node": "Insert only own sample vector",
      "type": "ai_document",
      "index": 0
     }
    ]
   ]
  },
  "Embeddings OpenAI": {
   "ai_embedding": [
    [
     {
      "node": "Insert only own sample vector",
      "type": "ai_embedding",
      "index": 0
     },
     {
      "node": "Direct lookup evidence",
      "type": "ai_embedding",
      "index": 0
     },
     {
      "node": "Retrieve own sample vector",
      "type": "ai_embedding",
      "index": 0
     }
    ]
   ]
  },
  "Retrieve own sample vector": {
   "ai_vectorStore": [
    [
     {
      "node": "Vector Store Retriever",
      "type": "ai_vectorStore",
      "index": 0
     }
    ]
   ]
  },
  "Vector Store Retriever": {
   "ai_retriever": [
    [
     {
      "node": "Question and Answer Chain",
      "type": "ai_retriever",
      "index": 0
     }
    ]
   ]
  },
  "OpenAI Chat Model": {
   "ai_languageModel": [
    [
     {
      "node": "Question and Answer Chain",
      "type": "ai_languageModel",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {
  "executionOrder": "v1"
 },
 "meta": {
  "templateCredsSetupCompleted": false,
  "source": "datapopcorn.ai/workflow/nodes"
 }
}